1*bf6873c5SCy Schubert /* 2*bf6873c5SCy Schubert * Testing interfaces to the fake PAM library. 3*bf6873c5SCy Schubert * 4*bf6873c5SCy Schubert * This header defines the interfaces to the fake PAM library that are used by 5*bf6873c5SCy Schubert * test code to initialize the library and recover test data from it. We 6*bf6873c5SCy Schubert * don't define any interface that we're going to duplicate from the main PAM 7*bf6873c5SCy Schubert * API. 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 2010-2012 14*bf6873c5SCy Schubert * The Board of Trustees of the Leland Stanford Junior University 15*bf6873c5SCy Schubert * 16*bf6873c5SCy Schubert * Permission is hereby granted, free of charge, to any person obtaining a 17*bf6873c5SCy Schubert * copy of this software and associated documentation files (the "Software"), 18*bf6873c5SCy Schubert * to deal in the Software without restriction, including without limitation 19*bf6873c5SCy Schubert * the rights to use, copy, modify, merge, publish, distribute, sublicense, 20*bf6873c5SCy Schubert * and/or sell copies of the Software, and to permit persons to whom the 21*bf6873c5SCy Schubert * Software is furnished to do so, subject to the following conditions: 22*bf6873c5SCy Schubert * 23*bf6873c5SCy Schubert * The above copyright notice and this permission notice shall be included in 24*bf6873c5SCy Schubert * all copies or substantial portions of the Software. 25*bf6873c5SCy Schubert * 26*bf6873c5SCy Schubert * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27*bf6873c5SCy Schubert * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28*bf6873c5SCy Schubert * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 29*bf6873c5SCy Schubert * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30*bf6873c5SCy Schubert * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 31*bf6873c5SCy Schubert * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 32*bf6873c5SCy Schubert * DEALINGS IN THE SOFTWARE. 33*bf6873c5SCy Schubert * 34*bf6873c5SCy Schubert * SPDX-License-Identifier: MIT 35*bf6873c5SCy Schubert */ 36*bf6873c5SCy Schubert 37*bf6873c5SCy Schubert #ifndef FAKEPAM_PAM_H 38*bf6873c5SCy Schubert #define FAKEPAM_PAM_H 1 39*bf6873c5SCy Schubert 40*bf6873c5SCy Schubert #include <config.h> 41*bf6873c5SCy Schubert #include <portable/macros.h> 42*bf6873c5SCy Schubert #include <portable/pam.h> 43*bf6873c5SCy Schubert 44*bf6873c5SCy Schubert /* Used inside the fake PAM library to hold data items. */ 45*bf6873c5SCy Schubert struct fakepam_data { 46*bf6873c5SCy Schubert char *name; 47*bf6873c5SCy Schubert void *data; 48*bf6873c5SCy Schubert void (*cleanup)(pam_handle_t *, void *, int); 49*bf6873c5SCy Schubert struct fakepam_data *next; 50*bf6873c5SCy Schubert }; 51*bf6873c5SCy Schubert 52*bf6873c5SCy Schubert /* This is an opaque data structure, so we can put whatever we want in it. */ 53*bf6873c5SCy Schubert struct pam_handle { 54*bf6873c5SCy Schubert const char *service; 55*bf6873c5SCy Schubert const char *user; 56*bf6873c5SCy Schubert char *authtok; 57*bf6873c5SCy Schubert char *oldauthtok; 58*bf6873c5SCy Schubert char *rhost; 59*bf6873c5SCy Schubert char *ruser; 60*bf6873c5SCy Schubert char *tty; 61*bf6873c5SCy Schubert const struct pam_conv *conversation; 62*bf6873c5SCy Schubert char **environ; 63*bf6873c5SCy Schubert struct fakepam_data *data; 64*bf6873c5SCy Schubert struct passwd *pwd; 65*bf6873c5SCy Schubert }; 66*bf6873c5SCy Schubert 67*bf6873c5SCy Schubert /* 68*bf6873c5SCy Schubert * Used to accumulate output from the PAM module. Each call to a logging 69*bf6873c5SCy Schubert * function will result in an additional line added to the array, and count 70*bf6873c5SCy Schubert * will hold the total. 71*bf6873c5SCy Schubert */ 72*bf6873c5SCy Schubert struct output { 73*bf6873c5SCy Schubert size_t count; 74*bf6873c5SCy Schubert size_t allocated; 75*bf6873c5SCy Schubert struct { 76*bf6873c5SCy Schubert int priority; 77*bf6873c5SCy Schubert char *line; 78*bf6873c5SCy Schubert } * lines; 79*bf6873c5SCy Schubert }; 80*bf6873c5SCy Schubert 81*bf6873c5SCy Schubert BEGIN_DECLS 82*bf6873c5SCy Schubert 83*bf6873c5SCy Schubert /* 84*bf6873c5SCy Schubert * Sets the struct passwd returned by getpwnam calls. The last struct passed 85*bf6873c5SCy Schubert * to this function will be returned provided the pw_name matches. 86*bf6873c5SCy Schubert */ 87*bf6873c5SCy Schubert void pam_set_pwd(struct passwd *pwd); 88*bf6873c5SCy Schubert 89*bf6873c5SCy Schubert /* 90*bf6873c5SCy Schubert * Returns the accumulated messages logged with pam_syslog or pam_vsyslog 91*bf6873c5SCy Schubert * since the last call to pam_output and then clears the output. Returns 92*bf6873c5SCy Schubert * newly allocated memory that the caller is responsible for freeing with 93*bf6873c5SCy Schubert * pam_output_free, or NULL if no output has been logged since the last call 94*bf6873c5SCy Schubert * or since startup. 95*bf6873c5SCy Schubert */ 96*bf6873c5SCy Schubert struct output *pam_output(void); 97*bf6873c5SCy Schubert void pam_output_free(struct output *); 98*bf6873c5SCy Schubert 99*bf6873c5SCy Schubert END_DECLS 100*bf6873c5SCy Schubert 101*bf6873c5SCy Schubert #endif /* !FAKEPAM_API_H */ 102