]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/patches/dhcp-4.2.2-CLOEXEC.patch
firewall: Remove redundant rule.
[people/teissler/ipfire-2.x.git] / src / patches / dhcp-4.2.2-CLOEXEC.patch
CommitLineData
78ab9b04
MT
1diff -up dhcp-4.2.2b1/client/clparse.c.cloexec dhcp-4.2.2b1/client/clparse.c
2--- dhcp-4.2.2b1/client/clparse.c.cloexec 2011-07-01 14:13:30.973887714 +0200
3+++ dhcp-4.2.2b1/client/clparse.c 2011-07-01 14:15:15.021580693 +0200
4@@ -246,7 +246,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@@ -283,7 +283,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;
22diff -up dhcp-4.2.2b1/client/dhclient.c.cloexec dhcp-4.2.2b1/client/dhclient.c
23--- dhcp-4.2.2b1/client/dhclient.c.cloexec 2011-07-01 14:13:30.970887717 +0200
24+++ dhcp-4.2.2b1/client/dhclient.c 2011-07-01 14:16:51.485930388 +0200
25@@ -148,11 +148,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@@ -506,7 +506,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@@ -548,7 +548,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@@ -573,7 +573,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@@ -2995,7 +2995,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@@ -3105,7 +3105,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@@ -3285,7 +3285,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@@ -3772,9 +3772,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@@ -3791,14 +3791,14 @@ void write_client_pid_file ()
108 return;
109 }
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 close(pfdesc);
123 log_error ("Can't fdopen %s: %m", path_dhclient_pid);
124diff -up dhcp-4.2.2b1/common/bpf.c.cloexec dhcp-4.2.2b1/common/bpf.c
125--- dhcp-4.2.2b1/common/bpf.c.cloexec 2011-07-01 14:13:30.976887712 +0200
126+++ dhcp-4.2.2b1/common/bpf.c 2011-07-01 14:13:31.030887673 +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;
136diff -up dhcp-4.2.2b1/common/discover.c.cloexec dhcp-4.2.2b1/common/discover.c
137--- dhcp-4.2.2b1/common/discover.c.cloexec 2011-06-27 18:18:20.000000000 +0200
138+++ dhcp-4.2.2b1/common/discover.c 2011-07-01 14:13:31.031887673 +0200
139@@ -421,7 +421,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@@ -456,7 +456,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");
157diff -up dhcp-4.2.2b1/common/dlpi.c.cloexec dhcp-4.2.2b1/common/dlpi.c
158--- dhcp-4.2.2b1/common/dlpi.c.cloexec 2011-07-01 14:13:30.977887712 +0200
159+++ dhcp-4.2.2b1/common/dlpi.c 2011-07-01 14:13:31.032887673 +0200
160@@ -806,7 +806,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 /*
169diff -up dhcp-4.2.2b1/common/nit.c.cloexec dhcp-4.2.2b1/common/nit.c
170--- dhcp-4.2.2b1/common/nit.c.cloexec 2011-07-01 14:13:30.978887712 +0200
171+++ dhcp-4.2.2b1/common/nit.c 2011-07-01 14:13:31.033887672 +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
181diff -up dhcp-4.2.2b1/common/resolv.c.cloexec dhcp-4.2.2b1/common/resolv.c
182--- dhcp-4.2.2b1/common/resolv.c.cloexec 2009-11-20 02:49:01.000000000 +0100
183+++ dhcp-4.2.2b1/common/resolv.c 2011-07-01 14:13:31.033887672 +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 }
193diff -up dhcp-4.2.2b1/common/upf.c.cloexec dhcp-4.2.2b1/common/upf.c
194--- dhcp-4.2.2b1/common/upf.c.cloexec 2011-07-01 14:13:30.979887712 +0200
195+++ dhcp-4.2.2b1/common/upf.c 2011-07-01 14:13:31.034887671 +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;
205diff -up dhcp-4.2.2b1/dst/dst_api.c.cloexec dhcp-4.2.2b1/dst/dst_api.c
206--- dhcp-4.2.2b1/dst/dst_api.c.cloexec 2009-10-29 01:46:48.000000000 +0100
207+++ dhcp-4.2.2b1/dst/dst_api.c 2011-07-01 14:13:31.035887670 +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)));
244diff -up dhcp-4.2.2b1/dst/prandom.c.cloexec dhcp-4.2.2b1/dst/prandom.c
245--- dhcp-4.2.2b1/dst/prandom.c.cloexec 2009-11-20 02:49:01.000000000 +0100
246+++ dhcp-4.2.2b1/dst/prandom.c 2011-07-01 14:13:31.035887670 +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)
265diff -up dhcp-4.2.2b1/omapip/trace.c.cloexec dhcp-4.2.2b1/omapip/trace.c
266--- dhcp-4.2.2b1/omapip/trace.c.cloexec 2010-05-27 02:34:57.000000000 +0200
267+++ dhcp-4.2.2b1/omapip/trace.c 2011-07-01 14:13:31.036887669 +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;
290diff -up dhcp-4.2.2b1/relay/dhcrelay.c.cloexec dhcp-4.2.2b1/relay/dhcrelay.c
291--- dhcp-4.2.2b1/relay/dhcrelay.c.cloexec 2011-05-10 15:07:37.000000000 +0200
292+++ dhcp-4.2.2b1/relay/dhcrelay.c 2011-07-01 14:18:07.630209767 +0200
293@@ -183,11 +183,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@@ -540,13 +540,13 @@ main(int argc, char **argv) {
309
310 if (no_pid_file == ISC_FALSE) {
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",
317 path_dhcrelay_pid);
318 } else {
319- pf = fdopen(pfdesc, "w");
320+ pf = fdopen(pfdesc, "we");
321 if (!pf)
322 log_error("Can't fdopen %s: %m",
323 path_dhcrelay_pid);
324diff -up dhcp-4.2.2b1/server/confpars.c.cloexec dhcp-4.2.2b1/server/confpars.c
325--- dhcp-4.2.2b1/server/confpars.c.cloexec 2010-10-14 00:34:45.000000000 +0200
326+++ dhcp-4.2.2b1/server/confpars.c 2011-07-01 14:13:31.039887666 +0200
327@@ -116,7 +116,7 @@ isc_result_t read_conf_file (const char
328 }
329 #endif
330
331- if ((file = open (filename, O_RDONLY)) < 0) {
332+ if ((file = open (filename, O_RDONLY | O_CLOEXEC)) < 0) {
333 if (leasep) {
334 log_error ("Can't open lease database %s: %m --",
335 path_dhcpd_db);
336diff -up dhcp-4.2.2b1/server/db.c.cloexec dhcp-4.2.2b1/server/db.c
337--- dhcp-4.2.2b1/server/db.c.cloexec 2010-09-14 00:15:26.000000000 +0200
338+++ dhcp-4.2.2b1/server/db.c 2011-07-01 14:13:31.040887665 +0200
339@@ -1035,7 +1035,7 @@ void db_startup (testp)
340 }
341 #endif
342 if (!testp) {
343- db_file = fopen (path_dhcpd_db, "a");
344+ db_file = fopen (path_dhcpd_db, "ae");
345 if (!db_file)
346 log_fatal ("Can't open %s for append.", path_dhcpd_db);
347 expire_all_pools ();
348@@ -1083,12 +1083,12 @@ int new_lease_file ()
349 path_dhcpd_db, (int)t) >= sizeof newfname)
350 log_fatal("new_lease_file: lease file path too long");
351
352- db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT, 0664);
353+ db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0664);
354 if (db_fd < 0) {
355 log_error ("Can't create new lease file: %m");
356 return 0;
357 }
358- if ((new_db_file = fdopen(db_fd, "w")) == NULL) {
359+ if ((new_db_file = fdopen(db_fd, "we")) == NULL) {
360 log_error("Can't fdopen new lease file: %m");
361 close(db_fd);
362 goto fdfail;
363diff -up dhcp-4.2.2b1/server/dhcpd.c.cloexec dhcp-4.2.2b1/server/dhcpd.c
364--- dhcp-4.2.2b1/server/dhcpd.c.cloexec 2011-04-21 16:08:15.000000000 +0200
365+++ dhcp-4.2.2b1/server/dhcpd.c 2011-07-01 14:19:40.354124505 +0200
366@@ -270,11 +270,11 @@ main(int argc, char **argv) {
367 /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
368 2 (stderr) are open. To do this, we assume that when we
369 open a file the lowest available file descriptor is used. */
370- fd = open("/dev/null", O_RDWR);
371+ fd = open("/dev/null", O_RDWR | O_CLOEXEC);
372 if (fd == 0)
373- fd = open("/dev/null", O_RDWR);
374+ fd = open("/dev/null", O_RDWR | O_CLOEXEC);
375 if (fd == 1)
376- fd = open("/dev/null", O_RDWR);
377+ fd = open("/dev/null", O_RDWR | O_CLOEXEC);
378 if (fd == 2)
379 log_perror = 0; /* No sense logging to /dev/null. */
380 else if (fd != -1)
381@@ -793,7 +793,7 @@ main(int argc, char **argv) {
382 */
383 if (no_pid_file == ISC_FALSE) {
384 /*Read previous pid file. */
385- if ((i = open (path_dhcpd_pid, O_RDONLY)) >= 0) {
386+ if ((i = open (path_dhcpd_pid, O_RDONLY | O_CLOEXEC)) >= 0) {
387 status = read(i, pbuf, (sizeof pbuf) - 1);
388 close (i);
389 if (status > 0) {
390@@ -812,7 +812,7 @@ main(int argc, char **argv) {
391 }
392
393 /* Write new pid file. */
394- i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC, 0644);
395+ i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0644);
396 if (i >= 0) {
397 sprintf(pbuf, "%d\n", (int) getpid());
398 IGNORE_RET (write(i, pbuf, strlen(pbuf)));
399@@ -840,9 +840,9 @@ main(int argc, char **argv) {
400 close(2);
401
402 /* Reopen them on /dev/null. */
403- open("/dev/null", O_RDWR);
404- open("/dev/null", O_RDWR);
405- open("/dev/null", O_RDWR);
406+ open("/dev/null", O_RDWR | O_CLOEXEC);
407+ open("/dev/null", O_RDWR | O_CLOEXEC);
408+ open("/dev/null", O_RDWR | O_CLOEXEC);
409 log_perror = 0; /* No sense logging to /dev/null. */
410
411 IGNORE_RET (chdir("/"));
412diff -up dhcp-4.2.2b1/server/ldap.c.cloexec dhcp-4.2.2b1/server/ldap.c
413--- dhcp-4.2.2b1/server/ldap.c.cloexec 2010-03-25 16:26:58.000000000 +0100
414+++ dhcp-4.2.2b1/server/ldap.c 2011-07-01 14:13:31.043887665 +0200
415@@ -685,7 +685,7 @@ ldap_start (void)
416
417 if (ldap_debug_file != NULL && ldap_debug_fd == -1)
418 {
419- if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY,
420+ if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
421 S_IRUSR | S_IWUSR)) < 0)
422 log_error ("Error opening debug LDAP log file %s: %s", ldap_debug_file,
423 strerror (errno));