* LDAP auth config now read from config file
authorArt Cancro <ajc@citadel.org>
Fri, 10 Apr 2009 07:53:04 +0000 (07:53 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 10 Apr 2009 07:53:04 +0000 (07:53 +0000)
citadel/citadel_ldap.h
citadel/ldap.c

index aff1a363f237f1263da3f4116664ea875f2f9149..41cae48ea1f203a7dd8d883af4e298d3596f9967 100644 (file)
@@ -1,12 +1,7 @@
 /*
- * 
+ * Configuration for LDAP authentication.  Most of this stuff gets pulled out of our site config file.
  */
 
-#define CTDL_LDAP_HOST "ldaptest.xand.com"
-#define CTDL_LDAP_PORT LDAP_PORT               /* defined as 389 */
-#define BASE_DN                "dc=xand,dc=com"
-#define BIND_DN                NULL                    /* "cn=Manager,dc=xand,dc=com" for authenticated bind */
-#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, uid_t *found_uid);
index 7a59747b3440b1847f7cb1a4fead89d2646ddc37..06f894f7dab3fcb5f1c8b17ec0040afeb1e86972 100644 (file)
@@ -75,17 +75,22 @@ int CtdlTryUserLDAP(char *username,
 
        if (fullname) safestrncpy(fullname, username, fullname_size);
 
-       ldserver = ldap_init(CTDL_LDAP_HOST, CTDL_LDAP_PORT);
+       ldserver = ldap_init(config.c_ldap_host, config.c_ldap_port);
        if (ldserver == NULL) {
                CtdlLogPrintf(CTDL_ALERT, "LDAP: Could not connect to %s:%d : %s\n",
-                       CTDL_LDAP_HOST, CTDL_LDAP_PORT,
+                       config.c_ldap_host, config.c_ldap_port,
                        strerror(errno));
                return(errno);
        }
 
        ldap_set_option(ldserver, LDAP_OPT_PROTOCOL_VERSION, &ldap_version);
 
-       i = ldap_simple_bind_s(ldserver, BIND_DN, BIND_PW);
+       striplt(config.c_ldap_bind_dn);
+       striplt(config.c_ldap_bind_pw);
+       i = ldap_simple_bind_s(ldserver,
+               (!IsEmptyStr(config.c_ldap_bind_dn) ? config.c_ldap_bind_dn : NULL),
+               (!IsEmptyStr(config.c_ldap_bind_pw) ? config.c_ldap_bind_pw : NULL)
+       );
        if (i != LDAP_SUCCESS) {
                CtdlLogPrintf(CTDL_ALERT, "LDAP: Cannot bind: %s (%d)\n", ldap_err2string(i), i);
                return(i);
@@ -97,7 +102,7 @@ int CtdlTryUserLDAP(char *username,
        sprintf(searchstring, SEARCH_STRING, username);
 
        i = ldap_search_st(ldserver,
-               BASE_DN,
+               config.c_ldap_base_dn,
                LDAP_SCOPE_SUBTREE,
                searchstring,
                NULL,   // return all attributes
@@ -181,7 +186,7 @@ int CtdlTryPasswordLDAP(char *user_dn, char *password)
        LDAP *ldserver = NULL;
        int i = (-1);
 
-       ldserver = ldap_init(CTDL_LDAP_HOST, CTDL_LDAP_PORT);
+       ldserver = ldap_init(config.c_ldap_host, config.c_ldap_port);
        if (ldserver) {
                ldap_set_option(ldserver, LDAP_OPT_PROTOCOL_VERSION, &ldap_version);
                i = ldap_simple_bind_s(ldserver, user_dn, password);