summaryrefslogtreecommitdiffstats
path: root/main/gross/gross-1.0.1-user.patch
blob: a20279f00305e3ba529c0de8166339838d25de46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Index: src/gross.c
===================================================================
--- a/src/gross.c	(revision 491)
+++ b/src/gross.c	(working copy)
@@ -553,7 +553,7 @@
 void
 usage(void)
 {
-	printf("Usage: grossd [-CDdhnPprV] [-f configfile]\n");
+	printf("Usage: grossd [-CDdhnPpruV] [-f configfile]\n");
 	printf("       -C	create statefile and exit\n");
 	printf("       -D	Enable debug logging (insane verbosity with -DD)\n");
 	printf("       -d	Run grossd as a foreground process\n");
@@ -563,6 +563,7 @@
 	printf("       -p file  write the process id in a pidfile\n");
 	printf("       -P file  same as -p, but pid file must not exist\n");
 	printf("       -r	disable replication\n");
+	printf("       -u user  run gross as user\n");	
 	printf("       -V	version information\n");
 	exit(EXIT_USAGE);
 }
@@ -612,6 +613,7 @@
 	pool_limits_t limits;
 	sigset_t mask, oldmask;
 	struct passwd *pwd;
+	char *user = "nobody";
 
 #ifdef DNSBL
 	dns_check_info_t *dns_check_info;
@@ -623,7 +625,7 @@
 		daemon_shutdown(EXIT_FATAL, "Couldn't initialize context");
 
 	/* command line arguments */
-	while ((c = getopt(argc, argv, ":drf:VCDnp:P:")) != -1) {
+	while ((c = getopt(argc, argv, ":drf:VCDnp:P:u:")) != -1) {
 		switch (c) {
 		case 'd':
 			ctx->config.flags |= FLG_NODAEMON;
@@ -663,6 +665,9 @@
 			ctx->config.flags |= FLG_CHECK_PIDFILE;
 			ctx->config.flags |= FLG_CREATE_PIDFILE;
 			break;
+		case 'u':
+			user = optarg;
+			break;
 		case 'h':
 			usage();
 			break;
@@ -675,16 +680,16 @@
 
 	/* grossd doesn't need to be running as root */
 	if (geteuid() == 0) {
-		logstr(GLOG_DEBUG, "Running as root: setuid() to 'nobody'");
-		pwd = getpwnam("nobody");
+		logstr(GLOG_DEBUG, "Running as root: setuid() to '%s'", user);
+		pwd = getpwnam(user);
 		if (NULL == pwd)
-			daemon_shutdown(EXIT_FATAL, "Running as root: can't find user 'nobody'");
+			daemon_shutdown(EXIT_FATAL, "Running as root: can't find user '%s'", user);
 		if (setgid(pwd->pw_gid) != 0)
-			daemon_shutdown(EXIT_FATAL, "Running as root: can't setgid(%d) to 'nobody': %s",
-			    pwd->pw_gid, strerror(errno));
+			daemon_shutdown(EXIT_FATAL, "Running as root: can't setgid(%d) to '%s': %s",
+			    pwd->pw_gid, user, strerror(errno));
 		if (setuid(pwd->pw_uid) != 0)
-			daemon_shutdown(EXIT_FATAL, "Running as root: can't setuid(%d) to 'nobody': %s",
-			    pwd->pw_uid, strerror(errno));
+			daemon_shutdown(EXIT_FATAL, "Running as root: can't setuid(%d) to '%s': %s",
+			    pwd->pw_uid, user, strerror(errno));
 	}
 
 	config = default_config();