Blame SOURCES/dhcp-4.2.2-CLOEXEC.patch

45d60a
diff -up dhcp-4.2.2b1/client/clparse.c.cloexec dhcp-4.2.2b1/client/clparse.c
45d60a
--- dhcp-4.2.2b1/client/clparse.c.cloexec	2011-07-01 14:13:30.973887714 +0200
45d60a
+++ dhcp-4.2.2b1/client/clparse.c	2011-07-01 14:15:15.021580693 +0200
45d60a
@@ -246,7 +246,7 @@ int read_client_conf_file (const char *n
45d60a
 	int token;
45d60a
 	isc_result_t status;
45d60a
 
45d60a
-	if ((file = open (name, O_RDONLY)) < 0)
45d60a
+	if ((file = open (name, O_RDONLY | O_CLOEXEC)) < 0)
45d60a
 		return uerr2isc (errno);
45d60a
 
45d60a
 	cfile = NULL;
45d60a
@@ -283,7 +283,7 @@ void read_client_leases ()
45d60a
 
45d60a
 	/* Open the lease file.   If we can't open it, just return -
45d60a
 	   we can safely trust the server to remember our state. */
45d60a
-	if ((file = open (path_dhclient_db, O_RDONLY)) < 0)
45d60a
+	if ((file = open (path_dhclient_db, O_RDONLY | O_CLOEXEC)) < 0)
45d60a
 		return;
45d60a
 
45d60a
 	cfile = NULL;
45d60a
diff -up dhcp-4.2.2b1/client/dhclient.c.cloexec dhcp-4.2.2b1/client/dhclient.c
45d60a
--- dhcp-4.2.2b1/client/dhclient.c.cloexec	2011-07-01 14:13:30.970887717 +0200
45d60a
+++ dhcp-4.2.2b1/client/dhclient.c	2011-07-01 14:16:51.485930388 +0200
45d60a
@@ -148,11 +148,11 @@ main(int argc, char **argv) {
45d60a
 	/* Make sure that file descriptors 0 (stdin), 1, (stdout), and
45d60a
 	   2 (stderr) are open. To do this, we assume that when we
45d60a
 	   open a file the lowest available file descriptor is used. */
45d60a
-	fd = open("/dev/null", O_RDWR);
45d60a
+	fd = open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
 	if (fd == 0)
45d60a
-		fd = open("/dev/null", O_RDWR);
45d60a
+		fd = open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
 	if (fd == 1)
45d60a
-		fd = open("/dev/null", O_RDWR);
45d60a
+		fd = open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
 	if (fd == 2)
45d60a
 		log_perror = 0; /* No sense logging to /dev/null. */
45d60a
 	else if (fd != -1)
45d60a
@@ -506,7 +506,7 @@ main(int argc, char **argv) {
45d60a
 		int e;
45d60a
 
45d60a
 		oldpid = 0;
45d60a
-		if ((pidfd = fopen(path_dhclient_pid, "r")) != NULL) {
45d60a
+		if ((pidfd = fopen(path_dhclient_pid, "re")) != NULL) {
45d60a
 			e = fscanf(pidfd, "%ld\n", &temp);
45d60a
 			oldpid = (pid_t)temp;
45d60a
 
45d60a
@@ -548,7 +548,7 @@ main(int argc, char **argv) {
45d60a
 					strncpy(new_path_dhclient_pid, path_dhclient_pid, pfx);
45d60a
 					sprintf(new_path_dhclient_pid + pfx, "-%s.pid", ip->name);
45d60a
 
45d60a
-					if ((pidfd = fopen(new_path_dhclient_pid, "r")) != NULL) {
45d60a
+					if ((pidfd = fopen(new_path_dhclient_pid, "re")) != NULL) {
45d60a
 						e = fscanf(pidfd, "%ld\n", &temp);
45d60a
 						oldpid = (pid_t)temp;
45d60a
 
45d60a
@@ -573,7 +573,7 @@ main(int argc, char **argv) {
45d60a
 		int dhc_running = 0;
45d60a
 		char procfn[256] = "";
45d60a
 
45d60a
-		if ((pidfp = fopen(path_dhclient_pid, "r")) != NULL) {
45d60a
+		if ((pidfp = fopen(path_dhclient_pid, "re")) != NULL) {
45d60a
 			if ((fscanf(pidfp, "%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
45d60a
 				snprintf(procfn,256,"/proc/%u",dhcpid);
45d60a
 				dhc_running = (access(procfn, F_OK) == 0);
45d60a
@@ -2995,7 +2995,7 @@ void rewrite_client_leases ()
45d60a
 
45d60a
 	if (leaseFile != NULL)
45d60a
 		fclose (leaseFile);
45d60a
-	leaseFile = fopen (path_dhclient_db, "w");
45d60a
+	leaseFile = fopen (path_dhclient_db, "we");
45d60a
 	if (leaseFile == NULL) {
45d60a
 		log_error ("can't create %s: %m", path_dhclient_db);
45d60a
 		return;
45d60a
@@ -3105,7 +3105,7 @@ write_duid(struct data_string *duid)
45d60a
 		return DHCP_R_INVALIDARG;
45d60a
 
45d60a
 	if (leaseFile == NULL) {	/* XXX? */
45d60a
-		leaseFile = fopen(path_dhclient_db, "w");
45d60a
+		leaseFile = fopen(path_dhclient_db, "we");
45d60a
 		if (leaseFile == NULL) {
45d60a
 			log_error("can't create %s: %m", path_dhclient_db);
45d60a
 			return ISC_R_IOERROR;
45d60a
@@ -3285,7 +3285,7 @@ int write_client_lease (client, lease, r
45d60a
 		return 1;
45d60a
 
45d60a
 	if (leaseFile == NULL) {	/* XXX */
45d60a
-		leaseFile = fopen (path_dhclient_db, "w");
45d60a
+		leaseFile = fopen (path_dhclient_db, "we");
45d60a
 		if (leaseFile == NULL) {
45d60a
 			log_error ("can't create %s: %m", path_dhclient_db);
45d60a
 			return 0;
45d60a
@@ -3772,9 +3772,9 @@ void go_daemon ()
45d60a
 	close(2);
45d60a
 
45d60a
 	/* Reopen them on /dev/null. */
45d60a
-	open("/dev/null", O_RDWR);
45d60a
-	open("/dev/null", O_RDWR);
45d60a
-	open("/dev/null", O_RDWR);
45d60a
+	open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
+	open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
+	open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
 
45d60a
 	write_client_pid_file ();
45d60a
 
45d60a
@@ -3791,14 +3791,14 @@ void write_client_pid_file ()
45d60a
 		return;
45d60a
 	}
45d60a
 
45d60a
-	pfdesc = open (path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY, 0644);
45d60a
+	pfdesc = open (path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
45d60a
 
45d60a
 	if (pfdesc < 0) {
45d60a
 		log_error ("Can't create %s: %m", path_dhclient_pid);
45d60a
 		return;
45d60a
 	}
45d60a
 
45d60a
-	pf = fdopen (pfdesc, "w");
45d60a
+	pf = fdopen (pfdesc, "we");
45d60a
 	if (!pf) {
45d60a
 		close(pfdesc);
45d60a
 		log_error ("Can't fdopen %s: %m", path_dhclient_pid);
45d60a
diff -up dhcp-4.2.2b1/common/bpf.c.cloexec dhcp-4.2.2b1/common/bpf.c
45d60a
--- dhcp-4.2.2b1/common/bpf.c.cloexec	2011-07-01 14:13:30.976887712 +0200
45d60a
+++ dhcp-4.2.2b1/common/bpf.c	2011-07-01 14:13:31.030887673 +0200
45d60a
@@ -94,7 +94,7 @@ int if_register_bpf (info)
45d60a
 	for (b = 0; 1; b++) {
45d60a
 		/* %Audit% 31 bytes max. %2004.06.17,Safe% */
45d60a
 		sprintf(filename, BPF_FORMAT, b);
45d60a
-		sock = open (filename, O_RDWR, 0);
45d60a
+		sock = open (filename, O_RDWR | O_CLOEXEC, 0);
45d60a
 		if (sock < 0) {
45d60a
 			if (errno == EBUSY) {
45d60a
 				continue;
45d60a
diff -up dhcp-4.2.2b1/common/dlpi.c.cloexec dhcp-4.2.2b1/common/dlpi.c
45d60a
--- dhcp-4.2.2b1/common/dlpi.c.cloexec	2011-07-01 14:13:30.977887712 +0200
45d60a
+++ dhcp-4.2.2b1/common/dlpi.c	2011-07-01 14:13:31.032887673 +0200
45d60a
@@ -806,7 +806,7 @@ dlpiopen(const char *ifname) {
45d60a
 	}
45d60a
 	*dp = '\0';
45d60a
 	
45d60a
-	return open (devname, O_RDWR, 0);
45d60a
+	return open (devname, O_RDWR | O_CLOEXEC, 0);
45d60a
 }
45d60a
 
45d60a
 /*
45d60a
diff -up dhcp-4.2.2b1/common/nit.c.cloexec dhcp-4.2.2b1/common/nit.c
45d60a
--- dhcp-4.2.2b1/common/nit.c.cloexec	2011-07-01 14:13:30.978887712 +0200
45d60a
+++ dhcp-4.2.2b1/common/nit.c	2011-07-01 14:13:31.033887672 +0200
45d60a
@@ -81,7 +81,7 @@ int if_register_nit (info)
45d60a
 	struct strioctl sio;
45d60a
 
45d60a
 	/* Open a NIT device */
45d60a
-	sock = open ("/dev/nit", O_RDWR);
45d60a
+	sock = open ("/dev/nit", O_RDWR | O_CLOEXEC);
45d60a
 	if (sock < 0)
45d60a
 		log_fatal ("Can't open NIT device for %s: %m", info -> name);
45d60a
 
45d60a
diff -up dhcp-4.2.2b1/common/resolv.c.cloexec dhcp-4.2.2b1/common/resolv.c
45d60a
--- dhcp-4.2.2b1/common/resolv.c.cloexec	2009-11-20 02:49:01.000000000 +0100
45d60a
+++ dhcp-4.2.2b1/common/resolv.c	2011-07-01 14:13:31.033887672 +0200
45d60a
@@ -49,7 +49,7 @@ void read_resolv_conf (parse_time)
45d60a
 	struct domain_search_list *dp, *dl, *nd;
45d60a
 	isc_result_t status;
45d60a
 
45d60a
-	if ((file = open (path_resolv_conf, O_RDONLY)) < 0) {
45d60a
+	if ((file = open (path_resolv_conf, O_RDONLY | O_CLOEXEC)) < 0) {
45d60a
 		log_error ("Can't open %s: %m", path_resolv_conf);
45d60a
 		return;
45d60a
 	}
45d60a
diff -up dhcp-4.2.2b1/common/upf.c.cloexec dhcp-4.2.2b1/common/upf.c
45d60a
--- dhcp-4.2.2b1/common/upf.c.cloexec	2011-07-01 14:13:30.979887712 +0200
45d60a
+++ dhcp-4.2.2b1/common/upf.c	2011-07-01 14:13:31.034887671 +0200
45d60a
@@ -77,7 +77,7 @@ int if_register_upf (info)
45d60a
 		/* %Audit% Cannot exceed 36 bytes. %2004.06.17,Safe% */
45d60a
 		sprintf(filename, "/dev/pf/pfilt%d", b);
45d60a
 
45d60a
-		sock = open (filename, O_RDWR, 0);
45d60a
+		sock = open (filename, O_RDWR | O_CLOEXEC, 0);
45d60a
 		if (sock < 0) {
45d60a
 			if (errno == EBUSY) {
45d60a
 				continue;
45d60a
diff -up dhcp-4.2.2b1/omapip/trace.c.cloexec dhcp-4.2.2b1/omapip/trace.c
45d60a
--- dhcp-4.2.2b1/omapip/trace.c.cloexec	2010-05-27 02:34:57.000000000 +0200
45d60a
+++ dhcp-4.2.2b1/omapip/trace.c	2011-07-01 14:13:31.036887669 +0200
45d60a
@@ -141,10 +141,10 @@ isc_result_t trace_begin (const char *fi
45d60a
 		return DHCP_R_INVALIDARG;
45d60a
 	}
45d60a
 
45d60a
-	traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL, 0600);
45d60a
+	traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL | O_CLOEXEC, 0600);
45d60a
 	if (traceoutfile < 0 && errno == EEXIST) {
45d60a
 		log_error ("WARNING: Overwriting trace file \"%s\"", filename);
45d60a
-		traceoutfile = open (filename, O_WRONLY | O_EXCL | O_TRUNC,
45d60a
+		traceoutfile = open (filename, O_WRONLY | O_EXCL | O_TRUNC | O_CLOEXEC,
45d60a
 				     0600);
45d60a
 	}
45d60a
 
45d60a
@@ -431,7 +431,7 @@ void trace_file_replay (const char *file
45d60a
 	isc_result_t result;
45d60a
 	int len;
45d60a
 
45d60a
-	traceinfile = fopen (filename, "r");
45d60a
+	traceinfile = fopen (filename, "re");
45d60a
 	if (!traceinfile) {
45d60a
 		log_error("Can't open tracefile %s: %m", filename);
45d60a
 		return;
45d60a
diff -up dhcp-4.2.2b1/relay/dhcrelay.c.cloexec dhcp-4.2.2b1/relay/dhcrelay.c
45d60a
--- dhcp-4.2.2b1/relay/dhcrelay.c.cloexec	2011-05-10 15:07:37.000000000 +0200
45d60a
+++ dhcp-4.2.2b1/relay/dhcrelay.c	2011-07-01 14:18:07.630209767 +0200
45d60a
@@ -183,11 +183,11 @@ main(int argc, char **argv) {
45d60a
 	/* Make sure that file descriptors 0(stdin), 1,(stdout), and
45d60a
 	   2(stderr) are open. To do this, we assume that when we
45d60a
 	   open a file the lowest available file descriptor is used. */
45d60a
-	fd = open("/dev/null", O_RDWR);
45d60a
+	fd = open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
 	if (fd == 0)
45d60a
-		fd = open("/dev/null", O_RDWR);
45d60a
+		fd = open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
 	if (fd == 1)
45d60a
-		fd = open("/dev/null", O_RDWR);
45d60a
+		fd = open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
 	if (fd == 2)
45d60a
 		log_perror = 0; /* No sense logging to /dev/null. */
45d60a
 	else if (fd != -1)
45d60a
@@ -540,13 +540,13 @@ main(int argc, char **argv) {
45d60a
 
45d60a
 		if (no_pid_file == ISC_FALSE) {
45d60a
 			pfdesc = open(path_dhcrelay_pid,
45d60a
-				      O_CREAT | O_TRUNC | O_WRONLY, 0644);
45d60a
+				      O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
45d60a
 
45d60a
 			if (pfdesc < 0) {
45d60a
 				log_error("Can't create %s: %m",
45d60a
 					  path_dhcrelay_pid);
45d60a
 			} else {
45d60a
-				pf = fdopen(pfdesc, "w");
45d60a
+				pf = fdopen(pfdesc, "we");
45d60a
 				if (!pf)
45d60a
 					log_error("Can't fdopen %s: %m",
45d60a
 						  path_dhcrelay_pid);
45d60a
diff -up dhcp-4.2.2b1/server/confpars.c.cloexec dhcp-4.2.2b1/server/confpars.c
45d60a
--- dhcp-4.2.2b1/server/confpars.c.cloexec	2010-10-14 00:34:45.000000000 +0200
45d60a
+++ dhcp-4.2.2b1/server/confpars.c	2011-07-01 14:13:31.039887666 +0200
45d60a
@@ -116,7 +116,7 @@ isc_result_t read_conf_file (const char 
45d60a
 	}
45d60a
 #endif
45d60a
 
45d60a
-	if ((file = open (filename, O_RDONLY)) < 0) {
45d60a
+	if ((file = open (filename, O_RDONLY | O_CLOEXEC)) < 0) {
45d60a
 		if (leasep) {
45d60a
 			log_error ("Can't open lease database %s: %m --",
45d60a
 				   path_dhcpd_db);
45d60a
diff -up dhcp-4.2.2b1/server/db.c.cloexec dhcp-4.2.2b1/server/db.c
45d60a
--- dhcp-4.2.2b1/server/db.c.cloexec	2010-09-14 00:15:26.000000000 +0200
45d60a
+++ dhcp-4.2.2b1/server/db.c	2011-07-01 14:13:31.040887665 +0200
45d60a
@@ -1035,7 +1035,7 @@ void db_startup (testp)
45d60a
 	}
45d60a
 #endif
45d60a
 	if (!testp) {
45d60a
-		db_file = fopen (path_dhcpd_db, "a");
45d60a
+		db_file = fopen (path_dhcpd_db, "ae");
45d60a
 		if (!db_file)
45d60a
 			log_fatal ("Can't open %s for append.", path_dhcpd_db);
45d60a
 		expire_all_pools ();
45d60a
@@ -1083,12 +1083,12 @@ int new_lease_file ()
45d60a
 		     path_dhcpd_db, (int)t) >= sizeof newfname)
45d60a
 		log_fatal("new_lease_file: lease file path too long");
45d60a
 
45d60a
-	db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT, 0664);
45d60a
+	db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0664);
45d60a
 	if (db_fd < 0) {
45d60a
 		log_error ("Can't create new lease file: %m");
45d60a
 		return 0;
45d60a
 	}
45d60a
-	if ((new_db_file = fdopen(db_fd, "w")) == NULL) {
45d60a
+	if ((new_db_file = fdopen(db_fd, "we")) == NULL) {
45d60a
 		log_error("Can't fdopen new lease file: %m");
45d60a
 		close(db_fd);
45d60a
 		goto fdfail;
45d60a
diff -up dhcp-4.2.2b1/server/dhcpd.c.cloexec dhcp-4.2.2b1/server/dhcpd.c
45d60a
--- dhcp-4.2.2b1/server/dhcpd.c.cloexec	2011-04-21 16:08:15.000000000 +0200
45d60a
+++ dhcp-4.2.2b1/server/dhcpd.c	2011-07-01 14:19:40.354124505 +0200
45d60a
@@ -270,11 +270,11 @@ main(int argc, char **argv) {
45d60a
         /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
45d60a
            2 (stderr) are open. To do this, we assume that when we
45d60a
            open a file the lowest available file descriptor is used. */
45d60a
-        fd = open("/dev/null", O_RDWR);
45d60a
+        fd = open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
         if (fd == 0)
45d60a
-                fd = open("/dev/null", O_RDWR);
45d60a
+                fd = open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
         if (fd == 1)
45d60a
-                fd = open("/dev/null", O_RDWR);
45d60a
+                fd = open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
         if (fd == 2)
45d60a
                 log_perror = 0; /* No sense logging to /dev/null. */
45d60a
         else if (fd != -1)
45d60a
@@ -793,7 +793,7 @@ main(int argc, char **argv) {
45d60a
 	 */
45d60a
 	if (no_pid_file == ISC_FALSE) {
45d60a
 		/*Read previous pid file. */
45d60a
-		if ((i = open (path_dhcpd_pid, O_RDONLY)) >= 0) {
45d60a
+		if ((i = open (path_dhcpd_pid, O_RDONLY | O_CLOEXEC)) >= 0) {
45d60a
 			status = read(i, pbuf, (sizeof pbuf) - 1);
45d60a
 			close (i);
45d60a
 			if (status > 0) {
45d60a
@@ -812,7 +812,7 @@ main(int argc, char **argv) {
45d60a
 		}
45d60a
 
45d60a
 		/* Write new pid file. */
45d60a
-		i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC, 0644);
45d60a
+		i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0644);
45d60a
 		if (i >= 0) {
45d60a
 			sprintf(pbuf, "%d\n", (int) getpid());
45d60a
 			IGNORE_RET (write(i, pbuf, strlen(pbuf)));
45d60a
@@ -840,9 +840,9 @@ main(int argc, char **argv) {
45d60a
                 close(2);
45d60a
 
45d60a
                 /* Reopen them on /dev/null. */
45d60a
-                open("/dev/null", O_RDWR);
45d60a
-                open("/dev/null", O_RDWR);
45d60a
-                open("/dev/null", O_RDWR);
45d60a
+                open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
+                open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
+                open("/dev/null", O_RDWR | O_CLOEXEC);
45d60a
                 log_perror = 0; /* No sense logging to /dev/null. */
45d60a
 
45d60a
        		IGNORE_RET (chdir("/"));
45d60a
diff -up dhcp-4.2.2b1/server/ldap.c.cloexec dhcp-4.2.2b1/server/ldap.c
45d60a
--- dhcp-4.2.2b1/server/ldap.c.cloexec	2010-03-25 16:26:58.000000000 +0100
45d60a
+++ dhcp-4.2.2b1/server/ldap.c	2011-07-01 14:13:31.043887665 +0200
45d60a
@@ -685,7 +685,7 @@ ldap_start (void)
45d60a
 
45d60a
   if (ldap_debug_file != NULL && ldap_debug_fd == -1)
45d60a
     {
45d60a
-      if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY,
45d60a
+      if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
45d60a
                                  S_IRUSR | S_IWUSR)) < 0)
45d60a
         log_error ("Error opening debug LDAP log file %s: %s", ldap_debug_file,
45d60a
                    strerror (errno));