commit 30c86dc2e71cef1d5c7c58bf5c3c454a49104c9ef197fef5f4753531f556ce51 from: Thomas Adam date: Wed Feb 25 16:43:01 2026 UTC gotwebd: propagate chroot path to child processes The config file is read in the parent process, but the chroot value is never passed to the children when execvp() is called. This means that the default value of "/var/www" is used, despite whatever the user has set in gotwebd.conf OK @op, @stsp commit - 1eb036f0c78909d367cfe35206f0506e87255bfedbb5138f5c582b0fc7eb7b3d commit + 30c86dc2e71cef1d5c7c58bf5c3c454a49104c9ef197fef5f4753531f556ce51 blob - b5c984a1cb85224c7812d379ebf055bb9a9b953532d70f6938d856daac6bd3c7 blob + 59f4c3df566af7bdd02c6c809892bef0157b60633aa395251ad9fef92c3ccb0f --- gotwebd/gotwebd.c +++ gotwebd/gotwebd.c @@ -498,7 +498,7 @@ spawn_process(struct gotwebd *env, const char *argv0, enum gotwebd_proc_type proc_type, const char *username, const char *www_user, void (*handler)(int, short, void *)) { - const char *argv[10]; + const char *argv[12]; int argc = 0; int p[2]; pid_t pid; @@ -557,6 +557,10 @@ spawn_process(struct gotwebd *env, const char *argv0, argv[argc++] = "-G"; argv[argc++] = usernames; } + if (strcmp(env->httpd_chroot, D_HTTPD_CHROOT) != 0) { + argv[argc++] = "-C"; + argv[argc++] = env->httpd_chroot; + } if (strcmp(env->gotwebd_conffile, GOTWEBD_CONF) != 0) { argv[argc++] = "-f"; argv[argc++] = env->gotwebd_conffile; @@ -923,12 +927,18 @@ main(int argc, char **argv) fatal("%s: calloc", __func__); config_init(env); - while ((ch = getopt(argc, argv, "A:D:dG:f:F:L:nS:vW:")) != -1) { + while ((ch = getopt(argc, argv, "A:C:D:dG:f:F:L:nS:vW:")) != -1) { switch (ch) { case 'A': proc_type = GOTWEBD_PROC_AUTH; get_usernames(&gotwebd_username, &www_username, optarg); break; + case 'C': + if (strlcpy(env->httpd_chroot, optarg, + sizeof(env->httpd_chroot)) >= + sizeof(env->httpd_chroot)) + fatalx("chroot path too long"); + break; case 'D': if (cmdline_symset(optarg) < 0) log_warnx("could not parse macro definition %s", @@ -1052,6 +1062,8 @@ main(int argc, char **argv) if (chdir("/") == -1) fatal("chdir /"); + log_info("Using chroot: %s", env->httpd_chroot); + if (setgroups(1, &pw->pw_gid) == -1 || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1 || setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1)