]>
Commit | Line | Data |
---|---|---|
6df985df SS |
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/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"); | |
157 | diff -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 | /* | |
169 | diff -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 | ||
181 | diff -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 | } | |
193 | diff -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; | |
6df985df SS |
205 | diff -up dhcp-4.2.2b1/omapip/trace.c.cloexec dhcp-4.2.2b1/omapip/trace.c |
206 | --- dhcp-4.2.2b1/omapip/trace.c.cloexec 2010-05-27 02:34:57.000000000 +0200 | |
207 | +++ dhcp-4.2.2b1/omapip/trace.c 2011-07-01 14:13:31.036887669 +0200 | |
208 | @@ -141,10 +141,10 @@ isc_result_t trace_begin (const char *fi | |
209 | return DHCP_R_INVALIDARG; | |
210 | } | |
211 | ||
212 | - traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL, 0600); | |
213 | + traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL | O_CLOEXEC, 0600); | |
214 | if (traceoutfile < 0 && errno == EEXIST) { | |
215 | log_error ("WARNING: Overwriting trace file \"%s\"", filename); | |
216 | - traceoutfile = open (filename, O_WRONLY | O_EXCL | O_TRUNC, | |
217 | + traceoutfile = open (filename, O_WRONLY | O_EXCL | O_TRUNC | O_CLOEXEC, | |
218 | 0600); | |
219 | } | |
220 | ||
221 | @@ -431,7 +431,7 @@ void trace_file_replay (const char *file | |
222 | isc_result_t result; | |
223 | int len; | |
224 | ||
225 | - traceinfile = fopen (filename, "r"); | |
226 | + traceinfile = fopen (filename, "re"); | |
227 | if (!traceinfile) { | |
228 | log_error("Can't open tracefile %s: %m", filename); | |
229 | return; | |
230 | diff -up dhcp-4.2.2b1/relay/dhcrelay.c.cloexec dhcp-4.2.2b1/relay/dhcrelay.c | |
231 | --- dhcp-4.2.2b1/relay/dhcrelay.c.cloexec 2011-05-10 15:07:37.000000000 +0200 | |
232 | +++ dhcp-4.2.2b1/relay/dhcrelay.c 2011-07-01 14:18:07.630209767 +0200 | |
233 | @@ -183,11 +183,11 @@ main(int argc, char **argv) { | |
234 | /* Make sure that file descriptors 0(stdin), 1,(stdout), and | |
235 | 2(stderr) are open. To do this, we assume that when we | |
236 | open a file the lowest available file descriptor is used. */ | |
237 | - fd = open("/dev/null", O_RDWR); | |
238 | + fd = open("/dev/null", O_RDWR | O_CLOEXEC); | |
239 | if (fd == 0) | |
240 | - fd = open("/dev/null", O_RDWR); | |
241 | + fd = open("/dev/null", O_RDWR | O_CLOEXEC); | |
242 | if (fd == 1) | |
243 | - fd = open("/dev/null", O_RDWR); | |
244 | + fd = open("/dev/null", O_RDWR | O_CLOEXEC); | |
245 | if (fd == 2) | |
246 | log_perror = 0; /* No sense logging to /dev/null. */ | |
247 | else if (fd != -1) | |
248 | @@ -540,13 +540,13 @@ main(int argc, char **argv) { | |
249 | ||
250 | if (no_pid_file == ISC_FALSE) { | |
251 | pfdesc = open(path_dhcrelay_pid, | |
252 | - O_CREAT | O_TRUNC | O_WRONLY, 0644); | |
253 | + O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644); | |
254 | ||
255 | if (pfdesc < 0) { | |
256 | log_error("Can't create %s: %m", | |
257 | path_dhcrelay_pid); | |
258 | } else { | |
259 | - pf = fdopen(pfdesc, "w"); | |
260 | + pf = fdopen(pfdesc, "we"); | |
261 | if (!pf) | |
262 | log_error("Can't fdopen %s: %m", | |
263 | path_dhcrelay_pid); | |
264 | diff -up dhcp-4.2.2b1/server/confpars.c.cloexec dhcp-4.2.2b1/server/confpars.c | |
265 | --- dhcp-4.2.2b1/server/confpars.c.cloexec 2010-10-14 00:34:45.000000000 +0200 | |
266 | +++ dhcp-4.2.2b1/server/confpars.c 2011-07-01 14:13:31.039887666 +0200 | |
267 | @@ -116,7 +116,7 @@ isc_result_t read_conf_file (const char | |
268 | } | |
269 | #endif | |
270 | ||
271 | - if ((file = open (filename, O_RDONLY)) < 0) { | |
272 | + if ((file = open (filename, O_RDONLY | O_CLOEXEC)) < 0) { | |
273 | if (leasep) { | |
274 | log_error ("Can't open lease database %s: %m --", | |
275 | path_dhcpd_db); | |
276 | diff -up dhcp-4.2.2b1/server/db.c.cloexec dhcp-4.2.2b1/server/db.c | |
277 | --- dhcp-4.2.2b1/server/db.c.cloexec 2010-09-14 00:15:26.000000000 +0200 | |
278 | +++ dhcp-4.2.2b1/server/db.c 2011-07-01 14:13:31.040887665 +0200 | |
279 | @@ -1035,7 +1035,7 @@ void db_startup (testp) | |
280 | } | |
281 | #endif | |
282 | if (!testp) { | |
283 | - db_file = fopen (path_dhcpd_db, "a"); | |
284 | + db_file = fopen (path_dhcpd_db, "ae"); | |
285 | if (!db_file) | |
286 | log_fatal ("Can't open %s for append.", path_dhcpd_db); | |
287 | expire_all_pools (); | |
288 | @@ -1083,12 +1083,12 @@ int new_lease_file () | |
289 | path_dhcpd_db, (int)t) >= sizeof newfname) | |
290 | log_fatal("new_lease_file: lease file path too long"); | |
291 | ||
292 | - db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT, 0664); | |
293 | + db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0664); | |
294 | if (db_fd < 0) { | |
295 | log_error ("Can't create new lease file: %m"); | |
296 | return 0; | |
297 | } | |
298 | - if ((new_db_file = fdopen(db_fd, "w")) == NULL) { | |
299 | + if ((new_db_file = fdopen(db_fd, "we")) == NULL) { | |
300 | log_error("Can't fdopen new lease file: %m"); | |
301 | close(db_fd); | |
302 | goto fdfail; | |
303 | diff -up dhcp-4.2.2b1/server/dhcpd.c.cloexec dhcp-4.2.2b1/server/dhcpd.c | |
304 | --- dhcp-4.2.2b1/server/dhcpd.c.cloexec 2011-04-21 16:08:15.000000000 +0200 | |
305 | +++ dhcp-4.2.2b1/server/dhcpd.c 2011-07-01 14:19:40.354124505 +0200 | |
306 | @@ -270,11 +270,11 @@ main(int argc, char **argv) { | |
307 | /* Make sure that file descriptors 0 (stdin), 1, (stdout), and | |
308 | 2 (stderr) are open. To do this, we assume that when we | |
309 | open a file the lowest available file descriptor is used. */ | |
310 | - fd = open("/dev/null", O_RDWR); | |
311 | + fd = open("/dev/null", O_RDWR | O_CLOEXEC); | |
312 | if (fd == 0) | |
313 | - fd = open("/dev/null", O_RDWR); | |
314 | + fd = open("/dev/null", O_RDWR | O_CLOEXEC); | |
315 | if (fd == 1) | |
316 | - fd = open("/dev/null", O_RDWR); | |
317 | + fd = open("/dev/null", O_RDWR | O_CLOEXEC); | |
318 | if (fd == 2) | |
319 | log_perror = 0; /* No sense logging to /dev/null. */ | |
320 | else if (fd != -1) | |
321 | @@ -793,7 +793,7 @@ main(int argc, char **argv) { | |
322 | */ | |
323 | if (no_pid_file == ISC_FALSE) { | |
324 | /*Read previous pid file. */ | |
325 | - if ((i = open (path_dhcpd_pid, O_RDONLY)) >= 0) { | |
326 | + if ((i = open (path_dhcpd_pid, O_RDONLY | O_CLOEXEC)) >= 0) { | |
327 | status = read(i, pbuf, (sizeof pbuf) - 1); | |
328 | close (i); | |
329 | if (status > 0) { | |
330 | @@ -812,7 +812,7 @@ main(int argc, char **argv) { | |
331 | } | |
332 | ||
333 | /* Write new pid file. */ | |
334 | - i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC, 0644); | |
335 | + i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0644); | |
336 | if (i >= 0) { | |
337 | sprintf(pbuf, "%d\n", (int) getpid()); | |
338 | IGNORE_RET (write(i, pbuf, strlen(pbuf))); | |
339 | @@ -840,9 +840,9 @@ main(int argc, char **argv) { | |
340 | close(2); | |
341 | ||
342 | /* Reopen them on /dev/null. */ | |
343 | - open("/dev/null", O_RDWR); | |
344 | - open("/dev/null", O_RDWR); | |
345 | - open("/dev/null", O_RDWR); | |
346 | + open("/dev/null", O_RDWR | O_CLOEXEC); | |
347 | + open("/dev/null", O_RDWR | O_CLOEXEC); | |
348 | + open("/dev/null", O_RDWR | O_CLOEXEC); | |
349 | log_perror = 0; /* No sense logging to /dev/null. */ | |
350 | ||
351 | IGNORE_RET (chdir("/")); | |
352 | diff -up dhcp-4.2.2b1/server/ldap.c.cloexec dhcp-4.2.2b1/server/ldap.c | |
353 | --- dhcp-4.2.2b1/server/ldap.c.cloexec 2010-03-25 16:26:58.000000000 +0100 | |
354 | +++ dhcp-4.2.2b1/server/ldap.c 2011-07-01 14:13:31.043887665 +0200 | |
355 | @@ -685,7 +685,7 @@ ldap_start (void) | |
356 | ||
357 | if (ldap_debug_file != NULL && ldap_debug_fd == -1) | |
358 | { | |
359 | - if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY, | |
360 | + if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, | |
361 | S_IRUSR | S_IWUSR)) < 0) | |
362 | log_error ("Error opening debug LDAP log file %s: %s", ldap_debug_file, | |
363 | strerror (errno)); |