File: basic-t.c

package info (click to toggle)
libpam-krb5 4.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,668 kB
  • sloc: ansic: 10,252; sh: 4,723; perl: 520; makefile: 196
file content (67 lines) | stat: -rw-r--r-- 1,697 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Basic tests for the pam-krb5 module.
 *
 * This test case includes all tests that can be done without having Kerberos
 * configured and a username and password available, and without any special
 * configuration.
 *
 * Written by Russ Allbery <eagle@eyrie.org>
 * Copyright 2020 Russ Allbery <eagle@eyrie.org>
 * Copyright 2011
 *     The Board of Trustees of the Leland Stanford Junior University
 *
 * SPDX-License-Identifier: BSD-3-clause or GPL-1+
 */

#include <config.h>
#include <portable/system.h>

#include <pwd.h>

#include <tests/fakepam/pam.h>
#include <tests/fakepam/script.h>
#include <tests/tap/basic.h>
#include <tests/tap/kerberos.h>
#include <tests/tap/string.h>


int
main(void)
{
    struct script_config config;
    struct passwd pwd;
    char *uid;
    char *uidplus;

    plan_lazy();

    /*
     * Generate a testing krb5.conf file with a nonexistent default realm so
     * that this test will run on any system.
     */
    kerberos_generate_conf("bogus.example.com");

    /* Create a fake passwd struct for our user. */
    memset(&pwd, 0, sizeof(pwd));
    pwd.pw_name = (char *) "root";
    pwd.pw_uid = getuid();
    pwd.pw_gid = getgid();
    pam_set_pwd(&pwd);

    /*
     * Attempt login as the root user to test ignore_root.  Set our current
     * UID and a UID one larger for testing minimum_uid.
     */
    basprintf(&uid, "%lu", (unsigned long) pwd.pw_uid);
    basprintf(&uidplus, "%lu", (unsigned long) pwd.pw_uid + 1);
    memset(&config, 0, sizeof(config));
    config.user = "root";
    config.extra[0] = uid;
    config.extra[1] = uidplus;

    run_script_dir("data/scripts/basic", &config);

    free(uid);
    free(uidplus);
    return 0;
}