Internal API change, create_user() now expects to be given a uid
authorArt Cancro <ajc@citadel.org>
Mon, 30 Oct 2017 21:24:37 +0000 (17:24 -0400)
committerArt Cancro <ajc@citadel.org>
Mon, 30 Oct 2017 21:24:37 +0000 (17:24 -0400)
citadel/modules/ctdlproto/serv_user.c
citadel/modules/openid/serv_openid_rp.c
citadel/user_ops.c
citadel/user_ops.h

index a3238a522c9663e36cc5f074ae1ba8edf8058f3f..1c8dbf8803f8c720da6255453bf35897cda1cdd6 100644 (file)
@@ -132,7 +132,7 @@ void cmd_newu(char *cmdbuf)
                return;
        }
 
-       a = create_user(username, CREATE_USER_BECOME_USER);
+       a = create_user(username, CREATE_USER_BECOME_USER, NATIVE_AUTH_UID);
 
        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, CREATE_USER_DO_NOT_BECOME_USER);
+       a = create_user(username, CREATE_USER_DO_NOT_BECOME_USER, NATIVE_AUTH_UID);
 
        if (a == 0) {
                if (!IsEmptyStr(password)) {
index 5b3a9ac4f15395668b2090f5469e688e9542aa53..b592d8156c090f548eff4f9469a050042b0cf530 100644 (file)
@@ -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, CREATE_USER_BECOME_USER)) return(6);
+       if (create_user(nickname, CREATE_USER_BECOME_USER, NATIVE_AUTH_UID)) return(6);
 
        /* Generate a random password.
         * The user doesn't care what the password is since he is using OpenID.
index af407b0d7a1ec686e2638b3a0995514846e83de1..b69bb33b55b93cf07badfd0319e66a420066c74e 100644 (file)
@@ -551,11 +551,11 @@ int CtdlLoginExistingUser(char *authname, const char *trythisname)
                 * If not found, make one attempt to create it.
                 */
                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, CREATE_USER_DO_NOT_BECOME_USER);
+                       create_user(username, CREATE_USER_DO_NOT_BECOME_USER, pd.pw_uid);
                        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);
 
        }
 
@@ -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, CREATE_USER_DO_NOT_BECOME_USER);
+                       create_user(username, CREATE_USER_DO_NOT_BECOME_USER, ldap_uid);
                        found_user = getuserbyuid(&CC->user, ldap_uid);
                }
 
@@ -1036,60 +1036,19 @@ 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 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
+ * 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
+ * Set 'uid' to some uid_t value to associate the account with an external auth user, or (-1) for native auth
  */
-int create_user(const char *newusername, int become_user)
+int create_user(char *username, int become_user, uid_t uid)
 {
        struct ctdluser usbuf;
        struct ctdlroom qrbuf;
-       char username[256];
        char mailboxname[ROOMNAMELEN];
        char buf[SIZ];
        int retval;
-       uid_t uid = (-1);
 
-       safestrncpy(username, newusername, sizeof username);
        strproc(username);
-       
-       if (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_HOST) {
-
-               /* host auth mode */
-
-               struct passwd pd;
-               struct passwd *tempPwdPtr;
-               char pwdbuffer[SIZ];
-       
-#ifdef HAVE_GETPWNAM_R
-#ifdef SOLARIS_GETPWUID
-               tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof(pwdbuffer));
-#else // SOLARIS_GETPWUID
-               getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
-#endif // SOLARIS_GETPWUID
-#else // HAVE_GETPWNAM_R
-               tempPwdPtr = NULL;
-#endif // HAVE_GETPWNAM_R
-               if (tempPwdPtr != NULL) {
-                       extract_token(username, pd.pw_gecos, 0, ',', sizeof username);
-                       uid = pd.pw_uid;
-                       if (IsEmptyStr (username))
-                       {
-                               safestrncpy(username, pd.pw_name, sizeof username);
-                       }
-               }
-               else {
-                       return (ERROR + NO_SUCH_USER);
-               }
-       }
-
-#ifdef HAVE_LDAP
-       if ((CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP) || (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP_AD)) {
-               if (CtdlTryUserLDAP(username, NULL, 0, username, sizeof username, &uid, 0) != 0) {
-                       return(ERROR + NO_SUCH_USER);
-               }
-       }
-#endif /* HAVE_LDAP */
-       
        if ((retval = internal_create_user(username, &usbuf, uid)) != 0)
                return retval;
        
index 8dace4ad6b6a351f76605e75b89d29efab2f1b9c..146a0eed5b68d66eb99478954e6f4f0c8aaf6a9c 100644 (file)
@@ -13,11 +13,12 @@ void session_startup (void);
 void logged_in_response(void);
 int purge_user (char *pname);
 
-int create_user (const char *newusername, int become_user);
+int create_user(char *newusername, int become_user, uid_t uid);
 enum {
        CREATE_USER_DO_NOT_BECOME_USER,
        CREATE_USER_BECOME_USER
 };
+#define NATIVE_AUTH_UID (-1)
 
 void do_login(void);
 int CtdlInvtKick(char *iuser, int op);