8 int plugin_api_version
= PLUGIN_API_VERSION
;
9 static struct pluginfuncs
*f
= 0;
11 char *plugin_control_help
[] = {
12 " snoop USER|SID IP PORT Intercept user traffic",
13 " unsnoop USER|SID Stop intercepting user",
17 int plugin_control(struct param_control
*data
)
27 if (strcmp(data
->argv
[0], "snoop") && strcmp(data
->argv
[0], "unsnoop"))
28 return PLUGIN_RET_OK
; // not for us
30 if (!data
->iam_master
)
31 return PLUGIN_RET_NOTMASTER
;
33 flag
= data
->argv
[0][0] != 'u';
39 data
->response
= NSCTL_RES_ERR
;
40 data
->additional
= "requires username or session id and host, port";
41 return PLUGIN_RET_STOP
;
48 data
->response
= NSCTL_RES_ERR
;
49 data
->additional
= "requires username or session id";
50 return PLUGIN_RET_STOP
;
54 if (!(session
= strtol(data
->argv
[1], &end
, 10)) || *end
)
55 session
= f
->get_session_by_username(data
->argv
[1]);
58 s
= f
->get_session_by_id(session
);
62 data
->response
= NSCTL_RES_ERR
;
63 data
->additional
= "session not found";
64 return PLUGIN_RET_STOP
;
69 in_addr_t ip
= inet_addr(data
->argv
[2]);
70 uint16_t port
= atoi(data
->argv
[3]);
72 if (!ip
|| ip
== INADDR_NONE
)
74 data
->response
= NSCTL_RES_ERR
;
75 data
->additional
= "invalid ip address";
76 return PLUGIN_RET_STOP
;
81 data
->response
= NSCTL_RES_ERR
;
82 data
->additional
= "invalid port";
83 return PLUGIN_RET_STOP
;
86 if (ip
== s
->snoop_ip
&& port
== s
->snoop_port
)
88 data
->response
= NSCTL_RES_ERR
;
89 data
->additional
= "already intercepted";
90 return PLUGIN_RET_STOP
;
100 data
->response
= NSCTL_RES_ERR
;
101 data
->additional
= "not intercepted";
102 return PLUGIN_RET_STOP
;
109 f
->session_changed(session
);
111 data
->response
= NSCTL_RES_OK
;
112 data
->additional
= 0;
114 return PLUGIN_RET_STOP
;
117 int plugin_init(struct pluginfuncs
*funcs
)
119 return ((f
= funcs
)) ? 1 : 0;