Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/tests/plugorder.c
34878 views
1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
/* tests/plugorder.c - Test harness to display the order of loaded plugins */
3
/*
4
* Copyright (C) 2013 by the Massachusetts Institute of Technology.
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
*
11
* * Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
*
14
* * Redistributions in binary form must reproduce the above copyright
15
* notice, this list of conditions and the following disclaimer in
16
* the documentation and/or other materials provided with the
17
* distribution.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30
* OF THE POSSIBILITY OF SUCH DAMAGE.
31
*/
32
33
/*
34
* This file registers a few dummy built-in pwqual modules, then prints out the
35
* order of pwqual modules returned by k5_plugin_load_all. The choice of the
36
* pwqual interface is mostly arbitrary; it is an interface which libkrb5
37
* itself doesn't use, for which we have a test module.
38
*/
39
40
#include "k5-int.h"
41
#include <krb5/pwqual_plugin.h>
42
43
static krb5_context ctx;
44
45
static void
46
check(krb5_error_code code)
47
{
48
const char *errmsg;
49
50
if (code) {
51
errmsg = krb5_get_error_message(ctx, code);
52
fprintf(stderr, "%s\n", errmsg);
53
krb5_free_error_message(ctx, errmsg);
54
exit(1);
55
}
56
}
57
58
static krb5_error_code
59
blt1(krb5_context context, int maj_ver, int min_ver, krb5_plugin_vtable vtable)
60
{
61
((krb5_pwqual_vtable)vtable)->name = "blt1";
62
return 0;
63
}
64
65
static krb5_error_code
66
blt2(krb5_context context, int maj_ver, int min_ver, krb5_plugin_vtable vtable)
67
{
68
((krb5_pwqual_vtable)vtable)->name = "blt2";
69
return 0;
70
}
71
72
static krb5_error_code
73
blt3(krb5_context context, int maj_ver, int min_ver, krb5_plugin_vtable vtable)
74
{
75
((krb5_pwqual_vtable)vtable)->name = "blt3";
76
return 0;
77
}
78
79
int
80
main(void)
81
{
82
krb5_plugin_initvt_fn *modules = NULL, *mod;
83
struct krb5_pwqual_vtable_st vt;
84
85
check(krb5_init_context(&ctx));
86
check(k5_plugin_register(ctx, PLUGIN_INTERFACE_PWQUAL, "blt1", blt1));
87
check(k5_plugin_register(ctx, PLUGIN_INTERFACE_PWQUAL, "blt2", blt2));
88
check(k5_plugin_register(ctx, PLUGIN_INTERFACE_PWQUAL, "blt3", blt3));
89
check(k5_plugin_load_all(ctx, PLUGIN_INTERFACE_PWQUAL, &modules));
90
for (mod = modules; *mod != NULL; mod++) {
91
check((*mod)(ctx, 1, 1, (krb5_plugin_vtable)&vt));
92
printf("%s\n", vt.name);
93
}
94
k5_plugin_free_modules(ctx, modules);
95
return 0;
96
}
97
98