]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Chdir to "/" before going into daemon mode. Use realpath() to
authorEvan Hunt <each@isc.org>
Thu, 7 Jun 2007 15:29:31 +0000 (15:29 +0000)
committerEvan Hunt <each@isc.org>
Thu, 7 Jun 2007 15:29:31 +0000 (15:29 +0000)
canonicalize relative pathnames. [rt16729]

RELNOTES
client/dhclient.c
relay/dhcrelay.c
server/dhcpd.c

index 7064897873fee2211a6be2999e1d95583b6de2fe..7c99f43db65eddb93d8f9ee512be34b7474dfbd3 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -66,6 +66,9 @@ suggested fixes to <dhcp-users@isc.org>.
 - Added -x option to dhclient, which triggers dhclient processes
   to exit gracefully without releasing leases first
 
+- All binaries (client, server, relay) now change directories
+  to / before going into daemon mode, so as not to hold $CWD open
+
                        Changes since 4.0.0-20070413
 
 - Old (expired) leases are now cleaned.
index 5466af928bc7ee4280d6fe70785aaaffb41827dd..f05a94ef4624a001ecb37493da4789d777ec5d77 100644 (file)
@@ -32,7 +32,7 @@
 
 #ifndef lint
 static char ocopyright[] =
-"$Id: dhclient.c,v 1.152 2007/06/06 22:57:32 each Exp $ Copyright (c) 2004-2007 Internet Systems Consortium.  All rights reserved.\n";
+"$Id: dhclient.c,v 1.153 2007/06/07 15:29:30 each Exp $ Copyright (c) 2004-2007 Internet Systems Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -276,7 +276,29 @@ main(int argc, char **argv) {
        else
                log_fatal("Impossible condition at %s:%d.", MDL);
 
-       /* first kill of any currently running client */
+       /*
+        * convert relative path names to absolute, for files that need
+        * to be reopened after chdir() has been called
+        */
+       if (path_dhclient_db[0] != '/') {
+               char *path = dmalloc(PATH_MAX, MDL);
+               if (path == NULL)
+                       log_fatal("No memory for filename\n");
+               path_dhclient_db = realpath(path_dhclient_db,   path);
+               if (path_dhclient_db == NULL)
+                       log_fatal("%s: %s", path, strerror(errno));
+       }
+       if (path_dhclient_script[0] != '/') {
+               char *path = dmalloc(PATH_MAX, MDL);
+               if (path == NULL)
+                       log_fatal("No memory for filename\n");
+               path_dhclient_script = realpath(path_dhclient_script,   path);
+               if (path_dhclient_script == NULL)
+                       log_fatal("%s: %s", path, strerror(errno));
+       }
+       /* first kill off any currently running client */
        if (release_mode || exit_mode) {
                FILE *pidfd;
                pid_t oldpid;
@@ -3049,6 +3071,8 @@ void go_daemon ()
        open("/dev/null", O_RDWR);
 
        write_client_pid_file ();
+
+        chdir("/");
 }
 
 void write_client_pid_file ()
index d3bfbcce14f6671060361a0c57a683e4e654ab09..96e0a97d030619b0c17e86221bf13085aaad4be3 100644 (file)
@@ -34,7 +34,7 @@
 
 #ifndef lint
 static char ocopyright[] =
-"$Id: dhcrelay.c,v 1.62 2007/05/19 19:16:26 dhankins Exp $ Copyright (c) 2004-2007 Internet Systems Consortium.  All rights reserved.\n";
+"$Id: dhcrelay.c,v 1.63 2007/06/07 15:29:31 each Exp $ Copyright (c) 2004-2007 Internet Systems Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -312,6 +312,8 @@ main(int argc, char **argv) {
                close (1);
                close (2);
                pid = setsid ();
+
+                chdir("/");
        }
 
        /* Start dispatching packets and timeouts... */
index 59c3f9f95278c7e0b7678fd744a6554de7050b42..913fe1f1b79eca17d3bf743424da99f63021e8d7 100644 (file)
@@ -34,7 +34,7 @@
 
 #ifndef lint
 static char ocopyright[] =
-"$Id: dhcpd.c,v 1.126 2007/05/29 18:11:56 each Exp $ Copyright 2004-2007 Internet Systems Consortium.";
+"$Id: dhcpd.c,v 1.127 2007/06/07 15:29:31 each Exp $ Copyright 2004-2007 Internet Systems Consortium.";
 #endif
 
   static char copyright[] =
@@ -46,6 +46,7 @@ static char url [] = "For info, please visit http://www.isc.org/sw/dhcp/";
 #include "dhcpd.h"
 #include <omapip/omapip_p.h>
 #include <syslog.h>
+#include <errno.h>
 
 static void usage PROTO ((void));
 
@@ -378,6 +379,19 @@ main(int argc, char **argv) {
                path_dhcpd_pid = s;
        }
 
+        /*
+         * convert relative path names to absolute, for files that need
+         * to be reopened after chdir() has been called
+         */
+        if (path_dhcpd_db[0] != '/') {
+                char *path = dmalloc(PATH_MAX, MDL);
+                if (path == NULL)
+                        log_fatal("No memory for filename\n");
+                path_dhcpd_db = realpath(path_dhcpd_db,  path);
+                if (path_dhcpd_db == NULL)
+                        log_fatal("%s: %s", path, strerror(errno));
+        }
+
        if (!quiet) {
                log_info("%s %s", message, PACKAGE_VERSION);
                log_info (copyright);
@@ -638,6 +652,21 @@ main(int argc, char **argv) {
        else
                log_perror = 0;
 
+       /* If we didn't write the pid file earlier because we found a
+          process running the logged pid, but we made it to here,
+          meaning nothing is listening on the bootp port, then write
+          the pid file out - what's in it now is bogus anyway. */
+       if (!pidfilewritten) {
+               unlink (path_dhcpd_pid);
+               if ((i = open (path_dhcpd_pid,
+                              O_WRONLY | O_CREAT, 0644)) >= 0) {
+                       sprintf (pbuf, "%d\n", (int)getpid ());
+                       write (i, pbuf, strlen (pbuf));
+                       close (i);
+                       pidfilewritten = 1;
+               }
+       }
+
        if (daemon) {
                /* Become session leader and get pid... */
                pid = setsid();
@@ -652,21 +681,8 @@ main(int argc, char **argv) {
                 open("/dev/null", O_RDWR);
                 open("/dev/null", O_RDWR);
                 log_perror = 0; /* No sense logging to /dev/null. */
-       }
 
-       /* If we didn't write the pid file earlier because we found a
-          process running the logged pid, but we made it to here,
-          meaning nothing is listening on the bootp port, then write
-          the pid file out - what's in it now is bogus anyway. */
-       if (!pidfilewritten) {
-               unlink (path_dhcpd_pid);
-               if ((i = open (path_dhcpd_pid,
-                              O_WRONLY | O_CREAT, 0644)) >= 0) {
-                       sprintf (pbuf, "%d\n", (int)getpid ());
-                       write (i, pbuf, strlen (pbuf));
-                       close (i);
-                       pidfilewritten = 1;
-               }
+                chdir("/");
        }
 #endif /* !DEBUG */