Sat Nov 27 01:16:44 CET 1999 Modified Files in squid configure configure.in Modified Files in squid/include autoconf.h.in Modified Files in squid/src cf.data.pre main.c structs.h tools.c Added squid.conf chroot directive for making Squid chroot itself when starting up. This also makes Squid permanently drop any root privilegies (requirement when chrooting, or there is not much of a point in chroot) Index: squid/configure diff -u squid/configure:1.1.1.35.2.6 squid/configure:1.1.1.35.2.7 --- squid/configure:1.1.1.35.2.6 Sun Oct 24 22:10:59 1999 +++ squid/configure Sat Nov 27 01:16:27 1999 @@ -4236,6 +4236,7 @@ regfree \ res_init \ rint \ + setgroups \ seteuid \ setpgrp \ setrlimit \ Index: squid/configure.in diff -u squid/configure.in:1.1.1.37.2.7 squid/configure.in:1.1.1.37.2.8 --- squid/configure.in:1.1.1.37.2.7 Sun Oct 24 22:06:54 1999 +++ squid/configure.in Sat Nov 27 01:16:33 1999 @@ -982,6 +982,7 @@ regfree \ res_init \ rint \ + setgroups \ seteuid \ setpgrp \ setrlimit \ Index: squid/include/autoconf.h.in diff -u squid/include/autoconf.h.in:1.1.1.30.2.6 squid/include/autoconf.h.in:1.1.1.30.2.7 --- squid/include/autoconf.h.in:1.1.1.30.2.6 Sun Oct 24 22:11:08 1999 +++ squid/include/autoconf.h.in Sat Nov 27 01:16:40 1999 @@ -367,6 +367,9 @@ /* Define if you have the seteuid function. */ #undef HAVE_SETEUID +/* Define if you have the setgroups function. */ +#undef HAVE_SETGROUPS + /* Define if you have the setpgrp function. */ #undef HAVE_SETPGRP Index: squid/src/cf.data.pre diff -u squid/src/cf.data.pre:1.1.1.40.2.10 squid/src/cf.data.pre:1.1.1.40.2.11 --- squid/src/cf.data.pre:1.1.1.40.2.10 Sun Oct 24 21:55:27 1999 +++ squid/src/cf.data.pre Sat Nov 27 01:16:43 1999 @@ -2908,4 +2908,14 @@ and coredump files will be left there. DOC_END +NAME: chroot +TYPE: string +LOC: Config.chroot_dir +DEFAULT: none +DOC_START + Use this to have Squid do a chroot() while initializing. This also + causes Squid to fully drop root privilegies after initializing + (with the side effect that HTTP connections using low port numbers + can't be reopened after a reconfigure) +DOC_END EOF Index: squid/src/main.c diff -u squid/src/main.c:1.1.1.35.2.4 squid/src/main.c:1.1.1.35.2.5 --- squid/src/main.c:1.1.1.35.2.4 Sun Oct 24 22:02:34 1999 +++ squid/src/main.c Sat Nov 27 01:16:43 1999 @@ -411,6 +411,10 @@ static void mainInitialize(void) { + /* chroot if configured to run inside chroot */ + if (Config.chroot_dir && chroot(Config.chroot_dir)) { + fatal("failed to chroot"); + } if (opt_catch_signals) { squid_signal(SIGSEGV, death, SA_NODEFER | SA_RESETHAND); squid_signal(SIGBUS, death, SA_NODEFER | SA_RESETHAND); @@ -484,6 +488,9 @@ else debug(1, 1) ("ICP port disabled in httpd_accelerator mode\n"); } + if (Config.chroot_dir) { + no_suid(); + } if (!configured_once) writePidFile(); /* write PID file */ @@ -575,10 +582,18 @@ /* send signal to running copy and exit */ if (opt_send_signal != -1) { + /* chroot if configured to run inside chroot */ + if (Config.chroot_dir && chroot(Config.chroot_dir)) { + fatal("failed to chroot"); + } sendSignal(); /* NOTREACHED */ } if (opt_create_swap_dirs) { + /* chroot if configured to run inside chroot */ + if (Config.chroot_dir && chroot(Config.chroot_dir)) { + fatal("failed to chroot"); + } setEffectiveUser(); debug(0, 0) ("Creating Swap Directories\n"); storeCreateSwapDirectories(); Index: squid/src/structs.h diff -u squid/src/structs.h:1.1.1.41.2.13 squid/src/structs.h:1.1.1.41.2.14 --- squid/src/structs.h:1.1.1.41.2.13 Sun Oct 24 21:45:36 1999 +++ squid/src/structs.h Sat Nov 27 01:16:44 1999 @@ -453,6 +453,7 @@ #endif HttpHeaderMask anonymize_headers; char *coredump_dir; + char *chroot_dir; }; struct _SquidConfig2 { Index: squid/src/tools.c diff -u squid/src/tools.c:1.1.1.25.2.3 squid/src/tools.c:1.1.1.25.2.4 --- squid/src/tools.c:1.1.1.25.2.3 Sun Oct 24 21:26:28 1999 +++ squid/src/tools.c Sat Nov 27 01:16:44 1999 @@ -495,6 +495,7 @@ { struct passwd *pwd = NULL; struct group *grp = NULL; + gid_t gid; debug(21, 3) ("leave_suid: PID %d called\n", getpid()); if (geteuid() != 0) return; @@ -508,12 +509,15 @@ aioSync(); #endif if (Config.effectiveGroup && (grp = getgrnam(Config.effectiveGroup))) { - if (setgid(grp->gr_gid) < 0) - debug(50, 1) ("leave_suid: setgid: %s\n", xstrerror()); + gid = grp->gr_gid; } else { - if (setgid(pwd->pw_gid) < 0) - debug(50, 1) ("leave_suid: setgid: %s\n", xstrerror()); + gid = pwd->pw_gid; } +#if HAVE_SETGROUPS + setgroups(1,&gid); +#endif + if (setgid(gid) < 0) + debug(50, 1) ("leave_suid: setgid: %s\n", xstrerror()); debug(21, 3) ("leave_suid: PID %d giving up root, becoming '%s'\n", getpid(), pwd->pw_name); #if HAVE_SETRESUID