From fd3bb074b1599bb655945a9979ba082181d4006e Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Tue, 21 May 2024 19:55:01 +0000 Subject: [PATCH] gotwebd: allow to change the user ok stsp@ --- gotwebd/gotwebd.c | 7 +++++-- gotwebd/gotwebd.conf.5 | 12 +++++++++--- gotwebd/gotwebd.h | 5 ++++- gotwebd/parse.y | 9 ++++++++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/gotwebd/gotwebd.c b/gotwebd/gotwebd.c index f86abeed..32eda3d2 100644 --- a/gotwebd/gotwebd.c +++ b/gotwebd/gotwebd.c @@ -273,6 +273,7 @@ main(int argc, char **argv) int no_action = 0; int server_proc = 0; const char *conffile = GOTWEBD_CONF; + const char *username = GOTWEBD_DEFAULT_USER; const char *argv0; if ((argv0 = argv[0]) == NULL) @@ -332,9 +333,11 @@ main(int argc, char **argv) if (geteuid()) fatalx("need root privileges"); - pw = getpwnam(GOTWEBD_USER); + if (env->user) + username = env->user; + pw = getpwnam(username); if (pw == NULL) - fatalx("unknown user %s", GOTWEBD_USER); + fatalx("unknown user %s", username); env->pw = pw; log_init(env->gotwebd_debug, LOG_DAEMON); diff --git a/gotwebd/gotwebd.conf.5 b/gotwebd/gotwebd.conf.5 index 89f71710..eeebc610 100644 --- a/gotwebd/gotwebd.conf.5 +++ b/gotwebd/gotwebd.conf.5 @@ -55,9 +55,9 @@ Set the path to the .Xr chroot 2 environment of .Xr httpd 8 . -If not specified then -.Pa /var/www -will be used. +If not specified, it defaults to +.Pa /var/www , +the home directory of the www user. .It Ic listen on Ar address Ic port Ar number Configure an address and port for incoming FastCGI connections. Valid @@ -77,6 +77,12 @@ May be specified multiple times to build up a list of listening sockets. Run the specified number of server processes. .Xr gotwebd 8 runs 3 server processes by default. +.It Ic user Ar user +Set the +.Ar user +which will run +.Xr gotwebd 8 . +If not specified, the user www will be used. .El .Pp If no diff --git a/gotwebd/gotwebd.h b/gotwebd/gotwebd.h index 55aa40d5..54d00805 100644 --- a/gotwebd/gotwebd.h +++ b/gotwebd/gotwebd.h @@ -31,7 +31,9 @@ /* GOTWEBD DEFAULTS */ #define GOTWEBD_CONF "/etc/gotwebd.conf" -#define GOTWEBD_USER "www" +#ifndef GOTWEBD_DEFAULT_USER +#define GOTWEBD_DEFAULT_USER "www" +#endif #define GOTWEBD_MAXDESCRSZ 1024 #define GOTWEBD_MAXCLONEURLSZ 1024 @@ -340,6 +342,7 @@ struct gotwebd { struct socketlist sockets; struct addresslist addresses; + char *user; const char *gotwebd_conffile; int gotwebd_debug; diff --git a/gotwebd/parse.y b/gotwebd/parse.y index ecb032f3..4c081b06 100644 --- a/gotwebd/parse.y +++ b/gotwebd/parse.y @@ -116,7 +116,7 @@ typedef struct { %token MAX_REPOS_DISPLAY REPOS_PATH MAX_COMMITS_DISPLAY ON ERROR %token SHOW_SITE_OWNER SHOW_REPO_CLONEURL PORT PREFORK RESPECT_EXPORTOK %token SERVER CHROOT CUSTOM_CSS SOCKET -%token SUMMARY_COMMITS_DISPLAY SUMMARY_TAGS_DISPLAY +%token SUMMARY_COMMITS_DISPLAY SUMMARY_TAGS_DISPLAY USER %token STRING %token NUMBER @@ -236,6 +236,12 @@ main : PREFORK NUMBER { } free($4); } + | USER STRING { + if (gotwebd->user != NULL) + yyerror("user already specified"); + free(gotwebd->user); + gotwebd->user = $2; + } ; server : SERVER STRING { @@ -461,6 +467,7 @@ lookup(char *s) { "socket", SOCKET }, { "summary_commits_display", SUMMARY_COMMITS_DISPLAY }, { "summary_tags_display", SUMMARY_TAGS_DISPLAY }, + { "user", USER }, }; const struct keywords *p; -- 2.11.4.GIT