* LDAP auth code is now complete. Config is still hardcoded, though; need to fix...
authorArt Cancro <ajc@citadel.org>
Fri, 10 Apr 2009 07:44:48 +0000 (07:44 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 10 Apr 2009 07:44:48 +0000 (07:44 +0000)
citadel/citadel_ldap.h
citadel/ldap.c
citadel/user_ops.c

index e39b9e611833dd7cfd6fe1ce3612e673f7f40c44..aff1a363f237f1263da3f4116664ea875f2f9149 100644 (file)
@@ -9,5 +9,5 @@
 #define BIND_PW                NULL                    /* put pw here for authenticated bind */
 #define SEARCH_STRING  "(&(objectclass=posixAccount)(uid=%s))"
 
-int CtdlTryUserLDAP(char *username, char *found_dn, int found_dn_size, char *fullname, int fullname_size, int *found_uid);
+int CtdlTryUserLDAP(char *username, char *found_dn, int found_dn_size, char *fullname, int fullname_size, uid_t *found_uid);
 int CtdlTryPasswordLDAP(char *user_dn, char *password);
index 4ece8527b6e31876ddc1a16ee33a8811246c1d4e..7a59747b3440b1847f7cb1a4fead89d2646ddc37 100644 (file)
@@ -62,7 +62,7 @@ int ldap_version = 3;
 int CtdlTryUserLDAP(char *username,
                char *found_dn, int found_dn_size,
                char *fullname, int fullname_size,
-               int *uid)
+               uid_t *uid)
 {
        LDAP *ldserver = NULL;
        int i;
@@ -73,7 +73,7 @@ int CtdlTryUserLDAP(char *username,
        char **values;
        char *user_dn = NULL;
 
-       safestrncpy(fullname, username, fullname_size);
+       if (fullname) safestrncpy(fullname, username, fullname_size);
 
        ldserver = ldap_init(CTDL_LDAP_HOST, CTDL_LDAP_PORT);
        if (ldserver == NULL) {
@@ -132,7 +132,7 @@ int CtdlTryUserLDAP(char *username,
                values = ldap_get_values(ldserver, search_result, "cn");
                if (values) {
                        if (values[0]) {
-                               safestrncpy(fullname, values[0], fullname_size);
+                               if (fullname) safestrncpy(fullname, values[0], fullname_size);
                                CtdlLogPrintf(CTDL_DEBUG, "cn = %s\n", values[0]);
                        }
                        ldap_value_free(values);
@@ -170,7 +170,7 @@ int CtdlTryUserLDAP(char *username,
                return(4);
        }
 
-       safestrncpy(found_dn, user_dn, found_dn_size);
+       if (found_dn) safestrncpy(found_dn, user_dn, found_dn_size);
        ldap_memfree(user_dn);
        return(0);
 }
index 099ca517ff90ada84ae5cd39de5d06d7acb0191d..2ea53478c22c3c7a0b285d831e2eeb4fe5f4e269 100644 (file)
@@ -547,7 +547,7 @@ int CtdlLoginExistingUser(char *authname, char *trythisname)
        
                /* LDAP auth mode */
 
-               int ldap_uid;
+               uid_t ldap_uid;
                char ldap_cn[256];
                char ldap_dn[256];
 
@@ -558,7 +558,7 @@ int CtdlLoginExistingUser(char *authname, char *trythisname)
 
                found_user = getuserbyuid(&CC->user, ldap_uid);
                if (found_user != 0) {
-                       create_user(ldap_cn, 0);
+                       create_user(trythisname, 0);
                        found_user = getuserbyuid(&CC->user, ldap_uid);
                }
 
@@ -1111,7 +1111,13 @@ int create_user(char *newusername, int become_user)
                }
        }
 
-       /* FIXME_LDAP put something here */
+#ifdef HAVE_LDAP
+       if (config.c_auth_mode == AUTHMODE_LDAP) {
+               if (CtdlTryUserLDAP(username, NULL, 0, username, sizeof username, &uid) != 0) {
+                       return(ERROR + NO_SUCH_USER);
+               }
+       }
+#endif /* HAVE_LDAP */
        
        if ((retval = internal_create_user(username, &usbuf, uid)) != 0)
                return retval;