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