1 /*
2 * Basic tests for the pam-krb5 module.
3 *
4 * This test case includes all tests that can be done without having Kerberos
5 * configured and a username and password available, and without any special
6 * configuration.
7 *
8 * Written by Russ Allbery <eagle@eyrie.org>
9 * Copyright 2020 Russ Allbery <eagle@eyrie.org>
10 * Copyright 2011
11 * The Board of Trustees of the Leland Stanford Junior University
12 *
13 * SPDX-License-Identifier: BSD-3-clause or GPL-1+
14 */
15
16 #include <config.h>
17 #include <portable/system.h>
18
19 #include <pwd.h>
20
21 #include <tests/fakepam/pam.h>
22 #include <tests/fakepam/script.h>
23 #include <tests/tap/basic.h>
24 #include <tests/tap/kerberos.h>
25 #include <tests/tap/string.h>
26
27
28 int
main(void)29 main(void)
30 {
31 struct script_config config;
32 struct passwd pwd;
33 char *uid;
34 char *uidplus;
35
36 plan_lazy();
37
38 /*
39 * Generate a testing krb5.conf file with a nonexistent default realm so
40 * that this test will run on any system.
41 */
42 kerberos_generate_conf("bogus.example.com");
43
44 /* Create a fake passwd struct for our user. */
45 memset(&pwd, 0, sizeof(pwd));
46 pwd.pw_name = (char *) "root";
47 pwd.pw_uid = getuid();
48 pwd.pw_gid = getgid();
49 pam_set_pwd(&pwd);
50
51 /*
52 * Attempt login as the root user to test ignore_root. Set our current
53 * UID and a UID one larger for testing minimum_uid.
54 */
55 basprintf(&uid, "%lu", (unsigned long) pwd.pw_uid);
56 basprintf(&uidplus, "%lu", (unsigned long) pwd.pw_uid + 1);
57 memset(&config, 0, sizeof(config));
58 config.user = "root";
59 config.extra[0] = uid;
60 config.extra[1] = uidplus;
61
62 run_script_dir("data/scripts/basic", &config);
63
64 free(uid);
65 free(uidplus);
66 return 0;
67 }
68