Browse Source

* fix handling search results

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

31
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 {
snprintf(config->error, sizeof(config->error), "can't get DN of found user"); if (ldap_msgtype(msg) != LDAP_RES_SEARCH_RESULT)
goto cleanup; continue;
}
if (oal_connect(&ald, config, udn, password) == 0) { if ((udn = ldap_get_dn(sld, msg)) == NULL || strlen(udn) == 0) {
rc = 1; snprintf(config->error, sizeof(config->error), "can't get DN of found user");
ldap_unbind(ald); continue;
goto cleanup; }
} else {
rc = 0; if (oal_connect(&ald, config, udn, password) == 0) {
} rc = 1;
ldap_unbind(ald);
break; /* success */
} else {
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