1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/kadm5/srv/pwqual.c */
4 * Copyright (C) 2010 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
29 * Consumer interface for password quality plugins.
33 #include "server_internal.h"
34 #include <krb5/pwqual_plugin.h>
36 struct pwqual_handle_st {
37 struct krb5_pwqual_vtable_st vt;
38 krb5_pwqual_moddata data;
42 k5_pwqual_load(krb5_context context, const char *dict_file,
43 pwqual_handle **handles_out)
46 krb5_plugin_initvt_fn *modules = NULL, *mod;
48 pwqual_handle *list = NULL, handle = NULL;
52 ret = k5_plugin_load_all(context, PLUGIN_INTERFACE_PWQUAL, &modules);
56 /* Allocate a large enough list of handles. */
57 for (count = 0; modules[count] != NULL; count++);
58 list = k5calloc(count + 1, sizeof(*list), &ret);
62 /* For each module, allocate a handle, initialize its vtable, and bind the
63 * dictionary filename. */
65 for (mod = modules; *mod != NULL; mod++) {
66 handle = k5alloc(sizeof(*handle), &ret);
69 ret = (*mod)(context, 1, 1, (krb5_plugin_vtable)&handle->vt);
70 if (ret != 0) { /* Failed vtable init is non-fatal. */
76 if (handle->vt.open != NULL) {
77 ret = handle->vt.open(context, dict_file, &handle->data);
78 if (ret != 0) /* Failed dictionary binding is fatal. */
81 list[count++] = handle;
93 k5_plugin_free_modules(context, modules);
94 k5_pwqual_free_handles(context, list);
99 k5_pwqual_free_handles(krb5_context context, pwqual_handle *handles)
101 pwqual_handle *hp, handle;
105 for (hp = handles; *hp != NULL; hp++) {
107 if (handle->vt.close != NULL)
108 handle->vt.close(context, handle->data);
115 k5_pwqual_name(krb5_context context, pwqual_handle handle)
117 return handle->vt.name;
121 k5_pwqual_check(krb5_context context, pwqual_handle handle,
122 const char *password, const char *policy_name,
123 krb5_principal princ)
125 return handle->vt.check(context, handle->data, password, policy_name,