]> code.citadel.org Git - citadel.git/blobdiff - citadel/user_ops.c
Started prepping for the move from LDAP Access to LDAP Sync
[citadel.git] / citadel / user_ops.c
index 7cff90d024847cdfc1292efd8278707d7c2553d6..5cdd4977a6881c1692755ccfc3bfe23845c17034 100644 (file)
@@ -461,8 +461,10 @@ 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.
+ * 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.
  */
 int getuserbyuid(struct ctdluser *usbuf, uid_t number)
 {
@@ -623,8 +625,7 @@ int CtdlLoginExistingUser(char *authname, const char *trythisname)
                if (((CC->nologin)) && (CC->user.axlevel < AxAideU)) {
                        return login_too_many_users;
                } else {
-                       safestrncpy(CC->curr_user, CC->user.fullname,
-                                       sizeof CC->curr_user);
+                       safestrncpy(CC->curr_user, CC->user.fullname, sizeof CC->curr_user);
                        return login_ok;
                }
        }
@@ -663,7 +664,18 @@ void do_login(void)
                }
        }
 
-       CtdlPutUserLock(&CCC->user);
+       /*
+        * 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];
+                       if (extract_email_addresses_from_ldap(CCC->ldap_dn, new_emailaddrs) == 0) {
+                               strcpy(CCC->user.emailaddrs, new_emailaddrs);
+                       }
+               }
+       #endif
 
        /*
         * No email address for user?  Make one up.
@@ -672,6 +684,8 @@ void do_login(void)
                sprintf(CCC->user.emailaddrs, "cit%ld@%s", CCC->user.usernum, CtdlGetConfigStr("c_fqdn"));
        }
        
+       CtdlPutUserLock(&CCC->user);
+
        /*
         * Populate cs_inet_email and cs_inet_other_emails with valid email addresses from the user record
         */
@@ -771,19 +785,19 @@ static int validpw(uid_t uid, const char *pass)
        begin_critical_section(S_CHKPWD);
        rv = write(chkpwd_write_pipe[1], &uid, sizeof(uid_t));
        if (rv == -1) {
-               syslog(LOG_EMERG, "user_ops: communication with chkpwd broken: %s", strerror(errno));
+               syslog(LOG_ERR, "user_ops: communication with chkpwd broken: %m");
                end_critical_section(S_CHKPWD);
                return 0;
        }
        rv = write(chkpwd_write_pipe[1], pass, 256);
        if (rv == -1) {
-               syslog(LOG_EMERG, "user_ops: communication with chkpwd broken: %s", strerror(errno));
+               syslog(LOG_ERR, "user_ops: communication with chkpwd broken: %m");
                end_critical_section(S_CHKPWD);
                return 0;
        }
        rv = read(chkpwd_read_pipe[0], buf, 4);
        if (rv == -1) {
-               syslog(LOG_EMERG, "user_ops: ommunication with chkpwd broken: %s", strerror(errno));
+               syslog(LOG_ERR, "user_ops: ommunication with chkpwd broken: %m");
                end_critical_section(S_CHKPWD);
                return 0;
        }
@@ -810,21 +824,21 @@ void start_chkpwd_daemon(void) {
        syslog(LOG_DEBUG, "user_ops: starting chkpwd daemon for host authentication mode");
 
        if ((stat(file_chkpwd, &filestats)==-1) || (filestats.st_size==0)) {
-               syslog(LOG_ERR, "user_ops: %s: %s", file_chkpwd, strerror(errno));
+               syslog(LOG_ERR, "user_ops: %s: %m", file_chkpwd);
                abort();
        }
        if (pipe(chkpwd_write_pipe) != 0) {
-               syslog(LOG_ERR, "user_ops: unable to create pipe for chkpwd daemon: %s", strerror(errno));
+               syslog(LOG_ERR, "user_ops: unable to create pipe for chkpwd daemon: %m");
                abort();
        }
        if (pipe(chkpwd_read_pipe) != 0) {
-               syslog(LOG_ERR, "user_ops: unable to create pipe for chkpwd daemon: %s", strerror(errno));
+               syslog(LOG_ERR, "user_ops: unable to create pipe for chkpwd daemon: %m");
                abort();
        }
 
        chkpwd_pid = fork();
        if (chkpwd_pid < 0) {
-               syslog(LOG_ERR, "user_ops: unable to fork chkpwd daemon: %s", strerror(errno));
+               syslog(LOG_ERR, "user_ops: unable to fork chkpwd daemon: %m");
                abort();
        }
        if (chkpwd_pid == 0) {
@@ -832,7 +846,7 @@ void start_chkpwd_daemon(void) {
                dup2(chkpwd_read_pipe[1], 1);
                for (i=2; i<256; ++i) close(i);
                execl(file_chkpwd, file_chkpwd, NULL);
-               syslog(LOG_ERR, "user_ops: unable to exec chkpwd daemon: %s", strerror(errno));
+               syslog(LOG_ERR, "user_ops: unable to exec chkpwd daemon: %m");
                abort();
                exit(errno);
        }