#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);
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;
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) {
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);
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);
}
/* LDAP auth mode */
- int ldap_uid;
+ uid_t ldap_uid;
char ldap_cn[256];
char ldap_dn[256];
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);
}
}
}
- /* 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;