Commit Diff


commit - 3b135bab5adc6aaaa9911f0198c31904e748863c936ce978c7c7b08fb39e707d
commit + cfe15c641560134cf0cce992d489842de99f6f9ade17e71309b9891a0312e4fa
blob - 076d8e86df5920ab384391611394ae572369e42b49972017329931b1d361f6e2
blob + cb7577e2e9a6494d7681af250c1f94c6388374b6241181ea36dce8b0fc92f211
--- gotd/gotd.c	
+++ gotd/gotd.c	
@@ -3014,7 +3014,7 @@ start_child(enum gotd_procid proc_id, const char *repo
     char *argv0, const char *confpath, const char *secretspath,
     int fd, int daemonize, int verbosity)
 {
-	const char	*argv[13];
+	const char	*argv[15];
 	int		 argc = 0;
 	pid_t		 pid;
 
@@ -3067,6 +3067,9 @@ start_child(enum gotd_procid proc_id, const char *repo
 	argv[argc++] = "-f";
 	argv[argc++] = confpath;
 
+	argv[argc++] = "-U";
+	argv[argc++] = gotd.user_name;
+
 	if (secretspath) {
 		argv[argc++] = "-s";
 		argv[argc++] = secretspath;
@@ -3431,7 +3434,7 @@ main(int argc, char **argv)
 
 	log_init(1, LOG_DAEMON); /* Log to stderr until daemonized. */
 
-	while ((ch = getopt_long(argc, argv, "df:nP:s:T:vV", longopts, NULL)) != -1) {
+	while ((ch = getopt_long(argc, argv, "df:nP:s:T:U:vV", longopts, NULL)) != -1) {
 		switch (ch) {
 		case 'd':
 			daemonize = 0;
@@ -3482,6 +3485,11 @@ main(int argc, char **argv)
 				errx(1, "unknown proc type %s", optarg);
 			}
 			break;
+		case 'U':
+			if (strlcpy(gotd.user_name, optarg,
+			    sizeof(gotd.user_name)) >= sizeof(gotd.user_name))
+				fatal("username too long: %s", optarg);
+			break;
 		case 'v':
 			if (verbosity < 3)
 				verbosity++;
@@ -3506,8 +3514,6 @@ main(int argc, char **argv)
 	}
 	if (geteuid() && proc_id == GOTD_PROC_GOTD)
 		fatalx("need root privileges");
-	if (geteuid() == 0 && proc_id != GOTD_PROC_GOTD)
-		fatalx("must not run as root");
 
 	if (proc_id == GOTD_PROC_GOTD) {
 		const char *p = secretspath ? secretspath : GOTD_SECRETS_PATH;
@@ -3746,9 +3752,6 @@ main(int argc, char **argv)
 
 	event_init();
 
-	if (proc_id == GOTD_PROC_RELOAD)
-		proc_id = GOTD_PROC_GOTD;
-
 	if (proc_id == GOTD_PROC_GOTD) {
 		/* Drop root privileges. */
 		if (setgid(pw->pw_gid) == -1)
@@ -3758,6 +3761,9 @@ main(int argc, char **argv)
 	}
 
 	switch (proc_id) {
+	case GOTD_PROC_RELOAD:
+		proc_id = GOTD_PROC_GOTD;
+		/* FALLTHOUGH */
 	case GOTD_PROC_GOTD:
 		if (verbosity) {
 			log_info("socket: %s", gotd.unix_socket_path);