From 1aabcbba9e94fd9bb27af2fb4721a7e8149a24ff Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 2 Jan 2008 19:06:39 +0000 Subject: [PATCH] Prepared some of the authmode stuff for the imminent addition of a third mode (LDAP without PAM). The mode itself will not be written until after the next production release of the code. Changed the use of 0 and 1 constants to AUTHMODE_NATIVE and AUTHMODE_HOST. --- citadel/citadel.h | 6 ++++++ citadel/citserver.c | 6 +++--- citadel/config.c | 5 +++-- citadel/modules/expire/serv_expire.c | 21 ++++++++++++--------- citadel/server_main.c | 2 +- citadel/setup.c | 4 ++-- citadel/user_ops.c | 12 ++++++------ 7 files changed, 33 insertions(+), 23 deletions(-) diff --git a/citadel/citadel.h b/citadel/citadel.h index 5963a6a19..1a759e4ff 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -284,6 +284,12 @@ enum { #define VIEW_CALBRIEF 7 /* Brief Calendar view */ #define VIEW_JOURNAL 8 /* Journal view (not yet implemented in native clients) */ +/* + * Authentication modes + */ +#define AUTHMODE_NATIVE 0 /* native Citadel authentication */ +#define AUTHMODE_HOST 1 /* host integrated */ + #ifdef __cplusplus } #endif diff --git a/citadel/citserver.c b/citadel/citserver.c index 24b76c1db..fcce7d239 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -293,11 +293,11 @@ void cmd_info(void) { cprintf("0\n"); /* 1 = no, this server is not LDAP-enabled */ #endif - if (config.c_auth_mode == 1) { - cprintf("1\n"); /* "create new user" never works with host auth */ + if (config.c_auth_mode == AUTHMODE_NATIVE) { + cprintf("%d\n", config.c_disable_newu); } else { - cprintf("%d\n", config.c_disable_newu); /* otherwise, site defined */ + cprintf("1\n"); /* "create new user" does not work with non-native auth modes */ } cprintf("%s\n", config.c_default_cal_zone); diff --git a/citadel/config.c b/citadel/config.c index a8d4ca6b7..48e04420c 100644 --- a/citadel/config.c +++ b/citadel/config.c @@ -106,9 +106,10 @@ void get_config(void) { if (config.c_net_freq < 300L) config.c_net_freq = 300L; - /* "create new user" never works with host auth */ - if (config.c_auth_mode == 1) + /* "create new user" only works with native authentication mode */ + if (config.c_auth_mode != AUTHMODE_NATIVE) { config.c_disable_newu = 1; + } } diff --git a/citadel/modules/expire/serv_expire.c b/citadel/modules/expire/serv_expire.c index 4ba4de53e..eaff4280b 100644 --- a/citadel/modules/expire/serv_expire.c +++ b/citadel/modules/expire/serv_expire.c @@ -460,15 +460,18 @@ int PurgeUsers(void) { lprintf(CTDL_DEBUG, "PurgeUsers() called\n"); users_not_purged = 0; - if (config.c_auth_mode == 1) { - /* host auth mode */ - ForEachUser(do_uid_user_purge, NULL); - } - else { - /* native auth mode */ - if (config.c_userpurge > 0) { - ForEachUser(do_user_purge, NULL); - } + switch(config.c_auth_mode) { + case AUTHMODE_NATIVE: + if (config.c_userpurge > 0) { + ForEachUser(do_user_purge, NULL); + } + break; + case AUTHMODE_HOST: + ForEachUser(do_uid_user_purge, NULL); + break; + default: + lprintf(CTDL_DEBUG, "Unknown authentication mode!\n"); + break; } transcript = malloc(SIZ); diff --git a/citadel/server_main.c b/citadel/server_main.c index a0d7b31f7..d9c6d17e8 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -293,7 +293,7 @@ int main(int argc, char **argv) /* * If we need host auth, start our chkpwd daemon. */ - if (config.c_auth_mode == 1) { + if (config.c_auth_mode == AUTHMODE_HOST) { start_chkpwd_daemon(); } diff --git a/citadel/setup.c b/citadel/setup.c index e21bdcce0..fc64eb78e 100644 --- a/citadel/setup.c +++ b/citadel/setup.c @@ -785,10 +785,10 @@ void edit_value(int curr) { if (getenv("ENABLE_UNIX_AUTH")) { if (!strcasecmp(getenv("ENABLE_UNIX_AUTH"), "yes")) { - config.c_auth_mode = 1; + config.c_auth_mode = AUTHMODE_HOST; } else { - config.c_auth_mode = 0; + config.c_auth_mode = AUTHMODE_NATIVE; } } } diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 45e9a1e80..67eab32fc 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -381,7 +381,7 @@ int CtdlLoginExistingUser(char *authname, char *trythisname) return login_not_found; } - if (config.c_auth_mode == 1) { + if (config.c_auth_mode == AUTHMODE_HOST) { /* host auth mode */ @@ -509,7 +509,7 @@ void session_startup(void) /* If we're authenticating off the host system, automatically give * root the highest level of access. */ - if (config.c_auth_mode == 1) { + if (config.c_auth_mode == AUTHMODE_HOST) { if (CC->user.uid == 0) { CC->user.axlevel = 6; } @@ -705,7 +705,7 @@ int CtdlTryPassword(char *password) code = strcmp(password, config.c_master_pass); } - else if (config.c_auth_mode == 1) { + else if (config.c_auth_mode == AUTHMODE_HOST) { /* host auth mode */ @@ -868,7 +868,7 @@ int create_user(char *newusername, int become_user) safestrncpy(username, newusername, sizeof username); strproc(username); - if (config.c_auth_mode == 1) { + if (config.c_auth_mode == AUTHMODE_HOST) { /* host auth mode */ @@ -987,7 +987,7 @@ void cmd_newu(char *cmdbuf) int a; char username[26]; - if (config.c_auth_mode == 1) { + if (config.c_auth_mode != AUTHMODE_NATIVE) { cprintf("%d This system does not use native mode authentication.\n", ERROR + NOT_HERE); return; @@ -1116,7 +1116,7 @@ void cmd_creu(char *cmdbuf) } else if (a == ERROR + ALREADY_EXISTS) { cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username); return; - } else if ( (config.c_auth_mode == 1) && (a == ERROR + NO_SUCH_USER) ) { + } else if ( (config.c_auth_mode != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) { cprintf("%d User accounts are not created within Citadel in host authentication mode.\n", ERROR + NO_SUCH_USER); return; -- 2.30.2