/* Set LDAP version to 3 and set connection timeout. */ ldap_set_option (NULL, LDAP_OPT_PROTOCOL_VERSION, &version); ldap_set_option (NULL, LDAP_OPT_NETWORK_TIMEOUT, &timeOut);
/* Bind to the server */ rc = ldap_simple_bind_s (ld, loginDN, password); if (rc != LDAP_SUCCESS) { printf ("ldap_simple_bind_s: %s\n", ldap_err2string (rc)); ldap_unbind_s (ld); return (1); } printf ("\n\tBind successful\n");
/* * Compare the test password with the userPassword attribute * of the object. */ rc = ldap_compare_s (ld, /* LDAP session handle */ objectDN, /* the object to verify password on */ "userPassword", /* attribute to compare */ testPassword); /* the password to verify */
if (rc == LDAP_COMPARE_TRUE) printf ("\n\tThe password is correct.\n"); else if (rc == LDAP_COMPARE_FALSE) printf ("\n\tThe password is not correct.\n"); else { printf ("\n\tldap_compare_s: %s\n", ldap_err2string (rc)); ldap_unbind_s (ld); return (1); }