summaryrefslogtreecommitdiffstats
path: root/chat-irc/ratbox-services/setuid.patch
blob: 31a9aaf904ebae12c2409ada81de8fa81298a912 (plain) (blame)
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
--- include/config.h.orig
+++ include/config.h
@@ -1,6 +1,11 @@
 #ifndef INCLUDED_config_h
 #define INCLUDED_config_h
 
+/* users */
+#ifndef IRCD_USER
+#define IRCD_USER "ratbox"
+#endif
+
 /* Paths to various things.
  * IMPORTANT: if you alter the directories these files go to,
  *            you must create those paths yourself.
--- include/stdinc.h.orig
+++ include/stdinc.h
@@ -41,6 +41,8 @@
 #include <string.h>
 #include <strings.h>
 #include <ctype.h>
+#include <unistd.h>
+#include <pwd.h>
 
 #include <time.h>
 #include <sys/time.h>
--- src/rserv.c.orig
+++ src/rserv.c
@@ -350,8 +350,17 @@
 
 	if(geteuid() == 0)
 	{
-		printf("ratbox-services will not run as root\n");
-		return -1;
+		struct passwd *pw;
+
+		if ((pw = getpwnam(IRCD_USER)) == NULL) {
+			printf("ratbox-services will not run as root\n");
+			return -1;
+		}
+
+		if (seteuid(pw->pw_uid) < 0) {
+			printf("Can's set effective user ID to %s\n", IRCD_USER);
+			return -1;
+		}
 	}
 
 	if(chdir(PREFIX))