Support the idea of a 'master user' logging in
authorArt Cancro <ajc@citadel.org>
Sat, 7 Jul 2007 04:25:14 +0000 (04:25 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 7 Jul 2007 04:25:14 +0000 (04:25 +0000)
as another user.  This will be used to support Asterisk voicemail.  It
is currently disabled because the master username/password is hardcoded
and we don't want anyone using that.

citadel/serv_imap.c
citadel/serv_managesieve.c
citadel/serv_pop3.c
citadel/serv_smtp.c
citadel/user_ops.c
citadel/user_ops.h

index 94dd32bb9976ea2a44996049728f09440b41d144..b91800a872ff8705de05fcf7bcd88716e9e18e21 100644 (file)
@@ -522,7 +522,7 @@ void imap_login(int num_parms, char *parms[])
                return;
        }
 
-       if (CtdlLoginExistingUser(parms[2]) == login_ok) {
+       if (CtdlLoginExistingUser(NULL, parms[2]) == login_ok) {
                if (CtdlTryPassword(parms[3]) == pass_ok) {
                        cprintf("%s OK [", parms[0]);
                        imap_output_capability_string();
@@ -562,8 +562,9 @@ void imap_authenticate(int num_parms, char *parms[])
        }
 
        if (!strcasecmp(parms[2], "PLAIN")) {
-               CtdlEncodeBase64(buf, "Username:", 9);
-               cprintf("+ %s\r\n", buf);
+               // CtdlEncodeBase64(buf, "Username:", 9);
+               // cprintf("+ %s\r\n", buf);
+               cprintf("+ \r\n");
                IMAP->authstate = imap_as_expecting_plainauth;
                strcpy(IMAP->authseq, parms[0]);
                return;
@@ -581,6 +582,7 @@ void imap_auth_plain(char *cmd)
        char ident[256];
        char user[256];
        char pass[256];
+       int result;
 
        CtdlDecodeBase64(decoded_authstring, cmd, strlen(cmd));
        safestrncpy(ident, decoded_authstring, sizeof ident);
@@ -588,7 +590,15 @@ void imap_auth_plain(char *cmd)
        safestrncpy(pass, &decoded_authstring[strlen(ident) + strlen(user) + 2], sizeof pass);
 
        IMAP->authstate = imap_as_normal;
-       if (CtdlLoginExistingUser(user) == login_ok) {
+
+       if (strlen(ident) > 0) {
+               result = CtdlLoginExistingUser(user, ident);
+       }
+       else {
+               result = CtdlLoginExistingUser(NULL, user);
+       }
+
+       if (result == login_ok) {
                if (CtdlTryPassword(pass) == pass_ok) {
                        cprintf("%s OK authentication succeeded\r\n", IMAP->authseq);
                        return;
@@ -602,7 +612,7 @@ void imap_auth_login_user(char *cmd)
        char buf[SIZ];
 
        CtdlDecodeBase64(buf, cmd, SIZ);
-       CtdlLoginExistingUser(buf);
+       CtdlLoginExistingUser(NULL, buf);
        CtdlEncodeBase64(buf, "Password:", 9);
        cprintf("+ %s\r\n", buf);
        IMAP->authstate = imap_as_expecting_password;
index 608318fb6e8148231a043524951ea7faa3d30ca7..11ad9da42129a2c8fd5a1e5598ae50ab6d720cbb 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * $Id$
+ * $Id$
  *
  * This module is an managesieve implementation for the Citadel system.
  * It is compliant with all of the following:
@@ -222,7 +222,7 @@ void cmd_mgsve_auth(int num_parms, char **parms, struct sdm_userdata *u)
                else 
                        retval = CtdlDecodeBase64(auth, parms[2], SIZ);
 
-               if (login_ok == CtdlLoginExistingUser(auth))
+               if (login_ok == CtdlLoginExistingUser(NULL, auth))
                {
                        char *pass;
                        pass = &(auth[strlen(auth)+1]);
@@ -581,7 +581,7 @@ char *serv_managesieve_init(void)
                                managesieve_command_loop,
                                NULL);
 
-       return "$Id: serv_managesieve.c 4570 2006-08-27 02:07:18Z dothebart $";
+       return "$Id$";
 }
 
 #else  /* HAVE_LIBSIEVE */
@@ -589,7 +589,7 @@ char *serv_managesieve_init(void)
 char *serv_managesieve_init(void)
 {
        lprintf(CTDL_INFO, "This server is missing libsieve.  Managesieve protocol is disabled..\n");
-       return "$Id:  $";
+       return "$Id$";
 }
 
 #endif /* HAVE_LIBSIEVE */
index 17255d1d16b65ee4e7c7362f90b7784de79d76df..5880b97e97a3be81b336f818aa5db84ee17ac7a2 100644 (file)
@@ -122,7 +122,7 @@ void pop3_user(char *argbuf) {
        striplt(username);
 
        /* lprintf(CTDL_DEBUG, "Trying <%s>\n", username); */
-       if (CtdlLoginExistingUser(username) == login_ok) {
+       if (CtdlLoginExistingUser(NULL, username) == login_ok) {
                cprintf("+OK Password required for %s\r\n", username);
        }
        else {
@@ -242,7 +242,7 @@ void pop3_apop(char *argbuf)
    memset(userdigest, MD5_HEXSTRING_SIZE, 0);
    strncpy(userdigest, sptr, MD5_HEXSTRING_SIZE-1);
    
-   if (CtdlLoginExistingUser(username) != login_ok)
+   if (CtdlLoginExistingUser(NULL, username) != login_ok)
    {
        cprintf("-ERR No such user.\r\n");
        return;
index df1e560054c8fb03ec4938647dfeb16cdc76deb5..91aa236467ae1670d69e27b2c59586a2dac619fb 100644 (file)
@@ -315,7 +315,7 @@ void smtp_get_user(char *argbuf) {
 
        CtdlDecodeBase64(username, argbuf, SIZ);
        /* lprintf(CTDL_DEBUG, "Trying <%s>\n", username); */
-       if (CtdlLoginExistingUser(username) == login_ok) {
+       if (CtdlLoginExistingUser(NULL, username) == login_ok) {
                CtdlEncodeBase64(buf, "Password:", 9);
                cprintf("334 %s\r\n", buf);
                SMTP->command_state = smtp_password;
@@ -353,16 +353,23 @@ void smtp_try_plain(char *encoded_authstring) {
        char ident[256];
        char user[256];
        char pass[256];
+       int result;
 
-       CtdlDecodeBase64(decoded_authstring,
-                       encoded_authstring,
-                       strlen(encoded_authstring) );
+       CtdlDecodeBase64(decoded_authstring, encoded_authstring, strlen(encoded_authstring) );
        safestrncpy(ident, decoded_authstring, sizeof ident);
        safestrncpy(user, &decoded_authstring[strlen(ident) + 1], sizeof user);
        safestrncpy(pass, &decoded_authstring[strlen(ident) + strlen(user) + 2], sizeof pass);
 
        SMTP->command_state = smtp_command;
-       if (CtdlLoginExistingUser(user) == login_ok) {
+
+       if (strlen(ident) > 0) {
+               result = CtdlLoginExistingUser(user, ident);
+       }
+       else {
+               result = CtdlLoginExistingUser(NULL, user);
+       }
+
+       if (result == login_ok) {
                if (CtdlTryPassword(pass) == pass_ok) {
                        smtp_auth_greeting();
                        return;
index 55d369d869374f607da977403dcab6bb22f24806..2b8e2015542a2d1ab1c08236452eabc0faa0daee 100644 (file)
@@ -338,13 +338,15 @@ int getuserbyuid(struct ctdluser *usbuf, uid_t number)
        return (-1);
 }
 
-#define MASTER_PREFIX          "master"
+#define MASTER_USER            "master"
 #define MASTER_PASSWORD                "d0nuts"
 
 /*
  * Back end for cmd_user() and its ilk
+ *
+ * NOTE: "authname" should only be used if we are attempting to use the "master user" feature
  */
-int CtdlLoginExistingUser(char *trythisname)
+int CtdlLoginExistingUser(char *authname, char *trythisname)
 {
        char username[SIZ];
        int found_user;
@@ -355,13 +357,16 @@ int CtdlLoginExistingUser(char *trythisname)
 
        if (trythisname == NULL) return login_not_found;
 
-       if (0) {        /* FIXME */
-               CC->is_master = 1;
-       }
-       else {
-               safestrncpy(username, trythisname, USERNAME_SIZE);
-               CC->is_master = 0;
+       CC->is_master = 0;
+/* This code WORKS!  It's commented out because we don't want anyone using the hardcoded password.
+       if (authname) {
+               if (!strcasecmp(authname, MASTER_USER)) {
+                       CC->is_master = 1;
+               }
        }
+ */
+
+       safestrncpy(username, trythisname, USERNAME_SIZE);
        striplt(username);
 
        if (strlen(username) == 0) {
@@ -446,7 +451,7 @@ void cmd_user(char *cmdbuf)
        extract_token(username, cmdbuf, 0, '|', sizeof username);
        striplt(username);
 
-       a = CtdlLoginExistingUser(username);
+       a = CtdlLoginExistingUser(NULL, username);
        switch (a) {
        case login_already_logged_in:
                cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
index 7b06f5d96016ae495a9ee18fe2952237383e98dd..2df249b96c23a896dc6136d2ac2ae0f09a35dcff 100644 (file)
@@ -50,7 +50,7 @@ int GenerateRelationshipIndex(  char *IndexBuf,
                                 long RoomGen,
                                 long UserID);
 int CtdlAssociateSystemUser(char *screenname, char *loginname);
-int CtdlLoginExistingUser(char *username);
+int CtdlLoginExistingUser(char *authname, char *username);
 
 /*
  * Values which may be returned by CtdlLoginExistingUser()