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