Pull up following revision(s) (requested by pettai in ticket #897): usr.sbin/syslogd/tls.c: revision 1.11 usr.sbin/syslogd/syslogd.h: revision 1.4 usr.sbin/syslogd/syslogd.c: revision 1.115 PR/47861: Fredrik Pettai: keep track of the address family for each socket opened and don't send the a message to the wrong family type.diff -r1.105 -r1.105.4.1 src/usr.sbin/syslogd/syslogd.c
(msaitoh)
--- src/usr.sbin/syslogd/syslogd.c 2011/08/31 16:25:00 1.105
+++ src/usr.sbin/syslogd/syslogd.c 2013/06/13 07:11:11 1.105.4.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: syslogd.c,v 1.105 2011/08/31 16:25:00 plunky Exp $ */ | 1 | /* $NetBSD: syslogd.c,v 1.105.4.1 2013/06/13 07:11:11 msaitoh Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1983, 1988, 1993, 1994 | 4 | * Copyright (c) 1983, 1988, 1993, 1994 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -29,27 +29,27 @@ | @@ -29,27 +29,27 @@ | |||
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #ifndef lint | 33 | #ifndef lint | |
34 | __COPYRIGHT("@(#) Copyright (c) 1983, 1988, 1993, 1994\ | 34 | __COPYRIGHT("@(#) Copyright (c) 1983, 1988, 1993, 1994\ | |
35 | The Regents of the University of California. All rights reserved."); | 35 | The Regents of the University of California. All rights reserved."); | |
36 | #endif /* not lint */ | 36 | #endif /* not lint */ | |
37 | 37 | |||
38 | #ifndef lint | 38 | #ifndef lint | |
39 | #if 0 | 39 | #if 0 | |
40 | static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94"; | 40 | static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94"; | |
41 | #else | 41 | #else | |
42 | __RCSID("$NetBSD: syslogd.c,v 1.105 2011/08/31 16:25:00 plunky Exp $"); | 42 | __RCSID("$NetBSD: syslogd.c,v 1.105.4.1 2013/06/13 07:11:11 msaitoh Exp $"); | |
43 | #endif | 43 | #endif | |
44 | #endif /* not lint */ | 44 | #endif /* not lint */ | |
45 | 45 | |||
46 | /* | 46 | /* | |
47 | * syslogd -- log system messages | 47 | * syslogd -- log system messages | |
48 | * | 48 | * | |
49 | * This program implements a system log. It takes a series of lines. | 49 | * This program implements a system log. It takes a series of lines. | |
50 | * Each line may have a priority, signified as "<n>" as | 50 | * Each line may have a priority, signified as "<n>" as | |
51 | * the first characters of the line. If this is | 51 | * the first characters of the line. If this is | |
52 | * not present, a default priority is used. | 52 | * not present, a default priority is used. | |
53 | * | 53 | * | |
54 | * To kill syslogd, send a signal 15 (terminate). A signal 1 (hup) will | 54 | * To kill syslogd, send a signal 15 (terminate). A signal 1 (hup) will | |
55 | * cause it to reread its configuration file. | 55 | * cause it to reread its configuration file. | |
@@ -2479,26 +2479,28 @@ udp_send(struct filed *f, char *line, si | @@ -2479,26 +2479,28 @@ udp_send(struct filed *f, char *line, si | |||
2479 | 2479 | |||
2480 | DPRINTF((D_NET|D_CALL), "udp_send(f=%p, line=\"%s\", " | 2480 | DPRINTF((D_NET|D_CALL), "udp_send(f=%p, line=\"%s\", " | |
2481 | "len=%zu) to dest.\n", f, line, len); | 2481 | "len=%zu) to dest.\n", f, line, len); | |
2482 | 2482 | |||
2483 | if (!finet) | 2483 | if (!finet) | |
2484 | return; | 2484 | return; | |
2485 | 2485 | |||
2486 | lsent = -1; | 2486 | lsent = -1; | |
2487 | fail = 0; | 2487 | fail = 0; | |
2488 | assert(f->f_type == F_FORW); | 2488 | assert(f->f_type == F_FORW); | |
2489 | for (r = f->f_un.f_forw.f_addr; r; r = r->ai_next) { | 2489 | for (r = f->f_un.f_forw.f_addr; r; r = r->ai_next) { | |
2490 | retry = 0; | 2490 | retry = 0; | |
2491 | for (j = 0; j < finet->fd; j++) { | 2491 | for (j = 0; j < finet->fd; j++) { | |
2492 | if (finet[j+1].af != r->ai_family) | |||
2493 | continue; | |||
2492 | sendagain: | 2494 | sendagain: | |
2493 | lsent = sendto(finet[j+1].fd, line, len, 0, | 2495 | lsent = sendto(finet[j+1].fd, line, len, 0, | |
2494 | r->ai_addr, r->ai_addrlen); | 2496 | r->ai_addr, r->ai_addrlen); | |
2495 | if (lsent == -1) { | 2497 | if (lsent == -1) { | |
2496 | switch (errno) { | 2498 | switch (errno) { | |
2497 | case ENOBUFS: | 2499 | case ENOBUFS: | |
2498 | /* wait/retry/drop */ | 2500 | /* wait/retry/drop */ | |
2499 | if (++retry < 5) { | 2501 | if (++retry < 5) { | |
2500 | usleep(1000); | 2502 | usleep(1000); | |
2501 | goto sendagain; | 2503 | goto sendagain; | |
2502 | } | 2504 | } | |
2503 | break; | 2505 | break; | |
2504 | case EHOSTDOWN: | 2506 | case EHOSTDOWN: | |
@@ -3965,26 +3967,27 @@ socksetup(int af, const char *hostname) | @@ -3965,26 +3967,27 @@ socksetup(int af, const char *hostname) | |||
3965 | if (!socks) { | 3967 | if (!socks) { | |
3966 | logerror("Couldn't allocate memory for sockets"); | 3968 | logerror("Couldn't allocate memory for sockets"); | |
3967 | die(0, 0, NULL); | 3969 | die(0, 0, NULL); | |
3968 | } | 3970 | } | |
3969 | 3971 | |||
3970 | socks->fd = 0; /* num of sockets counter at start of array */ | 3972 | socks->fd = 0; /* num of sockets counter at start of array */ | |
3971 | s = socks + 1; | 3973 | s = socks + 1; | |
3972 | for (r = res; r; r = r->ai_next) { | 3974 | for (r = res; r; r = r->ai_next) { | |
3973 | s->fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol); | 3975 | s->fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol); | |
3974 | if (s->fd < 0) { | 3976 | if (s->fd < 0) { | |
3975 | logerror("socket() failed"); | 3977 | logerror("socket() failed"); | |
3976 | continue; | 3978 | continue; | |
3977 | } | 3979 | } | |
3980 | s->af = r->ai_family; | |||
3978 | if (r->ai_family == AF_INET6 && setsockopt(s->fd, IPPROTO_IPV6, | 3981 | if (r->ai_family == AF_INET6 && setsockopt(s->fd, IPPROTO_IPV6, | |
3979 | IPV6_V6ONLY, &on, sizeof(on)) < 0) { | 3982 | IPV6_V6ONLY, &on, sizeof(on)) < 0) { | |
3980 | logerror("setsockopt(IPV6_V6ONLY) failed"); | 3983 | logerror("setsockopt(IPV6_V6ONLY) failed"); | |
3981 | close(s->fd); | 3984 | close(s->fd); | |
3982 | continue; | 3985 | continue; | |
3983 | } | 3986 | } | |
3984 | 3987 | |||
3985 | if (!SecureMode) { | 3988 | if (!SecureMode) { | |
3986 | if (bind(s->fd, r->ai_addr, r->ai_addrlen) < 0) { | 3989 | if (bind(s->fd, r->ai_addr, r->ai_addrlen) < 0) { | |
3987 | logerror("bind() failed"); | 3990 | logerror("bind() failed"); | |
3988 | close(s->fd); | 3991 | close(s->fd); | |
3989 | continue; | 3992 | continue; | |
3990 | } | 3993 | } |
--- src/usr.sbin/syslogd/syslogd.h 2009/04/20 09:56:08 1.3
+++ src/usr.sbin/syslogd/syslogd.h 2013/06/13 07:11:11 1.3.8.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: syslogd.h,v 1.3 2009/04/20 09:56:08 mschuett Exp $ */ | 1 | /* $NetBSD: syslogd.h,v 1.3.8.1 2013/06/13 07:11:11 msaitoh Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Martin Schütte. | 8 | * by Martin Schütte. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -292,26 +292,27 @@ struct buf_msg { | @@ -292,26 +292,27 @@ struct buf_msg { | |||
292 | size_t prilen; /* bytes for priority and version */ | 292 | size_t prilen; /* bytes for priority and version */ | |
293 | }; | 293 | }; | |
294 | 294 | |||
295 | /* queue of messages */ | 295 | /* queue of messages */ | |
296 | struct buf_queue { | 296 | struct buf_queue { | |
297 | struct buf_msg* msg; | 297 | struct buf_msg* msg; | |
298 | STAILQ_ENTRY(buf_queue) entries; | 298 | STAILQ_ENTRY(buf_queue) entries; | |
299 | }; | 299 | }; | |
300 | STAILQ_HEAD(buf_queue_head, buf_queue); | 300 | STAILQ_HEAD(buf_queue_head, buf_queue); | |
301 | 301 | |||
302 | /* a pair of a socket and an associated event object */ | 302 | /* a pair of a socket and an associated event object */ | |
303 | struct socketEvent { | 303 | struct socketEvent { | |
304 | int fd; | 304 | int fd; | |
305 | int af; | |||
305 | struct event *ev; | 306 | struct event *ev; | |
306 | }; | 307 | }; | |
307 | 308 | |||
308 | /* | 309 | /* | |
309 | * Flags to logmsg(). | 310 | * Flags to logmsg(). | |
310 | */ | 311 | */ | |
311 | #define IGN_CONS 0x001 /* don't print on console */ | 312 | #define IGN_CONS 0x001 /* don't print on console */ | |
312 | #define SYNC_FILE 0x002 /* do fsync on file after printing */ | 313 | #define SYNC_FILE 0x002 /* do fsync on file after printing */ | |
313 | #define ADDDATE 0x004 /* add a date to the message */ | 314 | #define ADDDATE 0x004 /* add a date to the message */ | |
314 | #define MARK 0x008 /* this message is a mark */ | 315 | #define MARK 0x008 /* this message is a mark */ | |
315 | #define ISKERNEL 0x010 /* kernel generated message */ | 316 | #define ISKERNEL 0x010 /* kernel generated message */ | |
316 | #define BSDSYSLOG 0x020 /* line in traditional BSD Syslog format */ | 317 | #define BSDSYSLOG 0x020 /* line in traditional BSD Syslog format */ | |
317 | #define SIGN_MSG 0x040 /* syslog-sign data, not signed again */ | 318 | #define SIGN_MSG 0x040 /* syslog-sign data, not signed again */ |
--- src/usr.sbin/syslogd/tls.c 2012/02/13 07:40:24 1.9
+++ src/usr.sbin/syslogd/tls.c 2013/06/13 07:11:11 1.9.2.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: tls.c,v 1.9 2012/02/13 07:40:24 spz Exp $ */ | 1 | /* $NetBSD: tls.c,v 1.9.2.1 2013/06/13 07:11:11 msaitoh Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Martin Schütte. | 8 | * by Martin Schütte. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -35,27 +35,27 @@ | @@ -35,27 +35,27 @@ | |||
35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
36 | * POSSIBILITY OF SUCH DAMAGE. | 36 | * POSSIBILITY OF SUCH DAMAGE. | |
37 | */ | 37 | */ | |
38 | /* | 38 | /* | |
39 | * tls.c TLS related code for syslogd | 39 | * tls.c TLS related code for syslogd | |
40 | * | 40 | * | |
41 | * implements the TLS init and handshake callbacks with all required | 41 | * implements the TLS init and handshake callbacks with all required | |
42 | * checks from http://tools.ietf.org/html/draft-ietf-syslog-transport-tls-13 | 42 | * checks from http://tools.ietf.org/html/draft-ietf-syslog-transport-tls-13 | |
43 | * | 43 | * | |
44 | * Martin Schütte | 44 | * Martin Schütte | |
45 | */ | 45 | */ | |
46 | 46 | |||
47 | #include <sys/cdefs.h> | 47 | #include <sys/cdefs.h> | |
48 | __RCSID("$NetBSD: tls.c,v 1.9 2012/02/13 07:40:24 spz Exp $"); | 48 | __RCSID("$NetBSD: tls.c,v 1.9.2.1 2013/06/13 07:11:11 msaitoh Exp $"); | |
49 | 49 | |||
50 | #ifndef DISABLE_TLS | 50 | #ifndef DISABLE_TLS | |
51 | #include "syslogd.h" | 51 | #include "syslogd.h" | |
52 | #include "tls.h" | 52 | #include "tls.h" | |
53 | #include <netinet/in.h> | 53 | #include <netinet/in.h> | |
54 | #include <ifaddrs.h> | 54 | #include <ifaddrs.h> | |
55 | #include "extern.h" | 55 | #include "extern.h" | |
56 | 56 | |||
57 | static unsigned getVerifySetting(const char *x509verifystring); | 57 | static unsigned getVerifySetting(const char *x509verifystring); | |
58 | 58 | |||
59 | /* to output SSL error codes */ | 59 | /* to output SSL error codes */ | |
60 | static const char *SSL_ERRCODE[] = { | 60 | static const char *SSL_ERRCODE[] = { | |
61 | "SSL_ERROR_NONE", | 61 | "SSL_ERROR_NONE", | |
@@ -841,26 +841,27 @@ socksetup_tls(const int af, const char * | @@ -841,26 +841,27 @@ socksetup_tls(const int af, const char * | |||
841 | if (!socks) { | 841 | if (!socks) { | |
842 | logerror("Unable to allocate memory for sockets"); | 842 | logerror("Unable to allocate memory for sockets"); | |
843 | die(0, 0, NULL); | 843 | die(0, 0, NULL); | |
844 | } | 844 | } | |
845 | 845 | |||
846 | socks->fd = 0; /* num of sockets counter at start of array */ | 846 | socks->fd = 0; /* num of sockets counter at start of array */ | |
847 | s = socks + 1; | 847 | s = socks + 1; | |
848 | for (r = res; r; r = r->ai_next) { | 848 | for (r = res; r; r = r->ai_next) { | |
849 | if ((s->fd = socket(r->ai_family, r->ai_socktype, | 849 | if ((s->fd = socket(r->ai_family, r->ai_socktype, | |
850 | r->ai_protocol)) == -1) { | 850 | r->ai_protocol)) == -1) { | |
851 | logerror("socket() failed: %s", strerror(errno)); | 851 | logerror("socket() failed: %s", strerror(errno)); | |
852 | continue; | 852 | continue; | |
853 | } | 853 | } | |
854 | s->af = r->ai_family; | |||
854 | if (r->ai_family == AF_INET6 | 855 | if (r->ai_family == AF_INET6 | |
855 | && setsockopt(s->fd, IPPROTO_IPV6, IPV6_V6ONLY, | 856 | && setsockopt(s->fd, IPPROTO_IPV6, IPV6_V6ONLY, | |
856 | &on, sizeof(on)) == -1) { | 857 | &on, sizeof(on)) == -1) { | |
857 | logerror("setsockopt(IPV6_V6ONLY) failed: %s", | 858 | logerror("setsockopt(IPV6_V6ONLY) failed: %s", | |
858 | strerror(errno)); | 859 | strerror(errno)); | |
859 | close(s->fd); | 860 | close(s->fd); | |
860 | continue; | 861 | continue; | |
861 | } | 862 | } | |
862 | if (setsockopt(s->fd, SOL_SOCKET, SO_REUSEADDR, | 863 | if (setsockopt(s->fd, SOL_SOCKET, SO_REUSEADDR, | |
863 | &on, sizeof(on)) == -1) { | 864 | &on, sizeof(on)) == -1) { | |
864 | DPRINTF(D_NET, "Unable to setsockopt(): %s\n", | 865 | DPRINTF(D_NET, "Unable to setsockopt(): %s\n", | |
865 | strerror(errno)); | 866 | strerror(errno)); | |
866 | } | 867 | } |