From 0d9264f88145887b75bcf3df71bd1185b8c50607 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 23 Jul 2007 12:16:31 +0000 Subject: rsyslogd now checks on startup if it is capable to performa any work at all. If it cant, it complains and terminates thanks to Michel Samia for providing the patch! --- syslogd.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'syslogd.c') diff --git a/syslogd.c b/syslogd.c index d85333ff..e8fde594 100644 --- a/syslogd.c +++ b/syslogd.c @@ -1608,7 +1608,7 @@ void getCurrTime(struct syslogTime *t) static int usage(void) { fprintf(stderr, "usage: rsyslogd [-46Adhvw] [-l hostlist] [-m markinterval] [-n] [-p path]\n" \ - " [-s domainlist] [-r[port]] [-tport[,max-sessions]] [-f conffile] [-x]\n"); + " [-s domainlist] [-r[port]] [-tport[,max-sessions]] [-f conffile] [-i pidfile] [-x]\n"); exit(1); /* "good" exit - done to terminate usage() */ } @@ -6121,6 +6121,33 @@ static void mainloop(void) } } +/* If user is not root, prints warnings or even exits + * TODO: check all dynafiles for write permission */ +static void checkPermissions() +{ + /* we are not root */ + if (geteuid() != 0) + { + fputs("WARNING: Local messages will not be logged! If you want to log them, run rsyslog as root.\n",stderr); + + /* udp enabled and port number less than or equal to 1024 */ + if ( AcceptRemote && (atoi(LogPort) <= 1024) ) + fprintf(stderr, "WARNING: Will not listen on UDP port %s. Use port number higher than 1024 or run rsyslog as root!\n", LogPort); + + /* tcp enabled and port number less or equal to 1024 */ + if( bEnableTCP && (atoi(TCPLstnPort) <= 1024) ) + fprintf(stderr, "WARNING: Will not listen on TCP port %s. Use port number higher than 1024 or run rsyslog as root!\n", TCPLstnPort); + + /* Neither explicit high UDP port nor explicit high TCP port. + * It is useless to run anymore */ + if( !(AcceptRemote && (atoi(LogPort) > 1024)) && !( bEnableTCP && (atoi(TCPLstnPort) > 1024)) ) + { + fprintf(stderr, "ERROR: Nothing to log, no reason to run. Please run rsyslog as root.\n"); + exit(EXIT_FAILURE); + } + } +} + int main(int argc, char **argv) { register int i; register char *p; @@ -6275,6 +6302,8 @@ int main(int argc, char **argv) if ((argc -= optind)) usage(); + checkPermissions(); + #ifndef TESTING if ( !(Debug || NoFork) ) { -- cgit v1.2.3