Browse Source

* fix handling search results

master
Alex 'AdUser' Z 9 years ago
parent
commit
28c5e6c3cf
  1. 15
      src/ldapauth.c

15
src/ldapauth.c

@ -162,27 +162,32 @@ oal_check_cred(oal_config_t * const config,
goto cleanup; goto cleanup;
} }
if ((msg = ldap_first_message(sld, res)) == NULL) { if ((msg = ldap_first_entry(sld, res)) == NULL) {
snprintf(config->error, sizeof(config->error), "ldap search found something, but can't get result"); snprintf(config->error, sizeof(config->error), "ldap search found something, but can't get result");
goto cleanup; goto cleanup;
} }
if ((udn = ldap_get_dn(sld, msg)) == NULL) { do {
if (ldap_msgtype(msg) != LDAP_RES_SEARCH_RESULT)
continue;
if ((udn = ldap_get_dn(sld, msg)) == NULL || strlen(udn) == 0) {
snprintf(config->error, sizeof(config->error), "can't get DN of found user"); snprintf(config->error, sizeof(config->error), "can't get DN of found user");
goto cleanup; continue;
} }
if (oal_connect(&ald, config, udn, password) == 0) { if (oal_connect(&ald, config, udn, password) == 0) {
rc = 1; rc = 1;
ldap_unbind(ald); ldap_unbind(ald);
goto cleanup; break; /* success */
} else { } else {
rc = 0; rc = 0;
} }
ldap_memfree(udn), udn = NULL;
} while ((msg = ldap_next_message(sld, msg)) != NULL);
cleanup: cleanup:
if (res) ldap_msgfree(res); if (res) ldap_msgfree(res);
if (msg) ldap_msgfree(msg);
if (udn) ldap_memfree(udn); if (udn) ldap_memfree(udn);
if (sld) ldap_unbind(sld); if (sld) ldap_unbind(sld);
return rc; return rc;

Loading…
Cancel
Save