From patchwork Mon Nov 20 03:40:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Peter_M=C3=BCller?= X-Patchwork-Id: 1556 Return-Path: Received: from mail01.ipfire.org (unknown [172.28.1.200]) by web02.ipfire.org (Postfix) with ESMTP id 3A0FD60971 for ; Sun, 19 Nov 2017 17:40:39 +0100 (CET) Received: from mail01.ipfire.org (localhost [IPv6:::1]) by mail01.ipfire.org (Postfix) with ESMTP id B5D1234CD; Sun, 19 Nov 2017 17:40:38 +0100 (CET) Received: from mx.link38.eu (mx.link38.eu [188.68.43.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mx.link38.eu", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 8ED4E34C7 for ; Sun, 19 Nov 2017 17:40:35 +0100 (CET) X-Virus-Scanned: ClamAV at mx.link38.eu Received: from mx-fra.brokers.link38.eu (mx-fra.brokers.link38.eu [10.141.75.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx.link38.eu (Postfix) with ESMTPS id B774F40123 for ; Sun, 19 Nov 2017 17:40:29 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx-fra.brokers.link38.eu (Postfix) with ESMTPSA id 416BD9F785 for ; Sun, 19 Nov 2017 17:40:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=link38.eu; s=201711; t=1511109629; bh=+uTn8n/GyXrVhgja15NnfQlzGIP+X1u0CbNobvpYrSU=; h=Date:From:To:Subject:Message-ID:Content-Type:From:To:Subject:Date: Cc; b=e/OJ+DUxKVPuWNEFG/GE+ypb7yKXQeHEY66sdK3odWV2hKFAtDqUKxYBRvTHRHzZo AYCFeE4HDb+UlXJltOEKgP0gkLVHdPvKqvUjR3g/1cBf7UlJ4AKagct7wkVDP+XCAM Ke0SzVg6AMSNdz1ujtTbm3jUXNKngXoRJ99sdos2I5/ZreWlCHjyLQJVjf7y9JEzBJ RaOIZKeGlHOaLHi5JbDuhyUToY7/LNS7doUgzqzADlVYTyDIFlZpF/jCebe8GQbBV8 Zke/8dDnmzMXzARdWh1NcDOdfMsOPzxZT44LpjcuhxGTHmfQvErygJLzd3ODJ3VUGh 0WGh1yjCoftlA== Date: Sun, 19 Nov 2017 17:40:29 +0100 From: Peter =?utf-8?q?M=C3=BCller?= To: "development@lists.ipfire.org" Subject: [PATCH 1/3 v3] allow remote syslog via TCP in syslogdctrl.c Message-ID: <20171119174029.5988ad10.peter.mueller@link38.eu> Organization: Link38 MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Make syslogctrl.c use TCP as remote logging file if specified so. Thanks to Michael for reviewing this. Signed-off-by: Peter Müller --- src/misc-progs/syslogdctrl.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/misc-progs/syslogdctrl.c b/src/misc-progs/syslogdctrl.c index 52719023e..83727162e 100644 --- a/src/misc-progs/syslogdctrl.c +++ b/src/misc-progs/syslogdctrl.c @@ -27,18 +27,19 @@ #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], command[STRING_SIZE], hostname[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); @@ -67,6 +68,12 @@ int main(void) exit(ERR_SETTINGS); } + if (!findkey(kv, "REMOTELOG_PROTOCOL", protocol)) + { + /* fall back to UDP if no protocol was given */ + protocol = "udp"; + } + if (strspn(hostname, VALID_FQDN) != strlen(hostname)) { fprintf(stderr, "Bad REMOTELOG_ADDR: %s\n", hostname); @@ -106,9 +113,24 @@ 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 + { + /* 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 ((rc = unpriv_system(buffer,99,99)) != 0)