summaryrefslogtreecommitdiffstats
path: root/src/tests/intg/sss_netgroup_thread_test.c
blob: d3bee9b3e636cea7cfbd8c71d7dab34404495381 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
    Helper program to test if innetgr() is thread-safe

    Authors:
        Sumit Bose <sbose@redhat.com>

    Copyright (c) 2021 Red Hat, Inc.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <stdbool.h>
#include <pthread.h>
#include <pwd.h>
#include <grp.h>
#include <netdb.h>
#include <unistd.h>
#include <sys/types.h>



struct data {
    const char *group;
    const char *host;
    const char *user;
    const char *domain;
    bool *failed;
};

static void *full_netgroup(void *arg)
{
    int ret;
    size_t c = 0;
    struct data *data = arg;

    do {
        ret = innetgr(data->group, data->host, data->user, data->domain);
        if (ret != 1) {
            *(data->failed) = true;
        }
        c++;
    } while (!*(data->failed) && c<100000);

    pthread_exit(NULL);
}

int main()
{
    pthread_t thread[2];
    bool failed[2] = {false, false};

    struct data data[3] = {{"ng1", "host1", "user924", "domain1", &failed[0]},
                           {"ng2", "host2", "user925", "domain2", &failed[1]},
                           {NULL, NULL, NULL, NULL, NULL}};


    pthread_create(&thread[0], NULL, full_netgroup, &data[0]);
    pthread_create(&thread[1], NULL, full_netgroup, &data[1]);

    pthread_join(thread[1], NULL);
    pthread_join(thread[0], NULL);

    if (failed[0] || failed[1]) {
        printf ("Test failed.\n");
        return 1;
    }

    return 0;
}