pam_wrapper  1.0.2
libpamtest.h
1 /*
2  * Copyright (c) 2015 Andreas Schneider <asn@samba.org>
3  * Copyright (c) 2015 Jakub Hrozek <jakub.hrozek@posteo.se>
4  *
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.
9  *
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.
14  *
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/>.
17  */
18 
19 #ifndef __LIBPAMTEST_H_
20 #define __LIBPAMTEST_H_
21 
22 #include <stdint.h>
23 #include <security/pam_appl.h>
24 
47 
58 };
59 
60 
67 struct pam_testcase {
68  enum pamtest_ops pam_operation; /* The pam operation to run */
69  int expected_rv; /* What we expect the op to return */
70  int flags; /* Extra flags to pass to the op */
71 
72  int op_rv; /* What the op really returns */
73 
74  union {
75  char **envlist; /* output of PAMTEST_ENVLIST */
76  pam_handle_t *ph; /* output of PAMTEST_KEEPHANDLE */
77  } case_out; /* depends on pam_operation, mostly unused */
78 };
79 
81 #define pam_test(op, expected) { op, expected, 0, 0, { .envlist = NULL } }
82 
83 #define pam_test_flags(op, expected, flags) { op, expected, flags, 0, { .envlist = NULL } }
84 
103 };
104 
111 typedef int (*pam_conv_fn)(int num_msg,
112  const struct pam_message **msg,
113  struct pam_response **resp,
114  void *appdata_ptr);
115 
125  const char **in_echo_off;
130  const char **in_echo_on;
131 
135  char **out_err;
139  char **out_info;
140 };
141 
142 #ifdef DOXYGEN
143 
174 enum pamtest_err run_pamtest_conv(const char *service,
175  const char *user,
176  pam_conv_fn conv_fn,
177  void *conv_userdata,
178  struct pam_testcase test_cases[]);
179 #else
180 #define run_pamtest_conv(service, user, conv_fn, conv_data, test_cases) \
181  _pamtest_conv(service, user, conv_fn, conv_data, test_cases, sizeof(test_cases)/sizeof(test_cases[0])
182 #endif
183 
184 #ifdef DOXYGEN
185 
214 enum pamtest_err run_pamtest(const char *service,
215  const char *user,
216  struct pamtest_conv_data *conv_data,
217  struct pam_testcase test_cases[]);
218 #else
219 #define run_pamtest(service, user, conv_data, test_cases) \
220  _pamtest(service, user, conv_data, test_cases, sizeof(test_cases)/sizeof(test_cases[0]))
221 #endif
222 
223 #ifdef DOXYGEN
224 
236 const struct pam_testcase *pamtest_failed_case(struct pam_testcase *test_cases);
237 #else
238 #define pamtest_failed_case(test_cases) \
239  _pamtest_failed_case(test_cases, sizeof(test_cases) / sizeof(test_cases[0]))
240 #endif
241 
249 const char *pamtest_strerror(enum pamtest_err perr);
250 
256 void pamtest_free_env(char **envlist);
257 
258 
259 /* Internal function protypes */
260 enum pamtest_err _pamtest_conv(const char *service,
261  const char *user,
262  pam_conv_fn conv_fn,
263  void *conv_userdata,
264  struct pam_testcase test_cases[],
265  size_t num_test_cases);
266 
267 enum pamtest_err _pamtest(const char *service,
268  const char *user,
269  struct pamtest_conv_data *conv_data,
270  struct pam_testcase test_cases[],
271  size_t num_test_cases);
272 
273 const struct pam_testcase *_pamtest_failed_case(struct pam_testcase test_cases[],
274  size_t num_test_cases);
275 
278 #endif /* __LIBPAMTEST_H_ */
enum pamtest_err run_pamtest(const char *service, const char *user, struct pamtest_conv_data *conv_data, struct pam_testcase test_cases[])
Run libpamtest test cases.
Handled internally.
Definition: libpamtest.h:100
pamtest_ops
The enum which describes the operations performed by pamtest().
Definition: libpamtest.h:34
Could not run a test case.
Definition: libpamtest.h:96
pamtest_err
The return code of the pamtest function.
Definition: libpamtest.h:88
void pamtest_free_env(char **envlist)
This frees the string array returned by the PAMTEST_GETENVLIST test.
Definition: libpamtest.c:118
char ** out_err
Captures messages through PAM_TEXT_INFO.
Definition: libpamtest.h:135
enum pamtest_err run_pamtest_conv(const char *service, const char *user, pam_conv_fn conv_fn, void *conv_userdata, struct pam_testcase test_cases[])
Run libpamtest test cases.
This will prevent calling pam_end() and will just return the PAM handle in case_out.ph.
Definition: libpamtest.h:57
The PAM testcase struction.
Definition: libpamtest.h:67
Internal error - bad input or similar.
Definition: libpamtest.h:102
int(* pam_conv_fn)(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
PAM conversation function, defined in pam_conv(3)
Definition: libpamtest.h:111
const struct pam_testcase * pamtest_failed_case(struct pam_testcase *test_cases)
Helper you can call if run_pamtest() fails.
const char * pamtest_strerror(enum pamtest_err perr)
return a string representation of libpamtest error code.
Definition: libpamtest.c:148
run pam_chauthtok() to update the authentication token
Definition: libpamtest.h:46
run pam_acct_mgmt() to validate the PAM account
Definition: libpamtest.h:40
If this option is set the test will call pam_getenvlist() and copy the environment into case_out...
Definition: libpamtest.h:52
This structure should be used when using run_pamtest, which uses an internal conversation function...
Definition: libpamtest.h:120
run pam_authenticate to authenticate the account
Definition: libpamtest.h:36
run pam_setcred() to establish/delete user credentials
Definition: libpamtest.h:38
Testcases returns correspond with input.
Definition: libpamtest.h:90
pam_start() failed
Definition: libpamtest.h:92
const char ** in_echo_on
When the conversation function receives PAM_PROMPT_ECHO_ON, it reads the input from the in_echo_off a...
Definition: libpamtest.h:130
run pam_open_session() to start a PAM session
Definition: libpamtest.h:42
char ** out_info
Captures messages through PAM_ERROR_MSG.
Definition: libpamtest.h:139
const char ** in_echo_off
When the conversation function receives PAM_PROMPT_ECHO_OFF, it reads the auth token from the in_echo...
Definition: libpamtest.h:125
A testcase failed.
Definition: libpamtest.h:94
pam_end failed
Definition: libpamtest.h:98
run pam_close_session() to end a PAM session
Definition: libpamtest.h:44