]> granicus.if.org Git - sudo/commitdiff
Create session dir earlier now that we update the seq number early.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 17 Sep 2009 09:54:33 +0000 (09:54 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 17 Sep 2009 09:54:33 +0000 (09:54 +0000)
script.c

index d50e4ea9e1968c92c0ec6efc64b0d30eb59db0e3..d575ca78c8b584ce31be5674a1724fa89de02958 100644 (file)
--- a/script.c
+++ b/script.c
@@ -112,6 +112,7 @@ fdcompar(v1, v2)
 void
 script_nextid()
 {
+    struct stat sb;
     char buf[32], *ep;
     int fd, i, ch;
     unsigned long id = 0;
@@ -119,6 +120,17 @@ script_nextid()
     ssize_t nread;
     char pathbuf[PATH_MAX];
 
+    /*
+     * Create _PATH_SUDO_SESSDIR if it doesn't already exist.
+     */
+    if (stat(_PATH_SUDO_SESSDIR, &sb) != 0) {
+       if (mkdir(_PATH_SUDO_SESSDIR, S_IRWXU) != 0)
+           log_error(USE_ERRNO, "Can't mkdir %s", _PATH_SUDO_SESSDIR);
+    } else if (!S_ISDIR(sb.st_mode)) {
+       log_error(0, "%s exists but is not a directory (0%o)",
+           _PATH_SUDO_SESSDIR, (unsigned int) sb.st_mode);
+    }
+
     /*
      * Open sequence file
      */
@@ -205,7 +217,6 @@ build_idpath(pathbuf)
 void
 script_setup()
 {
-    struct stat sb;
     char pathbuf[PATH_MAX];
     int len;
 
@@ -224,17 +235,6 @@ script_setup()
     if (!term_raw(STDIN_FILENO))
        log_error(USE_ERRNO, "Can't set terminal to raw mode");
 
-    /*
-     * Create _PATH_SUDO_SESSDIR if it doesn't already exist.
-     */
-    if (stat(_PATH_SUDO_SESSDIR, &sb) != 0) {
-       if (mkdir(_PATH_SUDO_SESSDIR, S_IRWXU) != 0)
-           log_error(USE_ERRNO, "Can't mkdir %s", _PATH_SUDO_SESSDIR);
-    } else if (!S_ISDIR(sb.st_mode)) {
-       log_error(0, "%s exists but is not a directory (0%o)",
-           _PATH_SUDO_SESSDIR, (unsigned int) sb.st_mode);
-    }
-
     /*
      * Build a path containing the session id split into two-digit subdirs,
      * so ID 000001 becomes /var/log/sudo-session/00/00/01.