From 5d8503a386f4b0b7a6fe4091e5c03e36a6fac737 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 30 Oct 2017 17:02:01 -0400 Subject: [PATCH] Change the become_user parameter of create_user() to an enum, to make calling code easier to read --- citadel/modules/ctdlproto/serv_user.c | 4 ++-- citadel/modules/openid/serv_openid_rp.c | 2 +- citadel/user_ops.c | 10 +++++----- citadel/user_ops.h | 6 ++++++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/citadel/modules/ctdlproto/serv_user.c b/citadel/modules/ctdlproto/serv_user.c index 7b7725a6e..a3238a522 100644 --- a/citadel/modules/ctdlproto/serv_user.c +++ b/citadel/modules/ctdlproto/serv_user.c @@ -132,7 +132,7 @@ void cmd_newu(char *cmdbuf) return; } - a = create_user(username, 1); + a = create_user(username, CREATE_USER_BECOME_USER); if (a == 0) { logged_in_response(); @@ -210,7 +210,7 @@ void cmd_creu(char *cmdbuf) extract_token(password, cmdbuf, 1, '|', sizeof password); - a = create_user(username, 0); + a = create_user(username, CREATE_USER_DO_NOT_BECOME_USER); if (a == 0) { if (!IsEmptyStr(password)) { diff --git a/citadel/modules/openid/serv_openid_rp.c b/citadel/modules/openid/serv_openid_rp.c index 69479190e..5b3a9ac4f 100644 --- a/citadel/modules/openid/serv_openid_rp.c +++ b/citadel/modules/openid/serv_openid_rp.c @@ -402,7 +402,7 @@ int openid_create_user_via_ax(StrBuf *claimed_id, HashList *sreg_keys) } /* The desired account name is available. Create the account and log it in! */ - if (create_user(nickname, 1)) return(6); + if (create_user(nickname, CREATE_USER_BECOME_USER)) return(6); /* Generate a random password. * The user doesn't care what the password is since he is using OpenID. diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 00b027283..af407b0d7 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -553,7 +553,7 @@ int CtdlLoginExistingUser(char *authname, const char *trythisname) found_user = getuserbyuid(&CC->user, pd.pw_uid); syslog(LOG_DEBUG, "user_ops: found it: uid=%ld, gecos=%s here: %d", (long)pd.pw_uid, pd.pw_gecos, found_user); if (found_user != 0) { - create_user(username, 0); + create_user(username, CREATE_USER_DO_NOT_BECOME_USER); found_user = getuserbyuid(&CC->user, pd.pw_uid); } @@ -575,7 +575,7 @@ int CtdlLoginExistingUser(char *authname, const char *trythisname) found_user = getuserbyuid(&CC->user, ldap_uid); if (found_user != 0) { - create_user(username, 0); + create_user(username, CREATE_USER_DO_NOT_BECOME_USER); found_user = getuserbyuid(&CC->user, ldap_uid); } @@ -1036,8 +1036,8 @@ int internal_create_user(char *username, struct ctdluser *usbuf, uid_t uid) * create_user() - back end processing to create a new user * * Set 'newusername' to the desired account name. - * Set 'become_user' to nonzero if this is self-service account creation and we want - * to actually log in as the user we just created, otherwise set it to 0. + * Set 'become_user' to CREATE_USER_BECOME_USER if this is self-service account creation and we want + * to actually log in as the user we just created, otherwise set it to CREATE_USER_DO_NOT_BECOME_USER */ int create_user(const char *newusername, int become_user) { @@ -1114,7 +1114,7 @@ int create_user(const char *newusername, int become_user) * creating a user, instead of doing self-service account creation */ - if (become_user) { + if (become_user == CREATE_USER_BECOME_USER) { /* Now become the user we just created */ memcpy(&CC->user, &usbuf, sizeof(struct ctdluser)); safestrncpy(CC->curr_user, username, sizeof CC->curr_user); diff --git a/citadel/user_ops.h b/citadel/user_ops.h index e53fab445..8dace4ad6 100644 --- a/citadel/user_ops.h +++ b/citadel/user_ops.h @@ -12,7 +12,13 @@ void rebuild_usersbynumber(void); void session_startup (void); void logged_in_response(void); int purge_user (char *pname); + int create_user (const char *newusername, int become_user); +enum { + CREATE_USER_DO_NOT_BECOME_USER, + CREATE_USER_BECOME_USER +}; + void do_login(void); int CtdlInvtKick(char *iuser, int op); void ForEachUser(void (*CallBack)(struct ctdluser *EachUser, void *out_data), -- 2.30.2