From dc3e60379e1563c55e4e4269e4011e7e1968fc5d Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 10 Apr 2009 07:44:48 +0000 Subject: [PATCH] * LDAP auth code is now complete. Config is still hardcoded, though; need to fix that. --- citadel/citadel_ldap.h | 2 +- citadel/ldap.c | 8 ++++---- citadel/user_ops.c | 12 +++++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/citadel/citadel_ldap.h b/citadel/citadel_ldap.h index e39b9e611..aff1a363f 100644 --- a/citadel/citadel_ldap.h +++ b/citadel/citadel_ldap.h @@ -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); diff --git a/citadel/ldap.c b/citadel/ldap.c index 4ece8527b..7a59747b3 100644 --- a/citadel/ldap.c +++ b/citadel/ldap.c @@ -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); } diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 099ca517f..2ea53478c 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -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; -- 2.30.2