philipp / rpms / dhcp

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