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