typedef int (*CertVerifyFn_t)(void *cert, LDAP *ld,
void *certmap_info, LDAPMessage *res,
LDAPMessage **entry);
LDAPU_SUCCESS
upon successful completion.LDAPU_FAILED
there is no unexpected error but cert could not be verified (probably because it was revoked).LDAPU_CERT_VERIFY_FUNCTION_FAILED
in all other cases.
ldapu_cert_to_ldap_entry()
after the search function finds one or more entries matching the certificate subject and if the value of the verifycert
property in the certmap.conf
file is on
.static int plugin_verify_fn (void *cert, LDAP *ld, void *certmap_info,
LDAPMessage *res, LDAPMessage **entry_out)
{
LDAPMessage *entry;
struct berval **bvals;
char *cert_attr = "userCertificate;binary";
int i, count = 0;
int rv;
*entry_out = 0;
/* Count and print the number of entries found (just to see how well the search function worked) */
count = ldap_count_entries( ld, res );
... /* Call a function to print out the count here. */ ...
/* Loop through the entries in the search results */
for (entry = ldap_first_entry(ld, res); entry != NULL;
entry = ldap_next_entry(ld, entry))
{
/* Get the values of the userCertificate;binary attribute, which should contain the user's certificate. */
if ((bvals = ldap_get_values_len(ld, entry, cert_attr)) == NULL) {
rv = LDAPU_CERT_VERIFY_FUNCTION_FAILED;
continue;
}
/* Compare the user's certificate against the certificate received by the server (plugin_cmp_certs is a function you define for comparing two certificates) */
for ( i = 0; bvals[i] != NULL; i++ ) {
rv = plugin_cmp_certs (cert, bvals[i]->bv_val,
bvals[i]->bv_len);
if (rv == LDAPU_SUCCESS) {
...
/* Log a message that you've found the entry. */
...
break;
}
}
/* Free the memory that you've allocated to get the certificate values */
ldap_value_free_len(bvals);
if (rv == LDAPU_SUCCESS) {
*entry_out = entry;
break;
}
}
return rv;
}