diff -r 4fd523fff13b -r 0a29110b94ec src/server/daemon/ldap_resource.c --- a/src/server/daemon/ldap_resource.c Sat Mar 11 13:57:30 2023 +0100 +++ b/src/server/daemon/ldap_resource.c Sat Mar 11 17:14:51 2023 +0100 @@ -57,26 +57,18 @@ #ifdef SOLARIS ld = ldap_init(config->hostname, config->port); - if(ld) { - ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &ldap_version); - } else { - log_ereport( - LOG_FAILURE, - "ldap_resource_create_connection failed: host: %s port: %d", - hostname, - port); - } #else char *ldap_uri = NULL; asprintf(&ldap_uri, "ldap://%s:%d", hostname, port); ld = ws_ldap_resource_create_uri_connection(ldap_uri, ldap_version); free(ldap_uri); #endif - if(!ld) { - return NULL; + + if(ld) { + ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &ldap_version); } - return NULL; + return ld; } LDAP* ws_ldap_resource_create_uri_connection( @@ -191,7 +183,7 @@ if(!ldap) { log_ereport( LOG_FAILURE, - "Resource pool %s: %s: cannot create LDAP session", + "resource pool %s: %s: cannot create LDAP session", respool->name, respool->ldap_uri ? respool->ldap_uri : respool->host); return NULL; @@ -199,8 +191,9 @@ if(respool->bind) { struct berval *server_cred; - if(ldap_resource_bind(respool, ldap, &server_cred) != LDAP_SUCCESS) { - log_ereport(LOG_FAILURE, "Resource pool %s: bind failed", respool->name); + int r = ldap_resource_bind(respool, ldap, &server_cred); + if(r != LDAP_SUCCESS) { + log_ereport(LOG_FAILURE, "resource pool %s: bind failed: %s", respool->name, ldap_err2string(r)); ws_ldap_close(ldap); return NULL; } @@ -244,16 +237,20 @@ if(!respool->binddn) { return -1; } - + return ws_ldap_bind(ldap, respool->binddn, respool->bindpw, server_cred); +} + +int ws_ldap_bind(LDAP *ldap, const char *binddn, const char *bindpw, struct berval **server_cred) { struct berval cred; - cred.bv_val = respool->bindpw; + cred.bv_val = (char*)bindpw; cred.bv_len = strlen(cred.bv_val); return ldap_sasl_bind_s( ldap, - respool->binddn, + binddn, LDAP_SASL_SIMPLE, &cred, NULL, NULL, server_cred); } +