0bb46da39fd5526fc695b5fc078c49d6e6fad5d1
8 char const *cvs_id
= "$Id: snoopctl.c,v 1.6 2005/10/11 07:59:09 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_control(struct param_control
*data
)
29 if (strcmp(data
->argv
[0], "snoop") && strcmp(data
->argv
[0], "unsnoop"))
30 return PLUGIN_RET_OK
; // not for us
32 if (!data
->iam_master
)
33 return PLUGIN_RET_NOTMASTER
;
35 flag
= data
->argv
[0][0] != 'u';
41 data
->response
= NSCTL_RES_ERR
;
42 data
->additional
= "requires username or session id and host, port";
43 return PLUGIN_RET_STOP
;
50 data
->response
= NSCTL_RES_ERR
;
51 data
->additional
= "requires username or session id";
52 return PLUGIN_RET_STOP
;
56 if (!(session
= strtol(data
->argv
[1], &end
, 10)) || *end
)
57 session
= p
->get_session_by_username(data
->argv
[1]);
60 s
= p
->get_session_by_id(session
);
64 data
->response
= NSCTL_RES_ERR
;
65 data
->additional
= "session not found";
66 return PLUGIN_RET_STOP
;
71 in_addr_t ip
= inet_addr(data
->argv
[2]);
72 uint16_t port
= atoi(data
->argv
[3]);
74 if (!ip
|| ip
== INADDR_NONE
)
76 data
->response
= NSCTL_RES_ERR
;
77 data
->additional
= "invalid ip address";
78 return PLUGIN_RET_STOP
;
83 data
->response
= NSCTL_RES_ERR
;
84 data
->additional
= "invalid port";
85 return PLUGIN_RET_STOP
;
88 if (ip
== s
->snoop_ip
&& port
== s
->snoop_port
)
90 data
->response
= NSCTL_RES_ERR
;
91 data
->additional
= "already intercepted";
92 return PLUGIN_RET_STOP
;
102 data
->response
= NSCTL_RES_ERR
;
103 data
->additional
= "not intercepted";
104 return PLUGIN_RET_STOP
;
111 p
->session_changed(session
);
113 data
->response
= NSCTL_RES_OK
;
114 data
->additional
= 0;
116 return PLUGIN_RET_STOP
;
119 int plugin_init(struct pluginfuncs
*funcs
)
121 return ((p
= funcs
)) ? 1 : 0;