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