Blame SOURCES/dhcp-4.2.5-paranoia.patch

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