3d7e120202cf4bf1d3f69fae2e629f5c88399760
8 char const *cvs_id
= "$Id: snoopctl.c,v 1.1 2004-11-17 15:08:19 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 static int iam_master
= 0;
21 int plugin_init(struct pluginfuncs
*funcs
)
30 int plugin_become_master(void)
36 int plugin_control(struct param_control
*data
)
46 if (strcmp(data
->argv
[0], "snoop") && strcmp(data
->argv
[0], "unsnoop"))
47 return PLUGIN_RET_OK
; // not for us
49 flag
= data
->argv
[0][0] != 'u';
53 data
->response
= NSCTL_RES_ERR
;
54 data
->additional
= "must be run on the cluster master";
55 return PLUGIN_RET_STOP
;
62 data
->response
= NSCTL_RES_ERR
;
63 data
->additional
= "requires username or session id and host, port";
64 return PLUGIN_RET_STOP
;
71 data
->response
= NSCTL_RES_ERR
;
72 data
->additional
= "requires username or session id";
73 return PLUGIN_RET_STOP
;
77 if (!(session
= strtol(data
->argv
[1], &end
, 10)) || *end
)
78 session
= p
->get_session_by_username(data
->argv
[1]);
81 s
= p
->get_session_by_id(session
);
85 data
->response
= NSCTL_RES_ERR
;
86 data
->additional
= "session not found";
87 return PLUGIN_RET_STOP
;
92 ipt ip
= inet_addr(data
->argv
[2]);
93 u16 port
= atoi(data
->argv
[3]);
95 if (!ip
|| ip
== INADDR_NONE
)
97 data
->response
= NSCTL_RES_ERR
;
98 data
->additional
= "invalid ip address";
99 return PLUGIN_RET_STOP
;
104 data
->response
= NSCTL_RES_ERR
;
105 data
->additional
= "invalid port";
106 return PLUGIN_RET_STOP
;
109 if (ip
== s
->snoop_ip
&& port
== s
->snoop_port
)
111 data
->response
= NSCTL_RES_ERR
;
112 data
->additional
= "already intercepted";
113 return PLUGIN_RET_STOP
;
117 s
->snoop_port
= port
;
123 data
->response
= NSCTL_RES_ERR
;
124 data
->additional
= "not intercepted";
125 return PLUGIN_RET_STOP
;
132 p
->sesssion_changed(session
);
134 data
->response
= NSCTL_RES_OK
;
135 data
->additional
= 0;
137 return PLUGIN_RET_STOP
;