]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/patches/dhcp/dhcp-CLOEXEC.patch
Merge remote-tracking branch 'origin/master' into next
[people/pmueller/ipfire-2.x.git] / src / patches / dhcp / dhcp-CLOEXEC.patch
1 diff -up dhcp-4.3.0a1/client/clparse.c.cloexec dhcp-4.3.0a1/client/clparse.c
2 --- dhcp-4.3.0a1/client/clparse.c.cloexec 2013-12-19 15:34:41.638886256 +0100
3 +++ dhcp-4.3.0a1/client/clparse.c 2013-12-19 15:34:41.657885985 +0100
4 @@ -253,7 +253,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 @@ -290,7 +290,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.3.0a1/client/dhclient.c.cloexec dhcp-4.3.0a1/client/dhclient.c
23 --- dhcp-4.3.0a1/client/dhclient.c.cloexec 2013-12-19 15:34:41.629886384 +0100
24 +++ dhcp-4.3.0a1/client/dhclient.c 2013-12-19 15:36:41.608180467 +0100
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 @@ -504,7 +504,7 @@ main(int argc, char **argv) {
41 long temp;
42 int e;
43
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 @@ -554,7 +554,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 @@ -579,7 +579,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 @@ -3077,7 +3077,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 @@ -3261,7 +3261,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 @@ -3441,7 +3441,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 @@ -3952,9 +3952,9 @@ void go_daemon ()
95 (void) close(2);
96
97 /* Reopen them on /dev/null. */
98 - (void) open("/dev/null", O_RDWR);
99 - (void) open("/dev/null", O_RDWR);
100 - (void) open("/dev/null", O_RDWR);
101 + (void) open("/dev/null", O_RDWR | O_CLOEXEC);
102 + (void) open("/dev/null", O_RDWR | O_CLOEXEC);
103 + (void) open("/dev/null", O_RDWR | O_CLOEXEC);
104
105 write_client_pid_file ();
106
107 @@ -3971,14 +3971,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.3.0a1/common/bpf.c.cloexec dhcp-4.3.0a1/common/bpf.c
125 --- dhcp-4.3.0a1/common/bpf.c.cloexec 2013-12-19 15:34:41.640886227 +0100
126 +++ dhcp-4.3.0a1/common/bpf.c 2013-12-19 15:34:41.661885928 +0100
127 @@ -95,7 +95,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.3.0a1/common/dlpi.c.cloexec dhcp-4.3.0a1/common/dlpi.c
137 --- dhcp-4.3.0a1/common/dlpi.c.cloexec 2013-12-19 15:34:41.641886213 +0100
138 +++ dhcp-4.3.0a1/common/dlpi.c 2013-12-19 15:34:41.662885914 +0100
139 @@ -804,7 +804,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.3.0a1/common/nit.c.cloexec dhcp-4.3.0a1/common/nit.c
149 --- dhcp-4.3.0a1/common/nit.c.cloexec 2013-12-19 15:34:41.642886199 +0100
150 +++ dhcp-4.3.0a1/common/nit.c 2013-12-19 15:34:41.662885914 +0100
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.3.0a1/common/resolv.c.cloexec dhcp-4.3.0a1/common/resolv.c
161 --- dhcp-4.3.0a1/common/resolv.c.cloexec 2013-12-11 01:25:12.000000000 +0100
162 +++ dhcp-4.3.0a1/common/resolv.c 2013-12-19 15:34:41.663885900 +0100
163 @@ -50,7 +50,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.3.0a1/common/upf.c.cloexec dhcp-4.3.0a1/common/upf.c
173 --- dhcp-4.3.0a1/common/upf.c.cloexec 2013-12-19 15:34:41.642886199 +0100
174 +++ dhcp-4.3.0a1/common/upf.c 2013-12-19 15:34:41.663885900 +0100
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.3.0a1/omapip/trace.c.cloexec dhcp-4.3.0a1/omapip/trace.c
185 --- dhcp-4.3.0a1/omapip/trace.c.cloexec 2013-12-11 01:01:03.000000000 +0100
186 +++ dhcp-4.3.0a1/omapip/trace.c 2013-12-19 15:34:41.663885900 +0100
187 @@ -142,10 +142,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 @@ -433,7 +433,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.3.0a1/relay/dhcrelay.c.cloexec dhcp-4.3.0a1/relay/dhcrelay.c
210 --- dhcp-4.3.0a1/relay/dhcrelay.c.cloexec 2013-12-13 22:26:21.000000000 +0100
211 +++ dhcp-4.3.0a1/relay/dhcrelay.c 2013-12-19 15:34:41.664885886 +0100
212 @@ -193,11 +193,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 @@ -564,13 +564,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.3.0a1/server/confpars.c.cloexec dhcp-4.3.0a1/server/confpars.c
244 --- dhcp-4.3.0a1/server/confpars.c.cloexec 2013-12-11 01:25:12.000000000 +0100
245 +++ dhcp-4.3.0a1/server/confpars.c 2013-12-19 15:34:41.665885871 +0100
246 @@ -117,7 +117,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.3.0a1/server/db.c.cloexec dhcp-4.3.0a1/server/db.c
256 --- dhcp-4.3.0a1/server/db.c.cloexec 2013-12-11 01:25:12.000000000 +0100
257 +++ dhcp-4.3.0a1/server/db.c 2013-12-19 15:34:41.666885857 +0100
258 @@ -1081,7 +1081,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 @@ -1129,12 +1129,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.3.0a1/server/dhcpd.c.cloexec dhcp-4.3.0a1/server/dhcpd.c
283 --- dhcp-4.3.0a1/server/dhcpd.c.cloexec 2013-12-13 22:26:01.000000000 +0100
284 +++ dhcp-4.3.0a1/server/dhcpd.c 2013-12-19 15:37:17.258674472 +0100
285 @@ -193,11 +193,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 @@ -716,7 +716,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 @@ -735,7 +735,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 @@ -763,9 +763,9 @@ main(int argc, char **argv) {
319 (void) close(2);
320
321 /* Reopen them on /dev/null. */
322 - (void) open("/dev/null", O_RDWR);
323 - (void) open("/dev/null", O_RDWR);
324 - (void) open("/dev/null", O_RDWR);
325 + (void) open("/dev/null", O_RDWR | O_CLOEXEC);
326 + (void) open("/dev/null", O_RDWR | O_CLOEXEC);
327 + (void) 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.3.0a1/server/ldap.c.cloexec dhcp-4.3.0a1/server/ldap.c
332 --- dhcp-4.3.0a1/server/ldap.c.cloexec 2013-12-11 01:25:12.000000000 +0100
333 +++ dhcp-4.3.0a1/server/ldap.c 2013-12-19 15:34:41.667885843 +0100
334 @@ -684,7 +684,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));