]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - dhcp/patches/dhcp-4.2.0-CLOEXEC.patch
2483f55421cd5deccaf5c2247ab8892c946226c8
[people/ms/ipfire-3.x.git] / dhcp / patches / dhcp-4.2.0-CLOEXEC.patch
1 diff -up dhcp-4.2.0/client/clparse.c.cloexec dhcp-4.2.0/client/clparse.c
2 --- dhcp-4.2.0/client/clparse.c.cloexec 2010-07-21 13:55:42.000000000 +0200
3 +++ dhcp-4.2.0/client/clparse.c 2010-07-21 14:31:13.000000000 +0200
4 @@ -211,7 +211,7 @@ int read_client_conf_file (const char *n
5 int token;
6 isc_result_t status;
7
8 - if ((file = open (name, O_RDONLY)) < 0)
9 + if ((file = open (name, O_RDONLY | O_CLOEXEC)) < 0)
10 return uerr2isc (errno);
11
12 cfile = NULL;
13 @@ -248,7 +248,7 @@ void read_client_leases ()
14
15 /* Open the lease file. If we can't open it, just return -
16 we can safely trust the server to remember our state. */
17 - if ((file = open (path_dhclient_db, O_RDONLY)) < 0)
18 + if ((file = open (path_dhclient_db, O_RDONLY | O_CLOEXEC)) < 0)
19 return;
20
21 cfile = NULL;
22 diff -up dhcp-4.2.0/client/dhclient.c.cloexec dhcp-4.2.0/client/dhclient.c
23 --- dhcp-4.2.0/client/dhclient.c.cloexec 2010-07-21 13:55:42.000000000 +0200
24 +++ dhcp-4.2.0/client/dhclient.c 2010-07-21 14:33:44.000000000 +0200
25 @@ -137,11 +137,11 @@ main(int argc, char **argv) {
26 /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
27 2 (stderr) are open. To do this, we assume that when we
28 open a file the lowest available file descriptor is used. */
29 - fd = open("/dev/null", O_RDWR);
30 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
31 if (fd == 0)
32 - fd = open("/dev/null", O_RDWR);
33 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
34 if (fd == 1)
35 - fd = open("/dev/null", O_RDWR);
36 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
37 if (fd == 2)
38 log_perror = 0; /* No sense logging to /dev/null. */
39 else if (fd != -1)
40 @@ -488,7 +488,7 @@ main(int argc, char **argv) {
41 int e;
42
43 oldpid = 0;
44 - if ((pidfd = fopen(path_dhclient_pid, "r")) != NULL) {
45 + if ((pidfd = fopen(path_dhclient_pid, "re")) != NULL) {
46 e = fscanf(pidfd, "%ld\n", &temp);
47 oldpid = (pid_t)temp;
48
49 @@ -530,7 +530,7 @@ main(int argc, char **argv) {
50 strncpy(new_path_dhclient_pid, path_dhclient_pid, pfx);
51 sprintf(new_path_dhclient_pid + pfx, "-%s.pid", ip->name);
52
53 - if ((pidfd = fopen(new_path_dhclient_pid, "r")) != NULL) {
54 + if ((pidfd = fopen(new_path_dhclient_pid, "re")) != NULL) {
55 e = fscanf(pidfd, "%ld\n", &temp);
56 oldpid = (pid_t)temp;
57
58 @@ -555,7 +555,7 @@ main(int argc, char **argv) {
59 int dhc_running = 0;
60 char procfn[256] = "";
61
62 - if ((pidfp = fopen(path_dhclient_pid, "r")) != NULL) {
63 + if ((pidfp = fopen(path_dhclient_pid, "re")) != NULL) {
64 if ((fscanf(pidfp, "%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
65 snprintf(procfn,256,"/proc/%u",dhcpid);
66 dhc_running = (access(procfn, F_OK) == 0);
67 @@ -2931,7 +2931,7 @@ void rewrite_client_leases ()
68
69 if (leaseFile != NULL)
70 fclose (leaseFile);
71 - leaseFile = fopen (path_dhclient_db, "w");
72 + leaseFile = fopen (path_dhclient_db, "we");
73 if (leaseFile == NULL) {
74 log_error ("can't create %s: %m", path_dhclient_db);
75 return;
76 @@ -3035,7 +3035,7 @@ write_duid(struct data_string *duid)
77 return DHCP_R_INVALIDARG;
78
79 if (leaseFile == NULL) { /* XXX? */
80 - leaseFile = fopen(path_dhclient_db, "w");
81 + leaseFile = fopen(path_dhclient_db, "we");
82 if (leaseFile == NULL) {
83 log_error("can't create %s: %m", path_dhclient_db);
84 return ISC_R_IOERROR;
85 @@ -3215,7 +3215,7 @@ int write_client_lease (client, lease, r
86 return 1;
87
88 if (leaseFile == NULL) { /* XXX */
89 - leaseFile = fopen (path_dhclient_db, "w");
90 + leaseFile = fopen (path_dhclient_db, "we");
91 if (leaseFile == NULL) {
92 log_error ("can't create %s: %m", path_dhclient_db);
93 return 0;
94 @@ -3668,9 +3668,9 @@ void go_daemon ()
95 close(2);
96
97 /* Reopen them on /dev/null. */
98 - open("/dev/null", O_RDWR);
99 - open("/dev/null", O_RDWR);
100 - open("/dev/null", O_RDWR);
101 + open("/dev/null", O_RDWR | O_CLOEXEC);
102 + open("/dev/null", O_RDWR | O_CLOEXEC);
103 + open("/dev/null", O_RDWR | O_CLOEXEC);
104
105 write_client_pid_file ();
106
107 @@ -3682,14 +3682,14 @@ void write_client_pid_file ()
108 FILE *pf;
109 int pfdesc;
110
111 - pfdesc = open (path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY, 0644);
112 + pfdesc = open (path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
113
114 if (pfdesc < 0) {
115 log_error ("Can't create %s: %m", path_dhclient_pid);
116 return;
117 }
118
119 - pf = fdopen (pfdesc, "w");
120 + pf = fdopen (pfdesc, "we");
121 if (!pf)
122 log_error ("Can't fdopen %s: %m", path_dhclient_pid);
123 else {
124 diff -up dhcp-4.2.0/common/bpf.c.cloexec dhcp-4.2.0/common/bpf.c
125 --- dhcp-4.2.0/common/bpf.c.cloexec 2009-11-20 02:48:59.000000000 +0100
126 +++ dhcp-4.2.0/common/bpf.c 2010-07-21 14:31:13.000000000 +0200
127 @@ -94,7 +94,7 @@ int if_register_bpf (info)
128 for (b = 0; 1; b++) {
129 /* %Audit% 31 bytes max. %2004.06.17,Safe% */
130 sprintf(filename, BPF_FORMAT, b);
131 - sock = open (filename, O_RDWR, 0);
132 + sock = open (filename, O_RDWR | O_CLOEXEC, 0);
133 if (sock < 0) {
134 if (errno == EBUSY) {
135 continue;
136 diff -up dhcp-4.2.0/common/discover.c.cloexec dhcp-4.2.0/common/discover.c
137 --- dhcp-4.2.0/common/discover.c.cloexec 2009-10-28 05:12:29.000000000 +0100
138 +++ dhcp-4.2.0/common/discover.c 2010-07-21 14:31:13.000000000 +0200
139 @@ -409,7 +409,7 @@ begin_iface_scan(struct iface_conf_list
140 int len;
141 int i;
142
143 - ifaces->fp = fopen("/proc/net/dev", "r");
144 + ifaces->fp = fopen("/proc/net/dev", "re");
145 if (ifaces->fp == NULL) {
146 log_error("Error opening '/proc/net/dev' to list interfaces");
147 return 0;
148 @@ -444,7 +444,7 @@ begin_iface_scan(struct iface_conf_list
149
150 #ifdef DHCPv6
151 if (local_family == AF_INET6) {
152 - ifaces->fp6 = fopen("/proc/net/if_inet6", "r");
153 + ifaces->fp6 = fopen("/proc/net/if_inet6", "re");
154 if (ifaces->fp6 == NULL) {
155 log_error("Error opening '/proc/net/if_inet6' to "
156 "list IPv6 interfaces; %m");
157 diff -up dhcp-4.2.0/common/dlpi.c.cloexec dhcp-4.2.0/common/dlpi.c
158 --- dhcp-4.2.0/common/dlpi.c.cloexec 2009-11-20 02:49:00.000000000 +0100
159 +++ dhcp-4.2.0/common/dlpi.c 2010-07-21 14:31:13.000000000 +0200
160 @@ -807,7 +807,7 @@ dlpiopen(const char *ifname) {
161 }
162 *dp = '\0';
163
164 - return open (devname, O_RDWR, 0);
165 + return open (devname, O_RDWR | O_CLOEXEC, 0);
166 }
167
168 /*
169 diff -up dhcp-4.2.0/common/nit.c.cloexec dhcp-4.2.0/common/nit.c
170 --- dhcp-4.2.0/common/nit.c.cloexec 2009-11-20 02:49:01.000000000 +0100
171 +++ dhcp-4.2.0/common/nit.c 2010-07-21 14:31:13.000000000 +0200
172 @@ -81,7 +81,7 @@ int if_register_nit (info)
173 struct strioctl sio;
174
175 /* Open a NIT device */
176 - sock = open ("/dev/nit", O_RDWR);
177 + sock = open ("/dev/nit", O_RDWR | O_CLOEXEC);
178 if (sock < 0)
179 log_fatal ("Can't open NIT device for %s: %m", info -> name);
180
181 diff -up dhcp-4.2.0/common/resolv.c.cloexec dhcp-4.2.0/common/resolv.c
182 --- dhcp-4.2.0/common/resolv.c.cloexec 2009-11-20 02:49:01.000000000 +0100
183 +++ dhcp-4.2.0/common/resolv.c 2010-07-21 14:31:13.000000000 +0200
184 @@ -49,7 +49,7 @@ void read_resolv_conf (parse_time)
185 struct domain_search_list *dp, *dl, *nd;
186 isc_result_t status;
187
188 - if ((file = open (path_resolv_conf, O_RDONLY)) < 0) {
189 + if ((file = open (path_resolv_conf, O_RDONLY | O_CLOEXEC)) < 0) {
190 log_error ("Can't open %s: %m", path_resolv_conf);
191 return;
192 }
193 diff -up dhcp-4.2.0/common/upf.c.cloexec dhcp-4.2.0/common/upf.c
194 --- dhcp-4.2.0/common/upf.c.cloexec 2009-11-20 02:49:01.000000000 +0100
195 +++ dhcp-4.2.0/common/upf.c 2010-07-21 14:31:13.000000000 +0200
196 @@ -77,7 +77,7 @@ int if_register_upf (info)
197 /* %Audit% Cannot exceed 36 bytes. %2004.06.17,Safe% */
198 sprintf(filename, "/dev/pf/pfilt%d", b);
199
200 - sock = open (filename, O_RDWR, 0);
201 + sock = open (filename, O_RDWR | O_CLOEXEC, 0);
202 if (sock < 0) {
203 if (errno == EBUSY) {
204 continue;
205 diff -up dhcp-4.2.0/dst/dst_api.c.cloexec dhcp-4.2.0/dst/dst_api.c
206 --- dhcp-4.2.0/dst/dst_api.c.cloexec 2009-10-29 01:46:48.000000000 +0100
207 +++ dhcp-4.2.0/dst/dst_api.c 2010-07-21 14:31:13.000000000 +0200
208 @@ -437,7 +437,7 @@ dst_s_write_private_key(const DST_KEY *k
209 PRIVATE_KEY, PATH_MAX);
210
211 /* Do not overwrite an existing file */
212 - if ((fp = dst_s_fopen(file, "w", 0600)) != NULL) {
213 + if ((fp = dst_s_fopen(file, "we", 0600)) != NULL) {
214 int nn;
215 if ((nn = fwrite(encoded_block, 1, len, fp)) != len) {
216 EREPORT(("dst_write_private_key(): Write failure on %s %d != %d errno=%d\n",
217 @@ -494,7 +494,7 @@ dst_s_read_public_key(const char *in_nam
218 * flags, proto, alg stored as decimal (or hex numbers FIXME).
219 * (FIXME: handle parentheses for line continuation.)
220 */
221 - if ((fp = dst_s_fopen(name, "r", 0)) == NULL) {
222 + if ((fp = dst_s_fopen(name, "re", 0)) == NULL) {
223 EREPORT(("dst_read_public_key(): Public Key not found %s\n",
224 name));
225 return (NULL);
226 @@ -620,7 +620,7 @@ dst_s_write_public_key(const DST_KEY *ke
227 return (0);
228 }
229 /* create public key file */
230 - if ((fp = dst_s_fopen(filename, "w+", 0644)) == NULL) {
231 + if ((fp = dst_s_fopen(filename, "w+e", 0644)) == NULL) {
232 EREPORT(("DST_write_public_key: open of file:%s failed (errno=%d)\n",
233 filename, errno));
234 return (0);
235 @@ -854,7 +854,7 @@ dst_s_read_private_key_file(char *name,
236 return (0);
237 }
238 /* first check if we can find the key file */
239 - if ((fp = dst_s_fopen(filename, "r", 0)) == NULL) {
240 + if ((fp = dst_s_fopen(filename, "re", 0)) == NULL) {
241 EREPORT(("dst_s_read_private_key_file: Could not open file %s in directory %s\n",
242 filename, dst_path[0] ? dst_path :
243 (char *) getcwd(NULL, PATH_MAX - 1)));
244 diff -up dhcp-4.2.0/dst/prandom.c.cloexec dhcp-4.2.0/dst/prandom.c
245 --- dhcp-4.2.0/dst/prandom.c.cloexec 2009-11-20 02:49:01.000000000 +0100
246 +++ dhcp-4.2.0/dst/prandom.c 2010-07-21 14:31:13.000000000 +0200
247 @@ -269,7 +269,7 @@ get_dev_random(u_char *output, unsigned
248
249 s = stat("/dev/random", &st);
250 if (s == 0 && S_ISCHR(st.st_mode)) {
251 - if ((fd = open("/dev/random", O_RDONLY | O_NONBLOCK)) != -1) {
252 + if ((fd = open("/dev/random", O_RDONLY | O_NONBLOCK | O_CLOEXEC)) != -1) {
253 if ((n = read(fd, output, size)) < 0)
254 n = 0;
255 close(fd);
256 @@ -480,7 +480,7 @@ digest_file(dst_work *work)
257 work->file_digest = dst_free_key(work->file_digest);
258 return (0);
259 }
260 - if ((fp = fopen(name, "r")) == NULL)
261 + if ((fp = fopen(name, "re")) == NULL)
262 return (0);
263 for (no = 0; (i = fread(buf, sizeof(*buf), sizeof(buf), fp)) > 0;
264 no += i)
265 diff -up dhcp-4.2.0/omapip/trace.c.cloexec dhcp-4.2.0/omapip/trace.c
266 --- dhcp-4.2.0/omapip/trace.c.cloexec 2010-06-01 19:29:59.000000000 +0200
267 +++ dhcp-4.2.0/omapip/trace.c 2010-07-21 14:36:48.000000000 +0200
268 @@ -141,10 +141,10 @@ isc_result_t trace_begin (const char *fi
269 return DHCP_R_INVALIDARG;
270 }
271
272 - traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL, 0600);
273 + traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL | O_CLOEXEC, 0600);
274 if (traceoutfile < 0 && errno == EEXIST) {
275 log_error ("WARNING: Overwriting trace file \"%s\"", filename);
276 - traceoutfile = open (filename, O_WRONLY | O_EXCL | O_TRUNC,
277 + traceoutfile = open (filename, O_WRONLY | O_EXCL | O_TRUNC | O_CLOEXEC,
278 0600);
279 }
280
281 @@ -431,7 +431,7 @@ void trace_file_replay (const char *file
282 isc_result_t result;
283 int len;
284
285 - traceinfile = fopen (filename, "r");
286 + traceinfile = fopen (filename, "re");
287 if (!traceinfile) {
288 log_error("Can't open tracefile %s: %m", filename);
289 return;
290 diff -up dhcp-4.2.0/relay/dhcrelay.c.cloexec dhcp-4.2.0/relay/dhcrelay.c
291 --- dhcp-4.2.0/relay/dhcrelay.c.cloexec 2010-02-17 21:33:55.000000000 +0100
292 +++ dhcp-4.2.0/relay/dhcrelay.c 2010-07-21 14:31:39.000000000 +0200
293 @@ -177,11 +177,11 @@ main(int argc, char **argv) {
294 /* Make sure that file descriptors 0(stdin), 1,(stdout), and
295 2(stderr) are open. To do this, we assume that when we
296 open a file the lowest available file descriptor is used. */
297 - fd = open("/dev/null", O_RDWR);
298 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
299 if (fd == 0)
300 - fd = open("/dev/null", O_RDWR);
301 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
302 if (fd == 1)
303 - fd = open("/dev/null", O_RDWR);
304 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
305 if (fd == 2)
306 log_perror = 0; /* No sense logging to /dev/null. */
307 else if (fd != -1)
308 @@ -520,12 +520,12 @@ main(int argc, char **argv) {
309 exit(0);
310
311 pfdesc = open(path_dhcrelay_pid,
312 - O_CREAT | O_TRUNC | O_WRONLY, 0644);
313 + O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
314
315 if (pfdesc < 0) {
316 log_error("Can't create %s: %m", path_dhcrelay_pid);
317 } else {
318 - pf = fdopen(pfdesc, "w");
319 + pf = fdopen(pfdesc, "we");
320 if (!pf)
321 log_error("Can't fdopen %s: %m",
322 path_dhcrelay_pid);
323 diff -up dhcp-4.2.0/server/confpars.c.cloexec dhcp-4.2.0/server/confpars.c
324 --- dhcp-4.2.0/server/confpars.c.cloexec 2010-03-24 22:49:47.000000000 +0100
325 +++ dhcp-4.2.0/server/confpars.c 2010-07-21 14:31:39.000000000 +0200
326 @@ -116,7 +116,7 @@ isc_result_t read_conf_file (const char
327 }
328 #endif
329
330 - if ((file = open (filename, O_RDONLY)) < 0) {
331 + if ((file = open (filename, O_RDONLY | O_CLOEXEC)) < 0) {
332 if (leasep) {
333 log_error ("Can't open lease database %s: %m --",
334 path_dhcpd_db);
335 diff -up dhcp-4.2.0/server/db.c.cloexec dhcp-4.2.0/server/db.c
336 --- dhcp-4.2.0/server/db.c.cloexec 2010-02-17 21:33:55.000000000 +0100
337 +++ dhcp-4.2.0/server/db.c 2010-07-21 14:31:39.000000000 +0200
338 @@ -1035,7 +1035,7 @@ void db_startup (testp)
339 }
340 #endif
341 if (!testp) {
342 - db_file = fopen (path_dhcpd_db, "a");
343 + db_file = fopen (path_dhcpd_db, "ae");
344 if (!db_file)
345 log_fatal ("Can't open %s for append.", path_dhcpd_db);
346 expire_all_pools ();
347 @@ -1083,12 +1083,12 @@ int new_lease_file ()
348 path_dhcpd_db, (int)t) >= sizeof newfname)
349 log_fatal("new_lease_file: lease file path too long");
350
351 - db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT, 0664);
352 + db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0664);
353 if (db_fd < 0) {
354 log_error ("Can't create new lease file: %m");
355 return 0;
356 }
357 - if ((new_db_file = fdopen(db_fd, "w")) == NULL) {
358 + if ((new_db_file = fdopen(db_fd, "we")) == NULL) {
359 log_error("Can't fdopen new lease file: %m");
360 close(db_fd);
361 goto fdfail;
362 diff -up dhcp-4.2.0/server/dhcpd.c.cloexec dhcp-4.2.0/server/dhcpd.c
363 --- dhcp-4.2.0/server/dhcpd.c.cloexec 2010-06-01 19:29:59.000000000 +0200
364 +++ dhcp-4.2.0/server/dhcpd.c 2010-07-21 14:31:39.000000000 +0200
365 @@ -268,11 +268,11 @@ main(int argc, char **argv) {
366 /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
367 2 (stderr) are open. To do this, we assume that when we
368 open a file the lowest available file descriptor is used. */
369 - fd = open("/dev/null", O_RDWR);
370 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
371 if (fd == 0)
372 - fd = open("/dev/null", O_RDWR);
373 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
374 if (fd == 1)
375 - fd = open("/dev/null", O_RDWR);
376 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
377 if (fd == 2)
378 log_perror = 0; /* No sense logging to /dev/null. */
379 else if (fd != -1)
380 @@ -780,7 +780,7 @@ main(int argc, char **argv) {
381 #endif /* PARANOIA */
382
383 /* Read previous pid file. */
384 - if ((i = open (path_dhcpd_pid, O_RDONLY)) >= 0) {
385 + if ((i = open (path_dhcpd_pid, O_RDONLY | O_CLOEXEC)) >= 0) {
386 status = read(i, pbuf, (sizeof pbuf) - 1);
387 close (i);
388 if (status > 0) {
389 @@ -798,7 +798,7 @@ main(int argc, char **argv) {
390 }
391
392 /* Write new pid file. */
393 - if ((i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC, 0644)) >= 0) {
394 + if ((i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0644)) >= 0) {
395 sprintf(pbuf, "%d\n", (int) getpid());
396 IGNORE_RET (write(i, pbuf, strlen(pbuf)));
397 close(i);
398 @@ -824,9 +824,9 @@ main(int argc, char **argv) {
399 close(2);
400
401 /* Reopen them on /dev/null. */
402 - open("/dev/null", O_RDWR);
403 - open("/dev/null", O_RDWR);
404 - open("/dev/null", O_RDWR);
405 + open("/dev/null", O_RDWR | O_CLOEXEC);
406 + open("/dev/null", O_RDWR | O_CLOEXEC);
407 + open("/dev/null", O_RDWR | O_CLOEXEC);
408 log_perror = 0; /* No sense logging to /dev/null. */
409
410 IGNORE_RET (chdir("/"));
411 diff -up dhcp-4.2.0/server/ldap.c.cloexec dhcp-4.2.0/server/ldap.c
412 --- dhcp-4.2.0/server/ldap.c.cloexec 2010-03-25 16:26:58.000000000 +0100
413 +++ dhcp-4.2.0/server/ldap.c 2010-07-21 14:31:39.000000000 +0200
414 @@ -685,7 +685,7 @@ ldap_start (void)
415
416 if (ldap_debug_file != NULL && ldap_debug_fd == -1)
417 {
418 - if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY,
419 + if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
420 S_IRUSR | S_IWUSR)) < 0)
421 log_error ("Error opening debug LDAP log file %s: %s", ldap_debug_file,
422 strerror (errno));