Path: blob/main/crypto/krb5/src/plugins/kadm5_hook/test/main.c
34890 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* plugins/kadm5_hook/test/main.c */2/*3* Copyright (C) 2010 by the Massachusetts Institute of Technology.4* All rights reserved.5*6* Export of this software from the United States of America may7* require a specific license from the United States Government.8* It is the responsibility of any person or organization contemplating9* export to obtain such a license before exporting.10*11* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and12* distribute this software and its documentation for any purpose and13* without fee is hereby granted, provided that the above copyright14* notice appear in all copies and that both that copyright notice and15* this permission notice appear in supporting documentation, and that16* the name of M.I.T. not be used in advertising or publicity pertaining17* to distribution of the software without specific, written prior18* permission. Furthermore if you modify this software you must label19* your software as modified software and not distribute it in such a20* fashion that it might be confused with the original M.I.T. software.21* M.I.T. makes no representations about the suitability of22* this software for any purpose. It is provided "as is" without express23* or implied warranty.24*/2526/**27* @file plugins/kadm5_hook/test/main.c28*29* This is a test kadm5_hook plugin. If enabled, it will print when kadm5_hook30* calls are made.31*/3233#include <krb5/krb5.h>34#include <krb5/kadm5_hook_plugin.h>35#include <stdio.h>36#include <assert.h>3738static void39log_call(krb5_context context,40const char *function,41int stage,42krb5_principal princ)43{44char *unparsed = NULL;45krb5_error_code ret;46ret = krb5_unparse_name(context, princ, &unparsed);47assert(ret == 0);48printf("%s: stage %s principal %s\n",49function,50(stage == KADM5_HOOK_STAGE_PRECOMMIT) ? "precommit" : "postcommit",51unparsed);52if (unparsed)53krb5_free_unparsed_name(context, unparsed);54}5556static kadm5_ret_t57chpass(krb5_context context,58kadm5_hook_modinfo *modinfo,59int stage,60krb5_principal princ, krb5_boolean keepold,61int n_ks_tuple,62krb5_key_salt_tuple *ks_tuple,63const char *newpass)64{65log_call(context, "chpass", stage, princ);66return 0;67}686970static kadm5_ret_t71create(krb5_context context,72kadm5_hook_modinfo *modinfo,73int stage,74kadm5_principal_ent_t princ, long mask,75int n_ks_tuple,76krb5_key_salt_tuple *ks_tuple,77const char *newpass)78{79log_call(context, "create", stage, princ->principal);80return 0;81}8283static kadm5_ret_t84rename_hook(krb5_context context, kadm5_hook_modinfo *modinfo, int stage,85krb5_principal oprinc, krb5_principal nprinc)86{87log_call(context, "rename", stage, oprinc);88return 0;89}9091krb5_error_code92kadm5_hook_test_initvt(krb5_context context, int maj_ver, int min_ver,93krb5_plugin_vtable vtable);9495krb5_error_code96kadm5_hook_test_initvt(krb5_context context, int maj_ver, int min_ver,97krb5_plugin_vtable vtable)98{99kadm5_hook_vftable_1 *vt = (kadm5_hook_vftable_1 *) vtable;100if (maj_ver != 1)101return KRB5_PLUGIN_VER_NOTSUPP;102103vt->name = "test";104vt->chpass = chpass;105vt->create = create;106vt->rename = rename_hook;107return 0;108}109110111