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