blob: ca24441c7a5436fcd69c0bdfca282fc43e1f48ef (
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
|
--- server/main.c.orig Wed Nov 27 01:26:42 1996
+++ server/main.c Mon Nov 19 20:49:24 2001
@@ -57,6 +57,7 @@
#include <errno.h>
#include <sys/types.h>
#include <signal.h>
+#include <pwd.h>
#include "IR.h"
#include "net.h"
@@ -82,6 +83,8 @@
#ifdef USE_UNIX_SOCKET
extern struct sockaddr_un unsock;
#endif
+ struct passwd *pw;
+ uid_t binuid;
/* サーバを子プロセス(デーモン)として起動する */
parentid = BecomeDaemon(argc, argv);
@@ -114,9 +117,21 @@
exit(2);
}
+ if ( (pw = getpwnam(cannaOwner)) == NULL ) {
+ fprintf(stderr, "User %s unknown\n", cannaOwner);
+ exit(1);
+ }
+
/* エラー出力の切り替え、TTYの切り離し */
if (parentid) kill(parentid, SIGTERM);
DetachTTY();
+
+ /* Drop root privilege. */
+ binuid = pw->pw_uid;
+ if ( setuid(binuid) < 0 ) {
+ fprintf(stderr, "Unable to setuid to %s(UID: %s).\n", cannaOwner, binuid);
+ exit(1);
+ }
/* ディスパッチループ */
Dispatch() ;
|