/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* tests/plugorder.c - Test harness to display the order of loaded plugins */2/*3* Copyright (C) 2013 by the Massachusetts Institute of Technology.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9*10* * Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12*13* * Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in15* the documentation and/or other materials provided with the16* distribution.17*18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS21* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE22* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,23* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES24* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR25* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,27* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)28* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED29* OF THE POSSIBILITY OF SUCH DAMAGE.30*/3132/*33* This file registers a few dummy built-in pwqual modules, then prints out the34* order of pwqual modules returned by k5_plugin_load_all. The choice of the35* pwqual interface is mostly arbitrary; it is an interface which libkrb536* itself doesn't use, for which we have a test module.37*/3839#include "k5-int.h"40#include <krb5/pwqual_plugin.h>4142static krb5_context ctx;4344static void45check(krb5_error_code code)46{47const char *errmsg;4849if (code) {50errmsg = krb5_get_error_message(ctx, code);51fprintf(stderr, "%s\n", errmsg);52krb5_free_error_message(ctx, errmsg);53exit(1);54}55}5657static krb5_error_code58blt1(krb5_context context, int maj_ver, int min_ver, krb5_plugin_vtable vtable)59{60((krb5_pwqual_vtable)vtable)->name = "blt1";61return 0;62}6364static krb5_error_code65blt2(krb5_context context, int maj_ver, int min_ver, krb5_plugin_vtable vtable)66{67((krb5_pwqual_vtable)vtable)->name = "blt2";68return 0;69}7071static krb5_error_code72blt3(krb5_context context, int maj_ver, int min_ver, krb5_plugin_vtable vtable)73{74((krb5_pwqual_vtable)vtable)->name = "blt3";75return 0;76}7778int79main(void)80{81krb5_plugin_initvt_fn *modules = NULL, *mod;82struct krb5_pwqual_vtable_st vt;8384check(krb5_init_context(&ctx));85check(k5_plugin_register(ctx, PLUGIN_INTERFACE_PWQUAL, "blt1", blt1));86check(k5_plugin_register(ctx, PLUGIN_INTERFACE_PWQUAL, "blt2", blt2));87check(k5_plugin_register(ctx, PLUGIN_INTERFACE_PWQUAL, "blt3", blt3));88check(k5_plugin_load_all(ctx, PLUGIN_INTERFACE_PWQUAL, &modules));89for (mod = modules; *mod != NULL; mod++) {90check((*mod)(ctx, 1, 1, (krb5_plugin_vtable)&vt));91printf("%s\n", vt.name);92}93k5_plugin_free_modules(ctx, modules);94return 0;95}969798