Blame SOURCES/dhcp-4.2.5-paranoia.patch

45d60a
diff -up dhcp-4.2.5/client/dhclient.c.paranoia dhcp-4.2.5/client/dhclient.c
45d60a
--- dhcp-4.2.5/client/dhclient.c.paranoia	2013-03-26 13:14:50.574542083 +0100
45d60a
+++ dhcp-4.2.5/client/dhclient.c	2013-03-26 13:14:50.584541964 +0100
45d60a
@@ -1698,11 +1698,6 @@ int write_host (host)
45d60a
 	return 0;
45d60a
 }
45d60a
 
45d60a
-void db_startup (testp)
45d60a
-	int testp;
45d60a
-{
45d60a
-}
45d60a
-
45d60a
 void bootp (packet)
45d60a
 	struct packet *packet;
45d60a
 {
45d60a
diff -up dhcp-4.2.5/includes/dhcpd.h.paranoia dhcp-4.2.5/includes/dhcpd.h
45d60a
--- dhcp-4.2.5/includes/dhcpd.h.paranoia	2013-03-26 13:14:50.576542059 +0100
45d60a
+++ dhcp-4.2.5/includes/dhcpd.h	2013-03-26 13:14:50.585541952 +0100
45d60a
@@ -2798,7 +2798,11 @@ void commit_leases_timeout (void *);
45d60a
 void commit_leases_readerdry(void *);
45d60a
 int commit_leases (void);
45d60a
 int commit_leases_timed (void);
45d60a
+#if defined (PARANOIA)
45d60a
+void db_startup (int, uid_t, gid_t);
45d60a
+#else
45d60a
 void db_startup (int);
45d60a
+#endif /* PARANOIA */
45d60a
 int new_lease_file (void);
45d60a
 int group_writer (struct group_object *);
45d60a
 int write_ia(const struct ia_xx *);
45d60a
diff -up dhcp-4.2.5/server/confpars.c.paranoia dhcp-4.2.5/server/confpars.c
45d60a
--- dhcp-4.2.5/server/confpars.c.paranoia	2013-03-26 13:14:50.522542705 +0100
45d60a
+++ dhcp-4.2.5/server/confpars.c	2013-03-26 13:14:50.587541928 +0100
45d60a
@@ -224,7 +224,11 @@ void trace_conf_input (trace_type_t *tty
45d60a
 	}
45d60a
 
45d60a
 	if (!leaseconf_initialized && ttype == trace_readleases_type) {
45d60a
+#if defined (PARANOIA)
45d60a
+		db_startup (0, 0, 0);
45d60a
+#else
45d60a
 		db_startup (0);
45d60a
+#endif /* PARANOIA */
45d60a
 		leaseconf_initialized = 1;
45d60a
 		postdb_startup ();
45d60a
 	}
45d60a
diff -up dhcp-4.2.5/server/db.c.paranoia dhcp-4.2.5/server/db.c
45d60a
--- dhcp-4.2.5/server/db.c.paranoia	2013-03-26 13:14:50.522542705 +0100
45d60a
+++ dhcp-4.2.5/server/db.c	2013-03-26 13:14:50.588541916 +0100
45d60a
@@ -47,6 +47,10 @@ static int counting = 0;
45d60a
 static int count = 0;
45d60a
 TIME write_time;
45d60a
 int lease_file_is_corrupt = 0;
45d60a
+#if defined (PARANOIA)
45d60a
+uid_t global_set_uid = 0;
45d60a
+gid_t global_set_gid = 0;
45d60a
+#endif /* PARANOIA */
45d60a
 
45d60a
 /* Write a single binding scope value in parsable format.
45d60a
  */
45d60a
@@ -1026,8 +1030,11 @@ int commit_leases_timed()
45d60a
 	return (1);
45d60a
 }
45d60a
 
45d60a
-void db_startup (testp)
45d60a
-	int testp;
45d60a
+#if defined (PARANOIA)
45d60a
+void db_startup (int testp, uid_t set_uid, gid_t set_gid)
45d60a
+#else
45d60a
+void db_startup (int testp)
45d60a
+#endif /* PARANOIA */
45d60a
 {
45d60a
 	isc_result_t status;
45d60a
 
45d60a
@@ -1046,6 +1053,11 @@ void db_startup (testp)
45d60a
 	}
45d60a
 #endif
45d60a
 
45d60a
+#if defined (PARANOIA)
45d60a
+	global_set_uid = set_uid;
45d60a
+	global_set_gid = set_gid;
45d60a
+#endif /* PARANOIA */
45d60a
+
45d60a
 #if defined (TRACING)
45d60a
 	/* If we're playing back, there is no lease file, so we can't
45d60a
 	   append it, so we create one immediately (maybe this isn't
45d60a
@@ -1108,6 +1120,17 @@ int new_lease_file ()
45d60a
 		log_error ("Can't create new lease file: %m");
45d60a
 		return 0;
45d60a
 	}
45d60a
+
45d60a
+#if defined (PARANOIA)
45d60a
+	if (global_set_uid && !geteuid() &&
45d60a
+	    global_set_gid && !getegid())
45d60a
+		if (fchown(db_fd, global_set_uid, global_set_gid)) {
45d60a
+			log_fatal ("Can't chown new lease file: %m");
45d60a
+			close(db_fd);
45d60a
+			goto fdfail;
45d60a
+	}
45d60a
+#endif /* PARANOIA */
45d60a
+
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
diff -up dhcp-4.2.5/server/dhcpd.8.paranoia dhcp-4.2.5/server/dhcpd.8
45d60a
--- dhcp-4.2.5/server/dhcpd.8.paranoia	2013-01-03 01:02:25.000000000 +0100
45d60a
+++ dhcp-4.2.5/server/dhcpd.8	2013-03-26 13:28:16.576604471 +0100
45d60a
@@ -82,6 +82,18 @@ dhcpd - Dynamic Host Configuration Proto
45d60a
 .I trace-output-file
45d60a
 ]
45d60a
 [
45d60a
+.B -user
45d60a
+.I user
45d60a
+]
45d60a
+[
45d60a
+.B -group
45d60a
+.I group
45d60a
+]
45d60a
+[
45d60a
+.B -chroot
45d60a
+.I dir
45d60a
+]
45d60a
+[
45d60a
 .B -play
45d60a
 .I trace-playback-file
45d60a
 ]
45d60a
@@ -269,6 +281,15 @@ lease file.
45d60a
 .TP
45d60a
 .BI --version
45d60a
 Print version number and exit.
45d60a
+.TP
45d60a
+.BI \-user \ user
45d60a
+Setuid to user after completing privileged operations, such as creating sockets that listen on privileged ports.
45d60a
+.TP
45d60a
+.BI \-group \ group
45d60a
+Setgid to group after completing privileged operations, such as creating sockets that listen on privileged ports.
45d60a
+.TP
45d60a
+.BI \-chroot \ dir
45d60a
+Chroot to directory after processing the command line arguments, but before reading the configuration file.
45d60a
 .PP
45d60a
 .I Modifying default file locations:
45d60a
 The following options can be used to modify the locations 
45d60a
diff -up dhcp-4.2.5/server/dhcpd.c.paranoia dhcp-4.2.5/server/dhcpd.c
45d60a
--- dhcp-4.2.5/server/dhcpd.c.paranoia	2013-03-26 13:14:50.523542693 +0100
45d60a
+++ dhcp-4.2.5/server/dhcpd.c	2013-03-26 13:14:50.589541904 +0100
45d60a
@@ -702,7 +702,11 @@ main(int argc, char **argv) {
45d60a
 	group_write_hook = group_writer;
45d60a
 
45d60a
 	/* Start up the database... */
45d60a
+#if defined (PARANOIA)
45d60a
+	db_startup (lftest, set_uid, set_gid);
45d60a
+#else
45d60a
 	db_startup (lftest);
45d60a
+#endif /* PARANOIA */
45d60a
 
45d60a
 	if (lftest)
45d60a
 		exit (0);
45d60a
@@ -773,22 +777,6 @@ main(int argc, char **argv) {
45d60a
 			exit (0);
45d60a
 	}
45d60a
  
45d60a
-#if defined (PARANOIA)
45d60a
-	/* change uid to the specified one */
45d60a
-
45d60a
-	if (set_gid) {
45d60a
-		if (setgroups (0, (void *)0))
45d60a
-			log_fatal ("setgroups: %m");
45d60a
-		if (setgid (set_gid))
45d60a
-			log_fatal ("setgid(%d): %m", (int) set_gid);
45d60a
-	}	
45d60a
-
45d60a
-	if (set_uid) {
45d60a
-		if (setuid (set_uid))
45d60a
-			log_fatal ("setuid(%d): %m", (int) set_uid);
45d60a
-	}
45d60a
-#endif /* PARANOIA */
45d60a
-
45d60a
 	/*
45d60a
 	 * Deal with pid files.  If the user told us
45d60a
 	 * not to write a file we don't read one either
45d60a
@@ -825,6 +813,22 @@ main(int argc, char **argv) {
45d60a
 		}
45d60a
 	}
45d60a
 
45d60a
+#if defined (PARANOIA)
45d60a
+	/* change uid to the specified one */
45d60a
+
45d60a
+	if (set_gid) {
45d60a
+		if (setgroups (0, (void *)0))
45d60a
+			log_fatal ("setgroups: %m");
45d60a
+		if (setgid (set_gid))
45d60a
+			log_fatal ("setgid(%d): %m", (int) set_gid);
45d60a
+	}	
45d60a
+
45d60a
+	if (set_uid) {
45d60a
+		if (setuid (set_uid))
45d60a
+			log_fatal ("setuid(%d): %m", (int) set_uid);
45d60a
+	}
45d60a
+#endif /* PARANOIA */
45d60a
+
45d60a
 	/* If we were requested to log to stdout on the command line,
45d60a
 	   keep doing so; otherwise, stop. */
45d60a
 	if (log_perror == -1)