bc5fa280d0b107d0894c5c906e42982e8fbdbe01
8 char const *cvs_id
= "$Id: snoopctl.c,v 1.4 2004-12-16 08:49:53 bodea Exp $";
10 int plugin_api_version
= PLUGIN_API_VERSION
;
11 static struct pluginfuncs
*p
= 0;
13 char *plugin_control_help
[] = {
14 " snoop USER|SID IP PORT Intercept user traffic",
15 " unsnoop USER|SID Stop intercepting user",
19 int plugin_init(struct pluginfuncs
*funcs
)
28 int plugin_control(struct param_control
*data
)
38 if (strcmp(data
->argv
[0], "snoop") && strcmp(data
->argv
[0], "unsnoop"))
39 return PLUGIN_RET_OK
; // not for us
41 if (!data
->iam_master
)
42 return PLUGIN_RET_NOTMASTER
;
44 flag
= data
->argv
[0][0] != 'u';
50 data
->response
= NSCTL_RES_ERR
;
51 data
->additional
= "requires username or session id and host, port";
52 return PLUGIN_RET_STOP
;
59 data
->response
= NSCTL_RES_ERR
;
60 data
->additional
= "requires username or session id";
61 return PLUGIN_RET_STOP
;
65 if (!(session
= strtol(data
->argv
[1], &end
, 10)) || *end
)
66 session
= p
->get_session_by_username(data
->argv
[1]);
69 s
= p
->get_session_by_id(session
);
73 data
->response
= NSCTL_RES_ERR
;
74 data
->additional
= "session not found";
75 return PLUGIN_RET_STOP
;
80 in_addr_t ip
= inet_addr(data
->argv
[2]);
81 uint16_t port
= atoi(data
->argv
[3]);
83 if (!ip
|| ip
== INADDR_NONE
)
85 data
->response
= NSCTL_RES_ERR
;
86 data
->additional
= "invalid ip address";
87 return PLUGIN_RET_STOP
;
92 data
->response
= NSCTL_RES_ERR
;
93 data
->additional
= "invalid port";
94 return PLUGIN_RET_STOP
;
97 if (ip
== s
->snoop_ip
&& port
== s
->snoop_port
)
99 data
->response
= NSCTL_RES_ERR
;
100 data
->additional
= "already intercepted";
101 return PLUGIN_RET_STOP
;
105 s
->snoop_port
= port
;
111 data
->response
= NSCTL_RES_ERR
;
112 data
->additional
= "not intercepted";
113 return PLUGIN_RET_STOP
;
120 p
->session_changed(session
);
122 data
->response
= NSCTL_RES_OK
;
123 data
->additional
= 0;
125 return PLUGIN_RET_STOP
;