getuserbyuid() now uses the extauth index, so we can do ldap sync
authorArt Cancro <ajc@citadel.org>
Mon, 6 Nov 2017 03:31:03 +0000 (22:31 -0500)
committerArt Cancro <ajc@citadel.org>
Mon, 6 Nov 2017 03:31:03 +0000 (22:31 -0500)
citadel/include/ctdl_module.h
citadel/modules/upgrade/serv_upgrade.c
citadel/user_ops.c

index dc78de3adc9a5cfa60d3aa57fe852081af98cb05..c08333e4b874c1761360de005217a6689fd75443 100644 (file)
@@ -430,7 +430,7 @@ long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf);
 
 
 /*
- * This is from modules/openid/serv_openid_rp.c in order to turn it into a generic external authentication driver
+ * Expose API calls from modules/openid/serv_openid_rp.c in order to turn it into a generic external authentication driver
  */
 int attach_extauth(struct ctdluser *who, StrBuf *claimed_id);
 
index 12261deb35c7c9271cd24b96db4b2135959a88d1..56ba219df0044f594d7395e0fc3005b3a2fa511b 100644 (file)
@@ -135,7 +135,11 @@ void reindex_uids_backend(struct ctdluser *usbuf, void *data) {
                                us.uid = NATIVE_AUTH_UID;
                        }
                        CtdlPutUserLock(&us);
-                       if (us.uid > 0) {               // if non-native auth , index by uid
+                       if ((us.uid > 0) && (us.uid != NATIVE_AUTH_UID)) {              // if non-native auth , index by uid
+
+                               syslog(LOG_DEBUG, "\033[31m attaching %d to %s \033[0m", us.uid , us.fullname);
+
+
                                StrBuf *claimed_id = NewStrBuf();
                                StrBufPrintf(claimed_id, "uid:%d", us.uid);
                                attach_extauth(&us, claimed_id);
index 7e82d3188184a900b491414c1fb59dca31dd1712..82f693a4ea0a83a1395818ea4688b248d24fd66b 100644 (file)
@@ -449,32 +449,32 @@ void rebuild_usersbynumber(void) {
 
 
 /*
- * getuserbyuid()  -     get user by system uid (for PAM mode authentication)
- *                    returns 0 if user was found
- *
- * WARNING:    don't use this function unless you absolutely have to.  It does
- *             a sequential search and therefore is computationally expensive.
- *
- * FIXME:      build an index, dummy.
+ * getuserbyuid()      Get user by system uid (for PAM mode authentication)
+ *                     Returns 0 if user was found
+ *                     This now uses an extauth index.
  */
 int getuserbyuid(struct ctdluser *usbuf, uid_t number)
 {
-       struct cdbdata *cdbus;
+       struct cdbdata *cdbextauth;
+       long usernum = 0;
+       StrBuf *claimed_id;
+
+       claimed_id = NewStrBuf();
+       StrBufPrintf(claimed_id, "uid:%d", number);
+       cdbextauth = cdb_fetch(CDB_EXTAUTH, ChrPtr(claimed_id), StrLength(claimed_id));
+       FreeStrBuf(&claimed_id);
+       if (cdbextauth == NULL) {
+               return(-1);
+       }
 
-       cdb_rewind(CDB_USERS);
+       memcpy(&usernum, cdbextauth->ptr, sizeof(long));
+       cdb_free(cdbextauth);
 
-       while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
-               memset(usbuf, 0, sizeof(struct ctdluser));
-               memcpy(usbuf, cdbus->ptr,
-                      ((cdbus->len > sizeof(struct ctdluser)) ?
-                       sizeof(struct ctdluser) : cdbus->len));
-               cdb_free(cdbus);
-               if (usbuf->uid == number) {
-                       cdb_close_cursor(CDB_USERS);
-                       return (0);
-               }
+       if (!CtdlGetUserByNumber(usbuf, usernum)) {
+               return(0);
        }
-       return (-1);
+
+       return(-1);
 }
 
 
@@ -594,9 +594,7 @@ int CtdlLoginExistingUser(char *authname, const char *trythisname)
                /* First, try to log in as if the supplied name is a display name */
                found_user = CtdlGetUser(&CC->user, username);
        
-               /* If that didn't work, try to log in as if the supplied name
-               * is an e-mail address
-               */
+               /* If that didn't work, try to log in as if the supplied name * is an e-mail address */
                if (found_user != 0) {
                        valid = validate_recipients(username, NULL, 0);
                        if (valid != NULL) {
@@ -1028,7 +1026,7 @@ int internal_create_user(char *username, struct ctdluser *usbuf, uid_t uid)
        cdb_store(CDB_USERSBYNUMBER, &usbuf->usernum, sizeof(long), usbuf->fullname, strlen(usbuf->fullname)+1);
 
        /* If non-native auth, index by uid */
-       if (usbuf->uid > 0) {
+       if ((usbuf->uid > 0) && (usbuf->uid != NATIVE_AUTH_UID)) {
                StrBuf *claimed_id = NewStrBuf();
                StrBufPrintf(claimed_id, "uid:%d", usbuf->uid);
                attach_extauth(usbuf, claimed_id);