xref: /freebsd/contrib/pam-krb5/tests/pam-util/args-t.c (revision 4b15965daa99044daf184221b7c283bf7f2d7e66)
1 /*
2  * PAM utility argument initialization test suite.
3  *
4  * The canonical version of this file is maintained in the rra-c-util package,
5  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
6  *
7  * Written by Russ Allbery <eagle@eyrie.org>
8  * Copyright 2010, 2012-2013
9  *     The Board of Trustees of the Leland Stanford Junior University
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  *
29  * SPDX-License-Identifier: MIT
30  */
31 
32 #include <config.h>
33 #include <portable/pam.h>
34 #include <portable/system.h>
35 
36 #include <pam-util/args.h>
37 #include <tests/fakepam/pam.h>
38 #include <tests/tap/basic.h>
39 
40 
41 int
42 main(void)
43 {
44     pam_handle_t *pamh;
45     struct pam_conv conv = {NULL, NULL};
46     struct pam_args *args;
47 
48     plan(12);
49 
50     if (pam_start("test", NULL, &conv, &pamh) != PAM_SUCCESS)
51         sysbail("Fake PAM initialization failed");
52     args = putil_args_new(pamh, 0);
53     ok(args != NULL, "New args struct is not NULL");
54     if (args == NULL)
55         ok_block(7, 0, "...args struct is NULL");
56     else {
57         ok(args->pamh == pamh, "...and pamh is correct");
58         ok(args->config == NULL, "...and config is NULL");
59         ok(args->user == NULL, "...and user is NULL");
60         is_int(args->debug, false, "...and debug is false");
61         is_int(args->silent, false, "...and silent is false");
62 #ifdef HAVE_KRB5
63         ok(args->ctx != NULL, "...and the Kerberos context is initialized");
64         ok(args->realm == NULL, "...and realm is NULL");
65 #else
66         skip_block(2, "Kerberos support not configured");
67 #endif
68     }
69     putil_args_free(args);
70     ok(1, "Freeing the args struct works");
71 
72     args = putil_args_new(pamh, PAM_SILENT);
73     ok(args != NULL, "New args struct with PAM_SILENT is not NULL");
74     if (args == NULL)
75         ok(0, "...args is NULL");
76     else
77         is_int(args->silent, true, "...and silent is true");
78     putil_args_free(args);
79 
80     putil_args_free(NULL);
81     ok(1, "Freeing a NULL args struct works");
82 
83     pam_end(pamh, 0);
84 
85     return 0;
86 }
87