if we are chrooting, write a symlink for the pid file so that ndc, etc,

continue to work as normal.  this allows named to run in a chroot jail
with zero loss of functionality.  with the bind8 -u <user> flag, we can
also make it run as non-root.  "stay tuned."
This commit is contained in:
mrg 1999-02-22 02:37:27 +00:00
parent 10817df7f0
commit 2aa01ad0b9
1 changed files with 19 additions and 1 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ns_main.c,v 1.2 1998/11/24 06:05:07 ross Exp $ */
/* $NetBSD: ns_main.c,v 1.3 1999/02/22 02:37:27 mrg Exp $ */
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)ns_main.c 4.55 (Berkeley) 7/1/91";
@ -372,6 +372,24 @@ main(int argc, char *argv[], char *envp[]) {
*/
if (chroot_dir != NULL) {
#ifdef HAVE_CHROOT
char *where;
/*
* first, symlink our pidfile from outside the chroot to
* inside, so that ndc still works properly, etc.
*/
if (asprintf(&where, "%s%s", chroot_dir, _PATH_PIDFILE) < 0) {
fprintf(stderr, "malloc failed: %s\n", strerror(errno));
exit(1);
}
(void)unlink(_PATH_PIDFILE);
if (symlink(where, _PATH_PIDFILE) < 0) {
fprintf(stderr, "symlink %s -> %s failed: %s\n",
_PATH_PIDFILE, where, strerror(errno));
exit(1);
}
free(where);
if (chroot(chroot_dir) < 0) {
fprintf(stderr, "chroot %s failed: %s\n", chroot_dir,
strerror(errno));