xref: /freebsd/crypto/krb5/src/plugins/kadm5_hook/test/main.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* plugins/kadm5_hook/test/main.c */
3 /*
4  * Copyright (C) 2010 by the Massachusetts Institute of Technology.
5  * All rights reserved.
6  *
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.
11  *
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.
25  */
26 
27 /**
28  * @file plugins/kadm5_hook/test/main.c
29  *
30  * This is a test kadm5_hook plugin. If enabled, it will print when kadm5_hook
31  * calls are made.
32  */
33 
34 #include <krb5/krb5.h>
35 #include <krb5/kadm5_hook_plugin.h>
36 #include <stdio.h>
37 #include <assert.h>
38 
39 static void
log_call(krb5_context context,const char * function,int stage,krb5_principal princ)40 log_call(krb5_context context,
41          const char *function,
42          int stage,
43          krb5_principal princ)
44 {
45     char *unparsed = NULL;
46     krb5_error_code ret;
47     ret = krb5_unparse_name(context, princ, &unparsed);
48     assert(ret == 0);
49     printf("%s: stage %s principal %s\n",
50            function,
51            (stage == KADM5_HOOK_STAGE_PRECOMMIT) ? "precommit" : "postcommit",
52            unparsed);
53     if (unparsed)
54         krb5_free_unparsed_name(context, unparsed);
55 }
56 
57 static kadm5_ret_t
chpass(krb5_context context,kadm5_hook_modinfo * modinfo,int stage,krb5_principal princ,krb5_boolean keepold,int n_ks_tuple,krb5_key_salt_tuple * ks_tuple,const char * newpass)58 chpass(krb5_context context,
59        kadm5_hook_modinfo *modinfo,
60        int stage,
61        krb5_principal princ, krb5_boolean keepold,
62        int n_ks_tuple,
63        krb5_key_salt_tuple *ks_tuple,
64        const char *newpass)
65 {
66     log_call(context, "chpass", stage, princ);
67     return 0;
68 }
69 
70 
71 static kadm5_ret_t
create(krb5_context context,kadm5_hook_modinfo * modinfo,int stage,kadm5_principal_ent_t princ,long mask,int n_ks_tuple,krb5_key_salt_tuple * ks_tuple,const char * newpass)72 create(krb5_context context,
73        kadm5_hook_modinfo *modinfo,
74        int stage,
75        kadm5_principal_ent_t princ, long mask,
76        int n_ks_tuple,
77        krb5_key_salt_tuple *ks_tuple,
78        const char *newpass)
79 {
80     log_call(context, "create", stage, princ->principal);
81     return 0;
82 }
83 
84 static kadm5_ret_t
rename_hook(krb5_context context,kadm5_hook_modinfo * modinfo,int stage,krb5_principal oprinc,krb5_principal nprinc)85 rename_hook(krb5_context context, kadm5_hook_modinfo *modinfo, int stage,
86             krb5_principal oprinc, krb5_principal nprinc)
87 {
88     log_call(context, "rename", stage, oprinc);
89     return 0;
90 }
91 
92 krb5_error_code
93 kadm5_hook_test_initvt(krb5_context context, int maj_ver, int min_ver,
94                        krb5_plugin_vtable vtable);
95 
96 krb5_error_code
kadm5_hook_test_initvt(krb5_context context,int maj_ver,int min_ver,krb5_plugin_vtable vtable)97 kadm5_hook_test_initvt(krb5_context context, int maj_ver, int min_ver,
98                        krb5_plugin_vtable vtable)
99 {
100     kadm5_hook_vftable_1 *vt = (kadm5_hook_vftable_1 *) vtable;
101     if (maj_ver != 1)
102         return KRB5_PLUGIN_VER_NOTSUPP;
103 
104     vt->name = "test";
105     vt->chpass = chpass;
106     vt->create = create;
107     vt->rename = rename_hook;
108     return 0;
109 }
110