From: Todd C. Miller Date: Thu, 17 Sep 2009 09:54:33 +0000 (+0000) Subject: Create session dir earlier now that we update the seq number early. X-Git-Tag: SUDO_1_7_3~296 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88a063b04740b461efced1e09b60f8626dcc52ce;p=sudo Create session dir earlier now that we update the seq number early. --- diff --git a/script.c b/script.c index d50e4ea9e..d575ca78c 100644 --- 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.