/*
- *
+ * 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);
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);
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
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);