Follow-up to r29036: Now that the "mergeinfo" transaction file is no
[svn.git] / tools / examples / svnserve-sgid.c
blob4d352648230bf20f32436ddf0992319ce8d42b90
1 /*
2 * Wrapper to run the svnserve process setgid.
3 * The idea is to avoid the problem that some interpreters like bash
4 * invoked by svnserve in hook scripts will reset the effective gid to
5 * the real gid, nuking the effect of an ordinary setgid svnserve binary.
6 * Sadly, to set the real gid portably, you need to be root, if only
7 * for a moment.
8 * Also smashes the environment to something known, so that games
9 * can't be played to try to break the security of the hook scripts,
10 * by setting IFS, PATH, and similar means.
13 * Written by Perry Metzger, and placed into the public domain.
16 #include <stdio.h>
17 #include <unistd.h>
19 #define REAL_PATH "/usr/bin/svnserve.real"
21 char *newenv[] = { "PATH=/bin:/usr/bin", "SHELL=/bin/sh", NULL };
23 int
24 main(int argc, char **argv)
26 if (setgid(getegid()) == -1) {
27 perror("setgid(getegid())");
28 return 1;
31 if (seteuid(getuid()) == -1) {
32 perror("seteuid(getuid())");
33 return 1;
36 execve(REAL_PATH, argv, newenv);
37 perror("attempting to exec " REAL_PATH " failed");
38 return 1;