#include "k5-int.h"
#include "server_internal.h"
#include <krb5/pwqual_plugin.h>
struct pwqual_handle_st {
struct krb5_pwqual_vtable_st vt;
krb5_pwqual_moddata data;
};
krb5_error_code
k5_pwqual_load(krb5_context context, const char *dict_file,
pwqual_handle **handles_out)
{
krb5_error_code ret;
krb5_plugin_initvt_fn *modules = NULL, *mod;
size_t count;
pwqual_handle *list = NULL, handle = NULL;
*handles_out = NULL;
ret = k5_plugin_load_all(context, PLUGIN_INTERFACE_PWQUAL, &modules);
if (ret != 0)
goto cleanup;
for (count = 0; modules[count] != NULL; count++);
list = k5calloc(count + 1, sizeof(*list), &ret);
if (list == NULL)
goto cleanup;
count = 0;
for (mod = modules; *mod != NULL; mod++) {
handle = k5alloc(sizeof(*handle), &ret);
if (handle == NULL)
goto cleanup;
ret = (*mod)(context, 1, 1, (krb5_plugin_vtable)&handle->vt);
if (ret != 0) {
free(handle);
handle = NULL;
continue;
}
handle->data = NULL;
if (handle->vt.open != NULL) {
ret = handle->vt.open(context, dict_file, &handle->data);
if (ret != 0)
goto cleanup;
}
list[count++] = handle;
list[count] = NULL;
handle = NULL;
}
list[count] = NULL;
ret = 0;
*handles_out = list;
list = NULL;
cleanup:
free(handle);
k5_plugin_free_modules(context, modules);
k5_pwqual_free_handles(context, list);
return ret;
}
void
k5_pwqual_free_handles(krb5_context context, pwqual_handle *handles)
{
pwqual_handle *hp, handle;
if (handles == NULL)
return;
for (hp = handles; *hp != NULL; hp++) {
handle = *hp;
if (handle->vt.close != NULL)
handle->vt.close(context, handle->data);
free(handle);
}
free(handles);
}
const char *
k5_pwqual_name(krb5_context context, pwqual_handle handle)
{
return handle->vt.name;
}
krb5_error_code
k5_pwqual_check(krb5_context context, pwqual_handle handle,
const char *password, const char *policy_name,
krb5_principal princ)
{
return handle->vt.check(context, handle->data, password, policy_name,
princ, NULL);
}