2 * Copyright (c) 2015 Andreas Schneider <asn@samba.org>
3 * Copyright (c) 2015 Jakub Hrozek <jakub.hrozek@posteo.se>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef __LIBPAMTEST_H_
20 #define __LIBPAMTEST_H_
23 #include <security/pam_appl.h>
27 /* These operations correspond to libpam ops */
32 PAMTEST_CLOSE_SESSION,
35 /* These operation affect test output */
36 PAMTEST_GETENVLIST, /* Call pam_getenvlist. */
37 PAMTEST_KEEPHANDLE, /* Don't call pam_end() but return handle */
39 /* The two below can't be set by API user, but are useful if pam_start()
40 * or pam_end() fails and the API user wants to find out what happened
41 * with pamtest_failed_case()
51 enum pamtest_ops pam_operation; /* The pam operation to run */
52 int expected_rv; /* What we expect the op to return */
53 int flags; /* Extra flags to pass to the op */
55 int op_rv; /* What the op really returns */
58 char **envlist; /* output of PAMTEST_ENVLIST */
59 pam_handle_t *ph; /* output of PAMTEST_KEEPHANDLE */
60 } case_out; /* depends on pam_operation, mostly unused */
63 #define PAMTEST_CASE_INIT 0, 0, { .envlist = NULL }
64 #define PAMTEST_CASE_SENTINEL PAMTEST_SENTINEL, 0, PAMTEST_CASE_INIT
67 PAMTEST_ERR_OK, /* Testcases returns correspond with input */
68 PAMTEST_ERR_START, /* pam_start() failed */
69 PAMTEST_ERR_CASE, /* A testcase failed. Use pamtest_failed_case */
70 PAMTEST_ERR_OP, /* Could not run a test case */
71 PAMTEST_ERR_END, /* pam_end failed */
72 PAMTEST_ERR_KEEPHANDLE, /* Handled internally */
73 PAMTEST_ERR_INTERNAL, /* Internal error - bad input or similar */
76 typedef int (*pam_conv_fn)(int num_msg,
77 const struct pam_message **msg,
78 struct pam_response **resp,
81 enum pamtest_err pamtest_ex(const char *service,
85 struct pamtest_case *test_cases);
87 void pamtest_free_env(char **envlist);
89 const struct pamtest_case *pamtest_failed_case(struct pamtest_case *test_cases);
91 struct pamtest_conv_data {
92 const char **in_echo_off;
93 const char **in_echo_on;
99 enum pamtest_err pamtest(const char *service,
101 struct pamtest_conv_data *conv_data,
102 struct pamtest_case *test_cases);
104 #endif /* __LIBPAMTEST_H_ */