X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Fmisc-progs%2Fsyslogdctrl.c;h=d73c4226518f3082086f993e0681db410d789597;hb=3925a0db6cc0ca91fe34eb7c0366f72b0af39ab6;hp=6991ccf353687ebf7fb5fe116f5a0304ae3934f7;hpb=1609fbfdaa46ed5bb953af3dca8efb23c3d8c6cb;p=ipfire-2.x.git diff --git a/src/misc-progs/syslogdctrl.c b/src/misc-progs/syslogdctrl.c index 6991ccf353..d73c422651 100644 --- a/src/misc-progs/syslogdctrl.c +++ b/src/misc-progs/syslogdctrl.c @@ -19,24 +19,29 @@ #include #include #include + #include "libsmooth.h" #include "setuid.h" +#include "netutil.h" #define ERR_ANY 1 #define ERR_SETTINGS 2 /* error in settings file */ #define ERR_ETC 3 /* error with /etc permissions */ -#define ERR_CONFIG 4 /* error updated sshd_config */ +#define ERR_CONFIG 4 /* error updating syslogd config */ #define ERR_SYSLOG 5 /* error restarting syslogd */ int main(void) { - char buffer[STRING_SIZE], hostname[STRING_SIZE], varmessages[STRING_SIZE]; + char buffer[STRING_SIZE], command[STRING_SIZE], hostname[STRING_SIZE], protocol[STRING_SIZE]; + char varmessages[STRING_SIZE], asynclog[STRING_SIZE]; int config_fd,rc,fd,pid; struct stat st; struct keyvalue *kv = NULL; memset(buffer, 0, STRING_SIZE); memset(hostname, 0, STRING_SIZE); + memset(protocol, 0, STRING_SIZE); memset(varmessages, 0, STRING_SIZE); + memset(asynclog, 0, STRING_SIZE); if (!(initsetuid())) exit(1); @@ -62,11 +67,11 @@ int main(void) fprintf(stderr, "Cannot read REMOTELOG_ADDR\n"); exit(ERR_SETTINGS); } - - if (!findkey(kv, "VARMESSAGES", varmessages)) + + if (!findkey(kv, "REMOTELOG_PROTOCOL", protocol)) { - fprintf(stderr, "Cannot read VARMESSAGES\n"); - exit(ERR_SETTINGS); + /* fall back to UDP if no protocol was given */ + strcpy(protocol, "udp"); } if (strspn(hostname, VALID_FQDN) != strlen(hostname)) @@ -108,13 +113,26 @@ int main(void) } if (!strcmp(buffer,"on")) - snprintf(buffer, STRING_SIZE - 1, "/bin/sed -e 's/^#\\?\\(\\*\\.\\*[[:blank:]]\\+@\\).\\+$/\\1%s/' /etc/syslog.conf >&%d", hostname, config_fd ); + { + /* check which transmission protocol was given */ + if (strcmp(protocol, "tcp") == 0) + { + /* write line for TCP */ + snprintf(buffer, STRING_SIZE - 1, "/bin/sed -e 's/^#\\?\\(\\*\\.\\*[[:blank:]]\\+\\)@@\\?.\\+$/\\1@@%s/' /etc/syslog.conf >&%d", hostname, config_fd); + } + else + { + /* write line for UDP */ + snprintf(buffer, STRING_SIZE - 1, "/bin/sed -e 's/^#\\?\\(\\*\\.\\*[[:blank:]]\\+\\)@@\\?.\\+$/\\1@%s/' /etc/syslog.conf >&%d", hostname, config_fd); + } + } else - snprintf(buffer, STRING_SIZE - 1, "/bin/sed -e 's/^#\\?\\(\\*\\.\\*[[:blank:]]\\+@.\\+\\)$/#\\1/' /etc/syslog.conf >&%d", config_fd ); - - snprintf(buffer, STRING_SIZE - 1, "/bin/sed -e 's#\\.\\*/var/log/messages\\.\\*#%s /var/log/messages#' /etc/syslog.conf >&%d", varmessages, config_fd ); + { + /* if remote syslog has been disabled */ + snprintf(buffer, STRING_SIZE - 1, "/bin/sed -e 's/^#\\?\\(\\*\\.\\*[[:blank:]]\\+@@\\?.\\+\\)$/#\\1/' /etc/syslog.conf >&%d", config_fd ); + } - /* if the return code isn't 0 failsafe */ + /* if the return code isn't 0 failsafe */ if ((rc = unpriv_system(buffer,99,99)) != 0) { fprintf(stderr, "sed returned bad exit code: %d\n", rc); @@ -123,6 +141,7 @@ int main(void) exit(ERR_CONFIG); } close(config_fd); + if (rename("/etc/syslog.conf.new", "/etc/syslog.conf") == -1) { perror("Unable to replace old config file");