mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-16 14:03:00 +02:00
allow remote syslog via TCP in syslogdctrl.c
Make syslogctrl.c use TCP as remote logging file if specified so. Thanks to Michael for reviewing this. Signed-off-by: Peter Müller <peter.mueller@link38.eu> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
committed by
Michael Tremer
parent
e9a57acd12
commit
cbd1f0e719
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user