-/* $OpenBSD: privsep.c,v 1.39 2014/08/21 00:04:58 bluhm Exp $ */
+/* $OpenBSD: privsep.c,v 1.40 2014/08/21 17:00:34 bluhm Exp $ */
/*
* Copyright (c) 2003 Anil Madhavapeddy <anil@recoil.org>
close(pfd[PFD_UNIX_0 + i].fd);
if (pfd[PFD_INET].fd != -1)
close(pfd[PFD_INET].fd);
+ if (pfd[PFD_INET6].fd != -1)
+ close(pfd[PFD_INET6].fd);
if (pfd[PFD_CTLSOCK].fd != -1)
close(pfd[PFD_CTLSOCK].fd);
if (pfd[PFD_CTLCONN].fd != -1)
must_read(socks[0], &servname, servname_len);
servname[servname_len - 1] = '\0';
- memset(&hints, '\0', sizeof(hints));
- hints.ai_family = AF_INET;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
i = getaddrinfo(hostname, servname, &hints, &res0);
if (i != 0 || res0 == NULL) {
-/* $OpenBSD: syslogd.c,v 1.115 2014/08/21 00:04:58 bluhm Exp $ */
+/* $OpenBSD: syslogd.c,v 1.116 2014/08/21 17:00:34 bluhm Exp $ */
/*
* Copyright (c) 1983, 1988, 1993, 1994
int Startup = 1; /* startup flag */
char LocalHostName[MAXHOSTNAMELEN]; /* our hostname */
char *LocalDomain; /* our local domain name */
-int InetInuse = 0; /* non-zero if INET sockets are being used */
int Initialized = 0; /* set when we have initialized ourselves */
int MarkInterval = 20 * 60; /* interval between marks in seconds */
{
int ch, i, linesize, fd;
struct sockaddr_un fromunix;
- struct sockaddr_in frominet;
+ struct sockaddr_storage from;
socklen_t len;
char *p, *line;
char resolve[MAXHOSTNAMELEN];
}
memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_INET;
+ hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP;
hints.ai_flags = AI_PASSIVE;
for (res = res0; res; res = res->ai_next) {
struct pollfd *pfdp;
- if (res->ai_family == AF_INET)
+ switch (res->ai_family) {
+ case AF_INET:
pfdp = &pfd[PFD_INET];
- else {
- /*
- * XXX AF_INET6 is skipped on purpose, need to
- * fix '@' handling first.
- */
+ break;
+ case AF_INET6:
+ pfdp = &pfd[PFD_INET6];
+ break;
+ default:
continue;
}
continue;
}
- InetInuse = 1;
pfdp->fd = fd;
if (SecureMode)
shutdown(pfdp->fd, SHUT_RD);
}
}
if ((pfd[PFD_INET].revents & POLLIN) != 0) {
- len = sizeof(frominet);
+ len = sizeof(from);
i = recvfrom(pfd[PFD_INET].fd, line, MAXLINE, 0,
- (struct sockaddr *)&frominet, &len);
+ (struct sockaddr *)&from, &len);
if (i > 0) {
line[i] = '\0';
- cvthname((struct sockaddr *)&frominet, resolve,
- sizeof resolve);
+ cvthname((struct sockaddr *)&from, resolve,
+ sizeof(resolve));
dprintf("cvthname res: %s\n", resolve);
printline(resolve, line);
} else if (i < 0 && errno != EINTR)
logerror("recvfrom inet");
}
+ if ((pfd[PFD_INET6].revents & POLLIN) != 0) {
+ len = sizeof(from);
+ i = recvfrom(pfd[PFD_INET6].fd, line, MAXLINE, 0,
+ (struct sockaddr *)&from, &len);
+ if (i > 0) {
+ line[i] = '\0';
+ cvthname((struct sockaddr *)&from, resolve,
+ sizeof(resolve));
+ dprintf("cvthname res: %s\n", resolve);
+ printline(resolve, line);
+ } else if (i < 0 && errno != EINTR)
+ logerror("recvfrom inet6");
+ }
if ((pfd[PFD_CTLSOCK].revents & POLLIN) != 0)
ctlsock_accept_handler();
if ((pfd[PFD_CTLCONN].revents & POLLIN) != 0)
{
struct iovec iov[6];
struct iovec *v;
- int l, retryonce;
+ int fd, l, retryonce;
char line[MAXLINE + 1], repbuf[80], greetings[500];
v = iov;
case F_FORW:
dprintf(" %s\n", f->f_un.f_forw.f_loghost);
+ switch (f->f_un.f_forw.f_addr.ss_family) {
+ case AF_INET:
+ fd = pfd[PFD_INET].fd;
+ break;
+ case AF_INET6:
+ fd = pfd[PFD_INET6].fd;
+ break;
+ default:
+ fd = -1;
+ break;
+ }
if ((l = snprintf(line, sizeof(line), "<%d>%.15s %s%s%s",
f->f_prevpri, (char *)iov[0].iov_base,
IncludeHostname ? LocalHostName : "",
IncludeHostname ? " " : "",
(char *)iov[4].iov_base)) >= sizeof(line) || l == -1)
l = strlen(line);
- if (sendto(pfd[PFD_INET].fd, line, l, 0,
+ if (sendto(fd, line, l, 0,
(struct sockaddr *)&f->f_un.f_forw.f_addr,
f->f_un.f_forw.f_addr.ss_len) != l) {
switch (errno) {
switch (*p) {
case '@':
- if (!InetInuse)
- break;
if ((strlcpy(f->f_un.f_forw.f_loghost, p,
sizeof(f->f_un.f_forw.f_loghost)) >=
sizeof(f->f_un.f_forw.f_loghost))) {