2 * Test for the MIT Kerberos shared module API.
4 * Written by Russ Allbery <rra@stanford.edu>
6 * The Board of Trustees of the Leland Stanford Junior University
8 * See LICENSE for licensing terms.
12 #include <portable/system.h>
18 /* Allow for a build without the plugin header. */
19 # ifdef HAVE_KRB5_PWCHECK_PLUGIN_H
20 # include <krb5/pwcheck_plugin.h>
22 typedef struct krb5plugin_kadmin_pwcheck_ftable_v0 {
24 krb5_error_code (*init)(krb5_context, void **);
25 void (*fini)(krb5_context, void *);
26 int (*check)(krb5_context, void *, krb5_const_principal,
27 const krb5_data *password);
28 } krb5plugin_kadmin_pwcheck_ftable_v0;
29 # endif /* !HAVE_KRB5_PWCHECK_PLUGIN_H */
33 * Expects a principal and a password to check on the command line. Loads the
34 * MIT Kerberos plugin, converts the input into the necessary format, calls
35 * the plugin, and reports the results. Exits with a status matching the
36 * return value of the plugin function.
38 * We assume that the plugin is available as:
40 * BUILD/../plugin/.libs/passwd_strength.so
42 * since we don't want to embed Libtool's libtldl just to run a test.
45 main(int argc, char *argv[])
53 krb5_error_code status;
55 struct krb5plugin_kadmin_pwcheck_ftable_v0 *verifier;
58 * If we're not building with MIT Kerberos, we can't run this test. Exit
59 * with a special status to communicate this to the test wrapper.
61 #ifdef HAVE_KRB5_REALM
65 /* Build the path of the plugin. */
67 fprintf(stderr, "Wrong number of arguments\n");
70 build = getenv("BUILD");
72 fprintf(stderr, "No BUILD environment variable set\n");
75 length = strlen(build) + strlen("/../plugin/.libs/passwd_strength.so");
76 path = malloc(length + 1);
78 fprintf(stderr, "Cannot allocate memory: %s\n", strerror(errno));
81 strlcpy(path, build, length + 1);
82 strlcat(path, "/../plugin/.libs/passwd_strength.so", length + 1);
84 /* Initialize the data structures. */
85 status = krb5_init_context(&ctx);
87 fprintf(stderr, "Cannot initialize Kerberos context\n");
90 status = krb5_parse_name(ctx, argv[1], &princ);
92 fprintf(stderr, "Cannot parse principal name\n");
95 password.length = strlen(argv[2]);
96 password.data = argv[2];
98 /* Load the module and find the correct symbol. */
99 handle = dlopen(path, RTLD_NOW);
100 if (handle == NULL) {
101 fprintf(stderr, "Cannot dlopen %s: %s\n", path, dlerror());
104 verifier = dlsym(handle, "kadmin_pwcheck_0");
105 if (verifier == NULL) {
106 fprintf(stderr, "Cannot get kadmin_pwcheck_0 symbol: %s\n", dlerror());
109 if (verifier->minor_version != 0
110 || verifier->init == NULL
111 || verifier->check == NULL
112 || verifier->fini == NULL) {
113 fprintf(stderr, "Invalid metadata in plugin\n");
116 status = verifier->init(ctx, &data);
118 fprintf(stderr, "%s\n", krb5_get_error_message(ctx, status));
121 status = verifier->check(ctx, data, princ, &password);
123 fprintf(stderr, "%s\n", krb5_get_error_message(ctx, status));
124 verifier->fini(ctx, data);