ppp: Import some more patches from Fedora.
[people/teissler/ipfire-2.x.git] / src / patches / ppp / 0014-everywhere-use-SOCK_CLOEXEC-when-creating-socket.patch
1 From 2a97ab28ee00586e5f06b3ef3a0e43ea0c7c6499 Mon Sep 17 00:00:00 2001
2 From: Michal Sekletar <msekleta@redhat.com>
3 Date: Mon, 7 Apr 2014 14:21:41 +0200
4 Subject: [PATCH 14/25] everywhere: use SOCK_CLOEXEC when creating socket
5
6 ---
7 pppd/plugins/pppoatm/pppoatm.c | 2 +-
8 pppd/plugins/pppol2tp/openl2tp.c | 2 +-
9 pppd/plugins/pppol2tp/pppol2tp.c | 2 +-
10 pppd/plugins/rp-pppoe/if.c | 2 +-
11 pppd/plugins/rp-pppoe/plugin.c | 6 +++---
12 pppd/plugins/rp-pppoe/pppoe-discovery.c | 2 +-
13 pppd/sys-linux.c | 10 +++++-----
14 pppd/tty.c | 2 +-
15 8 files changed, 14 insertions(+), 14 deletions(-)
16
17 diff --git a/pppd/plugins/pppoatm/pppoatm.c b/pppd/plugins/pppoatm/pppoatm.c
18 index d693350..c31bb34 100644
19 --- a/pppd/plugins/pppoatm/pppoatm.c
20 +++ b/pppd/plugins/pppoatm/pppoatm.c
21 @@ -135,7 +135,7 @@ static int connect_pppoatm(void)
22
23 if (!device_got_set)
24 no_device_given_pppoatm();
25 - fd = socket(AF_ATMPVC, SOCK_DGRAM, 0);
26 + fd = socket(AF_ATMPVC, SOCK_DGRAM | SOCK_CLOEXEC, 0);
27 if (fd < 0)
28 fatal("failed to create socket: %m");
29 memset(&qos, 0, sizeof qos);
30 diff --git a/pppd/plugins/pppol2tp/openl2tp.c b/pppd/plugins/pppol2tp/openl2tp.c
31 index 9643b96..1099575 100644
32 --- a/pppd/plugins/pppol2tp/openl2tp.c
33 +++ b/pppd/plugins/pppol2tp/openl2tp.c
34 @@ -83,7 +83,7 @@ static int openl2tp_client_create(void)
35 int result;
36
37 if (openl2tp_fd < 0) {
38 - openl2tp_fd = socket(PF_UNIX, SOCK_DGRAM, 0);
39 + openl2tp_fd = socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
40 if (openl2tp_fd < 0) {
41 error("openl2tp connection create: %m");
42 return -ENOTCONN;
43 diff --git a/pppd/plugins/pppol2tp/pppol2tp.c b/pppd/plugins/pppol2tp/pppol2tp.c
44 index a7e3400..e64a778 100644
45 --- a/pppd/plugins/pppol2tp/pppol2tp.c
46 +++ b/pppd/plugins/pppol2tp/pppol2tp.c
47 @@ -208,7 +208,7 @@ static void send_config_pppol2tp(int mtu,
48 struct ifreq ifr;
49 int fd;
50
51 - fd = socket(AF_INET, SOCK_DGRAM, 0);
52 + fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
53 if (fd >= 0) {
54 memset (&ifr, '\0', sizeof (ifr));
55 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
56 diff --git a/pppd/plugins/rp-pppoe/if.c b/pppd/plugins/rp-pppoe/if.c
57 index 91e9a57..72aba41 100644
58 --- a/pppd/plugins/rp-pppoe/if.c
59 +++ b/pppd/plugins/rp-pppoe/if.c
60 @@ -116,7 +116,7 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
61 stype = SOCK_PACKET;
62 #endif
63
64 - if ((fd = socket(domain, stype, htons(type))) < 0) {
65 + if ((fd = socket(domain, stype | SOCK_CLOEXEC, htons(type))) < 0) {
66 /* Give a more helpful message for the common error case */
67 if (errno == EPERM) {
68 fatal("Cannot create raw socket -- pppoe must be run as root.");
69 diff --git a/pppd/plugins/rp-pppoe/plugin.c b/pppd/plugins/rp-pppoe/plugin.c
70 index a8c2bb4..24bdf8f 100644
71 --- a/pppd/plugins/rp-pppoe/plugin.c
72 +++ b/pppd/plugins/rp-pppoe/plugin.c
73 @@ -137,7 +137,7 @@ PPPOEConnectDevice(void)
74 /* server equipment). */
75 /* Opening this socket just before waitForPADS in the discovery() */
76 /* function would be more appropriate, but it would mess-up the code */
77 - conn->sessionSocket = socket(AF_PPPOX, SOCK_STREAM, PX_PROTO_OE);
78 + conn->sessionSocket = socket(AF_PPPOX, SOCK_STREAM | SOCK_CLOEXEC, PX_PROTO_OE);
79 if (conn->sessionSocket < 0) {
80 error("Failed to create PPPoE socket: %m");
81 return -1;
82 @@ -148,7 +148,7 @@ PPPOEConnectDevice(void)
83 lcp_wantoptions[0].mru = conn->mru;
84
85 /* Update maximum MRU */
86 - s = socket(AF_INET, SOCK_DGRAM, 0);
87 + s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
88 if (s < 0) {
89 error("Can't get MTU for %s: %m", conn->ifName);
90 goto errout;
91 @@ -320,7 +320,7 @@ PPPoEDevnameHook(char *cmd, char **argv, int doit)
92 }
93
94 /* Open a socket */
95 - if ((fd = socket(PF_PACKET, SOCK_RAW, 0)) < 0) {
96 + if ((fd = socket(PF_PACKET, SOCK_RAW | SOCK_CLOEXEC, 0)) < 0) {
97 r = 0;
98 }
99
100 diff --git a/pppd/plugins/rp-pppoe/pppoe-discovery.c b/pppd/plugins/rp-pppoe/pppoe-discovery.c
101 index 3d3bf4e..c0d927d 100644
102 --- a/pppd/plugins/rp-pppoe/pppoe-discovery.c
103 +++ b/pppd/plugins/rp-pppoe/pppoe-discovery.c
104 @@ -121,7 +121,7 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
105 stype = SOCK_PACKET;
106 #endif
107
108 - if ((fd = socket(domain, stype, htons(type))) < 0) {
109 + if ((fd = socket(domain, stype | SOCK_CLOEXEC, htons(type))) < 0) {
110 /* Give a more helpful message for the common error case */
111 if (errno == EPERM) {
112 rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
113 diff --git a/pppd/sys-linux.c b/pppd/sys-linux.c
114 index 00a2cf5..0690019 100644
115 --- a/pppd/sys-linux.c
116 +++ b/pppd/sys-linux.c
117 @@ -308,12 +308,12 @@ static int modify_flags(int fd, int clear_bits, int set_bits)
118 void sys_init(void)
119 {
120 /* Get an internet socket for doing socket ioctls. */
121 - sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
122 + sock_fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
123 if (sock_fd < 0)
124 fatal("Couldn't create IP socket: %m(%d)", errno);
125
126 #ifdef INET6
127 - sock6_fd = socket(AF_INET6, SOCK_DGRAM, 0);
128 + sock6_fd = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0);
129 if (sock6_fd < 0)
130 sock6_fd = -errno; /* save errno for later */
131 #endif
132 @@ -1857,7 +1857,7 @@ get_if_hwaddr(u_char *addr, char *name)
133 struct ifreq ifreq;
134 int ret, sock_fd;
135
136 - sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
137 + sock_fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
138 if (sock_fd < 0)
139 return 0;
140 memset(&ifreq.ifr_hwaddr, 0, sizeof(struct sockaddr));
141 @@ -2067,7 +2067,7 @@ int ppp_available(void)
142 /*
143 * Open a socket for doing the ioctl operations.
144 */
145 - s = socket(AF_INET, SOCK_DGRAM, 0);
146 + s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
147 if (s < 0)
148 return 0;
149
150 @@ -2860,7 +2860,7 @@ ether_to_eui64(eui64_t *p_eui64)
151 int skfd;
152 const unsigned char *ptr;
153
154 - skfd = socket(PF_INET6, SOCK_DGRAM, 0);
155 + skfd = socket(PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0);
156 if(skfd == -1)
157 {
158 warn("could not open IPv6 socket");
159 diff --git a/pppd/tty.c b/pppd/tty.c
160 index bc96695..8e76a5d 100644
161 --- a/pppd/tty.c
162 +++ b/pppd/tty.c
163 @@ -896,7 +896,7 @@ open_socket(dest)
164 *sep = ':';
165
166 /* get a socket and connect it to the other end */
167 - sock = socket(PF_INET, SOCK_STREAM, 0);
168 + sock = socket(PF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
169 if (sock < 0) {
170 error("Can't create socket: %m");
171 return -1;
172 --
173 1.8.3.1
174