PR/14563: Brian A. Seklecki: syslogd binds udp sockets on all interfaces

Add -b option to pass a bind address.
This commit is contained in:
christos 2006-09-15 20:32:59 +00:00
parent fb62ed2d80
commit ca09b578d0
2 changed files with 20 additions and 9 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: syslogd.8,v 1.41 2006/04/23 16:51:56 wiz Exp $
.\" $NetBSD: syslogd.8,v 1.42 2006/09/15 20:32:59 christos Exp $
.\"
.\" Copyright (c) 1983, 1986, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\"
.\" from: @(#)syslogd.8 8.1 (Berkeley) 6/6/93
.\"
.Dd April 19, 2006
.Dd September 15, 2006
.Dt SYSLOGD 8
.Os
.Sh NAME
@ -39,6 +39,9 @@
.Nm
.Op Fl dnrSsTUv
.Bk -words
.Op Fl b Ar bind_address
.Ek
.Bk -words
.Op Fl f Ar config_file
.Ek
.Bk -words
@ -68,6 +71,10 @@ reads and logs messages to the system console, log files, other
machines and/or users as specified by its configuration file.
The options are as follows:
.Bl -tag -width 15n
.It Fl b Ar bind_address
Specify one specific IP address or hostname to bind to.
If a hostname is specified, the IPv4 or IPv6 address
which corresponds to it is used.
.It Fl d
Enable debugging to the standard output,
and do not disassociate from the controlling terminal.

View File

@ -1,4 +1,4 @@
/* $NetBSD: syslogd.c,v 1.78 2006/04/24 19:00:30 snj Exp $ */
/* $NetBSD: syslogd.c,v 1.79 2006/09/15 20:32:59 christos Exp $ */
/*
* Copyright (c) 1983, 1988, 1993, 1994
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1988, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94";
#else
__RCSID("$NetBSD: syslogd.c,v 1.78 2006/04/24 19:00:30 snj Exp $");
__RCSID("$NetBSD: syslogd.c,v 1.79 2006/09/15 20:32:59 christos Exp $");
#endif
#endif /* not lint */
@ -257,7 +257,7 @@ void die(struct kevent *); /* SIGTERM kevent dispatch routine */
void domark(struct kevent *);/* timer kevent dispatch routine */
void fprintlog(struct filed *, int, char *);
int getmsgbufsize(void);
int* socksetup(int);
int* socksetup(int, const char *);
void init(struct kevent *); /* SIGHUP kevent dispatch routine */
void logerror(const char *, ...);
void logmsg(int, char *, char *, int);
@ -290,6 +290,7 @@ static void dispatch_read_funix(struct kevent *);
*/
static char *linebuf;
static size_t linebufsize;
static const char *bindhostname = NULL;
#define A_CNT(x) (sizeof((x)) / sizeof((x)[0]))
@ -314,8 +315,11 @@ main(int argc, char *argv[])
(void)setlocale(LC_ALL, "");
while ((ch = getopt(argc, argv, "dnsSf:m:p:P:ru:g:t:TUv")) != -1)
while ((ch = getopt(argc, argv, "b:dnsSf:m:p:P:ru:g:t:TUv")) != -1)
switch(ch) {
case 'b':
bindhostname = optarg;
break;
case 'd': /* debug */
Debug++;
break;
@ -1784,7 +1788,7 @@ init(struct kevent *ev)
}
}
finet = socksetup(PF_UNSPEC);
finet = socksetup(PF_UNSPEC, bindhostname);
if (finet) {
if (SecureMode) {
for (i = 0; i < *finet; i++) {
@ -2093,7 +2097,7 @@ getmsgbufsize(void)
}
int *
socksetup(int af)
socksetup(int af, const char *hostname)
{
struct addrinfo hints, *res, *r;
struct kevent *ev;
@ -2107,7 +2111,7 @@ socksetup(int af)
hints.ai_flags = AI_PASSIVE;
hints.ai_family = af;
hints.ai_socktype = SOCK_DGRAM;
error = getaddrinfo(NULL, "syslog", &hints, &res);
error = getaddrinfo(hostname, "syslog", &hints, &res);
if (error) {
logerror(gai_strerror(error));
errno = 0;