X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fuser_ops.c;h=5dc4790a915ac1730a88e5be299cbb0ef3bced81;hb=8996a310a8255f702e139f09dbb7fae697ba7841;hp=b69bb33b55b93cf07badfd0319e66a420066c74e;hpb=92b1da07f5a90221fdf7f2adfb2258c9c2cdc7a1;p=citadel.git diff --git a/citadel/user_ops.c b/citadel/user_ops.c index b69bb33b5..5dc4790a9 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -367,8 +367,7 @@ int is_room_aide(void) return (0); } - if ((CC->user.axlevel >= AxAideU) - || (CC->room.QRroomaide == CC->user.usernum)) { + if ((CC->user.axlevel >= AxAideU) || (CC->room.QRroomaide == CC->user.usernum)) { return (1); } else { return (0); @@ -450,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); } @@ -568,14 +567,14 @@ int CtdlLoginExistingUser(char *authname, const char *trythisname) char ldap_cn[256]; char ldap_dn[256]; - found_user = CtdlTryUserLDAP(username, ldap_dn, sizeof ldap_dn, ldap_cn, sizeof ldap_cn, &ldap_uid, 0); + found_user = CtdlTryUserLDAP(username, ldap_dn, sizeof ldap_dn, ldap_cn, sizeof ldap_cn, &ldap_uid); if (found_user != 0) { return login_not_found; } found_user = getuserbyuid(&CC->user, ldap_uid); if (found_user != 0) { - create_user(username, CREATE_USER_DO_NOT_BECOME_USER, ldap_uid); + create_user(ldap_cn, CREATE_USER_DO_NOT_BECOME_USER, ldap_uid); found_user = getuserbyuid(&CC->user, ldap_uid); } @@ -595,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) { @@ -657,14 +654,16 @@ void do_login(void) * If we are using LDAP authentication, extract the user's email addresses from the directory. * FIXME make this a site configurable setting */ - #ifdef HAVE_LDAP - if ((CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP) || (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP_AD)) { - char new_emailaddrs[512]; +#ifdef HAVE_LDAP + if ((CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP) || (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP_AD)) { + char new_emailaddrs[512]; + if (CtdlGetConfigInt("c_ldap_sync_email_addrs") > 0) { if (extract_email_addresses_from_ldap(CCC->ldap_dn, new_emailaddrs) == 0) { - strcpy(CCC->user.emailaddrs, new_emailaddrs); + CtdlSetEmailAddressesForUser(CCC->user.fullname, new_emailaddrs); } } - #endif + } +#endif /* * No email address for user? Make one up. @@ -1028,6 +1027,14 @@ int internal_create_user(char *username, struct ctdluser *usbuf, uid_t uid) CtdlPutUser(usbuf); 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) && (usbuf->uid != NATIVE_AUTH_UID)) { + StrBuf *claimed_id = NewStrBuf(); + StrBufPrintf(claimed_id, "uid:%d", usbuf->uid); + attach_extauth(usbuf, claimed_id); + FreeStrBuf(&claimed_id); + } + return 0; } @@ -1049,9 +1056,10 @@ int create_user(char *username, int become_user, uid_t uid) int retval; strproc(username); - if ((retval = internal_create_user(username, &usbuf, uid)) != 0) + if ((retval = internal_create_user(username, &usbuf, uid)) != 0) { return retval; - + } + /* * Give the user a private mailbox and a configuration room. * Make the latter an invisible system room.