Synchronization of LDAP users to Citadel is now complete, including email addresses...
authorArt Cancro <ajc@citadel.org>
Thu, 30 Nov 2017 03:50:15 +0000 (22:50 -0500)
committerArt Cancro <ajc@citadel.org>
Thu, 30 Nov 2017 03:50:15 +0000 (22:50 -0500)
citadel/internet_addressing.c
citadel/internet_addressing.h
citadel/ldap.c
citadel/modules/ctdlproto/serv_user.c
citadel/user_ops.c

index 7730e8794e3039c99b051120959f7f8adb855d0f..9cc6a7dbefa4fa4ec47b3031421f4d64adddf102 100644 (file)
@@ -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<num_tokens(usbuf.emailaddrs, '|'); ++i) {
+               extract_token(buf, usbuf.emailaddrs, i, '|', sizeof buf);
+               CtdlDirectoryDelUser(buf, requested_user);
+       }
+
+       strcpy(usbuf.emailaddrs, new_emailaddrs);               // make it official.
+
+       /* Index all of the new email addresses (they've already been sanitized) */
+       for (i=0; i<num_tokens(usbuf.emailaddrs, '|'); ++i) {
+               extract_token(buf, usbuf.emailaddrs, i, '|', sizeof buf);
+               CtdlDirectoryAddUser(buf, requested_user);
+       }
+
+       CtdlPutUserLock(&usbuf);
+}
index 971ba38a157c9c34057f2439d009dd90b1dc3aec..cb19085c5bf0aeec36e57aa5aa4131191eefa997 100644 (file)
@@ -14,6 +14,7 @@ void CtdlRebuildDirectoryIndex(void);
 int CtdlDirectoryAddUser(char *internet_addr, char *citadel_addr);
 int CtdlDirectoryDelUser(char *internet_addr, char *citadel_addr);
 int CtdlDirectoryLookup(char *target, char *internet_addr, size_t targbuflen);
+void CtdlSetEmailAddressesForUser(char *requested_user, char *new_emailaddrs);
 struct CtdlMessage *convert_internet_message(char *rfc822);
 struct CtdlMessage *convert_internet_message_buf(StrBuf **rfc822);
 int CtdlIsMe(char *addr, int addr_buf_len);
index bdc18d1489e1f7dd8dc01a94e97f34fff36e49d5..904baf3897fb8e2f250cc79263b9cfc12ccbeb38 100644 (file)
@@ -129,7 +129,6 @@ LDAP *ctdl_ldap_bind(void) {
 
        striplt(CtdlGetConfigStr("c_ldap_bind_dn"));
        striplt(CtdlGetConfigStr("c_ldap_bind_pw"));
-       syslog(LOG_DEBUG, "ldap: bind DN: %s", CtdlGetConfigStr("c_ldap_bind_dn"));
        i = ldap_simple_bind_s(ldserver,
                (!IsEmptyStr(CtdlGetConfigStr("c_ldap_bind_dn")) ? CtdlGetConfigStr("c_ldap_bind_dn") : NULL),
                (!IsEmptyStr(CtdlGetConfigStr("c_ldap_bind_pw")) ? CtdlGetConfigStr("c_ldap_bind_pw") : NULL)
@@ -594,23 +593,34 @@ void CtdlSynchronizeUsersFromLDAP(void)
                        int fullname_size = 256;
                        char fullname[256] = { 0 } ;
                        uid_t uid = (-1);
+                       char new_emailaddrs[512] = { 0 } ;
 
                        derive_fullname_from_ldap_result(fullname, fullname_size, ldserver, entry);
                        uid = derive_uid_from_ldap(ldserver, entry);
-                       syslog(LOG_DEBUG, "\033[33mldap: display name: <%s> , 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);
                }
 
index 1c8dbf8803f8c720da6255453bf35897cda1cdd6..5f8e9791bfdbcf5dca73f6db6556a22a1e2c49fb 100644 (file)
@@ -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; i<num_tokens(usbuf.emailaddrs, '|'); ++i) {
-               extract_token(buf, usbuf.emailaddrs, i, '|', sizeof buf);
-               CtdlDirectoryDelUser(buf, requested_user);
-       }
-
-       strcpy(usbuf.emailaddrs, new_emailaddrs);               // make it official.
 
-       /* Index all of the new email addresses (they've already been sanitized) */
-       for (i=0; i<num_tokens(usbuf.emailaddrs, '|'); ++i) {
-               extract_token(buf, usbuf.emailaddrs, i, '|', sizeof buf);
-               CtdlDirectoryAddUser(buf, requested_user);
-       }
-
-       CtdlPutUserLock(&usbuf);
+       CtdlSetEmailAddressesForUser(requested_user, new_emailaddrs);
 }
 
 
index fe830092701028dc7c3fd35added29a94ca64bdb..191582b6e602a441c9e934ca73e985cca4906275 100644 (file)
@@ -658,7 +658,7 @@ void do_login(void)
        if ((CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP) || (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP_AD)) {
                char new_emailaddrs[512];
                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