Blame SOURCES/dhcp-4.2.2-CLOEXEC.patch

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