diff --git a/usr.sbin/syslogd/syslogd.8 b/usr.sbin/syslogd/syslogd.8 index 5b175a6..7b24aac 100644 --- a/usr.sbin/syslogd/syslogd.8 +++ b/usr.sbin/syslogd/syslogd.8 @@ -194,6 +194,8 @@ The default .Ar service is .Ql syslog . +This option can be specified multiple times to bind to +multiple addresses and/or ports. .It Fl C Create log files that do not exist (permission is set to .Li 0600 ) . diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 60c74d1..6bd546f 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -124,6 +124,15 @@ const char ctty[] = _PATH_CONSOLE; #define MAXUNAMES 20 /* maximum number of user names */ /* + * List of hosts for binding. + */ +static STAILQ_HEAD(, host) hqueue; +struct host { + char *name; + STAILQ_ENTRY(host) next; +}; + +/* * Unix sockets. * We have two default sockets, one with 666 permissions, * and one for privileged programs. @@ -274,7 +283,7 @@ static int Debug; /* debug flag */ static int resolve = 1; /* resolve hostname */ static char LocalHostName[MAXHOSTNAMELEN]; /* our hostname */ static const char *LocalDomain; /* our local domain name */ -static int *finet; /* Internet datagram socket */ +static int *finet; /* Internet datagram sockets */ static int fklog = -1; /* /dev/klog */ static int Initialized; /* set when we have initialized ourselves */ static int MarkInterval = 20 * 60; /* interval between marks in seconds */ @@ -347,10 +356,10 @@ main(int argc, char *argv[]) struct sockaddr_storage frominet; fd_set *fdsr = NULL; char line[MAXLINE + 1]; - char *bindhostname; const char *hname; struct timeval tv, *tvp; struct sigaction sact; + struct host *host; struct funix *fx, *fx1; sigset_t mask; pid_t ppid = 1, spid; @@ -359,7 +368,8 @@ main(int argc, char *argv[]) if (madvise(NULL, 0, MADV_PROTECT) != 0) dprintf("madvise() failed: %s\n", strerror(errno)); - bindhostname = NULL; + STAILQ_INIT(&hqueue); + while ((ch = getopt(argc, argv, "468Aa:b:cCdf:kl:m:nNop:P:sS:Tuv")) != -1) switch (ch) { @@ -382,8 +392,13 @@ main(int argc, char *argv[]) usage(); break; case 'b': - bindhostname = optarg; + { + if ((host = malloc(sizeof(struct host))) == NULL) + err(1, "malloc failed"); + host->name = optarg; + STAILQ_INSERT_TAIL(&hqueue, host, next); break; + } case 'c': no_compress++; break; @@ -429,7 +444,7 @@ main(int argc, char *argv[]) if (strlen(name) >= sizeof(sunx.sun_path)) errx(1, "%s path too long, exiting", name); if ((fx = malloc(sizeof(struct funix))) == NULL) - errx(1, "malloc failed"); + err(1, "malloc failed"); fx->s = -1; fx->name = name; fx->mode = mode; @@ -551,8 +566,26 @@ main(int argc, char *argv[]) } increase_rcvbuf(fx->s); } - if (SecureMode <= 1) - finet = socksetup(family, bindhostname); + if (SecureMode <= 1) { + if (STAILQ_EMPTY(&hqueue)) + finet = socksetup(family, NULL); + STAILQ_FOREACH(host, &hqueue, next) { + int *finet0, total; + finet0 = socksetup(family, host->name); + if (finet0 && !finet) { + finet = finet0; + } else if (finet0 && finet) { + total = *finet0 + *finet + 1; + finet = realloc(finet, total * sizeof(int)); + if (finet == NULL) + err(1, "realloc failed"); + for (i = 1; i <= *finet0; i++) { + finet[(*finet)+i] = finet0[i]; + } + *finet = --total; + } + } + } if (finet) { if (SecureMode) { @@ -2727,6 +2760,7 @@ socksetup(int af, char *bindhostname) } (*socks)++; + dprintf("socksetup: new socket fd is %d\n", *s); s++; }