]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
[master] Add fchown to the paranoia patch
authorShawn Routhier <sar@isc.org>
Wed, 15 Jul 2015 21:14:39 +0000 (14:14 -0700)
committerShawn Routhier <sar@isc.org>
Wed, 15 Jul 2015 21:14:39 +0000 (14:14 -0700)
Add code to fchown the lease file to the paranoia patch to avoid
having issues with a file that the server can't manipulate.

RELNOTES
includes/dhcpd.h
server/db.c
server/dhcpd.8
server/dhcpd.c

index dca0795df67fc8036d918a05f32a8f6759191e75..3db92141d557a07da0bee70e964608e85274ab6e 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -162,6 +162,11 @@ by Eric Young (eay@cryptsoft.com).
   the encoding specified by the vendor-option-space statement.
   [ISC-Bugs #36449]
 
+- Enhance the PARANOIA patch to include fchown() the lease file to
+  allow it to be manipulated after the server does a chown().
+  Thanks to Jiri Popelka at Red Hat for the patch.
+  [ISC-Bugs #36978]
+
                        Changes since 4.3.2rc2
 - None
 
index 916e18eb37b0e2e1816171c6da4d563a5ac9c5ac..4e75421e72098f1af70f47d22cc0ec3515d732fd 100644 (file)
@@ -2040,6 +2040,11 @@ extern const char *path_dhcpd_pid;
 extern int dhcp_max_agent_option_packet_length;
 extern struct eventqueue *rw_queue_empty;
 
+#if defined (PARANOIA)
+extern uid_t set_uid;
+extern gid_t set_gid;
+#endif
+
 int main(int, char **);
 void postconf_initialization(int);
 void postdb_startup(void);
index d4d42feb911bf2365feb9491c360143ec46e2551..5238ed86c7522646d438c933dd44fd1b073a32b0 100644 (file)
@@ -1125,6 +1125,22 @@ int new_lease_file ()
                log_error ("Can't create new lease file: %m");
                return 0;
        }
+
+#if defined (PARANOIA)
+       /*
+        * If we are currently root and plan to change the
+        * uid and gid change the file information so we
+        * can manipulate it later, after we've changed
+        * our group and user (that is dropped privileges.)
+        */
+       if ((set_uid != 0) && (geteuid() == 0) &&
+           (set_gid != 0) && (getegid() == 0)) {
+               if (fchown(db_fd, set_uid, set_gid)) {
+                       log_fatal ("Can't chown new lease file: %m");
+               }
+       }
+#endif /* PARANOIA */
+
        if ((new_db_file = fdopen(db_fd, "w")) == NULL) {
                log_error("Can't fdopen new lease file: %m");
                close(db_fd);
index f4b13dcd1b418d4cc7b5cbcb4106e1d4c695f7fb..239dd488368239ab8b56341f7bc3f8843f2388e0 100644 (file)
@@ -78,6 +78,18 @@ dhcpd - Dynamic Host Configuration Protocol Server
 .B --no-pid
 ]
 [
+.B -user
+.I user
+]
+[
+.B -group
+.I group
+]
+[
+.B -chroot
+.I dir
+]
+[
 .B -tf
 .I trace-output-file
 ]
@@ -249,6 +261,28 @@ for correct syntax, but will not attempt to perform any network
 operations.  This can be used to test a new lease file
 automatically before installing it.
 .TP
+.BI \-user \ user
+Setuid to user after completing privileged operations,
+such as creating sockets that listen on privileged ports.
+This also causes the lease file to be owned by user.
+This option is only available if the code was compiled
+with the PARANOIA patch (./configure --enable-paranoia).
+.TP
+.BI \-group \ group
+Setgid to group after completing privileged operations,
+such as creating sockets that listen on privileged ports.
+This also causes the lease file to use group.
+This option is only available if the code was compiled
+with the PARANOIA patch (./configure --enable-paranoia).
+.TP
+.BI \-chroot \ dir
+Chroot to directory.  This may occur before or after
+reading the configuration files depending on whether
+the code was compiled with the EARLY_CHROOT option
+enabled (./configure --enable-early-chroot).
+This option is only available if the code was compiled
+with the PARANOIA patch (./configure --enable-paranoia).
+.TP
 .BI \-tf \ tracefile
 Specify a file into which the entire startup state of the server and
 all the transactions it processes are logged.  This can be
index ebb6d3e333215fcac6941350b0271f1b649feaf4..db95f17249b6c91bf89efedb3b9448ed2e716f6b 100644 (file)
@@ -50,6 +50,10 @@ static const char url [] =
 #  define group real_group 
 #    include <grp.h>
 #  undef group
+
+/* global values so db.c can look at them */
+uid_t set_uid = 0;
+gid_t set_gid = 0;
 #endif /* PARANOIA */
 
 #ifndef UNIT_TEST
@@ -126,6 +130,12 @@ static void omapi_listener_start (void *foo)
        omapi_object_dereference (&listener, MDL);
 }
 
+#ifndef UNIT_TEST
+
+/* Note: If we add unit tests to test setup_chroot it will
+ * need to be moved to be outside the ifndef UNIT_TEST block.
+ */
+
 #if defined (PARANOIA)
 /* to be used in one of two possible scenarios */
 static void setup_chroot (char *chroot_dir) {
@@ -142,7 +152,6 @@ static void setup_chroot (char *chroot_dir) {
 }
 #endif /* PARANOIA */
 
-#ifndef UNIT_TEST
 int 
 main(int argc, char **argv) {
        int fd;
@@ -180,9 +189,6 @@ main(int argc, char **argv) {
        char *set_user   = 0;
        char *set_group  = 0;
        char *set_chroot = 0;
-
-       uid_t set_uid = 0;
-       gid_t set_gid = 0;
 #endif /* PARANOIA */
 
         /* Make sure that file descriptors 0 (stdin), 1, (stdout), and