windc: update test windc plugin to use new load SPI
[metze/heimdal/wip.git] / tests / plugin / windc.c
1 #include <string.h>
2 #include <krb5.h>
3 #include <hdb.h>
4 #include <kdc.h>
5 #include <windc_plugin.h>
6
7 static krb5_error_code
8 windc_init(krb5_context context, void **ctx)
9 {
10     krb5_warnx(context, "windc init");
11     *ctx = NULL;
12     return 0;
13 }
14
15 static void
16 windc_fini(void *ctx)
17 {
18 }
19
20 static krb5_error_code
21 pac_generate(void *ctx, krb5_context context,
22              struct hdb_entry_ex *client, krb5_pac *pac)
23 {
24     krb5_error_code ret;
25     krb5_data data;
26
27     krb5_warnx(context, "pac generate");
28
29     data.data = "\x00\x01";
30     data.length = 2;
31
32     ret = krb5_pac_init(context, pac);
33     if (ret)
34         return ret;
35
36     ret = krb5_pac_add_buffer(context, *pac, 1, &data);
37     if (ret)
38         return ret;
39
40     return 0;
41 }
42
43 static krb5_error_code
44 pac_verify(void *ctx, krb5_context context,
45            const krb5_principal new_ticket_client,
46            const krb5_principal delegation_proxy,
47            struct hdb_entry_ex * client,
48            struct hdb_entry_ex * server,
49            struct hdb_entry_ex * krbtgt,
50            krb5_pac *pac)
51 {
52     krb5_error_code ret;
53     krb5_data data;
54
55     krb5_warnx(context, "pac_verify");
56
57     ret = krb5_pac_get_buffer(context, *pac, 1, &data);
58     if (ret)
59         return ret;
60
61     krb5_data_free(&data);
62
63     return 0;
64 }
65
66 static krb5_error_code
67 client_access(void *ctx,
68               krb5_context context,
69               krb5_kdc_configuration *config,
70               hdb_entry_ex *client, const char *client_name,
71               hdb_entry_ex *server, const char *server_name,
72               KDC_REQ *req,
73               METHOD_DATA *data)
74 {
75     krb5_warnx(context, "client_access");
76     return 0;
77 }
78
79 static krb5plugin_windc_ftable windc = {
80     KRB5_WINDC_PLUGING_MINOR,
81     windc_init,
82     windc_fini,
83     pac_generate,
84     pac_verify,
85     client_access
86 };
87
88 static const krb5plugin_windc_ftable *const windc_plugins[] = {
89     &windc
90 };
91
92 krb5_error_code
93 windc_plugin_load(krb5_context context,
94                        krb5_get_instance_func_t *get_instance,
95                        size_t *num_plugins,
96                        const krb5plugin_windc_ftable *const **plugins);
97
98 static uintptr_t
99 windc_get_instance(const char *libname)
100 {
101     if (strcmp(libname, "kdc") == 0)
102         return kdc_get_instance(libname);
103     else if (strcmp(libname, "hdb") == 0)
104         return hdb_get_instance(libname);
105     else if (strcmp(libname, "krb5") == 0)
106         return krb5_get_instance(libname);
107
108     return 0;
109 }
110
111 krb5_error_code
112 windc_plugin_load(krb5_context context,
113                   krb5_get_instance_func_t *get_instance,
114                   size_t *num_plugins,
115                   const krb5plugin_windc_ftable *const **plugins)
116 {
117     *get_instance = windc_get_instance;
118     *num_plugins = sizeof(windc_plugins) / sizeof(windc_plugins[0]);
119     *plugins = windc_plugins;
120
121     return 0;
122 }