1 /* $Cambridge: exim/test/src/checkaccess.c,v 1.1 2006/02/06 16:24:05 ph10 Exp $ */
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. */
11 #include <sys/types.h>
21 int main(int argc
, char **argv
)
25 struct passwd
*pw
= getpwnam(argv
[2]);
26 struct group
*gr
= getgrnam(argv
[3]);
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;
34 fd
= open(argv
[1], O_RDONLY
);