|
|
91cda35 |
diff -up dhcp-4.0.0/client/clparse.c.cloexec dhcp-4.0.0/client/clparse.c
|
|
|
91cda35 |
--- dhcp-4.0.0/client/clparse.c.cloexec 2008-10-29 12:59:29.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/client/clparse.c 2008-10-29 13:11:34.000000000 -1000
|
|
|
91cda35 |
@@ -221,7 +221,7 @@ int read_client_conf_file (const char *n
|
|
|
91cda35 |
int token;
|
|
|
91cda35 |
isc_result_t status;
|
|
|
91cda35 |
|
|
|
91cda35 |
- if ((file = open (name, O_RDONLY)) < 0)
|
|
|
91cda35 |
+ if ((file = open (name, O_RDONLY | O_CLOEXEC)) < 0)
|
|
|
91cda35 |
return uerr2isc (errno);
|
|
|
91cda35 |
|
|
|
91cda35 |
cfile = (struct parse *)0;
|
|
|
91cda35 |
@@ -258,7 +258,7 @@ void read_client_leases ()
|
|
|
91cda35 |
|
|
|
91cda35 |
/* Open the lease file. If we can't open it, just return -
|
|
|
91cda35 |
we can safely trust the server to remember our state. */
|
|
|
91cda35 |
- if ((file = open (path_dhclient_db, O_RDONLY)) < 0)
|
|
|
91cda35 |
+ if ((file = open (path_dhclient_db, O_RDONLY | O_CLOEXEC)) < 0)
|
|
|
91cda35 |
return;
|
|
|
91cda35 |
cfile = (struct parse *)0;
|
|
|
91cda35 |
/* new_parse() may fail if the file is of zero length. */
|
|
|
91cda35 |
diff -up dhcp-4.0.0/client/dhclient.c.cloexec dhcp-4.0.0/client/dhclient.c
|
|
|
91cda35 |
--- dhcp-4.0.0/client/dhclient.c.cloexec 2008-10-29 12:59:29.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/client/dhclient.c 2008-10-29 13:26:16.000000000 -1000
|
|
|
91cda35 |
@@ -125,11 +125,11 @@ main(int argc, char **argv) {
|
|
|
91cda35 |
/* Make sure that file descriptors 0 (stdin), 1, (stdout), and
|
|
|
91cda35 |
2 (stderr) are open. To do this, we assume that when we
|
|
|
91cda35 |
open a file the lowest available file descriptor is used. */
|
|
|
91cda35 |
- fd = open("/dev/null", O_RDWR);
|
|
|
91cda35 |
+ fd = open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
if (fd == 0)
|
|
|
91cda35 |
- fd = open("/dev/null", O_RDWR);
|
|
|
91cda35 |
+ fd = open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
if (fd == 1)
|
|
|
91cda35 |
- fd = open("/dev/null", O_RDWR);
|
|
|
91cda35 |
+ fd = open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
if (fd == 2)
|
|
|
91cda35 |
log_perror = 0; /* No sense logging to /dev/null. */
|
|
|
91cda35 |
else if (fd != -1)
|
|
|
91cda35 |
@@ -403,7 +403,7 @@ main(int argc, char **argv) {
|
|
|
91cda35 |
int e;
|
|
|
91cda35 |
|
|
|
91cda35 |
oldpid = 0;
|
|
|
91cda35 |
- if ((pidfd = fopen(path_dhclient_pid, "r")) != NULL) {
|
|
|
91cda35 |
+ if ((pidfd = fopen(path_dhclient_pid, "re")) != NULL) {
|
|
|
91cda35 |
e = fscanf(pidfd, "%ld\n", &temp);
|
|
|
91cda35 |
oldpid = (pid_t)temp;
|
|
|
91cda35 |
|
|
|
91cda35 |
@@ -445,7 +445,7 @@ main(int argc, char **argv) {
|
|
|
91cda35 |
strncpy(new_path_dhclient_pid, path_dhclient_pid, pfx);
|
|
|
91cda35 |
sprintf(new_path_dhclient_pid + pfx, "-%s.pid", ip->name);
|
|
|
91cda35 |
|
|
|
91cda35 |
- if ((pidfd = fopen(new_path_dhclient_pid, "r")) != NULL) {
|
|
|
91cda35 |
+ if ((pidfd = fopen(new_path_dhclient_pid, "re")) != NULL) {
|
|
|
91cda35 |
e = fscanf(pidfd, "%ld\n", &temp);
|
|
|
91cda35 |
oldpid = (pid_t)temp;
|
|
|
91cda35 |
|
|
|
91cda35 |
@@ -470,7 +470,7 @@ main(int argc, char **argv) {
|
|
|
91cda35 |
int dhc_running = 0;
|
|
|
91cda35 |
char procfn[256] = "";
|
|
|
91cda35 |
|
|
|
91cda35 |
- if ((pidfp = fopen(path_dhclient_pid, "r")) != NULL) {
|
|
|
91cda35 |
+ if ((pidfp = fopen(path_dhclient_pid, "re")) != NULL) {
|
|
|
91cda35 |
if ((fscanf(pidfp, "%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
|
|
|
91cda35 |
snprintf(procfn,256,"/proc/%u",dhcpid);
|
|
|
91cda35 |
dhc_running = (access(procfn, F_OK) == 0);
|
|
|
91cda35 |
@@ -2702,7 +2702,7 @@ void rewrite_client_leases ()
|
|
|
91cda35 |
|
|
|
91cda35 |
if (leaseFile != NULL)
|
|
|
91cda35 |
fclose (leaseFile);
|
|
|
91cda35 |
- leaseFile = fopen (path_dhclient_db, "w");
|
|
|
91cda35 |
+ leaseFile = fopen (path_dhclient_db, "we");
|
|
|
91cda35 |
if (leaseFile == NULL) {
|
|
|
91cda35 |
log_error ("can't create %s: %m", path_dhclient_db);
|
|
|
91cda35 |
return;
|
|
|
91cda35 |
@@ -2806,7 +2806,7 @@ write_duid(struct data_string *duid)
|
|
|
91cda35 |
return ISC_R_INVALIDARG;
|
|
|
91cda35 |
|
|
|
91cda35 |
if (leaseFile == NULL) { /* XXX? */
|
|
|
91cda35 |
- leaseFile = fopen(path_dhclient_db, "w");
|
|
|
91cda35 |
+ leaseFile = fopen(path_dhclient_db, "we");
|
|
|
91cda35 |
if (leaseFile == NULL) {
|
|
|
91cda35 |
log_error("can't create %s: %m", path_dhclient_db);
|
|
|
91cda35 |
return ISC_R_IOERROR;
|
|
|
91cda35 |
@@ -2853,7 +2853,7 @@ write_client6_lease(struct client_state
|
|
|
91cda35 |
return ISC_R_INVALIDARG;
|
|
|
91cda35 |
|
|
|
91cda35 |
if (leaseFile == NULL) { /* XXX? */
|
|
|
91cda35 |
- leaseFile = fopen(path_dhclient_db, "w");
|
|
|
91cda35 |
+ leaseFile = fopen(path_dhclient_db, "we");
|
|
|
91cda35 |
if (leaseFile == NULL) {
|
|
|
91cda35 |
log_error("can't create %s: %m", path_dhclient_db);
|
|
|
91cda35 |
return ISC_R_IOERROR;
|
|
|
91cda35 |
@@ -2956,7 +2956,7 @@ int write_client_lease (client, lease, r
|
|
|
91cda35 |
return 1;
|
|
|
91cda35 |
|
|
|
91cda35 |
if (leaseFile == NULL) { /* XXX */
|
|
|
91cda35 |
- leaseFile = fopen (path_dhclient_db, "w");
|
|
|
91cda35 |
+ leaseFile = fopen (path_dhclient_db, "we");
|
|
|
91cda35 |
if (leaseFile == NULL) {
|
|
|
91cda35 |
log_error ("can't create %s: %m", path_dhclient_db);
|
|
|
91cda35 |
return 0;
|
|
|
91cda35 |
@@ -3402,9 +3402,9 @@ void go_daemon ()
|
|
|
91cda35 |
close(2);
|
|
|
91cda35 |
|
|
|
91cda35 |
/* Reopen them on /dev/null. */
|
|
|
91cda35 |
- open("/dev/null", O_RDWR);
|
|
|
91cda35 |
- open("/dev/null", O_RDWR);
|
|
|
91cda35 |
- open("/dev/null", O_RDWR);
|
|
|
91cda35 |
+ open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
+ open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
+ open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
|
|
|
91cda35 |
write_client_pid_file ();
|
|
|
91cda35 |
|
|
|
91cda35 |
@@ -3416,14 +3416,14 @@ void write_client_pid_file ()
|
|
|
91cda35 |
FILE *pf;
|
|
|
91cda35 |
int pfdesc;
|
|
|
91cda35 |
|
|
|
91cda35 |
- pfdesc = open (path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY, 0644);
|
|
|
91cda35 |
+ pfdesc = open (path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
|
|
|
91cda35 |
|
|
|
91cda35 |
if (pfdesc < 0) {
|
|
|
91cda35 |
log_error ("Can't create %s: %m", path_dhclient_pid);
|
|
|
91cda35 |
return;
|
|
|
91cda35 |
}
|
|
|
91cda35 |
|
|
|
91cda35 |
- pf = fdopen (pfdesc, "w");
|
|
|
91cda35 |
+ pf = fdopen (pfdesc, "we");
|
|
|
91cda35 |
if (!pf)
|
|
|
91cda35 |
log_error ("Can't fdopen %s: %m", path_dhclient_pid);
|
|
|
91cda35 |
else {
|
|
|
91cda35 |
diff -up dhcp-4.0.0/common/bpf.c.cloexec dhcp-4.0.0/common/bpf.c
|
|
|
91cda35 |
--- dhcp-4.0.0/common/bpf.c.cloexec 2008-10-29 12:59:29.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/common/bpf.c 2008-10-29 13:03:48.000000000 -1000
|
|
|
91cda35 |
@@ -94,7 +94,7 @@ int if_register_bpf (info)
|
|
|
91cda35 |
for (b = 0; 1; b++) {
|
|
|
91cda35 |
/* %Audit% 31 bytes max. %2004.06.17,Safe% */
|
|
|
91cda35 |
sprintf(filename, BPF_FORMAT, b);
|
|
|
91cda35 |
- sock = open (filename, O_RDWR, 0);
|
|
|
91cda35 |
+ sock = open (filename, O_RDWR | O_CLOEXEC, 0);
|
|
|
91cda35 |
if (sock < 0) {
|
|
|
91cda35 |
if (errno == EBUSY) {
|
|
|
91cda35 |
continue;
|
|
|
91cda35 |
diff -up dhcp-4.0.0/common/discover.c.cloexec dhcp-4.0.0/common/discover.c
|
|
|
91cda35 |
--- dhcp-4.0.0/common/discover.c.cloexec 2007-10-05 12:29:51.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/common/discover.c 2008-10-29 13:04:07.000000000 -1000
|
|
|
91cda35 |
@@ -388,7 +388,7 @@ begin_iface_scan(struct iface_conf_list
|
|
|
91cda35 |
int len;
|
|
|
91cda35 |
int i;
|
|
|
91cda35 |
|
|
|
91cda35 |
- ifaces->fp = fopen("/proc/net/dev", "r");
|
|
|
91cda35 |
+ ifaces->fp = fopen("/proc/net/dev", "re");
|
|
|
91cda35 |
if (ifaces->fp == NULL) {
|
|
|
91cda35 |
log_error("Error opening '/proc/net/dev' to list interfaces");
|
|
|
91cda35 |
return 0;
|
|
|
91cda35 |
@@ -422,7 +422,7 @@ begin_iface_scan(struct iface_conf_list
|
|
|
91cda35 |
}
|
|
|
91cda35 |
|
|
|
91cda35 |
#ifdef DHCPv6
|
|
|
91cda35 |
- ifaces->fp6 = fopen("/proc/net/if_inet6", "r");
|
|
|
91cda35 |
+ ifaces->fp6 = fopen("/proc/net/if_inet6", "re");
|
|
|
91cda35 |
if (ifaces->fp6 == NULL) {
|
|
|
91cda35 |
log_error("Error opening '/proc/net/if_inet6' to "
|
|
|
91cda35 |
"list IPv6 interfaces; %m");
|
|
|
91cda35 |
diff -up dhcp-4.0.0/common/dlpi.c.cloexec dhcp-4.0.0/common/dlpi.c
|
|
|
91cda35 |
--- dhcp-4.0.0/common/dlpi.c.cloexec 2008-10-29 12:59:29.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/common/dlpi.c 2008-10-29 13:04:35.000000000 -1000
|
|
|
91cda35 |
@@ -795,7 +795,7 @@ dlpiopen(const char *ifname) {
|
|
|
91cda35 |
}
|
|
|
91cda35 |
*dp = '\0';
|
|
|
91cda35 |
|
|
|
91cda35 |
- return open (devname, O_RDWR, 0);
|
|
|
91cda35 |
+ return open (devname, O_RDWR | O_CLOEXEC, 0);
|
|
|
91cda35 |
}
|
|
|
91cda35 |
|
|
|
91cda35 |
/*
|
|
|
91cda35 |
diff -up dhcp-4.0.0/common/nit.c.cloexec dhcp-4.0.0/common/nit.c
|
|
|
91cda35 |
--- dhcp-4.0.0/common/nit.c.cloexec 2008-10-29 12:59:29.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/common/nit.c 2008-10-29 13:04:53.000000000 -1000
|
|
|
91cda35 |
@@ -81,7 +81,7 @@ int if_register_nit (info)
|
|
|
91cda35 |
struct strioctl sio;
|
|
|
91cda35 |
|
|
|
91cda35 |
/* Open a NIT device */
|
|
|
91cda35 |
- sock = open ("/dev/nit", O_RDWR);
|
|
|
91cda35 |
+ sock = open ("/dev/nit", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
if (sock < 0)
|
|
|
91cda35 |
log_fatal ("Can't open NIT device for %s: %m", info -> name);
|
|
|
91cda35 |
|
|
|
91cda35 |
diff -up dhcp-4.0.0/common/resolv.c.cloexec dhcp-4.0.0/common/resolv.c
|
|
|
91cda35 |
--- dhcp-4.0.0/common/resolv.c.cloexec 2007-11-30 11:51:43.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/common/resolv.c 2008-10-29 13:05:08.000000000 -1000
|
|
|
91cda35 |
@@ -48,7 +48,7 @@ void read_resolv_conf (parse_time)
|
|
|
91cda35 |
struct name_server *sp, *sl, *ns;
|
|
|
91cda35 |
struct domain_search_list *dp, *dl, *nd;
|
|
|
91cda35 |
|
|
|
91cda35 |
- if ((file = open (path_resolv_conf, O_RDONLY)) < 0) {
|
|
|
91cda35 |
+ if ((file = open (path_resolv_conf, O_RDONLY | O_CLOEXEC)) < 0) {
|
|
|
91cda35 |
log_error ("Can't open %s: %m", path_resolv_conf);
|
|
|
91cda35 |
return;
|
|
|
91cda35 |
}
|
|
|
91cda35 |
diff -up dhcp-4.0.0/common/upf.c.cloexec dhcp-4.0.0/common/upf.c
|
|
|
91cda35 |
--- dhcp-4.0.0/common/upf.c.cloexec 2008-10-29 12:59:29.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/common/upf.c 2008-10-29 13:05:27.000000000 -1000
|
|
|
91cda35 |
@@ -77,7 +77,7 @@ int if_register_upf (info)
|
|
|
91cda35 |
/* %Audit% Cannot exceed 36 bytes. %2004.06.17,Safe% */
|
|
|
91cda35 |
sprintf(filename, "/dev/pf/pfilt%d", b);
|
|
|
91cda35 |
|
|
|
91cda35 |
- sock = open (filename, O_RDWR, 0);
|
|
|
91cda35 |
+ sock = open (filename, O_RDWR | O_CLOEXEC, 0);
|
|
|
91cda35 |
if (sock < 0) {
|
|
|
91cda35 |
if (errno == EBUSY) {
|
|
|
91cda35 |
continue;
|
|
|
91cda35 |
diff -up dhcp-4.0.0/dst/dst_api.c.cloexec dhcp-4.0.0/dst/dst_api.c
|
|
|
91cda35 |
--- dhcp-4.0.0/dst/dst_api.c.cloexec 2007-11-30 11:51:43.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/dst/dst_api.c 2008-10-29 13:06:22.000000000 -1000
|
|
|
91cda35 |
@@ -436,7 +436,7 @@ dst_s_write_private_key(const DST_KEY *k
|
|
|
91cda35 |
PRIVATE_KEY, PATH_MAX);
|
|
|
91cda35 |
|
|
|
91cda35 |
/* Do not overwrite an existing file */
|
|
|
91cda35 |
- if ((fp = dst_s_fopen(file, "w", 0600)) != NULL) {
|
|
|
91cda35 |
+ if ((fp = dst_s_fopen(file, "we", 0600)) != NULL) {
|
|
|
91cda35 |
int nn;
|
|
|
91cda35 |
if ((nn = fwrite(encoded_block, 1, len, fp)) != len) {
|
|
|
91cda35 |
EREPORT(("dst_write_private_key(): Write failure on %s %d != %d errno=%d\n",
|
|
|
91cda35 |
@@ -493,7 +493,7 @@ dst_s_read_public_key(const char *in_nam
|
|
|
91cda35 |
* flags, proto, alg stored as decimal (or hex numbers FIXME).
|
|
|
91cda35 |
* (FIXME: handle parentheses for line continuation.)
|
|
|
91cda35 |
*/
|
|
|
91cda35 |
- if ((fp = dst_s_fopen(name, "r", 0)) == NULL) {
|
|
|
91cda35 |
+ if ((fp = dst_s_fopen(name, "re", 0)) == NULL) {
|
|
|
91cda35 |
EREPORT(("dst_read_public_key(): Public Key not found %s\n",
|
|
|
91cda35 |
name));
|
|
|
91cda35 |
return (NULL);
|
|
|
91cda35 |
@@ -615,7 +615,7 @@ dst_s_write_public_key(const DST_KEY *ke
|
|
|
91cda35 |
return (0);
|
|
|
91cda35 |
}
|
|
|
91cda35 |
/* create public key file */
|
|
|
91cda35 |
- if ((fp = dst_s_fopen(filename, "w+", 0644)) == NULL) {
|
|
|
91cda35 |
+ if ((fp = dst_s_fopen(filename, "w+e", 0644)) == NULL) {
|
|
|
91cda35 |
EREPORT(("DST_write_public_key: open of file:%s failed (errno=%d)\n",
|
|
|
91cda35 |
filename, errno));
|
|
|
91cda35 |
return (0);
|
|
|
91cda35 |
@@ -849,7 +849,7 @@ dst_s_read_private_key_file(char *name,
|
|
|
91cda35 |
return (0);
|
|
|
91cda35 |
}
|
|
|
91cda35 |
/* first check if we can find the key file */
|
|
|
91cda35 |
- if ((fp = dst_s_fopen(filename, "r", 0)) == NULL) {
|
|
|
91cda35 |
+ if ((fp = dst_s_fopen(filename, "re", 0)) == NULL) {
|
|
|
91cda35 |
EREPORT(("dst_s_read_private_key_file: Could not open file %s in directory %s\n",
|
|
|
91cda35 |
filename, dst_path[0] ? dst_path :
|
|
|
91cda35 |
(char *) getcwd(NULL, PATH_MAX - 1)));
|
|
|
91cda35 |
diff -up dhcp-4.0.0/dst/prandom.c.cloexec dhcp-4.0.0/dst/prandom.c
|
|
|
91cda35 |
--- dhcp-4.0.0/dst/prandom.c.cloexec 2007-11-30 11:51:43.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/dst/prandom.c 2008-10-29 13:06:50.000000000 -1000
|
|
|
91cda35 |
@@ -267,7 +267,7 @@ get_dev_random(u_char *output, unsigned
|
|
|
91cda35 |
|
|
|
91cda35 |
s = stat("/dev/random", &st);
|
|
|
91cda35 |
if (s == 0 && S_ISCHR(st.st_mode)) {
|
|
|
91cda35 |
- if ((fd = open("/dev/random", O_RDONLY | O_NONBLOCK)) != -1) {
|
|
|
91cda35 |
+ if ((fd = open("/dev/random", O_RDONLY | O_NONBLOCK | O_CLOEXEC)) != -1) {
|
|
|
91cda35 |
if ((n = read(fd, output, size)) < 0)
|
|
|
91cda35 |
n = 0;
|
|
|
91cda35 |
close(fd);
|
|
|
91cda35 |
@@ -478,7 +478,7 @@ digest_file(dst_work *work)
|
|
|
91cda35 |
work->file_digest = dst_free_key(work->file_digest);
|
|
|
91cda35 |
return (0);
|
|
|
91cda35 |
}
|
|
|
91cda35 |
- if ((fp = fopen(name, "r")) == NULL)
|
|
|
91cda35 |
+ if ((fp = fopen(name, "re")) == NULL)
|
|
|
91cda35 |
return (0);
|
|
|
91cda35 |
for (no = 0; (i = fread(buf, sizeof(*buf), sizeof(buf), fp)) > 0;
|
|
|
91cda35 |
no += i)
|
|
|
91cda35 |
diff -up dhcp-4.0.0/minires/res_init.c.cloexec dhcp-4.0.0/minires/res_init.c
|
|
|
91cda35 |
--- dhcp-4.0.0/minires/res_init.c.cloexec 2007-10-01 04:47:35.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/minires/res_init.c 2008-10-29 13:07:12.000000000 -1000
|
|
|
91cda35 |
@@ -234,7 +234,7 @@ minires_vinit(res_state statp, int prein
|
|
|
91cda35 |
(line[sizeof(name) - 1] == ' ' || \
|
|
|
91cda35 |
line[sizeof(name) - 1] == '\t'))
|
|
|
91cda35 |
|
|
|
91cda35 |
- if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
|
|
|
91cda35 |
+ if ((fp = fopen(_PATH_RESCONF, "re")) != NULL) {
|
|
|
91cda35 |
/* read the config file */
|
|
|
91cda35 |
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
|
|
91cda35 |
/* skip comments */
|
|
|
91cda35 |
diff -up dhcp-4.0.0/minires/res_query.c.cloexec dhcp-4.0.0/minires/res_query.c
|
|
|
91cda35 |
--- dhcp-4.0.0/minires/res_query.c.cloexec 2007-09-05 07:32:10.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/minires/res_query.c 2008-10-29 13:07:30.000000000 -1000
|
|
|
91cda35 |
@@ -391,7 +391,7 @@ res_hostalias(const res_state statp, con
|
|
|
91cda35 |
if (statp->options & RES_NOALIASES)
|
|
|
91cda35 |
return (NULL);
|
|
|
91cda35 |
file = getenv("HOSTALIASES");
|
|
|
91cda35 |
- if (file == NULL || (fp = fopen(file, "r")) == NULL)
|
|
|
91cda35 |
+ if (file == NULL || (fp = fopen(file, "re")) == NULL)
|
|
|
91cda35 |
return (NULL);
|
|
|
91cda35 |
setbuf(fp, NULL);
|
|
|
91cda35 |
buf[sizeof(buf) - 1] = '\0';
|
|
|
91cda35 |
diff -up dhcp-4.0.0/omapip/trace.c.cloexec dhcp-4.0.0/omapip/trace.c
|
|
|
91cda35 |
--- dhcp-4.0.0/omapip/trace.c.cloexec 2007-07-12 20:43:42.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/omapip/trace.c 2008-10-29 13:08:04.000000000 -1000
|
|
|
91cda35 |
@@ -140,10 +140,10 @@ isc_result_t trace_begin (const char *fi
|
|
|
91cda35 |
return ISC_R_INVALIDARG;
|
|
|
91cda35 |
}
|
|
|
91cda35 |
|
|
|
91cda35 |
- traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL, 0600);
|
|
|
91cda35 |
+ traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL | O_CLOEXEC, 0600);
|
|
|
91cda35 |
if (traceoutfile < 0 && errno == EEXIST) {
|
|
|
91cda35 |
log_error ("WARNING: Overwriting trace file \"%s\"", filename);
|
|
|
91cda35 |
- traceoutfile = open (filename, O_WRONLY | O_EXCL, 0600);
|
|
|
91cda35 |
+ traceoutfile = open (filename, O_WRONLY | O_EXCL | O_CLOEXEC, 0600);
|
|
|
91cda35 |
}
|
|
|
91cda35 |
|
|
|
91cda35 |
if (traceoutfile < 0) {
|
|
|
91cda35 |
@@ -429,7 +429,7 @@ void trace_file_replay (const char *file
|
|
|
91cda35 |
isc_result_t result;
|
|
|
91cda35 |
int len;
|
|
|
91cda35 |
|
|
|
91cda35 |
- traceinfile = fopen (filename, "r");
|
|
|
91cda35 |
+ traceinfile = fopen (filename, "re");
|
|
|
91cda35 |
if (!traceinfile) {
|
|
|
91cda35 |
log_error ("Can't open tracefile %s: %m", filename);
|
|
|
91cda35 |
return;
|
|
|
91cda35 |
diff -up dhcp-4.0.0/relay/dhcrelay.c.cloexec dhcp-4.0.0/relay/dhcrelay.c
|
|
|
91cda35 |
--- dhcp-4.0.0/relay/dhcrelay.c.cloexec 2007-11-30 11:51:43.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/relay/dhcrelay.c 2008-10-29 13:08:49.000000000 -1000
|
|
|
91cda35 |
@@ -112,11 +112,11 @@ main(int argc, char **argv) {
|
|
|
91cda35 |
/* Make sure that file descriptors 0 (stdin), 1, (stdout), and
|
|
|
91cda35 |
2 (stderr) are open. To do this, we assume that when we
|
|
|
91cda35 |
open a file the lowest available file descriptor is used. */
|
|
|
91cda35 |
- fd = open("/dev/null", O_RDWR);
|
|
|
91cda35 |
+ fd = open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
if (fd == 0)
|
|
|
91cda35 |
- fd = open("/dev/null", O_RDWR);
|
|
|
91cda35 |
+ fd = open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
if (fd == 1)
|
|
|
91cda35 |
- fd = open("/dev/null", O_RDWR);
|
|
|
91cda35 |
+ fd = open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
if (fd == 2)
|
|
|
91cda35 |
log_perror = 0; /* No sense logging to /dev/null. */
|
|
|
91cda35 |
else if (fd != -1)
|
|
|
91cda35 |
@@ -288,12 +288,12 @@ main(int argc, char **argv) {
|
|
|
91cda35 |
exit (0);
|
|
|
91cda35 |
|
|
|
91cda35 |
pfdesc = open (path_dhcrelay_pid,
|
|
|
91cda35 |
- O_CREAT | O_TRUNC | O_WRONLY, 0644);
|
|
|
91cda35 |
+ O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
|
|
|
91cda35 |
|
|
|
91cda35 |
if (pfdesc < 0) {
|
|
|
91cda35 |
log_error ("Can't create %s: %m", path_dhcrelay_pid);
|
|
|
91cda35 |
} else {
|
|
|
91cda35 |
- pf = fdopen (pfdesc, "w");
|
|
|
91cda35 |
+ pf = fdopen (pfdesc, "we");
|
|
|
91cda35 |
if (!pf)
|
|
|
91cda35 |
log_error ("Can't fdopen %s: %m",
|
|
|
91cda35 |
path_dhcrelay_pid);
|
|
|
91cda35 |
diff -up dhcp-4.0.0/server/confpars.c.cloexec dhcp-4.0.0/server/confpars.c
|
|
|
91cda35 |
--- dhcp-4.0.0/server/confpars.c.cloexec 2008-10-29 12:59:28.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/server/confpars.c 2008-10-29 13:09:17.000000000 -1000
|
|
|
91cda35 |
@@ -115,7 +115,7 @@ isc_result_t read_conf_file (const char
|
|
|
91cda35 |
}
|
|
|
91cda35 |
#endif
|
|
|
91cda35 |
|
|
|
91cda35 |
- if ((file = open (filename, O_RDONLY)) < 0) {
|
|
|
91cda35 |
+ if ((file = open (filename, O_RDONLY | O_CLOEXEC)) < 0) {
|
|
|
91cda35 |
if (leasep) {
|
|
|
91cda35 |
log_error ("Can't open lease database %s: %m --",
|
|
|
91cda35 |
path_dhcpd_db);
|
|
|
91cda35 |
diff -up dhcp-4.0.0/server/db.c.cloexec dhcp-4.0.0/server/db.c
|
|
|
91cda35 |
--- dhcp-4.0.0/server/db.c.cloexec 2007-10-05 12:29:51.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/server/db.c 2008-10-29 13:09:39.000000000 -1000
|
|
|
91cda35 |
@@ -974,7 +974,7 @@ void db_startup (testp)
|
|
|
91cda35 |
}
|
|
|
91cda35 |
#endif
|
|
|
91cda35 |
if (!testp) {
|
|
|
91cda35 |
- db_file = fopen (path_dhcpd_db, "a");
|
|
|
91cda35 |
+ db_file = fopen (path_dhcpd_db, "ae");
|
|
|
91cda35 |
if (!db_file)
|
|
|
91cda35 |
log_fatal ("Can't open %s for append.", path_dhcpd_db);
|
|
|
91cda35 |
expire_all_pools ();
|
|
|
91cda35 |
@@ -1022,12 +1022,12 @@ int new_lease_file ()
|
|
|
91cda35 |
path_dhcpd_db, (int)t) >= sizeof newfname)
|
|
|
91cda35 |
log_fatal("new_lease_file: lease file path too long");
|
|
|
91cda35 |
|
|
|
91cda35 |
- db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT, 0664);
|
|
|
91cda35 |
+ db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0664);
|
|
|
91cda35 |
if (db_fd < 0) {
|
|
|
91cda35 |
log_error ("Can't create new lease file: %m");
|
|
|
91cda35 |
return 0;
|
|
|
91cda35 |
}
|
|
|
91cda35 |
- if ((new_db_file = fdopen(db_fd, "w")) == NULL) {
|
|
|
91cda35 |
+ if ((new_db_file = fdopen(db_fd, "we")) == NULL) {
|
|
|
91cda35 |
log_error("Can't fdopen new lease file: %m");
|
|
|
91cda35 |
close(db_fd);
|
|
|
91cda35 |
goto fdfail;
|
|
|
91cda35 |
diff -up dhcp-4.0.0/server/dhcpd.c.cloexec dhcp-4.0.0/server/dhcpd.c
|
|
|
91cda35 |
--- dhcp-4.0.0/server/dhcpd.c.cloexec 2008-10-29 12:59:28.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/server/dhcpd.c 2008-10-29 13:10:42.000000000 -1000
|
|
|
91cda35 |
@@ -225,11 +225,11 @@ main(int argc, char **argv) {
|
|
|
91cda35 |
/* Make sure that file descriptors 0 (stdin), 1, (stdout), and
|
|
|
91cda35 |
2 (stderr) are open. To do this, we assume that when we
|
|
|
91cda35 |
open a file the lowest available file descriptor is used. */
|
|
|
91cda35 |
- fd = open("/dev/null", O_RDWR);
|
|
|
91cda35 |
+ fd = open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
if (fd == 0)
|
|
|
91cda35 |
- fd = open("/dev/null", O_RDWR);
|
|
|
91cda35 |
+ fd = open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
if (fd == 1)
|
|
|
91cda35 |
- fd = open("/dev/null", O_RDWR);
|
|
|
91cda35 |
+ fd = open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
if (fd == 2)
|
|
|
91cda35 |
log_perror = 0; /* No sense logging to /dev/null. */
|
|
|
91cda35 |
else if (fd != -1)
|
|
|
91cda35 |
@@ -658,7 +658,7 @@ main(int argc, char **argv) {
|
|
|
91cda35 |
}
|
|
|
91cda35 |
|
|
|
91cda35 |
/* Read previous pid file. */
|
|
|
91cda35 |
- if ((i = open (path_dhcpd_pid, O_RDONLY)) >= 0) {
|
|
|
91cda35 |
+ if ((i = open (path_dhcpd_pid, O_RDONLY | O_CLOEXEC)) >= 0) {
|
|
|
91cda35 |
status = read(i, pbuf, (sizeof pbuf) - 1);
|
|
|
91cda35 |
close (i);
|
|
|
91cda35 |
if (status > 0) {
|
|
|
91cda35 |
@@ -676,7 +676,7 @@ main(int argc, char **argv) {
|
|
|
91cda35 |
}
|
|
|
91cda35 |
|
|
|
91cda35 |
/* Write new pid file. */
|
|
|
91cda35 |
- if ((i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC, 0644)) >= 0) {
|
|
|
91cda35 |
+ if ((i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0644)) >= 0) {
|
|
|
91cda35 |
sprintf(pbuf, "%d\n", (int) getpid());
|
|
|
91cda35 |
write(i, pbuf, strlen(pbuf));
|
|
|
91cda35 |
close(i);
|
|
|
91cda35 |
@@ -702,9 +702,9 @@ main(int argc, char **argv) {
|
|
|
91cda35 |
close(2);
|
|
|
91cda35 |
|
|
|
91cda35 |
/* Reopen them on /dev/null. */
|
|
|
91cda35 |
- open("/dev/null", O_RDWR);
|
|
|
91cda35 |
- open("/dev/null", O_RDWR);
|
|
|
91cda35 |
- open("/dev/null", O_RDWR);
|
|
|
91cda35 |
+ open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
+ open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
+ open("/dev/null", O_RDWR | O_CLOEXEC);
|
|
|
91cda35 |
log_perror = 0; /* No sense logging to /dev/null. */
|
|
|
91cda35 |
|
|
|
91cda35 |
chdir("/");
|
|
|
91cda35 |
diff -up dhcp-4.0.0/server/ldap.c.cloexec dhcp-4.0.0/server/ldap.c
|
|
|
91cda35 |
--- dhcp-4.0.0/server/ldap.c.cloexec 2008-10-29 12:59:28.000000000 -1000
|
|
|
91cda35 |
+++ dhcp-4.0.0/server/ldap.c 2008-10-29 13:11:10.000000000 -1000
|
|
|
91cda35 |
@@ -685,7 +685,7 @@ ldap_start (void)
|
|
|
91cda35 |
|
|
|
91cda35 |
if (ldap_debug_file != NULL && ldap_debug_fd == -1)
|
|
|
91cda35 |
{
|
|
|
91cda35 |
- if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY,
|
|
|
91cda35 |
+ if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
|
|
|
91cda35 |
S_IRUSR | S_IWUSR)) < 0)
|
|
|
91cda35 |
log_error ("Error opening debug LDAP log file %s: %s", ldap_debug_file,
|
|
|
91cda35 |
strerror (errno));
|