CC->kill_me now contains an enum indicating the REASON session was killed
authorArt Cancro <ajc@uncensored.citadel.org>
Sun, 13 Mar 2011 17:32:47 +0000 (13:32 -0400)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 4 Sep 2011 15:06:51 +0000 (15:06 +0000)
13 files changed:
citadel/citserver.c
citadel/context.c
citadel/modules/imap/serv_imap.c
citadel/modules/managesieve/serv_managesieve.c
citadel/modules/migrate/serv_migrate.c
citadel/modules/pop3/serv_pop3.c
citadel/modules/smtp/serv_smtp.c
citadel/modules/vcard/serv_vcard.c
citadel/modules/xmpp/serv_xmpp.c
citadel/modules/xmpp/xmpp_presence.c
citadel/server.h
citadel/sysdep.c
citadel/threads.c

index 86bd0687c9fe4caea3a9ca93aebccca24d3179d2..42fb045a49665adde0c52e2381cc996de92f3def 100644 (file)
@@ -791,7 +791,7 @@ void cmd_ipgm(char *argbuf)
                sleep(5);
                cprintf("%d Authentication failed.\n", ERROR + PASSWORD_REQUIRED);
                syslog(LOG_ERR, "Warning: ipgm authentication failed.\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_AUTHFAILED;
        }
 }
 
@@ -825,7 +825,7 @@ void cmd_down(char *argbuf) {
        {
                cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN); 
        }
-       CC->kill_me = 1; /* Even the DOWN command has to follow correct proceedure when disconecting */
+       CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
        CtdlThreadStopAll();
 }
 
@@ -994,7 +994,7 @@ void citproto_begin_session() {
                        ERROR + MAX_SESSIONS_EXCEEDED,
                        config.c_nodename, config.c_maxsessions
                );
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_MAX_SESSIONS_EXCEEDED;
        }
        else {
                cprintf("%d %s Citadel server ready.\n", CIT_OK, config.c_nodename);
@@ -1018,7 +1018,7 @@ void cmd_qnop(char *argbuf)
 void cmd_quit(char *argbuf)
 {
        cprintf("%d Goodbye.\n", CIT_OK);
-       CC->kill_me = 1;
+       CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
 }
 
 
@@ -1043,7 +1043,7 @@ void do_command_loop(void) {
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
        if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
                syslog(LOG_ERR, "Client disconnected: ending session.\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_CLIENT_DISCONNECTED;
                CtdlThreadName(old_name);
                return;
        }
index 9801c23621335a5e20a92bc1ae5143e05341bc9f..cfe30334ecdd3526d95bf1fb17659ec0b7798621 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Copyright (c) 1987-2010 by the citadel.org team
  *
- * This program is free software; you can redistribute it and/or modify
+ * This program is open source software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
@@ -16,7 +16,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
 #include "sysdep.h"
@@ -167,7 +167,7 @@ int CtdlTerminateOtherSession (int session_num)
                        if ((ccptr->user.usernum == CC->user.usernum)
                           || (CC->user.axlevel >= AxAideU)) {
                                ret |= TERM_ALLOWED;
-                               ccptr->kill_me = 1;
+                               ccptr->kill_me = KILLME_ADMIN_TERMINATE;
                        }
                }
        }
@@ -292,7 +292,7 @@ void terminate_idle_sessions(void)
                && (config.c_sleeping > 0)
                && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
                        if (!ccptr->dont_term) {
-                               ccptr->kill_me = 1;
+                               ccptr->kill_me = KILLME_IDLE;
                                ++killed;
                        }
                        else 
@@ -592,23 +592,6 @@ void context_cleanup(void)
 
 
 
-/*
- * Terminate another session.
- * (This could justifiably be moved out of sysdep.c because it
- * no longer does anything that is system-dependent.)
- */
-void kill_session(int session_to_kill) {
-       CitContext *ptr;
-
-       begin_critical_section(S_SESSION_TABLE);
-       for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
-               if (ptr->cs_pid == session_to_kill) {
-                       ptr->kill_me = 1;
-               }
-       }
-       end_critical_section(S_SESSION_TABLE);
-}
-
 /*
  * Purge all sessions which have the 'kill_me' flag set.
  * This function has code to prevent it from running more than once every
@@ -660,7 +643,7 @@ void dead_session_purge(int force) {
         * is allocated privately on this thread's stack.
         */
        while (rem != NULL) {
-               syslog(LOG_DEBUG, "dead_session_purge(): purging session %d\n", rem->cs_pid);
+               syslog(LOG_DEBUG, "dead_session_purge(): purging session %d, reason=%d\n", rem->cs_pid, rem->kill_me);
                RemoveContext(rem);
                ptr = rem;
                rem = rem->next;
index 21f71a2b0c5395f69947b68836908d5734ceea00..29ab6536b579436f1115c485ac5545241a166aa4 100644 (file)
@@ -589,7 +589,7 @@ void imap_greeting(void)
        if (CCC->nologin)
        {
                IAPuts("* BYE; Server busy, try later\r\n");
-               CCC->kill_me = 1;
+               CCC->kill_me = KILLME_NOLOGIN;
                IUnbuffer();
                return;
        }
@@ -607,7 +607,7 @@ void imap_greeting(void)
 void imaps_greeting(void) {
        CtdlModuleStartCryptoMsgs(NULL, NULL, NULL);
 #ifdef HAVE_OPENSSL
-       if (!CC->redirect_ssl) CC->kill_me = 1;         /* kill session if no crypto */
+       if (!CC->redirect_ssl) CC->kill_me = KILLME_NO_CRYPTO;          /* kill session if no crypto */
 #endif
        imap_greeting();
 }
@@ -1493,7 +1493,7 @@ void imap_command_loop(void)
 
        if (CtdlClientGetLine(Imap->Cmd.CmdBuf) < 1) {
                syslog(LOG_ERR, "Client disconnected: ending session.\r\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_CLIENT_DISCONNECTED;
                return;
        }
 
@@ -1645,7 +1645,7 @@ void imap_logout(int num_parms, ConstStr *Params)
        }
        IAPrintf("* BYE %s logging out\r\n", config.c_fqdn);
        IReply("OK Citadel IMAP session ended.");
-       CC->kill_me = 1;
+       CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
        return;
 }
 
index 0bdc0f1001fe03873b7dbbd0e6b7593d3c742720..db1d92ce50b9be8d1413f9103601e3c3212bf5a9 100644 (file)
@@ -251,13 +251,13 @@ char *ReadString(long size, char *command)
        if (size < 1) {
                cprintf("NO %s: %ld BAD Message length must be at least 1.\r\n",
                        command, size);
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_READSTRING_FAILED;
                return NULL;
        }
        MGSVE->transmitted_message = malloc(size + 2);
        if (MGSVE->transmitted_message == NULL) {
                cprintf("NO %s Cannot allocate memory.\r\n", command);
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_MALLOC_FAILED;
                return NULL;
        }
        MGSVE->transmitted_length = size;
@@ -314,7 +314,7 @@ void cmd_mgsve_auth(int num_parms, char **parms, struct sdm_userdata *u)
                }
        }
        cprintf("NO \"Authentication Failure.\"\r\n");/* we just support auth plain. */
-       CC->kill_me = 1;
+       CC->kill_me = KILLME_AUTHFAILED;
 }
 
 
@@ -330,18 +330,18 @@ void cmd_mgsve_starttls(void)
 
 
 
-/**
- *LOGOUT command, see chapter 2.3 
+/*
+ * LOGOUT command, see chapter 2.3 
  */
 void cmd_mgsve_logout(struct sdm_userdata *u)
 {
        cprintf("OK\r\n");
        syslog(LOG_NOTICE, "MgSve bye.");
-       CC->kill_me = 1;
+       CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
 }
 
 
-/**
+/*
  * HAVESPACE command. see chapter 2.5 
  */
 void cmd_mgsve_havespace(void)
@@ -352,7 +352,7 @@ void cmd_mgsve_havespace(void)
        if (MGSVE->command_state != mgsve_password)
        {
                cprintf("NO\r\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_QUOTA;
        }
        else
        {
@@ -362,7 +362,7 @@ void cmd_mgsve_havespace(void)
        }
 }
 
-/**
+/*
  * PUTSCRIPT command, see chapter 2.6 
  */
 void cmd_mgsve_putscript(int num_parms, char **parms, struct sdm_userdata *u)
@@ -396,7 +396,7 @@ void cmd_mgsve_putscript(int num_parms, char **parms, struct sdm_userdata *u)
        }
        else {
                cprintf("%s NO Read failed.\r\n", parms[0]);
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_READ_FAILED;
                return;
        } 
 
@@ -586,7 +586,7 @@ void managesieve_command_loop(void) {
        }
        if (length < 1) {
                syslog(LOG_CRIT, "Client disconnected: ending session.\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_CLIENT_DISCONNECTED;
                return;
        }
        syslog(LOG_INFO, "MANAGESIEVE: %s\n", cmdbuf);
@@ -635,7 +635,7 @@ void managesieve_command_loop(void) {
        else {
                cprintf("No Invalid access or command.\r\n");
                syslog(LOG_INFO, "illegal Managesieve command: %s", parms[0]);
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_ILLEGAL_MANAGESIEVE_COMMAND;
        }
 
 
index 0a69a1a82f5730bab87199f16c2e46efab8b00a4..10404772b3f2647a0fb676e77a84730d58033984 100644 (file)
@@ -373,7 +373,7 @@ void migr_export_messages(void) {
        migr_global_message_list = fopen(migr_tempfilename1, "r");
        if (migr_global_message_list != NULL) {
                syslog(LOG_INFO, "Opened %s\n", migr_tempfilename1);
-               while ((Ctx->kill_me != 1) && 
+               while ((Ctx->kill_me == 0) && 
                       (fgets(buf, sizeof(buf), migr_global_message_list) != NULL)) {
                        msgnum = atol(buf);
                        if (msgnum > 0L) {
@@ -383,7 +383,7 @@ void migr_export_messages(void) {
                }
                fclose(migr_global_message_list);
        }
-       if (Ctx->kill_me != 1)
+       if (Ctx->kill_me == 0)
                syslog(LOG_INFO, "Exported %d messages.\n", count);
        else
                syslog(LOG_ERR, "Export aborted due to client disconnect! \n");
@@ -494,12 +494,12 @@ void migr_do_export(void) {
        cprintf("<control_version>%d</control_version>\n", CitControl.version);
        client_write("</control>\n", 11);
 
-       if (Ctx->kill_me != 1)  migr_export_users();
-       if (Ctx->kill_me != 1)  migr_export_openids();
-       if (Ctx->kill_me != 1)  migr_export_rooms();
-       if (Ctx->kill_me != 1)  migr_export_floors();
-       if (Ctx->kill_me != 1)  migr_export_visits();
-       if (Ctx->kill_me != 1)  migr_export_messages();
+       if (Ctx->kill_me == 0)  migr_export_users();
+       if (Ctx->kill_me == 0)  migr_export_openids();
+       if (Ctx->kill_me == 0)  migr_export_rooms();
+       if (Ctx->kill_me == 0)  migr_export_floors();
+       if (Ctx->kill_me == 0)  migr_export_visits();
+       if (Ctx->kill_me == 0)  migr_export_messages();
        client_write("</citadel_migrate_data>\n", 24);
        client_write("000\n", 4);
        Ctx->dont_term = 0;
index ec98569c24c1d295718e5cd4a358fe01c9f35ecf..b8f3cb0735ea2f99455420c9b246db52b047b8c6 100644 (file)
@@ -110,9 +110,9 @@ void pop3s_greeting(void) {
 
 /* kill session if no crypto */
 #ifdef HAVE_OPENSSL
-       if (!CC->redirect_ssl) CC->kill_me = 1;
+       if (!CC->redirect_ssl) CC->kill_me = KILLME_NO_CRYPTO;
 #else
-       CC->kill_me = 1;
+       CC->kill_me = KILLME_NO_CRYPTO;
 #endif
 
        pop3_greeting();
@@ -570,7 +570,7 @@ void pop3_command_loop(void) {
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
        if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
                syslog(LOG_ERR, "Client disconnected: ending session.");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_CLIENT_DISCONNECTED;
                return;
        }
        if (!strncasecmp(cmdbuf, "PASS", 4)) {
@@ -592,7 +592,7 @@ void pop3_command_loop(void) {
        else if (!strncasecmp(cmdbuf, "QUIT", 4)) {
                cprintf("+OK Goodbye...\r\n");
                pop3_update();
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
                return;
        }
 
@@ -616,7 +616,7 @@ void pop3_command_loop(void) {
        
        else if (CC->nologin) {
                cprintf("-ERR System busy, try later.\r\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_NOLOGIN;
        }
 
        else if (!strncasecmp(cmdbuf, "LIST", 4)) {
index d2fbe63840b603778225dcc9640bc590bf52c3d0..6c7480adfa0d0fddcd0fc02601deb58e804b34d6 100644 (file)
@@ -135,7 +135,7 @@ void smtp_greeting(int is_msa)
                                cprintf("421 %s\r\n", message_to_spammer);
                        else
                                cprintf("550 %s\r\n", message_to_spammer);
-                       CC->kill_me = 1;
+                       CC->kill_me = KILLME_SPAMMER;
                        /* no need to free_recipients(valid), it's not allocated yet */
                        return;
                }
@@ -147,7 +147,7 @@ void smtp_greeting(int is_msa)
                cprintf("500 Too many users are already online (maximum is %d)\r\n",
                        config.c_maxsessions
                );
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_MAX_SESSIONS_EXCEEDED;
                /* no need to free_recipients(valid), it's not allocated yet */
                return;
        }
@@ -165,7 +165,7 @@ void smtp_greeting(int is_msa)
 void smtps_greeting(void) {
        CtdlModuleStartCryptoMsgs(NULL, NULL, NULL);
 #ifdef HAVE_OPENSSL
-       if (!CC->redirect_ssl) CC->kill_me = 1;         /* kill session if no crypto */
+       if (!CC->redirect_ssl) CC->kill_me = KILLME_NO_CRYPTO;          /* kill session if no crypto */
 #endif
        smtp_greeting(0);
 }
@@ -841,7 +841,7 @@ void smtp_command_loop(void) {
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
        if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
                syslog(LOG_CRIT, "Client disconnected: ending session.\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_CLIENT_DISCONNECTED;
                return;
        }
        syslog(LOG_INFO, "SMTP server: %s\n", cmdbuf);
@@ -893,7 +893,7 @@ void smtp_command_loop(void) {
 
        else if (!strncasecmp(cmdbuf, "QUIT", 4)) {
                cprintf("221 Goodbye...\r\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
                return;
        }
 
index 0aba02889749b845e7f3ac68d36368774ee194e9..39c4017868c74a26351ab5c23297e9c385114324 100644 (file)
@@ -1117,7 +1117,7 @@ void check_get(void) {
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
        if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
                syslog(LOG_CRIT, "Client disconnected: ending session.\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_CLIENT_DISCONNECTED;
                return;
        }
        syslog(LOG_INFO, ": %s\n", cmdbuf);
index aa3017e49184e2bcd8f993279aa0e489e048c24d..d158b819d9b7114c623b803f3f41deca6a752de0 100644 (file)
@@ -439,10 +439,10 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
 #ifdef HAVE_OPENSSL
                cprintf("<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>");
                CtdlModuleStartCryptoMsgs(NULL, NULL, NULL);
-               if (!CC->redirect_ssl) CC->kill_me = 1;
+               if (!CC->redirect_ssl) CC->kill_me = KILLME_NO_CRYPTO;
 #else
                cprintf("<failure xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_NO_CRYPTO;
 #endif
        }
 
@@ -454,7 +454,7 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
                syslog(LOG_DEBUG, "XMPP client shut down their stream\n");
                xmpp_massacre_roster();
                cprintf("</stream>\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
        }
 
        else {
@@ -524,7 +524,7 @@ void xmpp_greeting(void) {
        XMPP->xp = XML_ParserCreateNS("UTF-8", ':');
        if (XMPP->xp == NULL) {
                syslog(LOG_ALERT, "Cannot create XML parser!\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_XML_PARSER;
                return;
        }
 
@@ -550,7 +550,7 @@ void xmpp_command_loop(void) {
        }
        else {
                syslog(LOG_ERR, "Client disconnected: ending session.\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_CLIENT_DISCONNECTED;
        }
        FreeStrBuf(&stream_input);
 }
index 2ef90858c0e25fd0c9c5a169959bfdef0624515e..4175771c48bd5bae1b1eaa3ad52c93228e1475d2 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2007-2010 by Art Cancro
  *
- * This program is free software; you can redistribute it and/or modify
+ * This program is open source software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
index 70770a15a931cbde9814401bcadf3b4cf969a330..d3b89f21541895a498ec93753d83541cb99f4b79 100644 (file)
@@ -46,6 +46,33 @@ struct CtdlMessage {
 #define CTDLEXIT_LIBCITADEL    106     /* Incorrect version of libcitadel */
 #define CTDL_EXIT_UNSUP_AUTH   107     /* Unsupported auth mode configured */
 
+/*
+ * Reasons why a session would be terminated (set CC->kill_me to these values)
+ */
+enum {
+       KILLME_NOT,
+       KILLME_UNKNOWN,
+       KILLME_CLIENT_LOGGED_OUT,
+       KILLME_IDLE,
+       KILLME_CLIENT_DISCONNECTED,
+       KILLME_AUTHFAILED,
+       KILLME_SERVER_SHUTTING_DOWN,
+       KILLME_MAX_SESSIONS_EXCEEDED,
+       KILLME_ADMIN_TERMINATE,
+       KILLME_SELECT_INTERRUPTED,
+       KILLME_SELECT_FAILED,
+       KILLME_WRITE_FAILED,
+       KILLME_SIMULATION_WORKER,
+       KILLME_NOLOGIN,
+       KILLME_NO_CRYPTO,
+       KILLME_READSTRING_FAILED,
+       KILLME_MALLOC_FAILED,
+       KILLME_QUOTA,
+       KILLME_READ_FAILED,
+       KILLME_ILLEGAL_MANAGESIEVE_COMMAND,
+       KILLME_SPAMMER,
+       KILLME_XML_PARSER
+};
 
 
 #define CS_STEALTH     1       /* stealth mode */
index 5468d24ca7519af883d5aa7a1209466479b31d95..628e955b3e4577ad57f70803cccd1f93c970c5d1 100644 (file)
@@ -496,7 +496,7 @@ int client_write(const char *buf, int nbytes)
                                {
                                        syslog(LOG_DEBUG, "client_write(%d bytes) select() interrupted.\n", nbytes-bytes_written);
                                        if (CtdlThreadCheckStop()) {
-                                               CC->kill_me = 1;
+                                               CC->kill_me = KILLME_SELECT_INTERRUPTED;
                                                return (-1);
                                        } else {
                                                /* can't trust fd's and stuff so we need to re-create them */
@@ -508,7 +508,7 @@ int client_write(const char *buf, int nbytes)
                                                nbytes - bytes_written,
                                                strerror(errno), errno);
                                        cit_backtrace();
-                                       Ctx->kill_me = 1;
+                                       Ctx->kill_me = KILLME_SELECT_FAILED;
                                        return -1;
                                }
                        }
@@ -523,7 +523,7 @@ int client_write(const char *buf, int nbytes)
                                strerror(errno), errno);
                        cit_backtrace();
                        // syslog(LOG_DEBUG, "Tried to send: %s",  &buf[bytes_written]);
-                       Ctx->kill_me = 1;
+                       Ctx->kill_me = KILLME_WRITE_FAILED;
                        return -1;
                }
                bytes_written = bytes_written + retval;
@@ -744,10 +744,10 @@ int client_read_to(char *buf, int bytes, int timeout)
 
 int HaveMoreLinesWaiting(CitContext *CCC)
 {
-       if ((CCC->kill_me == 1) || (
-           (CCC->RecvBuf.ReadWritePointer == NULL) && 
-           (StrLength(CCC->RecvBuf.Buf) == 0) && 
-           (CCC->client_socket != -1)) )
+       if ((CCC->kill_me != 0) ||
+           ( (CCC->RecvBuf.ReadWritePointer == NULL) && 
+             (StrLength(CCC->RecvBuf.Buf) == 0) && 
+             (CCC->client_socket != -1)) )
                return 0;
        else
                return 1;
index 3f7aa7ee2e2b8b914b1eba53ead5cb69eac530b0..1b605d0577da572882aa3f6fad5e1422a8b4c80f 100644 (file)
@@ -1209,7 +1209,7 @@ void *simulation_worker (void*arg) {
 
        this = CreateNewContext();
        CtdlThreadSleep(1);
-       this->kill_me = 1;
+       this->kill_me = KILLME_SIMULATION_WORKER;
        this->state = CON_IDLE;
        dead_session_purge(1);
        begin_critical_section(S_SESSION_TABLE);