]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/managesieve/serv_managesieve.c
Removed the logging facility from citserver, use syslog instead
[citadel.git] / citadel / modules / managesieve / serv_managesieve.c
index 8904ea1cfff53b34eae3f4882ff21d95a3177446..0bdc0f1001fe03873b7dbbd0e6b7593d3c742720 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * This module is an managesieve implementation for the Citadel system.
  * It is compliant with all of the following:
  *
 #include "support.h"
 #include "config.h"
 #include "control.h"
-#include "room_ops.h"
 #include "user_ops.h"
-#include "policy.h"
 #include "database.h"
 #include "msgbase.h"
 #include "internet_addressing.h"
-#include "imap_tools.h"        /* Needed for imap_parameterize */
 #include "genstamp.h"
 #include "domain.h"
 #include "clientsocket.h"
@@ -108,6 +103,66 @@ enum {     /** Command states for login authentication */
 
 #define MGSVE          ((struct citmgsve *)CC->session_specific_data)
 
+int old_imap_parameterize(char** args, char *in)
+{
+       char* out = in;
+       int num = 0;
+
+       for (;;)
+       {
+               /* Skip whitespace. */
+
+               while (isspace(*in))
+                       in++;
+               if (*in == 0)
+                       break;
+
+               /* Found the start of a token. */
+               
+               args[num++] = out;
+
+               /* Read in the token. */
+
+               for (;;)
+               {
+                       int c = *in++;
+                       if (isspace(c))
+                               break;
+                       
+                       if (c == '\"')
+                       {
+                               /* Found a quoted section. */
+
+                               for (;;)
+                               {
+                                       c = *in++;
+                                       if (c == '\"')
+                                               break;
+                                       else if (c == '\\')
+                                               c = *in++;
+
+                                       *out++ = c;
+                                       if (c == 0)
+                                               return num;
+                               }
+                       }
+                       else if (c == '\\')
+                       {
+                               c = *in++;
+                               *out++ = c;
+                       }
+                       else
+                               *out++ = c;
+
+                       if (c == 0)
+                               return num;
+               }
+               *out++ = '\0';
+       }
+
+       return num;
+}
+
 /*****************************************************************************/
 /*                      MANAGESIEVE Server                                   */
 /*****************************************************************************/
@@ -245,11 +300,12 @@ void cmd_mgsve_auth(int num_parms, char **parms, struct sdm_userdata *u)
                if (login_ok == CtdlLoginExistingUser(NULL, username))
                {
                        char *pass;
+
                        pass = &(auth[strlen(auth)+1]);
                        /* for some reason the php script sends us the username twice. y? */
                        pass = &(pass[strlen(pass)+1]);
                        
-                       if (pass_ok == CtdlTryPassword(pass))
+                       if (pass_ok == CtdlTryPassword(pass, strlen(pass)))
                        {
                                MGSVE->command_state = mgsve_password;
                                cprintf("OK\r\n");
@@ -280,7 +336,7 @@ void cmd_mgsve_starttls(void)
 void cmd_mgsve_logout(struct sdm_userdata *u)
 {
        cprintf("OK\r\n");
-       CtdlLogPrintf(CTDL_NOTICE, "MgSve bye.");
+       syslog(LOG_NOTICE, "MgSve bye.");
        CC->kill_me = 1;
 }
 
@@ -524,16 +580,16 @@ void managesieve_command_loop(void) {
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
        length = client_getln(cmdbuf, sizeof cmdbuf);
        if (length >= 1) {
-               num_parms = imap_parameterize(parms, cmdbuf);
+               num_parms = old_imap_parameterize(parms, cmdbuf);
                if (num_parms == 0) return;
                length = strlen(parms[0]);
        }
        if (length < 1) {
-               CtdlLogPrintf(CTDL_CRIT, "Client disconnected: ending session.\n");
+               syslog(LOG_CRIT, "Client disconnected: ending session.\n");
                CC->kill_me = 1;
                return;
        }
-       CtdlLogPrintf(CTDL_INFO, "MANAGESIEVE: %s\n", cmdbuf);
+       syslog(LOG_INFO, "MANAGESIEVE: %s\n", cmdbuf);
        if ((length>= 12) && (!strncasecmp(parms[0], "AUTHENTICATE", 12))){
                cmd_mgsve_auth(num_parms, parms, &u);
        }
@@ -578,7 +634,7 @@ void managesieve_command_loop(void) {
        }
        else {
                cprintf("No Invalid access or command.\r\n");
-               CtdlLogPrintf(CTDL_INFO, "illegal Managesieve command: %s", parms[0]);
+               syslog(LOG_INFO, "illegal Managesieve command: %s", parms[0]);
                CC->kill_me = 1;
        }
 
@@ -594,7 +650,7 @@ void managesieve_cleanup_function(void) {
        /* Don't do this stuff if this is not a managesieve session! */
        if (CC->h_command_function != managesieve_command_loop) return;
 
-       CtdlLogPrintf(CTDL_DEBUG, "Performing managesieve cleanup hook\n");
+       syslog(LOG_DEBUG, "Performing managesieve cleanup hook\n");
        free(MGSVE);
 }
 
@@ -615,7 +671,7 @@ CTDL_MODULE_INIT(managesieve)
        }
        
        /* return our Subversion id for the Log */
-       return "$Id$";
+       return "managesieve";
 }