]> granicus.if.org Git - sudo/commitdiff
now deal with situations where we getwd() fails
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 19 Nov 1995 00:17:31 +0000 (00:17 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 19 Nov 1995 00:17:31 +0000 (00:17 +0000)
sudo.c

diff --git a/sudo.c b/sudo.c
index 484a78cc33677304d3dde18d9c39f33f1bdacddf..8841f4fff77bd17a41f0a26ef54bd39c99cb3c1c 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -431,21 +431,28 @@ static void load_globals(sudo_mode)
     (void) umask((mode_t)UMASK);
 #endif /* UMASK */
 
-    /*
-     * so we know where we are... (do as user)
-     */
-    if (!getwd(cwd)) {
-       (void) fprintf(stderr, "%s:  Can't get working directory!\n", Argv[0]);
-       exit(1);
-    }
-
 #ifdef NO_ROOT_SUDO
     if (uid == 0) {
-       (void) fprintf(stderr, "You are already root, you don't need to use sudo.\n");
+       (void) fprintf(stderr,
+                      "You are already root, you don't need to use sudo.\n");
        exit(1);
     }
 #endif
 
+    /*
+     * so we know where we are... (do as user)
+     */
+    if (!getwd(cwd)) {
+       /* try as root... */
+       set_perms(PERM_ROOT);
+       if (!getwd(cwd)) {
+           (void) fprintf(stderr, "%s:  Can't get working directory!\n",
+                          Argv[0]);
+           (void) strcpy(cwd, "unknown");
+       }
+       set_perms(PERM_USER);
+    }
+
     /*
      * load the host global variable from gethostname()
      * and use gethostbyname() if we want it to be fully qualified.