]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - dhcp/patches/dhcp-4.2.2-CLOEXEC.patch
dhcp: Update to 4.2.5.
[people/ms/ipfire-3.x.git] / dhcp / patches / dhcp-4.2.2-CLOEXEC.patch
1 diff -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;
22 diff -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);
124 diff -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;
136 diff -up dhcp-4.2.2b1/common/dlpi.c.cloexec dhcp-4.2.2b1/common/dlpi.c
137 --- dhcp-4.2.2b1/common/dlpi.c.cloexec 2011-07-01 14:13:30.977887712 +0200
138 +++ dhcp-4.2.2b1/common/dlpi.c 2011-07-01 14:13:31.032887673 +0200
139 @@ -806,7 +806,7 @@ dlpiopen(const char *ifname) {
140 }
141 *dp = '\0';
142
143 - return open (devname, O_RDWR, 0);
144 + return open (devname, O_RDWR | O_CLOEXEC, 0);
145 }
146
147 /*
148 diff -up dhcp-4.2.2b1/common/nit.c.cloexec dhcp-4.2.2b1/common/nit.c
149 --- dhcp-4.2.2b1/common/nit.c.cloexec 2011-07-01 14:13:30.978887712 +0200
150 +++ dhcp-4.2.2b1/common/nit.c 2011-07-01 14:13:31.033887672 +0200
151 @@ -81,7 +81,7 @@ int if_register_nit (info)
152 struct strioctl sio;
153
154 /* Open a NIT device */
155 - sock = open ("/dev/nit", O_RDWR);
156 + sock = open ("/dev/nit", O_RDWR | O_CLOEXEC);
157 if (sock < 0)
158 log_fatal ("Can't open NIT device for %s: %m", info -> name);
159
160 diff -up dhcp-4.2.2b1/common/resolv.c.cloexec dhcp-4.2.2b1/common/resolv.c
161 --- dhcp-4.2.2b1/common/resolv.c.cloexec 2009-11-20 02:49:01.000000000 +0100
162 +++ dhcp-4.2.2b1/common/resolv.c 2011-07-01 14:13:31.033887672 +0200
163 @@ -49,7 +49,7 @@ void read_resolv_conf (parse_time)
164 struct domain_search_list *dp, *dl, *nd;
165 isc_result_t status;
166
167 - if ((file = open (path_resolv_conf, O_RDONLY)) < 0) {
168 + if ((file = open (path_resolv_conf, O_RDONLY | O_CLOEXEC)) < 0) {
169 log_error ("Can't open %s: %m", path_resolv_conf);
170 return;
171 }
172 diff -up dhcp-4.2.2b1/common/upf.c.cloexec dhcp-4.2.2b1/common/upf.c
173 --- dhcp-4.2.2b1/common/upf.c.cloexec 2011-07-01 14:13:30.979887712 +0200
174 +++ dhcp-4.2.2b1/common/upf.c 2011-07-01 14:13:31.034887671 +0200
175 @@ -77,7 +77,7 @@ int if_register_upf (info)
176 /* %Audit% Cannot exceed 36 bytes. %2004.06.17,Safe% */
177 sprintf(filename, "/dev/pf/pfilt%d", b);
178
179 - sock = open (filename, O_RDWR, 0);
180 + sock = open (filename, O_RDWR | O_CLOEXEC, 0);
181 if (sock < 0) {
182 if (errno == EBUSY) {
183 continue;
184 diff -up dhcp-4.2.2b1/omapip/trace.c.cloexec dhcp-4.2.2b1/omapip/trace.c
185 --- dhcp-4.2.2b1/omapip/trace.c.cloexec 2010-05-27 02:34:57.000000000 +0200
186 +++ dhcp-4.2.2b1/omapip/trace.c 2011-07-01 14:13:31.036887669 +0200
187 @@ -141,10 +141,10 @@ isc_result_t trace_begin (const char *fi
188 return DHCP_R_INVALIDARG;
189 }
190
191 - traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL, 0600);
192 + traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL | O_CLOEXEC, 0600);
193 if (traceoutfile < 0 && errno == EEXIST) {
194 log_error ("WARNING: Overwriting trace file \"%s\"", filename);
195 - traceoutfile = open (filename, O_WRONLY | O_EXCL | O_TRUNC,
196 + traceoutfile = open (filename, O_WRONLY | O_EXCL | O_TRUNC | O_CLOEXEC,
197 0600);
198 }
199
200 @@ -431,7 +431,7 @@ void trace_file_replay (const char *file
201 isc_result_t result;
202 int len;
203
204 - traceinfile = fopen (filename, "r");
205 + traceinfile = fopen (filename, "re");
206 if (!traceinfile) {
207 log_error("Can't open tracefile %s: %m", filename);
208 return;
209 diff -up dhcp-4.2.2b1/relay/dhcrelay.c.cloexec dhcp-4.2.2b1/relay/dhcrelay.c
210 --- dhcp-4.2.2b1/relay/dhcrelay.c.cloexec 2011-05-10 15:07:37.000000000 +0200
211 +++ dhcp-4.2.2b1/relay/dhcrelay.c 2011-07-01 14:18:07.630209767 +0200
212 @@ -183,11 +183,11 @@ main(int argc, char **argv) {
213 /* Make sure that file descriptors 0(stdin), 1,(stdout), and
214 2(stderr) are open. To do this, we assume that when we
215 open a file the lowest available file descriptor is used. */
216 - fd = open("/dev/null", O_RDWR);
217 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
218 if (fd == 0)
219 - fd = open("/dev/null", O_RDWR);
220 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
221 if (fd == 1)
222 - fd = open("/dev/null", O_RDWR);
223 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
224 if (fd == 2)
225 log_perror = 0; /* No sense logging to /dev/null. */
226 else if (fd != -1)
227 @@ -540,13 +540,13 @@ main(int argc, char **argv) {
228
229 if (no_pid_file == ISC_FALSE) {
230 pfdesc = open(path_dhcrelay_pid,
231 - O_CREAT | O_TRUNC | O_WRONLY, 0644);
232 + O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
233
234 if (pfdesc < 0) {
235 log_error("Can't create %s: %m",
236 path_dhcrelay_pid);
237 } else {
238 - pf = fdopen(pfdesc, "w");
239 + pf = fdopen(pfdesc, "we");
240 if (!pf)
241 log_error("Can't fdopen %s: %m",
242 path_dhcrelay_pid);
243 diff -up dhcp-4.2.2b1/server/confpars.c.cloexec dhcp-4.2.2b1/server/confpars.c
244 --- dhcp-4.2.2b1/server/confpars.c.cloexec 2010-10-14 00:34:45.000000000 +0200
245 +++ dhcp-4.2.2b1/server/confpars.c 2011-07-01 14:13:31.039887666 +0200
246 @@ -116,7 +116,7 @@ isc_result_t read_conf_file (const char
247 }
248 #endif
249
250 - if ((file = open (filename, O_RDONLY)) < 0) {
251 + if ((file = open (filename, O_RDONLY | O_CLOEXEC)) < 0) {
252 if (leasep) {
253 log_error ("Can't open lease database %s: %m --",
254 path_dhcpd_db);
255 diff -up dhcp-4.2.2b1/server/db.c.cloexec dhcp-4.2.2b1/server/db.c
256 --- dhcp-4.2.2b1/server/db.c.cloexec 2010-09-14 00:15:26.000000000 +0200
257 +++ dhcp-4.2.2b1/server/db.c 2011-07-01 14:13:31.040887665 +0200
258 @@ -1035,7 +1035,7 @@ void db_startup (testp)
259 }
260 #endif
261 if (!testp) {
262 - db_file = fopen (path_dhcpd_db, "a");
263 + db_file = fopen (path_dhcpd_db, "ae");
264 if (!db_file)
265 log_fatal ("Can't open %s for append.", path_dhcpd_db);
266 expire_all_pools ();
267 @@ -1083,12 +1083,12 @@ int new_lease_file ()
268 path_dhcpd_db, (int)t) >= sizeof newfname)
269 log_fatal("new_lease_file: lease file path too long");
270
271 - db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT, 0664);
272 + db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0664);
273 if (db_fd < 0) {
274 log_error ("Can't create new lease file: %m");
275 return 0;
276 }
277 - if ((new_db_file = fdopen(db_fd, "w")) == NULL) {
278 + if ((new_db_file = fdopen(db_fd, "we")) == NULL) {
279 log_error("Can't fdopen new lease file: %m");
280 close(db_fd);
281 goto fdfail;
282 diff -up dhcp-4.2.2b1/server/dhcpd.c.cloexec dhcp-4.2.2b1/server/dhcpd.c
283 --- dhcp-4.2.2b1/server/dhcpd.c.cloexec 2011-04-21 16:08:15.000000000 +0200
284 +++ dhcp-4.2.2b1/server/dhcpd.c 2011-07-01 14:19:40.354124505 +0200
285 @@ -270,11 +270,11 @@ main(int argc, char **argv) {
286 /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
287 2 (stderr) are open. To do this, we assume that when we
288 open a file the lowest available file descriptor is used. */
289 - fd = open("/dev/null", O_RDWR);
290 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
291 if (fd == 0)
292 - fd = open("/dev/null", O_RDWR);
293 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
294 if (fd == 1)
295 - fd = open("/dev/null", O_RDWR);
296 + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
297 if (fd == 2)
298 log_perror = 0; /* No sense logging to /dev/null. */
299 else if (fd != -1)
300 @@ -793,7 +793,7 @@ main(int argc, char **argv) {
301 */
302 if (no_pid_file == ISC_FALSE) {
303 /*Read previous pid file. */
304 - if ((i = open (path_dhcpd_pid, O_RDONLY)) >= 0) {
305 + if ((i = open (path_dhcpd_pid, O_RDONLY | O_CLOEXEC)) >= 0) {
306 status = read(i, pbuf, (sizeof pbuf) - 1);
307 close (i);
308 if (status > 0) {
309 @@ -812,7 +812,7 @@ main(int argc, char **argv) {
310 }
311
312 /* Write new pid file. */
313 - i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC, 0644);
314 + i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0644);
315 if (i >= 0) {
316 sprintf(pbuf, "%d\n", (int) getpid());
317 IGNORE_RET (write(i, pbuf, strlen(pbuf)));
318 @@ -840,9 +840,9 @@ main(int argc, char **argv) {
319 close(2);
320
321 /* Reopen them on /dev/null. */
322 - open("/dev/null", O_RDWR);
323 - open("/dev/null", O_RDWR);
324 - open("/dev/null", O_RDWR);
325 + open("/dev/null", O_RDWR | O_CLOEXEC);
326 + open("/dev/null", O_RDWR | O_CLOEXEC);
327 + open("/dev/null", O_RDWR | O_CLOEXEC);
328 log_perror = 0; /* No sense logging to /dev/null. */
329
330 IGNORE_RET (chdir("/"));
331 diff -up dhcp-4.2.2b1/server/ldap.c.cloexec dhcp-4.2.2b1/server/ldap.c
332 --- dhcp-4.2.2b1/server/ldap.c.cloexec 2010-03-25 16:26:58.000000000 +0100
333 +++ dhcp-4.2.2b1/server/ldap.c 2011-07-01 14:13:31.043887665 +0200
334 @@ -685,7 +685,7 @@ ldap_start (void)
335
336 if (ldap_debug_file != NULL && ldap_debug_fd == -1)
337 {
338 - if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY,
339 + if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
340 S_IRUSR | S_IWUSR)) < 0)
341 log_error ("Error opening debug LDAP log file %s: %s", ldap_debug_file,
342 strerror (errno));