2 #include <sys/socket.h>
3 #include <linux/rtnetlink.h>
11 int plugin_api_version
= PLUGIN_API_VERSION
;
12 static struct pluginfuncs
*f
= 0;
14 char *plugin_control_help
[] = {
15 " snoop USER|SID IP PORT Intercept user traffic",
16 " unsnoop USER|SID Stop intercepting user",
20 int plugin_control(struct param_control
*data
)
30 if (strcmp(data
->argv
[0], "snoop") && strcmp(data
->argv
[0], "unsnoop"))
31 return PLUGIN_RET_OK
; // not for us
33 if (!data
->iam_master
)
34 return PLUGIN_RET_NOTMASTER
;
36 flag
= data
->argv
[0][0] != 'u';
42 data
->response
= NSCTL_RES_ERR
;
43 data
->additional
= "requires username or session id and host, port";
44 return PLUGIN_RET_STOP
;
51 data
->response
= NSCTL_RES_ERR
;
52 data
->additional
= "requires username or session id";
53 return PLUGIN_RET_STOP
;
57 if (!(session
= strtol(data
->argv
[1], &end
, 10)) || *end
)
58 session
= f
->get_session_by_username(data
->argv
[1]);
61 s
= f
->get_session_by_id(session
);
65 data
->response
= NSCTL_RES_ERR
;
66 data
->additional
= "session not found";
67 return PLUGIN_RET_STOP
;
72 in_addr_t ip
= inet_addr(data
->argv
[2]);
73 uint16_t port
= atoi(data
->argv
[3]);
75 if (!ip
|| ip
== INADDR_NONE
)
77 data
->response
= NSCTL_RES_ERR
;
78 data
->additional
= "invalid ip address";
79 return PLUGIN_RET_STOP
;
84 data
->response
= NSCTL_RES_ERR
;
85 data
->additional
= "invalid port";
86 return PLUGIN_RET_STOP
;
89 if (ip
== s
->snoop_ip
&& port
== s
->snoop_port
)
91 data
->response
= NSCTL_RES_ERR
;
92 data
->additional
= "already intercepted";
93 return PLUGIN_RET_STOP
;
103 data
->response
= NSCTL_RES_ERR
;
104 data
->additional
= "not intercepted";
105 return PLUGIN_RET_STOP
;
112 f
->session_changed(session
);
114 data
->response
= NSCTL_RES_OK
;
115 data
->additional
= 0;
117 return PLUGIN_RET_STOP
;
120 int plugin_init(struct pluginfuncs
*funcs
)
122 return ((f
= funcs
)) ? 1 : 0;