move chrooting to common.c

This commit is contained in:
Erik Ekman 2007-03-01 21:14:51 +00:00
parent e3245fbd76
commit baf1ab4201
4 changed files with 15 additions and 13 deletions

View file

@ -67,3 +67,14 @@ close_dns(int fd)
close(fd);
}
void
do_chroot(char *newroot)
{
if (newroot) {
if (chroot(newroot) != 0 || chdir("/") != 0)
err(1, "%s", newroot);
seteuid(geteuid());
setuid(getuid());
}
}

View file

@ -45,4 +45,6 @@ struct query {
int open_dns(int, in_addr_t);
void close_dns(int);
void do_chroot(char *);
#endif

View file

@ -568,13 +568,7 @@ main(int argc, char **argv)
printf("Sending queries for %s to %s\n", argv[1], argv[0]);
if (newroot) {
if (chroot(newroot) != 0 || chdir("/") != 0)
err(1, "%s", newroot);
seteuid(geteuid());
setuid(getuid());
}
do_chroot(newroot);
if (!foreground) {
printf("Detaching from terminal...\n");

View file

@ -535,12 +535,7 @@ main(int argc, char **argv)
printf("Listening to dns for domain %s\n", argv[1]);
if (newroot) {
if (chroot(newroot) != 0 || chdir("/") != 0)
err(1, "%s", newroot);
seteuid(geteuid());
setuid(getuid());
}
do_chroot(newroot);
if (!foreground) {
printf("Detaching from terminal...\n");