diff -ru sysklogd-1.4/Makefile sysklogd-1.4-droproot/Makefile --- sysklogd-1.4/Makefile Wed Jan 10 15:16:12 2001 +++ sysklogd-1.4-droproot/Makefile Mon May 28 09:42:47 2001 @@ -3,7 +3,7 @@ CC= gcc #CFLAGS= -g -DSYSV -Wall #LDFLAGS= -g -CFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce +CFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -DDROPROOT -fomit-frame-pointer -Wall -fno-strength-reduce LDFLAGS= -s # Look where your install program is. diff -ru sysklogd-1.4/klogd.8 sysklogd-1.4-droproot/klogd.8 --- sysklogd-1.4/klogd.8 Tue Sep 12 23:15:28 2000 +++ sysklogd-1.4-droproot/klogd.8 Mon May 28 09:50:56 2001 @@ -22,6 +22,9 @@ .RB [ " \-o " ] .RB [ " \-p " ] .RB [ " \-s " ] +.RB [ " \-u " +.I uid +] .RB [ " \-k " .I fname ] @@ -75,6 +78,11 @@ .TP .BI "\-k " file Use the specified file as the source of kernel symbol information. +.TP +.BI "\-u " uid +After opening pid file and sockets, drop root privileges and set userid +to \fIuid\fR. Note that this option is only available if the sysklogd +package was compiled with \fBDROPROOT\fP defined. .TP .B "\-v" Print version and exit. diff -ru sysklogd-1.4/klogd.c sysklogd-1.4-droproot/klogd.c --- sysklogd-1.4/klogd.c Mon Sep 18 09:34:11 2000 +++ sysklogd-1.4-droproot/klogd.c Mon May 28 10:11:34 2001 @@ -268,6 +268,10 @@ #define LOG_BUFFER_SIZE 4096 #define LOG_LINE_LENGTH 1000 +#ifdef DROPROOT +#define DEFUID 65534 +#endif + #ifndef TESTING #if defined(FSSTND) static char *PidFile = _PATH_VARRUN "klogd.pid"; @@ -298,6 +302,9 @@ int debugging = 0; int symbols_twice = 0; +#ifdef DROPROOT +int d_uid = -1; /* uid to set when dropping root privileges */ +#endif /* Function prototypes. */ extern int ksyslog(int type, char *buf, int len); @@ -975,7 +982,11 @@ chdir ("/"); #endif /* Parse the command-line. */ +#ifdef DROPROOT + while ((ch = getopt(argc, argv, "c:df:iIk:nopsu:vx2")) != EOF) +#else while ((ch = getopt(argc, argv, "c:df:iIk:nopsvx2")) != EOF) +#endif switch((char)ch) { case '2': /* Print lines with symbols twice. */ @@ -1012,6 +1023,12 @@ case 's': /* Use syscall interface. */ use_syscall = 1; break; +#ifdef DROPROOT + case 'u': + d_uid = atoi(optarg); + if ( d_uid <= 0 ) d_uid = DEFUID; + break; +#endif case 'v': printf("klogd %s-%s\n", VERSION, PATCHLEVEL); exit (1); @@ -1144,6 +1161,10 @@ InitMsyms(); } +#ifdef DROPROOT + /* drop root privileges if d_uid is set to a positive value */ + if (d_uid > 0) setuid(d_uid); +#endif /* The main loop. */ while (1) { diff -ru sysklogd-1.4/sysklogd.8 sysklogd-1.4-droproot/sysklogd.8 --- sysklogd-1.4/sysklogd.8 Sat Aug 21 12:49:14 1999 +++ sysklogd-1.4-droproot/sysklogd.8 Mon May 28 10:16:08 2001 @@ -29,6 +29,9 @@ .RB [ " \-s " .I domainlist ] +.RB [ " \-u " +.I uid +] .RB [ " \-v " ] .LP .SH DESCRIPTION @@ -143,6 +146,11 @@ Specify a domainname that should be stripped off before logging. Multiple domains may be specified using the colon (``:'') separator. Remember that the first match is used, not the best. +.TP +.BI "\-u " uid +After opening pid file and sockets, drop root privileges and set userid +to \fIuid\fR. Note that this option is only available if the sysklogd +package was compiled with \fBDROPROOT\fP defined. .TP .B "\-v" Print version and exit. diff -ru sysklogd-1.4/syslogd.c sysklogd-1.4-droproot/syslogd.c --- sysklogd-1.4/syslogd.c Mon Sep 18 15:41:33 2000 +++ sysklogd-1.4-droproot/syslogd.c Mon May 28 10:38:03 2001 @@ -544,6 +544,10 @@ #define _PATH_LOG "/dev/log" #endif +#ifdef DROPROOT +#define DEFUID 65534 +#endif + char *ConfFile = _PATH_LOGCONF; char *PidFile = _PATH_LOGPID; char ctty[] = _PATH_CONSOLE; @@ -730,6 +734,9 @@ char **LocalHosts = NULL; /* these hosts are logged with their hostname */ int NoHops = 1; /* Can we bounce syslog messages through an intermediate host. */ +#ifdef DROPROOT +int d_uid = -1; /* uid to set when dropping root privileges */ +#endif extern int errno; @@ -824,7 +831,11 @@ funix[i] = -1; } +#ifdef DROPROOT + while ((ch = getopt(argc, argv, "a:dhf:l:m:np:rs:u:v")) != EOF) +#else while ((ch = getopt(argc, argv, "a:dhf:l:m:np:rs:v")) != EOF) +#endif switch((char)ch) { case 'a': if (nfunix < MAXFUNIX) @@ -869,6 +880,12 @@ } StripDomains = crunch_list(optarg); break; +#ifdef DROPROOT + case 'u': + d_uid = atoi(optarg); + if ( d_uid <= 0 ) d_uid = DEFUID; + break; +#endif case 'v': printf("syslogd %s-%s\n", VERSION, PATCHLEVEL); exit (0); @@ -1065,6 +1082,10 @@ dprintf("%d ", nfds); dprintf("\n"); } +#ifdef DROPROOT + /* drop root privileges if d_uid is set to a positive value */ + if (d_uid > 0) setuid(d_uid); +#endif nfds = select(maxfds+1, (fd_set *) &readfds, (fd_set *) NULL, (fd_set *) NULL, (struct timeval *) NULL); if ( restart ) @@ -1169,8 +1190,13 @@ int usage() { +#ifdef DROPROOT + fprintf(stderr, "usage: syslogd [-drvh] [-l hostlist] [-m markinterval] [-n] [-p path]\n" \ + " [-s domainlist] [-u uid] [-f conffile]\n"); +#else fprintf(stderr, "usage: syslogd [-drvh] [-l hostlist] [-m markinterval] [-n] [-p path]\n" \ " [-s domainlist] [-f conffile]\n"); +#endif exit(1); }