From: Art Cancro Date: Sat, 7 Jul 2007 04:25:14 +0000 (+0000) Subject: Support the idea of a 'master user' logging in X-Git-Tag: v7.86~3254 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=d16aa2142aedbca19cbc11efc57df4ce62769729;p=citadel.git Support the idea of a 'master user' logging in 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. --- diff --git a/citadel/serv_imap.c b/citadel/serv_imap.c index 94dd32bb9..b91800a87 100644 --- a/citadel/serv_imap.c +++ b/citadel/serv_imap.c @@ -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; diff --git a/citadel/serv_managesieve.c b/citadel/serv_managesieve.c index 608318fb6..11ad9da42 100644 --- a/citadel/serv_managesieve.c +++ b/citadel/serv_managesieve.c @@ -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 */ diff --git a/citadel/serv_pop3.c b/citadel/serv_pop3.c index 17255d1d1..5880b97e9 100644 --- a/citadel/serv_pop3.c +++ b/citadel/serv_pop3.c @@ -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; diff --git a/citadel/serv_smtp.c b/citadel/serv_smtp.c index df1e56005..91aa23646 100644 --- a/citadel/serv_smtp.c +++ b/citadel/serv_smtp.c @@ -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; diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 55d369d86..2b8e20155 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -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); diff --git a/citadel/user_ops.h b/citadel/user_ops.h index 7b06f5d96..2df249b96 100644 --- a/citadel/user_ops.h +++ b/citadel/user_ops.h @@ -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()