philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

Blame SOURCES/dhcp-4.2.5-paranoia.patch

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