Testsuite: fakens/inet_pton on solaris again
[exim.git] / test / src / checkaccess.c
CommitLineData
c55a77db
PH
1/* This is a baby program that is run as root from the runtest script. It is
2passed the Exim uid and gid as arguments, and the name of a file in the
3test-suite directory. It gives up all supplementary groups, changes to the
4given uid/gid, and then tries to read the file. The yield is 0 if that is
5successful, and non-zero otherwise (use different values to aid debugging). See
6comments in the exim.c source file about the use of setgroups() for getting rid
7of extraneous groups. */
8
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <fcntl.h>
12#include <unistd.h>
13#include <pwd.h>
14#include <grp.h>
15
16#include <stdio.h>
17
18
19int main(int argc, char **argv)
20{
21int fd;
22gid_t group_list[10];
23struct passwd *pw = getpwnam(argv[2]);
24struct group *gr = getgrnam(argv[3]);
25
26if (pw == NULL) return 1;
27if (gr == NULL) return 2;
28if (setgroups(0, NULL) != 0 && setgroups(1, group_list) != 0) return 4;
29if (setgid(gr->gr_gid) != 0) return 5;
30if (setuid(pw->pw_uid) != 0) return 6;
31
32fd = open(argv[1], O_RDONLY);
33if (fd < 0) return 7;
34
35close(fd);
36return 0;
37}
38
39/* End */