d3e04d
diff -up dhcp-4.1.1/client/clparse.c.cloexec dhcp-4.1.1/client/clparse.c
d3e04d
--- dhcp-4.1.1/client/clparse.c.cloexec	2010-01-20 17:21:53.000000000 +0100
d3e04d
+++ dhcp-4.1.1/client/clparse.c	2010-01-20 17:21:53.000000000 +0100
3161ff
@@ -226,7 +226,7 @@ int read_client_conf_file (const char *n
91cda3
 	int token;
91cda3
 	isc_result_t status;
91cda3
 	
91cda3
-	if ((file = open (name, O_RDONLY)) < 0)
91cda3
+	if ((file = open (name, O_RDONLY | O_CLOEXEC)) < 0)
91cda3
 		return uerr2isc (errno);
91cda3
 
3161ff
 	cfile = NULL;
3161ff
@@ -263,7 +263,7 @@ void read_client_leases ()
91cda3
 
91cda3
 	/* Open the lease file.   If we can't open it, just return -
91cda3
 	   we can safely trust the server to remember our state. */
91cda3
-	if ((file = open (path_dhclient_db, O_RDONLY)) < 0)
91cda3
+	if ((file = open (path_dhclient_db, O_RDONLY | O_CLOEXEC)) < 0)
91cda3
 		return;
3161ff
 
3161ff
 	cfile = NULL;
d3e04d
diff -up dhcp-4.1.1/client/dhclient.c.cloexec dhcp-4.1.1/client/dhclient.c
d3e04d
--- dhcp-4.1.1/client/dhclient.c.cloexec	2010-01-20 17:21:53.000000000 +0100
d3e04d
+++ dhcp-4.1.1/client/dhclient.c	2010-01-20 17:21:53.000000000 +0100
d3e04d
@@ -137,11 +137,11 @@ main(int argc, char **argv) {
3161ff
 	/* Make sure that file descriptors 0 (stdin), 1, (stdout), and
3161ff
 	   2 (stderr) are open. To do this, we assume that when we
3161ff
 	   open a file the lowest available file descriptor is used. */
3161ff
-	fd = open("/dev/null", O_RDWR);
3161ff
+	fd = open("/dev/null", O_RDWR | O_CLOEXEC);
3161ff
 	if (fd == 0)
3161ff
-		fd = open("/dev/null", O_RDWR);
3161ff
+		fd = open("/dev/null", O_RDWR | O_CLOEXEC);
3161ff
 	if (fd == 1)
3161ff
-		fd = open("/dev/null", O_RDWR);
3161ff
+		fd = open("/dev/null", O_RDWR | O_CLOEXEC);
3161ff
 	if (fd == 2)
3161ff
 		log_perror = 0; /* No sense logging to /dev/null. */
3161ff
 	else if (fd != -1)
d3e04d
@@ -467,7 +467,7 @@ main(int argc, char **argv) {
91cda3
 		int e;
91cda3
 
91cda3
 		oldpid = 0;
91cda3
-		if ((pidfd = fopen(path_dhclient_pid, "r")) != NULL) {
91cda3
+		if ((pidfd = fopen(path_dhclient_pid, "re")) != NULL) {
91cda3
 			e = fscanf(pidfd, "%ld\n", &temp);
91cda3
 			oldpid = (pid_t)temp;
91cda3
 
d3e04d
@@ -509,7 +509,7 @@ main(int argc, char **argv) {
91cda3
 					strncpy(new_path_dhclient_pid, path_dhclient_pid, pfx);
91cda3
 					sprintf(new_path_dhclient_pid + pfx, "-%s.pid", ip->name);
91cda3
 
91cda3
-					if ((pidfd = fopen(new_path_dhclient_pid, "r")) != NULL) {
91cda3
+					if ((pidfd = fopen(new_path_dhclient_pid, "re")) != NULL) {
91cda3
 						e = fscanf(pidfd, "%ld\n", &temp);
91cda3
 						oldpid = (pid_t)temp;
91cda3
 
d3e04d
@@ -534,7 +534,7 @@ main(int argc, char **argv) {
91cda3
 		int dhc_running = 0;
91cda3
 		char procfn[256] = "";
91cda3
 
91cda3
-		if ((pidfp = fopen(path_dhclient_pid, "r")) != NULL) {
91cda3
+		if ((pidfp = fopen(path_dhclient_pid, "re")) != NULL) {
91cda3
 			if ((fscanf(pidfp, "%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
91cda3
 				snprintf(procfn,256,"/proc/%u",dhcpid);
3161ff
 				dhc_running = (access(procfn, F_OK) == 0);
d3e04d
@@ -2910,7 +2910,7 @@ void rewrite_client_leases ()
91cda3
 
91cda3
 	if (leaseFile != NULL)
91cda3
 		fclose (leaseFile);
91cda3
-	leaseFile = fopen (path_dhclient_db, "w");
91cda3
+	leaseFile = fopen (path_dhclient_db, "we");
91cda3
 	if (leaseFile == NULL) {
91cda3
 		log_error ("can't create %s: %m", path_dhclient_db);
91cda3
 		return;
d3e04d
@@ -3014,7 +3014,7 @@ write_duid(struct data_string *duid)
91cda3
 		return ISC_R_INVALIDARG;
91cda3
 
91cda3
 	if (leaseFile == NULL) {	/* XXX? */
91cda3
-		leaseFile = fopen(path_dhclient_db, "w");
91cda3
+		leaseFile = fopen(path_dhclient_db, "we");
91cda3
 		if (leaseFile == NULL) {
91cda3
 			log_error("can't create %s: %m", path_dhclient_db);
91cda3
 			return ISC_R_IOERROR;
d3e04d
@@ -3194,7 +3194,7 @@ int write_client_lease (client, lease, r
91cda3
 		return 1;
91cda3
 
91cda3
 	if (leaseFile == NULL) {	/* XXX */
91cda3
-		leaseFile = fopen (path_dhclient_db, "w");
91cda3
+		leaseFile = fopen (path_dhclient_db, "we");
91cda3
 		if (leaseFile == NULL) {
91cda3
 			log_error ("can't create %s: %m", path_dhclient_db);
91cda3
 			return 0;
d3e04d
@@ -3647,9 +3647,9 @@ void go_daemon ()
3161ff
 	close(2);
91cda3
 
91cda3
 	/* Reopen them on /dev/null. */
91cda3
-	open("/dev/null", O_RDWR);
91cda3
-	open("/dev/null", O_RDWR);
91cda3
-	open("/dev/null", O_RDWR);
91cda3
+	open("/dev/null", O_RDWR | O_CLOEXEC);
91cda3
+	open("/dev/null", O_RDWR | O_CLOEXEC);
91cda3
+	open("/dev/null", O_RDWR | O_CLOEXEC);
91cda3
 
91cda3
 	write_client_pid_file ();
91cda3
 
d3e04d
@@ -3661,14 +3661,14 @@ void write_client_pid_file ()
91cda3
 	FILE *pf;
91cda3
 	int pfdesc;
91cda3
 
91cda3
-	pfdesc = open (path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY, 0644);
91cda3
+	pfdesc = open (path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
91cda3
 
91cda3
 	if (pfdesc < 0) {
91cda3
 		log_error ("Can't create %s: %m", path_dhclient_pid);
91cda3
 		return;
91cda3
 	}
91cda3
 
91cda3
-	pf = fdopen (pfdesc, "w");
91cda3
+	pf = fdopen (pfdesc, "we");
91cda3
 	if (!pf)
91cda3
 		log_error ("Can't fdopen %s: %m", path_dhclient_pid);
91cda3
 	else {
d3e04d
diff -up dhcp-4.1.1/common/bpf.c.cloexec dhcp-4.1.1/common/bpf.c
d3e04d
--- dhcp-4.1.1/common/bpf.c.cloexec	2010-01-20 17:21:53.000000000 +0100
d3e04d
+++ dhcp-4.1.1/common/bpf.c	2010-01-20 17:21:53.000000000 +0100
91cda3
@@ -94,7 +94,7 @@ int if_register_bpf (info)
91cda3
 	for (b = 0; 1; b++) {
91cda3
 		/* %Audit% 31 bytes max. %2004.06.17,Safe% */
91cda3
 		sprintf(filename, BPF_FORMAT, b);
91cda3
-		sock = open (filename, O_RDWR, 0);
91cda3
+		sock = open (filename, O_RDWR | O_CLOEXEC, 0);
91cda3
 		if (sock < 0) {
91cda3
 			if (errno == EBUSY) {
91cda3
 				continue;
d3e04d
diff -up dhcp-4.1.1/common/discover.c.cloexec dhcp-4.1.1/common/discover.c
d3e04d
--- dhcp-4.1.1/common/discover.c.cloexec	2009-09-29 21:44:49.000000000 +0200
d3e04d
+++ dhcp-4.1.1/common/discover.c	2010-01-20 17:21:53.000000000 +0100
3161ff
@@ -409,7 +409,7 @@ begin_iface_scan(struct iface_conf_list 
91cda3
 	int len;
91cda3
 	int i;
91cda3
 
91cda3
-	ifaces->fp = fopen("/proc/net/dev", "r");
91cda3
+	ifaces->fp = fopen("/proc/net/dev", "re");
91cda3
 	if (ifaces->fp == NULL) {
91cda3
 		log_error("Error opening '/proc/net/dev' to list interfaces");
91cda3
 		return 0;
d3e04d
@@ -444,7 +444,7 @@ begin_iface_scan(struct iface_conf_list 
91cda3
 
91cda3
 #ifdef DHCPv6
d3e04d
 	if (local_family == AF_INET6) {
d3e04d
-		ifaces->fp6 = fopen("/proc/net/if_inet6", "r");
d3e04d
+		ifaces->fp6 = fopen("/proc/net/if_inet6", "re");
d3e04d
 		if (ifaces->fp6 == NULL) {
d3e04d
 			log_error("Error opening '/proc/net/if_inet6' to "
d3e04d
 				  "list IPv6 interfaces; %m");
d3e04d
diff -up dhcp-4.1.1/common/dlpi.c.cloexec dhcp-4.1.1/common/dlpi.c
d3e04d
--- dhcp-4.1.1/common/dlpi.c.cloexec	2010-01-20 17:21:53.000000000 +0100
d3e04d
+++ dhcp-4.1.1/common/dlpi.c	2010-01-20 17:21:53.000000000 +0100
d3e04d
@@ -804,7 +804,7 @@ dlpiopen(const char *ifname) {
91cda3
 	}
91cda3
 	*dp = '\0';
91cda3
 	
91cda3
-	return open (devname, O_RDWR, 0);
91cda3
+	return open (devname, O_RDWR | O_CLOEXEC, 0);
91cda3
 }
91cda3
 
91cda3
 /*
d3e04d
diff -up dhcp-4.1.1/common/nit.c.cloexec dhcp-4.1.1/common/nit.c
d3e04d
--- dhcp-4.1.1/common/nit.c.cloexec	2010-01-20 17:21:53.000000000 +0100
d3e04d
+++ dhcp-4.1.1/common/nit.c	2010-01-20 17:21:53.000000000 +0100
91cda3
@@ -81,7 +81,7 @@ int if_register_nit (info)
91cda3
 	struct strioctl sio;
91cda3
 
91cda3
 	/* Open a NIT device */
91cda3
-	sock = open ("/dev/nit", O_RDWR);
91cda3
+	sock = open ("/dev/nit", O_RDWR | O_CLOEXEC);
91cda3
 	if (sock < 0)
91cda3
 		log_fatal ("Can't open NIT device for %s: %m", info -> name);
91cda3
 
d3e04d
diff -up dhcp-4.1.1/common/resolv.c.cloexec dhcp-4.1.1/common/resolv.c
d3e04d
--- dhcp-4.1.1/common/resolv.c.cloexec	2009-07-25 00:04:52.000000000 +0200
d3e04d
+++ dhcp-4.1.1/common/resolv.c	2010-01-20 17:21:53.000000000 +0100
3161ff
@@ -49,7 +49,7 @@ void read_resolv_conf (parse_time)
91cda3
 	struct domain_search_list *dp, *dl, *nd;
3161ff
 	isc_result_t status;
91cda3
 
91cda3
-	if ((file = open (path_resolv_conf, O_RDONLY)) < 0) {
91cda3
+	if ((file = open (path_resolv_conf, O_RDONLY | O_CLOEXEC)) < 0) {
91cda3
 		log_error ("Can't open %s: %m", path_resolv_conf);
91cda3
 		return;
91cda3
 	}
d3e04d
diff -up dhcp-4.1.1/common/upf.c.cloexec dhcp-4.1.1/common/upf.c
d3e04d
--- dhcp-4.1.1/common/upf.c.cloexec	2010-01-20 17:21:53.000000000 +0100
d3e04d
+++ dhcp-4.1.1/common/upf.c	2010-01-20 17:21:53.000000000 +0100
91cda3
@@ -77,7 +77,7 @@ int if_register_upf (info)
91cda3
 		/* %Audit% Cannot exceed 36 bytes. %2004.06.17,Safe% */
91cda3
 		sprintf(filename, "/dev/pf/pfilt%d", b);
91cda3
 
91cda3
-		sock = open (filename, O_RDWR, 0);
91cda3
+		sock = open (filename, O_RDWR | O_CLOEXEC, 0);
91cda3
 		if (sock < 0) {
91cda3
 			if (errno == EBUSY) {
91cda3
 				continue;
d3e04d
diff -up dhcp-4.1.1/dst/dst_api.c.cloexec dhcp-4.1.1/dst/dst_api.c
d3e04d
--- dhcp-4.1.1/dst/dst_api.c.cloexec	2009-01-22 03:07:42.000000000 +0100
d3e04d
+++ dhcp-4.1.1/dst/dst_api.c	2010-01-20 17:21:53.000000000 +0100
91cda3
@@ -436,7 +436,7 @@ dst_s_write_private_key(const DST_KEY *k
91cda3
 			     PRIVATE_KEY, PATH_MAX);
91cda3
 
91cda3
 	/* Do not overwrite an existing file */
91cda3
-	if ((fp = dst_s_fopen(file, "w", 0600)) != NULL) {
91cda3
+	if ((fp = dst_s_fopen(file, "we", 0600)) != NULL) {
91cda3
 		int nn;
91cda3
 		if ((nn = fwrite(encoded_block, 1, len, fp)) != len) {
91cda3
 			EREPORT(("dst_write_private_key(): Write failure on %s %d != %d errno=%d\n",
91cda3
@@ -493,7 +493,7 @@ dst_s_read_public_key(const char *in_nam
91cda3
 	 * flags, proto, alg stored as decimal (or hex numbers FIXME).
91cda3
 	 * (FIXME: handle parentheses for line continuation.)
91cda3
 	 */
91cda3
-	if ((fp = dst_s_fopen(name, "r", 0)) == NULL) {
91cda3
+	if ((fp = dst_s_fopen(name, "re", 0)) == NULL) {
91cda3
 		EREPORT(("dst_read_public_key(): Public Key not found %s\n",
91cda3
 			 name));
91cda3
 		return (NULL);
d3e04d
@@ -619,7 +619,7 @@ dst_s_write_public_key(const DST_KEY *ke
91cda3
 		return (0);
91cda3
 	}
91cda3
 	/* create public key file */
91cda3
-	if ((fp = dst_s_fopen(filename, "w+", 0644)) == NULL) {
91cda3
+	if ((fp = dst_s_fopen(filename, "w+e", 0644)) == NULL) {
91cda3
 		EREPORT(("DST_write_public_key: open of file:%s failed (errno=%d)\n",
91cda3
 			 filename, errno));
91cda3
 		return (0);
d3e04d
@@ -853,7 +853,7 @@ dst_s_read_private_key_file(char *name, 
91cda3
 		return (0);
91cda3
 	}
91cda3
 	/* first check if we can find the key file */
91cda3
-	if ((fp = dst_s_fopen(filename, "r", 0)) == NULL) {
91cda3
+	if ((fp = dst_s_fopen(filename, "re", 0)) == NULL) {
91cda3
 		EREPORT(("dst_s_read_private_key_file: Could not open file %s in directory %s\n",
91cda3
 			 filename, dst_path[0] ? dst_path :
91cda3
 			 (char *) getcwd(NULL, PATH_MAX - 1)));
d3e04d
diff -up dhcp-4.1.1/dst/prandom.c.cloexec dhcp-4.1.1/dst/prandom.c
d3e04d
--- dhcp-4.1.1/dst/prandom.c.cloexec	2007-11-30 22:51:43.000000000 +0100
d3e04d
+++ dhcp-4.1.1/dst/prandom.c	2010-01-20 17:21:53.000000000 +0100
91cda3
@@ -267,7 +267,7 @@ get_dev_random(u_char *output, unsigned 
91cda3
 
91cda3
 	s = stat("/dev/random", &st);
91cda3
 	if (s == 0 && S_ISCHR(st.st_mode)) {
91cda3
-		if ((fd = open("/dev/random", O_RDONLY | O_NONBLOCK)) != -1) {
91cda3
+		if ((fd = open("/dev/random", O_RDONLY | O_NONBLOCK | O_CLOEXEC)) != -1) {
91cda3
 			if ((n = read(fd, output, size)) < 0)
91cda3
 				n = 0;
91cda3
 			close(fd);
91cda3
@@ -478,7 +478,7 @@ digest_file(dst_work *work) 
91cda3
 		work->file_digest = dst_free_key(work->file_digest);
91cda3
 		return (0);
91cda3
 	}
91cda3
-	if ((fp = fopen(name, "r")) == NULL) 
91cda3
+	if ((fp = fopen(name, "re")) == NULL) 
91cda3
 		return (0);
91cda3
 	for (no = 0; (i = fread(buf, sizeof(*buf), sizeof(buf), fp)) > 0; 
91cda3
 	     no += i) 
d3e04d
diff -up dhcp-4.1.1/minires/res_init.c.cloexec dhcp-4.1.1/minires/res_init.c
d3e04d
--- dhcp-4.1.1/minires/res_init.c.cloexec	2009-07-25 00:04:52.000000000 +0200
d3e04d
+++ dhcp-4.1.1/minires/res_init.c	2010-01-20 17:21:53.000000000 +0100
3161ff
@@ -233,7 +233,7 @@ minires_vinit(res_state statp, int prein
91cda3
 	(line[sizeof(name) - 1] == ' ' || \
91cda3
 	 line[sizeof(name) - 1] == '\t'))
91cda3
 
91cda3
-	if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
91cda3
+	if ((fp = fopen(_PATH_RESCONF, "re")) != NULL) {
91cda3
 	    /* read the config file */
91cda3
 	    while (fgets(buf, sizeof(buf), fp) != NULL) {
91cda3
 		/* skip comments */
d3e04d
diff -up dhcp-4.1.1/minires/res_query.c.cloexec dhcp-4.1.1/minires/res_query.c
d3e04d
--- dhcp-4.1.1/minires/res_query.c.cloexec	2009-07-25 00:04:52.000000000 +0200
d3e04d
+++ dhcp-4.1.1/minires/res_query.c	2010-01-20 17:21:53.000000000 +0100
3161ff
@@ -379,7 +379,7 @@ res_hostalias(const res_state statp, con
91cda3
 	if (statp->options & RES_NOALIASES)
91cda3
 		return (NULL);
91cda3
 	file = getenv("HOSTALIASES");
91cda3
-	if (file == NULL || (fp = fopen(file, "r")) == NULL)
91cda3
+	if (file == NULL || (fp = fopen(file, "re")) == NULL)
91cda3
 		return (NULL);
91cda3
 	setbuf(fp, NULL);
91cda3
 	buf[sizeof(buf) - 1] = '\0';
d3e04d
diff -up dhcp-4.1.1/omapip/trace.c.cloexec dhcp-4.1.1/omapip/trace.c
d3e04d
--- dhcp-4.1.1/omapip/trace.c.cloexec	2009-07-25 00:04:52.000000000 +0200
d3e04d
+++ dhcp-4.1.1/omapip/trace.c	2010-01-20 17:21:53.000000000 +0100
91cda3
@@ -140,10 +140,10 @@ isc_result_t trace_begin (const char *fi
91cda3
 		return ISC_R_INVALIDARG;
91cda3
 	}
91cda3
 
91cda3
-	traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL, 0600);
91cda3
+	traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL | O_CLOEXEC, 0600);
91cda3
 	if (traceoutfile < 0 && errno == EEXIST) {
91cda3
 		log_error ("WARNING: Overwriting trace file \"%s\"", filename);
91cda3
-		traceoutfile = open (filename, O_WRONLY | O_EXCL, 0600);
91cda3
+		traceoutfile = open (filename, O_WRONLY | O_EXCL | O_CLOEXEC, 0600);
91cda3
 	}
91cda3
 
91cda3
 	if (traceoutfile < 0) {
91cda3
@@ -429,7 +429,7 @@ void trace_file_replay (const char *file
91cda3
 	isc_result_t result;
91cda3
 	int len;
91cda3
 
91cda3
-	traceinfile = fopen (filename, "r");
91cda3
+	traceinfile = fopen (filename, "re");
91cda3
 	if (!traceinfile) {
91cda3
 		log_error ("Can't open tracefile %s: %m", filename);
91cda3
 		return;
d3e04d
diff -up dhcp-4.1.1/relay/dhcrelay.c.cloexec dhcp-4.1.1/relay/dhcrelay.c
d3e04d
--- dhcp-4.1.1/relay/dhcrelay.c.cloexec	2010-01-07 22:48:02.000000000 +0100
d3e04d
+++ dhcp-4.1.1/relay/dhcrelay.c	2010-01-20 17:21:53.000000000 +0100
d3e04d
@@ -177,11 +177,11 @@ main(int argc, char **argv) {
3161ff
 	/* Make sure that file descriptors 0(stdin), 1,(stdout), and
3161ff
 	   2(stderr) are open. To do this, we assume that when we
3161ff
 	   open a file the lowest available file descriptor is used. */
3161ff
-	fd = open("/dev/null", O_RDWR);
3161ff
+	fd = open("/dev/null", O_RDWR | O_CLOEXEC);
3161ff
 	if (fd == 0)
3161ff
-		fd = open("/dev/null", O_RDWR);
3161ff
+		fd = open("/dev/null", O_RDWR | O_CLOEXEC);
3161ff
 	if (fd == 1)
3161ff
-		fd = open("/dev/null", O_RDWR);
3161ff
+		fd = open("/dev/null", O_RDWR | O_CLOEXEC);
3161ff
 	if (fd == 2)
3161ff
 		log_perror = 0; /* No sense logging to /dev/null. */
3161ff
 	else if (fd != -1)
d3e04d
@@ -514,12 +514,12 @@ main(int argc, char **argv) {
3161ff
 			exit(0);
3161ff
 
3161ff
 		pfdesc = open(path_dhcrelay_pid,
91cda3
-			       O_CREAT | O_TRUNC | O_WRONLY, 0644);
91cda3
+			       O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
91cda3
 
91cda3
 		if (pfdesc < 0) {
3161ff
 			log_error("Can't create %s: %m", path_dhcrelay_pid);
91cda3
 		} else {
3161ff
-			pf = fdopen(pfdesc, "w");
3161ff
+			pf = fdopen(pfdesc, "we");
91cda3
 			if (!pf)
3161ff
 				log_error("Can't fdopen %s: %m",
91cda3
 				      path_dhcrelay_pid);
d3e04d
diff -up dhcp-4.1.1/server/confpars.c.cloexec dhcp-4.1.1/server/confpars.c
d3e04d
--- dhcp-4.1.1/server/confpars.c.cloexec	2010-01-20 17:21:53.000000000 +0100
d3e04d
+++ dhcp-4.1.1/server/confpars.c	2010-01-20 17:21:53.000000000 +0100
3161ff
@@ -116,7 +116,7 @@ isc_result_t read_conf_file (const char 
91cda3
 	}
91cda3
 #endif
91cda3
 
91cda3
-	if ((file = open (filename, O_RDONLY)) < 0) {
91cda3
+	if ((file = open (filename, O_RDONLY | O_CLOEXEC)) < 0) {
91cda3
 		if (leasep) {
91cda3
 			log_error ("Can't open lease database %s: %m --",
91cda3
 				   path_dhcpd_db);
d3e04d
diff -up dhcp-4.1.1/server/db.c.cloexec dhcp-4.1.1/server/db.c
d3e04d
--- dhcp-4.1.1/server/db.c.cloexec	2009-07-25 00:04:52.000000000 +0200
d3e04d
+++ dhcp-4.1.1/server/db.c	2010-01-20 17:21:53.000000000 +0100
3161ff
@@ -1021,7 +1021,7 @@ void db_startup (testp)
91cda3
 	}
91cda3
 #endif
91cda3
 	if (!testp) {
91cda3
-		db_file = fopen (path_dhcpd_db, "a");
91cda3
+		db_file = fopen (path_dhcpd_db, "ae");
91cda3
 		if (!db_file)
91cda3
 			log_fatal ("Can't open %s for append.", path_dhcpd_db);
91cda3
 		expire_all_pools ();
3161ff
@@ -1069,12 +1069,12 @@ int new_lease_file ()
91cda3
 		     path_dhcpd_db, (int)t) >= sizeof newfname)
91cda3
 		log_fatal("new_lease_file: lease file path too long");
91cda3
 
91cda3
-	db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT, 0664);
91cda3
+	db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0664);
91cda3
 	if (db_fd < 0) {
91cda3
 		log_error ("Can't create new lease file: %m");
91cda3
 		return 0;
91cda3
 	}
91cda3
-	if ((new_db_file = fdopen(db_fd, "w")) == NULL) {
91cda3
+	if ((new_db_file = fdopen(db_fd, "we")) == NULL) {
91cda3
 		log_error("Can't fdopen new lease file: %m");
91cda3
 		close(db_fd);
91cda3
 		goto fdfail;
d3e04d
diff -up dhcp-4.1.1/server/dhcpd.c.cloexec dhcp-4.1.1/server/dhcpd.c
d3e04d
--- dhcp-4.1.1/server/dhcpd.c.cloexec	2010-01-20 17:21:53.000000000 +0100
d3e04d
+++ dhcp-4.1.1/server/dhcpd.c	2010-01-20 17:21:53.000000000 +0100
d3e04d
@@ -267,11 +267,11 @@ main(int argc, char **argv) {
91cda3
         /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
91cda3
            2 (stderr) are open. To do this, we assume that when we
91cda3
            open a file the lowest available file descriptor is used. */
91cda3
-        fd = open("/dev/null", O_RDWR);
91cda3
+        fd = open("/dev/null", O_RDWR | O_CLOEXEC);
91cda3
         if (fd == 0)
91cda3
-                fd = open("/dev/null", O_RDWR);
91cda3
+                fd = open("/dev/null", O_RDWR | O_CLOEXEC);
91cda3
         if (fd == 1)
91cda3
-                fd = open("/dev/null", O_RDWR);
91cda3
+                fd = open("/dev/null", O_RDWR | O_CLOEXEC);
91cda3
         if (fd == 2)
91cda3
                 log_perror = 0; /* No sense logging to /dev/null. */
91cda3
         else if (fd != -1)
d3e04d
@@ -772,7 +772,7 @@ main(int argc, char **argv) {
3161ff
 #endif /* PARANOIA */
91cda3
 
91cda3
 	/* Read previous pid file. */
91cda3
-	if ((i = open (path_dhcpd_pid, O_RDONLY)) >= 0) {
91cda3
+	if ((i = open (path_dhcpd_pid, O_RDONLY | O_CLOEXEC)) >= 0) {
91cda3
 		status = read(i, pbuf, (sizeof pbuf) - 1);
91cda3
 		close (i);
91cda3
 		if (status > 0) {
d3e04d
@@ -790,7 +790,7 @@ main(int argc, char **argv) {
91cda3
 	}
91cda3
 
91cda3
         /* Write new pid file. */
91cda3
-        if ((i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC, 0644)) >= 0) {
91cda3
+        if ((i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0644)) >= 0) {
91cda3
                 sprintf(pbuf, "%d\n", (int) getpid());
d3e04d
                 IGNORE_RET (write(i, pbuf, strlen(pbuf)));
91cda3
                 close(i);
d3e04d
@@ -816,9 +816,9 @@ main(int argc, char **argv) {
91cda3
                 close(2);
91cda3
 
91cda3
                 /* Reopen them on /dev/null. */
91cda3
-                open("/dev/null", O_RDWR);
91cda3
-                open("/dev/null", O_RDWR);
91cda3
-                open("/dev/null", O_RDWR);
91cda3
+                open("/dev/null", O_RDWR | O_CLOEXEC);
91cda3
+                open("/dev/null", O_RDWR | O_CLOEXEC);
91cda3
+                open("/dev/null", O_RDWR | O_CLOEXEC);
91cda3
                 log_perror = 0; /* No sense logging to /dev/null. */
91cda3
 
d3e04d
        		IGNORE_RET (chdir("/"));
d3e04d
diff -up dhcp-4.1.1/server/ldap.c.cloexec dhcp-4.1.1/server/ldap.c
d3e04d
--- dhcp-4.1.1/server/ldap.c.cloexec	2010-01-20 17:21:53.000000000 +0100
d3e04d
+++ dhcp-4.1.1/server/ldap.c	2010-01-20 17:21:53.000000000 +0100
91cda3
@@ -685,7 +685,7 @@ ldap_start (void)
91cda3
 
91cda3
   if (ldap_debug_file != NULL && ldap_debug_fd == -1)
91cda3
     {
91cda3
-      if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY,
91cda3
+      if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
91cda3
                                  S_IRUSR | S_IWUSR)) < 0)
91cda3
         log_error ("Error opening debug LDAP log file %s: %s", ldap_debug_file,
91cda3
                    strerror (errno));