commit df3d15f3663597c19334b0a50326ff2d07fab70d from: Omar Polo date: Tue Aug 06 13:38:26 2024 UTC gotd: support UIDs in the user directive Requested by PyR3X on IRC. ok/improvements stsp@ commit - e9b573a27efa4d681a69e784708e3cdfd1999771 commit + df3d15f3663597c19334b0a50326ff2d07fab70d blob - d767e207751a606a2f1d4daf3666723e6fe5db5b blob + e087575f78236937985aeb124917d2ff9962a9de --- gotd/gotd.c +++ gotd/gotd.c @@ -2007,6 +2007,7 @@ main(int argc, char **argv) char *argv0 = argv[0]; char title[2048]; struct passwd *pw = NULL; + uid_t uid; char *repo_path = NULL; enum gotd_procid proc_id = PROC_GOTD; struct event evsigint, evsigterm, evsighup, evsigusr1, evsigchld; @@ -2016,6 +2017,7 @@ main(int argc, char **argv) char hostname[HOST_NAME_MAX + 1]; FILE *diff_f1 = NULL, *diff_f2 = NULL; int diff_fd1 = -1, diff_fd2 = -1; + const char *errstr; TAILQ_INIT(&procs); @@ -2080,6 +2082,11 @@ main(int argc, char **argv) return 1; pw = getpwnam(gotd.user_name); + if (pw == NULL) { + uid = strtonum(gotd.user_name, 0, UID_MAX - 1, &errstr); + if (errstr == NULL) + pw = getpwuid(uid); + } if (pw == NULL) fatalx("user %s not found", gotd.user_name); blob - bd6a17f9a4698f159dcf27a9d7f9e2b96e89a9bd blob + fd312076688c5cf8bb47bce4dc90bb1df44222db --- gotd/gotd.conf.5 +++ gotd/gotd.conf.5 @@ -105,6 +105,7 @@ Afterwards, drops privileges to the specified .Ar user . If not specified, the user _gotd will be used. +Numeric user IDs are also accepted. .El .Sh REPOSITORY CONFIGURATION At least one repository context must exist for blob - 01af5e5c4c08dcca08f25a7062b410af4dc78b2f blob + 01ee6087b16167393b859e94a1c702f7c64af765 --- gotd/parse.y +++ gotd/parse.y @@ -242,7 +242,7 @@ main : LISTEN ON STRING { } free($3); } - | USER STRING { + | USER numberstring { if (strlcpy(gotd->user_name, $2, sizeof(gotd->user_name)) >= sizeof(gotd->user_name)) {