1*bf6873c5SCy Schubert /* 2*bf6873c5SCy Schubert * Internal data types and prototypes for the fake PAM test framework. 3*bf6873c5SCy Schubert * 4*bf6873c5SCy Schubert * The canonical version of this file is maintained in the rra-c-util package, 5*bf6873c5SCy Schubert * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>. 6*bf6873c5SCy Schubert * 7*bf6873c5SCy Schubert * Written by Russ Allbery <eagle@eyrie.org> 8*bf6873c5SCy Schubert * Copyright 2021 Russ Allbery <eagle@eyrie.org> 9*bf6873c5SCy Schubert * Copyright 2011-2012 10*bf6873c5SCy Schubert * The Board of Trustees of the Leland Stanford Junior University 11*bf6873c5SCy Schubert * 12*bf6873c5SCy Schubert * Permission is hereby granted, free of charge, to any person obtaining a 13*bf6873c5SCy Schubert * copy of this software and associated documentation files (the "Software"), 14*bf6873c5SCy Schubert * to deal in the Software without restriction, including without limitation 15*bf6873c5SCy Schubert * the rights to use, copy, modify, merge, publish, distribute, sublicense, 16*bf6873c5SCy Schubert * and/or sell copies of the Software, and to permit persons to whom the 17*bf6873c5SCy Schubert * Software is furnished to do so, subject to the following conditions: 18*bf6873c5SCy Schubert * 19*bf6873c5SCy Schubert * The above copyright notice and this permission notice shall be included in 20*bf6873c5SCy Schubert * all copies or substantial portions of the Software. 21*bf6873c5SCy Schubert * 22*bf6873c5SCy Schubert * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23*bf6873c5SCy Schubert * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24*bf6873c5SCy Schubert * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25*bf6873c5SCy Schubert * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26*bf6873c5SCy Schubert * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 27*bf6873c5SCy Schubert * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28*bf6873c5SCy Schubert * DEALINGS IN THE SOFTWARE. 29*bf6873c5SCy Schubert * 30*bf6873c5SCy Schubert * SPDX-License-Identifier: MIT 31*bf6873c5SCy Schubert */ 32*bf6873c5SCy Schubert 33*bf6873c5SCy Schubert #ifndef FAKEPAM_INTERNAL_H 34*bf6873c5SCy Schubert #define FAKEPAM_INTERNAL_H 1 35*bf6873c5SCy Schubert 36*bf6873c5SCy Schubert #include <portable/pam.h> 37*bf6873c5SCy Schubert #include <sys/types.h> 38*bf6873c5SCy Schubert 39*bf6873c5SCy Schubert /* Forward declarations to avoid unnecessary includes. */ 40*bf6873c5SCy Schubert struct output; 41*bf6873c5SCy Schubert struct script_config; 42*bf6873c5SCy Schubert 43*bf6873c5SCy Schubert /* The type of a PAM module call. */ 44*bf6873c5SCy Schubert typedef int (*pam_call)(pam_handle_t *, int, int, const char **); 45*bf6873c5SCy Schubert 46*bf6873c5SCy Schubert /* The possible PAM groups as element numbers in an array of options. */ 47*bf6873c5SCy Schubert enum group_type 48*bf6873c5SCy Schubert { 49*bf6873c5SCy Schubert GROUP_ACCOUNT = 0, 50*bf6873c5SCy Schubert GROUP_AUTH = 1, 51*bf6873c5SCy Schubert GROUP_PASSWORD = 2, 52*bf6873c5SCy Schubert GROUP_SESSION = 3, 53*bf6873c5SCy Schubert }; 54*bf6873c5SCy Schubert 55*bf6873c5SCy Schubert /* Holds a PAM argc and argv. */ 56*bf6873c5SCy Schubert struct options { 57*bf6873c5SCy Schubert char **argv; 58*bf6873c5SCy Schubert int argc; 59*bf6873c5SCy Schubert }; 60*bf6873c5SCy Schubert 61*bf6873c5SCy Schubert /* 62*bf6873c5SCy Schubert * Holds a linked list of actions: a PAM call that should return some 63*bf6873c5SCy Schubert * status. 64*bf6873c5SCy Schubert */ 65*bf6873c5SCy Schubert struct action { 66*bf6873c5SCy Schubert char *name; 67*bf6873c5SCy Schubert pam_call call; 68*bf6873c5SCy Schubert int flags; 69*bf6873c5SCy Schubert enum group_type group; 70*bf6873c5SCy Schubert int status; 71*bf6873c5SCy Schubert struct action *next; 72*bf6873c5SCy Schubert }; 73*bf6873c5SCy Schubert 74*bf6873c5SCy Schubert /* Holds an expected PAM prompt style, the prompt, and the response. */ 75*bf6873c5SCy Schubert struct prompt { 76*bf6873c5SCy Schubert int style; 77*bf6873c5SCy Schubert char *prompt; 78*bf6873c5SCy Schubert char *response; 79*bf6873c5SCy Schubert }; 80*bf6873c5SCy Schubert 81*bf6873c5SCy Schubert /* Holds an array of PAM prompts and the current index into that array. */ 82*bf6873c5SCy Schubert struct prompts { 83*bf6873c5SCy Schubert struct prompt *prompts; 84*bf6873c5SCy Schubert size_t size; 85*bf6873c5SCy Schubert size_t allocated; 86*bf6873c5SCy Schubert size_t current; 87*bf6873c5SCy Schubert }; 88*bf6873c5SCy Schubert 89*bf6873c5SCy Schubert /* 90*bf6873c5SCy Schubert * Holds the complete set of things that we should do, configuration for them, 91*bf6873c5SCy Schubert * and expected output and return values. 92*bf6873c5SCy Schubert */ 93*bf6873c5SCy Schubert struct work { 94*bf6873c5SCy Schubert struct options options[4]; 95*bf6873c5SCy Schubert struct action *actions; 96*bf6873c5SCy Schubert struct prompts *prompts; 97*bf6873c5SCy Schubert struct output *output; 98*bf6873c5SCy Schubert int end_flags; 99*bf6873c5SCy Schubert }; 100*bf6873c5SCy Schubert 101*bf6873c5SCy Schubert BEGIN_DECLS 102*bf6873c5SCy Schubert 103*bf6873c5SCy Schubert 104*bf6873c5SCy Schubert /* Create a new output struct. */ 105*bf6873c5SCy Schubert struct output *output_new(void); 106*bf6873c5SCy Schubert 107*bf6873c5SCy Schubert /* Add a new output line (with numeric priority) to an output struct. */ 108*bf6873c5SCy Schubert void output_add(struct output *, int, const char *); 109*bf6873c5SCy Schubert 110*bf6873c5SCy Schubert 111*bf6873c5SCy Schubert /* 112*bf6873c5SCy Schubert * Parse a PAM interaction script. Returns the total work to do as a work 113*bf6873c5SCy Schubert * struct. 114*bf6873c5SCy Schubert */ 115*bf6873c5SCy Schubert struct work *parse_script(FILE *, const struct script_config *); 116*bf6873c5SCy Schubert 117*bf6873c5SCy Schubert END_DECLS 118*bf6873c5SCy Schubert 119*bf6873c5SCy Schubert #endif /* !FAKEPAM_API_H */ 120