release
[hcoop/zz_old/debian/djbdns.git] / droproot.c
CommitLineData
dc0d77d7
CE
1#include <unistd.h>
2#include "env.h"
3#include "scan.h"
4#include "prot.h"
5#include "strerr.h"
6
7void droproot(const char *fatal)
8{
9 char *x;
10 unsigned long id;
11
12 x = env_get("ROOT");
13 if (!x)
14 strerr_die2x(111,fatal,"$ROOT not set");
15 if (chdir(x) == -1)
16 strerr_die4sys(111,fatal,"unable to chdir to ",x,": ");
17 if (chroot(".") == -1)
18 strerr_die4sys(111,fatal,"unable to chroot to ",x,": ");
19
20 x = env_get("GID");
21 if (!x)
22 strerr_die2x(111,fatal,"$GID not set");
23 scan_ulong(x,&id);
24 if (prot_gid((int) id) == -1)
25 strerr_die2sys(111,fatal,"unable to setgid: ");
26
27 x = env_get("UID");
28 if (!x)
29 strerr_die2x(111,fatal,"$UID not set");
30 scan_ulong(x,&id);
31 if (prot_uid((int) id) == -1)
32 strerr_die2sys(111,fatal,"unable to setuid: ");
33}