void cmd_term(char *cmdbuf)
{
int session_num;
- CitContext *ccptr;
- int found_it = 0;
- int allowed = 0;
+ int terminated = 0;
session_num = extract_int(cmdbuf, 0);
- if (session_num == CC->cs_pid) {
+
+ terminated = CtdlTerminateOtherSession(session_num);
+
+ if (terminated < 0) {
cprintf("%d You can't kill your own session.\n", ERROR + ILLEGAL_VALUE);
return;
}
- CtdlLogPrintf(CTDL_DEBUG, "Locating session to kill\n");
- begin_critical_section(S_SESSION_TABLE);
- for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
- if (session_num == ccptr->cs_pid) {
- found_it = 1;
- if ((ccptr->user.usernum == CC->user.usernum)
- || (CC->user.axlevel >= 6)) {
- allowed = 1;
- ccptr->kill_me = 1;
- }
- else {
- allowed = 0;
- }
- }
- }
- end_critical_section(S_SESSION_TABLE);
-
- if (found_it) {
- if (allowed) {
+ if (terminated & TERM_FOUND) {
+ if (terminated == TERM_KILLED) {
cprintf("%d Session terminated.\n", CIT_OK);
}
else {
+
+/*
+ * Locate a context by its session number and terminate it if the user is able.
+ * User can NOT terminate their current session.
+ * User CAN terminate any other session that has them logged in.
+ * Aide CAN terminate any session except the current one.
+ */
+int CtdlTerminateOtherSession (int session_num)
+{
+ int ret = 0;
+ CitContext *ccptr;
+
+ if (session_num == CC->cs_pid) {
+ return TERM_NOTALLOWED;
+ }
+
+ CtdlLogPrintf(CTDL_DEBUG, "Locating session to kill\n");
+ begin_critical_section(S_SESSION_TABLE);
+ for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
+ if (session_num == ccptr->cs_pid) {
+ ret |= TERM_FOUND;
+ if ((ccptr->user.usernum == CC->user.usernum)
+ || (CC->user.axlevel >= 6)) {
+ ret |= TERM_ALLOWED;
+ ccptr->kill_me = 1;
+ }
+ }
+ }
+ end_critical_section(S_SESSION_TABLE);
+ return ret;
+}
+
+
+
/*
* Check to see if the user who we just sent mail to is logged in. If yes,
* bump the 'new mail' counter for their session. That enables them to
void BumpNewMailCounter(long) __attribute__ ((deprecated));
void terminate_idle_sessions(void);
-
+int CtdlTerminateOtherSession (int session_num);
+/* bits returned by CtdlTerminateOtherSession */
+#define TERM_FOUND 0x01
+#define TERM_ALLOWED 0x02
+#define TERM_KILLED 0x03
+#define TERM_NOTALLOWED -1
#endif /* CONTEXT_H */