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