From: Dave West Date: Tue, 10 Nov 2009 21:07:22 +0000 (+0000) Subject: Grabbed a chunk of code out of citserver.c cmd_term() and used it to create X-Git-Tag: v7.86~630 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=deb65694d70e9c17749ffcb3d072bb8a24c351cb Grabbed a chunk of code out of citserver.c cmd_term() and used it to create a new function CtdlTerminateOtherSession() Placed this function in context.c since it manipulates the contexts. Exposed this function to the API Noticed we don't seem to have a client that uses the TERM command. --- diff --git a/citadel/citserver.c b/citadel/citserver.c index d0c7007ff..e61ed3fd0 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -708,35 +708,19 @@ int CtdlAccessCheck(int required_level) { 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 { diff --git a/citadel/context.c b/citadel/context.c index c67882914..70fdd2795 100644 --- a/citadel/context.c +++ b/citadel/context.c @@ -129,6 +129,40 @@ int CtdlIsSingleUser(void) + +/* + * 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 diff --git a/citadel/context.h b/citadel/context.h index 3754a20be..ecf08a0ad 100644 --- a/citadel/context.h +++ b/citadel/context.h @@ -150,5 +150,10 @@ void dead_session_purge(int force); 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 */