From: Art Cancro Date: Thu, 30 Nov 2017 03:50:15 +0000 (-0500) Subject: Synchronization of LDAP users to Citadel is now complete, including email addresses... X-Git-Tag: v939~492 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=fcec795dc7d0d125028ca1bd3a5f35b3f97b265f Synchronization of LDAP users to Citadel is now complete, including email addresses. FIXME: need to make the email piece a site-configurable setting. --- diff --git a/citadel/internet_addressing.c b/citadel/internet_addressing.c index 7730e8794..9cc6a7dbe 100644 --- a/citadel/internet_addressing.c +++ b/citadel/internet_addressing.c @@ -1718,3 +1718,36 @@ void CtdlRebuildDirectoryIndex(void) { ForEachUser(CtdlRebuildDirectoryIndex_backend, NULL); CtdlRebuildDirectoryIndex_backend(NULL, NULL); } + + +/* + * Configure Internet email addresses for a user account, updating the Directory Index in the process + */ +void CtdlSetEmailAddressesForUser(char *requested_user, char *new_emailaddrs) +{ + struct ctdluser usbuf; + int i; + char buf[SIZ]; + + if (CtdlGetUserLock(&usbuf, requested_user) != 0) { // We are relying on the fact that the DirectoryIndex functions don't lock. + return; // Silently fail here if we can't acquire a lock on the user record. + } + + syslog(LOG_DEBUG, "internet_addressing: setting email addresses for <%s> to <%s>", usbuf.fullname, new_emailaddrs); + + /* Delete all of the existing directory index records for the user (easier this way) */ + for (i=0; i , uid = <%d>\033[0m", fullname, uid); + syslog(LOG_DEBUG, "ldap: display name: <%s> , uid = <%d>", fullname, uid); - // FIXME now create or update the user - int i; + // now create or update the user + int found_user; struct ctdluser usbuf; - i = getuserbyuid(&usbuf, uid); - if (i == 0) { - syslog(LOG_DEBUG, "\033[32m...and that user EXISTZ0RS!!!\033[0m"); - } - else { - syslog(LOG_DEBUG, "\033[31m...and that user D0EZ N0T EXISTZ0R!!\033[0m"); + found_user = getuserbyuid(&usbuf, uid); + if (found_user != 0) { + create_user(fullname, CREATE_USER_DO_NOT_BECOME_USER, uid); + found_user = getuserbyuid(&usbuf, uid); + strcpy(fullname, usbuf.fullname); } + if (found_user == 0) { // user record exists + + // now update the account email addresses if necessary + // FIXME make this a site configurable setting + + if (extract_email_addresses_from_ldap(user_dn, new_emailaddrs) == 0) { + if (strcmp(usbuf.emailaddrs, new_emailaddrs)) { // update only if changed + CtdlSetEmailAddressesForUser(usbuf.fullname, new_emailaddrs); + } + } + } ldap_memfree(user_dn); } diff --git a/citadel/modules/ctdlproto/serv_user.c b/citadel/modules/ctdlproto/serv_user.c index 1c8dbf880..5f8e9791b 100644 --- a/citadel/modules/ctdlproto/serv_user.c +++ b/citadel/modules/ctdlproto/serv_user.c @@ -701,7 +701,6 @@ void cmd_asea(char *cmdbuf) char buf[SIZ]; char whodat[64]; char new_emailaddrs[512] = { 0 } ; - int i; if (CtdlAccessCheck(ac_aide)) return; @@ -729,25 +728,8 @@ void cmd_asea(char *cmdbuf) } } - if (CtdlGetUserLock(&usbuf, requested_user) != 0) { // We are relying on the fact that the DirectoryIndex functions don't lock. - return; // Silently fail here if we can't acquire a lock on the user record. - } - - /* Delete all of the existing directory index records for the user (easier this way) */ - for (i=0; ildap_dn, new_emailaddrs) == 0) { - strcpy(CCC->user.emailaddrs, new_emailaddrs); + CtdlSetEmailAddressesForUser(CCC->user.fullname, new_emailaddrs); } } #endif