1*bf6873c5SCy Schubert /* 2*bf6873c5SCy Schubert * PAM interaction script API. 3*bf6873c5SCy Schubert * 4*bf6873c5SCy Schubert * Provides an interface that loads a PAM interaction script from a file and 5*bf6873c5SCy Schubert * runs through that script, calling the internal PAM module functions and 6*bf6873c5SCy Schubert * checking their results. This allows automation of PAM testing through 7*bf6873c5SCy Schubert * external data files instead of coding everything in C. 8*bf6873c5SCy Schubert * 9*bf6873c5SCy Schubert * The canonical version of this file is maintained in the rra-c-util package, 10*bf6873c5SCy Schubert * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>. 11*bf6873c5SCy Schubert * 12*bf6873c5SCy Schubert * Written by Russ Allbery <eagle@eyrie.org> 13*bf6873c5SCy Schubert * Copyright 2016 Russ Allbery <eagle@eyrie.org> 14*bf6873c5SCy Schubert * Copyright 2011-2012 15*bf6873c5SCy Schubert * The Board of Trustees of the Leland Stanford Junior University 16*bf6873c5SCy Schubert * 17*bf6873c5SCy Schubert * Permission is hereby granted, free of charge, to any person obtaining a 18*bf6873c5SCy Schubert * copy of this software and associated documentation files (the "Software"), 19*bf6873c5SCy Schubert * to deal in the Software without restriction, including without limitation 20*bf6873c5SCy Schubert * the rights to use, copy, modify, merge, publish, distribute, sublicense, 21*bf6873c5SCy Schubert * and/or sell copies of the Software, and to permit persons to whom the 22*bf6873c5SCy Schubert * Software is furnished to do so, subject to the following conditions: 23*bf6873c5SCy Schubert * 24*bf6873c5SCy Schubert * The above copyright notice and this permission notice shall be included in 25*bf6873c5SCy Schubert * all copies or substantial portions of the Software. 26*bf6873c5SCy Schubert * 27*bf6873c5SCy Schubert * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28*bf6873c5SCy Schubert * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29*bf6873c5SCy Schubert * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 30*bf6873c5SCy Schubert * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31*bf6873c5SCy Schubert * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 32*bf6873c5SCy Schubert * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 33*bf6873c5SCy Schubert * DEALINGS IN THE SOFTWARE. 34*bf6873c5SCy Schubert * 35*bf6873c5SCy Schubert * SPDX-License-Identifier: MIT 36*bf6873c5SCy Schubert */ 37*bf6873c5SCy Schubert 38*bf6873c5SCy Schubert #ifndef TESTS_MODULE_SCRIPT_H 39*bf6873c5SCy Schubert #define TESTS_MODULE_SCRIPT_H 1 40*bf6873c5SCy Schubert 41*bf6873c5SCy Schubert #include <portable/pam.h> 42*bf6873c5SCy Schubert 43*bf6873c5SCy Schubert #include <tests/tap/basic.h> 44*bf6873c5SCy Schubert 45*bf6873c5SCy Schubert /* A test callback called after PAM functions are run but before pam_end. */ 46*bf6873c5SCy Schubert struct script_config; 47*bf6873c5SCy Schubert typedef void (*script_callback)(pam_handle_t *, const struct script_config *, 48*bf6873c5SCy Schubert void *); 49*bf6873c5SCy Schubert 50*bf6873c5SCy Schubert /* Configuration for the PAM interaction script API. */ 51*bf6873c5SCy Schubert struct script_config { 52*bf6873c5SCy Schubert const char *user; /* Username to pass into pam_start (%u). */ 53*bf6873c5SCy Schubert const char *password; /* Substituted for %p in prompts. */ 54*bf6873c5SCy Schubert const char *newpass; /* Substituted for %n in prompts. */ 55*bf6873c5SCy Schubert const char *extra[10]; /* Substituted for %0-%9 in logging. */ 56*bf6873c5SCy Schubert const char *authtok; /* Stored as AUTHTOK before PAM. */ 57*bf6873c5SCy Schubert const char *oldauthtok; /* Stored as OLDAUTHTOK before PAM. */ 58*bf6873c5SCy Schubert script_callback callback; /* Called after PAM, before pam_end. */ 59*bf6873c5SCy Schubert void *data; /* Passed to the callback function. */ 60*bf6873c5SCy Schubert }; 61*bf6873c5SCy Schubert 62*bf6873c5SCy Schubert BEGIN_DECLS 63*bf6873c5SCy Schubert 64*bf6873c5SCy Schubert /* 65*bf6873c5SCy Schubert * Given the file name of an interaction script (which may be a full path or 66*bf6873c5SCy Schubert * relative to C_TAP_SOURCE or C_TAP_BUILD) and configuration containing other 67*bf6873c5SCy Schubert * parameters such as the user, run that script, reporting the results via the 68*bf6873c5SCy Schubert * TAP format. 69*bf6873c5SCy Schubert */ 70*bf6873c5SCy Schubert void run_script(const char *file, const struct script_config *) 71*bf6873c5SCy Schubert __attribute__((__nonnull__)); 72*bf6873c5SCy Schubert 73*bf6873c5SCy Schubert /* 74*bf6873c5SCy Schubert * The same as run_script, but run every script found in the given directory, 75*bf6873c5SCy Schubert * skipping file names that contain characters other than alphanumerics and -. 76*bf6873c5SCy Schubert */ 77*bf6873c5SCy Schubert void run_script_dir(const char *dir, const struct script_config *) 78*bf6873c5SCy Schubert __attribute__((__nonnull__)); 79*bf6873c5SCy Schubert 80*bf6873c5SCy Schubert END_DECLS 81*bf6873c5SCy Schubert 82*bf6873c5SCy Schubert #endif /* !TESTS_MODULE_SCRIPT_H */ 83