]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/user_ops.c
We are no longer using the EXTAUTH table.
[citadel.git] / citadel / server / user_ops.c
index a47e5a987ed4e6ddbb5f239cbd89a5d2c2e53819..99bf5b0229f1cbda915430aef94bed937bc24cc0 100644 (file)
@@ -419,22 +419,32 @@ void rebuild_usersbynumber(void) {
 }
 
 
-// Helper function for getuserbyuid()
-void getuserbyuid_backend(char *username, void *data) {
-       struct ctdluser u;
-       syslog(LOG_DEBUG, "user_ops: FIXME %s", username);
-}
-
-
 // getuserbyuid()      Get user by system uid (for PAM mode authentication)
 //                     Returns 0 if user was found
-//                      TODO: make an index so we don't have to do this the long way
 int getuserbyuid(struct ctdluser *usbuf, uid_t number) {
 
-       ForEachUser(getuserbyuid_backend, NULL);
+       struct cdbdata *cdbus;
+       struct ctdluser *usptr;
+       int return_value = (-1);
+
+       // Yes, we do this the long way.
+       // No, we don't use CtdlForEachUser() because that requires multiple reads for each record
+       // TODO: make an index
+       cdb_rewind(CDB_USERS);
+       while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
+               usptr = (struct ctdluser *) cdbus->ptr;
 
-       //return(CtdlGetUser(usbuf, key));
-       return(-1);
+               if (usptr->uid == number) {
+                       syslog(LOG_DEBUG, "user_ops: found uid=%d username=%s", usptr->uid, usptr->fullname);
+                       memcpy(usbuf, usptr, sizeof(struct ctdluser));
+                       return_value = 0;       // success
+               }
+       }
+
+       if (return_value != 0) {
+               syslog(LOG_DEBUG, "user_ops: no user found with uid=%d", number);
+       }
+       return(return_value);
 }