From: Omar Polo Subject: gotd: support UIDs in the `user' directive To: gameoftrees@openbsd.org Date: Mon, 05 Aug 2024 18:37:32 +0200 This adds support to use both user ids in addition to user login names in the `user' directive. My first attempt was more like `connection limit user' is handled, i.e. with gotd_parseuid(), except that I found awkward to parse /etc/passwd twice, hence the user_name/user_id split in this diff. thoughts/comments? Thanks, Omar Polo diff /home/op/w/got commit - 9971ff29fe3ba1bd765e5c2d3d99ac33f7d00ce1 path + /home/op/w/got blob - d767e207751a606a2f1d4daf3666723e6fe5db5b file + gotd/gotd.c --- gotd/gotd.c +++ gotd/gotd.c @@ -2079,9 +2079,15 @@ main(int argc, char **argv) if (parse_config(confpath, proc_id, &gotd) != 0) return 1; - pw = getpwnam(gotd.user_name); - if (pw == NULL) - fatalx("user %s not found", gotd.user_name); + if (*gotd.user_name != '\0') { + pw = getpwnam(gotd.user_name); + if (pw == NULL) + fatalx("user %s not found", gotd.user_name); + } else { + pw = getpwuid(gotd.user_id); + if (pw == NULL) + fatalx("user %ld not found", (long)gotd.user_id); + } if (pw->pw_uid == 0) fatalx("cannot run %s as the superuser", getprogname()); blob - bd6a17f9a4698f159dcf27a9d7f9e2b96e89a9bd file + gotd/gotd.conf.5 --- gotd/gotd.conf.5 +++ gotd/gotd.conf.5 @@ -97,6 +97,9 @@ Set the .Ar user which will run .Xr gotd 8 . +The +.Ar user +may be either a numeric user ID or a user name. Initially, .Xr gotd 8 requires root privileges in order to create its unix socket. blob - c51b69d2d80fd63e6ed9b528b0fb749a764c65d7 file + gotd/gotd.h --- gotd/gotd.h +++ gotd/gotd.h @@ -156,6 +156,7 @@ struct gotd { pid_t pid; char unix_socket_path[PATH_MAX]; char user_name[32]; + uid_t user_id; struct gotd_repolist repos; int nrepos; struct gotd_child_proc *listen_proc; blob - 775f13f301bbb2743b0dd8d3cea68054ca32e779 file + gotd/parse.y --- gotd/parse.y +++ gotd/parse.y @@ -232,6 +232,10 @@ main : LISTEN ON STRING { } free($3); } + | USER NUMBER { + gotd->user_id = $2; + gotd->user_name[0] = '\0'; + } | USER STRING { if (strlcpy(gotd->user_name, $2, sizeof(gotd->user_name)) >=