File: 050_add-user-group.patch

package info (click to toggle)
ample 0.5.7-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 696 kB
  • sloc: ansic: 2,885; sh: 255; makefile: 203
file content (83 lines) | stat: -rw-r--r-- 2,299 bytes parent folder | download | duplicates (3)
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
73
74
75
76
77
78
79
80
81
82
83
Description: adds the user and group
Author: Michael Stapelberg <stapelberg@debian.org>
Last-Update: 2012-12-04
Index: ample/src/ample.c
===================================================================
--- ample.orig/src/ample.c
+++ ample/src/ample.c
@@ -54,6 +54,8 @@
 int allow_severity = LOG_INFO;
 int deny_severity = LOG_WARNING;
 #endif
+#include <pwd.h>
+#include <grp.h>
 
 
 #include "ample.h"
@@ -502,6 +504,23 @@ main(int argc, char *argv[])
 	/**/
 
 	preparelog();
+
+        if(gconf.group) {
+                struct group *pwent = getgrnam(gconf.group);
+                if (pwent == NULL)
+                        die("No such group");
+                if (setgid(pwent->gr_gid) != 0)
+                        die("Could not setgid()");
+        }
+
+        if(gconf.user) {
+                struct passwd *pwent = getpwnam(gconf.user);
+                if (pwent == NULL)
+                        die("No such user");
+                if (setuid(pwent->pw_uid) != 0)
+                        die("Could not change to specified user");
+        }
+
 	if(!gconf.inetd)
 		logmsg("Ample/%s started\n", AMPLE_VERSION);
 
Index: ample/src/ample.h
===================================================================
--- ample.orig/src/ample.h
+++ ample/src/ample.h
@@ -37,6 +37,8 @@ struct global_config {
 	char * serveraddress;
 	char * filter;
 	char * pidfile;
+	char * user;
+	char * group;
 };
 
 struct childstat {
Index: ample/src/configuration.c
===================================================================
--- ample.orig/src/configuration.c
+++ ample/src/configuration.c
@@ -679,10 +679,10 @@ setcmdopt(int argc, char * argv[])
 		{NULL, 0, NULL, 0}
 	};
 
-	while((c = getopt_long(argc, argv, "p:oc:nf:m:hd::ti:v", longopts, &i)) 
+	while((c = getopt_long(argc, argv, "p:oc:nf:m:hd::ti:vu:g:", longopts, &i))
 	      != -1) {
 #else
-	while((c = getopt(argc, argv, "p:oc:nf:m:hd::ti:v")) != -1) {
+	while((c = getopt(argc, argv, "p:oc:nf:m:hd::ti:vu:g:")) != -1) {
 #endif
 		switch(c) {
 		case 'p':
@@ -723,6 +723,12 @@ setcmdopt(int argc, char * argv[])
 		case 'i':
 			gconf.pidfile = strdup(optarg);
 			break;
+		case 'u':
+			gconf.user = strdup(optarg);
+			break;
+		case 'g':
+			gconf.group = strdup(optarg);
+			break;
 		default:
 			usage(TRUE);
 		}