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 " drop USER|SID [REASON] Shutdown user session",
16 " kill USER|SID [REASON] Kill user session",
20 int plugin_control(struct param_control
*data
)
30 if (strcmp(data
->argv
[0], "drop") && strcmp(data
->argv
[0], "kill"))
31 return PLUGIN_RET_OK
; // not for us
33 if (!data
->iam_master
)
34 return PLUGIN_RET_NOTMASTER
;
36 if (data
->argc
< 2 || data
->argc
> 3)
38 data
->response
= NSCTL_RES_ERR
;
39 data
->additional
= "requires username or session id and optional reason";
40 return PLUGIN_RET_STOP
;
43 if (!(session
= strtol(data
->argv
[1], &end
, 10)) || *end
)
44 session
= f
->get_session_by_username(data
->argv
[1]);
47 s
= f
->get_session_by_id(session
);
51 data
->response
= NSCTL_RES_ERR
;
52 data
->additional
= "session not found";
53 return PLUGIN_RET_STOP
;
57 reason
= data
->argv
[2];
59 reason
= "Requested by administrator.";
61 if (data
->argv
[0][0] == 'd')
62 f
->sessionshutdown(session
, reason
, CDN_ADMIN_DISC
, TERM_ADMIN_RESET
);
64 f
->sessionkill(session
, reason
);
66 data
->response
= NSCTL_RES_OK
;
69 return PLUGIN_RET_STOP
;
72 int plugin_init(struct pluginfuncs
*funcs
)
74 return ((f
= funcs
)) ? 1 : 0;