Imported Upstream version 1.8.5
[debian/sudo] / plugins / sudoers / check.c
index 2850fe83a197987de17ab3ddab7c1103376ccd96..d66445ce0ccb0ace1368b129b47be6290cc14ee5 100644 (file)
@@ -246,11 +246,11 @@ update_timestamp(char *timestampdir, char *timestampfile)
         */
        int fd = open(timestampfile, O_WRONLY|O_CREAT, 0600);
        if (fd == -1)
-           log_error(NO_EXIT|USE_ERRNO, _("unable to open %s"), timestampfile);
+           log_error(USE_ERRNO, _("unable to open %s"), timestampfile);
        else {
            lock_file(fd, SUDO_LOCK);
            if (write(fd, &tty_info, sizeof(tty_info)) != sizeof(tty_info)) {
-               log_error(NO_EXIT|USE_ERRNO, _("unable to write to %s"),
+               log_error(USE_ERRNO, _("unable to write to %s"),
                    timestampfile);
            }
            close(fd);
@@ -258,7 +258,7 @@ update_timestamp(char *timestampdir, char *timestampfile)
     } else {
        if (touch(-1, timestampdir, NULL) == -1) {
            if (mkdir(timestampdir, 0700) == -1) {
-               log_error(NO_EXIT|USE_ERRNO, _("unable to mkdir %s"),
+               log_error(USE_ERRNO, _("unable to mkdir %s"),
                    timestampdir);
            }
        }
@@ -453,7 +453,7 @@ build_timestamp(char **timestampdir, char **timestampfile)
 
     debug_return_int(len);
 bad:
-    log_error(0, _("timestamp path too long: %s"), *timestampfile);
+    log_fatal(0, _("timestamp path too long: %s"), *timestampfile);
     debug_return_int(-1);
 }
 
@@ -482,14 +482,14 @@ timestamp_status(char *timestampdir, char *timestampfile, char *user, int flags)
      */
     if (lstat(dirparent, &sb) == 0) {
        if (!S_ISDIR(sb.st_mode))
-           log_error(NO_EXIT, _("%s exists but is not a directory (0%o)"),
+           log_error(0, _("%s exists but is not a directory (0%o)"),
                dirparent, (unsigned int) sb.st_mode);
        else if (sb.st_uid != timestamp_uid)
-           log_error(NO_EXIT, _("%s owned by uid %u, should be uid %u"),
+           log_error(0, _("%s owned by uid %u, should be uid %u"),
                dirparent, (unsigned int) sb.st_uid,
                (unsigned int) timestamp_uid);
        else if ((sb.st_mode & 0000022))
-           log_error(NO_EXIT,
+           log_error(0,
                _("%s writable by non-owner (0%o), should be mode 0700"),
                dirparent, (unsigned int) sb.st_mode);
        else {
@@ -498,12 +498,12 @@ timestamp_status(char *timestampdir, char *timestampfile, char *user, int flags)
            status = TS_MISSING;
        }
     } else if (errno != ENOENT) {
-       log_error(NO_EXIT|USE_ERRNO, _("unable to stat %s"), dirparent);
+       log_error(USE_ERRNO, _("unable to stat %s"), dirparent);
     } else {
        /* No dirparent, try to make one. */
        if (ISSET(flags, TS_MAKE_DIRS)) {
            if (mkdir(dirparent, S_IRWXU))
-               log_error(NO_EXIT|USE_ERRNO, _("unable to mkdir %s"),
+               log_error(USE_ERRNO, _("unable to mkdir %s"),
                    dirparent);
            else
                status = TS_MISSING;
@@ -526,14 +526,14 @@ timestamp_status(char *timestampdir, char *timestampfile, char *user, int flags)
                if (unlink(timestampdir) == 0)
                    status = TS_MISSING;
            } else
-               log_error(NO_EXIT, _("%s exists but is not a directory (0%o)"),
+               log_error(0, _("%s exists but is not a directory (0%o)"),
                    timestampdir, (unsigned int) sb.st_mode);
        } else if (sb.st_uid != timestamp_uid)
-           log_error(NO_EXIT, _("%s owned by uid %u, should be uid %u"),
+           log_error(0, _("%s owned by uid %u, should be uid %u"),
                timestampdir, (unsigned int) sb.st_uid,
                (unsigned int) timestamp_uid);
        else if ((sb.st_mode & 0000022))
-           log_error(NO_EXIT,
+           log_error(0,
                _("%s writable by non-owner (0%o), should be mode 0700"),
                timestampdir, (unsigned int) sb.st_mode);
        else {
@@ -542,7 +542,7 @@ timestamp_status(char *timestampdir, char *timestampfile, char *user, int flags)
            status = TS_OLD;            /* do date check later */
        }
     } else if (errno != ENOENT) {
-       log_error(NO_EXIT|USE_ERRNO, _("unable to stat %s"), timestampdir);
+       log_error(USE_ERRNO, _("unable to stat %s"), timestampdir);
     } else
        status = TS_MISSING;
 
@@ -553,7 +553,7 @@ timestamp_status(char *timestampdir, char *timestampfile, char *user, int flags)
     if (status == TS_MISSING && timestampfile && ISSET(flags, TS_MAKE_DIRS)) {
        if (mkdir(timestampdir, S_IRWXU) == -1) {
            status = TS_ERROR;
-           log_error(NO_EXIT|USE_ERRNO, _("unable to mkdir %s"), timestampdir);
+           log_error(USE_ERRNO, _("unable to mkdir %s"), timestampdir);
        }
     }
 
@@ -568,18 +568,18 @@ timestamp_status(char *timestampdir, char *timestampfile, char *user, int flags)
        if (lstat(timestampfile, &sb) == 0) {
            if (!S_ISREG(sb.st_mode)) {
                status = TS_ERROR;
-               log_error(NO_EXIT, _("%s exists but is not a regular file (0%o)"),
+               log_error(0, _("%s exists but is not a regular file (0%o)"),
                    timestampfile, (unsigned int) sb.st_mode);
            } else {
                /* If bad uid or file mode, complain and kill the bogus file. */
                if (sb.st_uid != timestamp_uid) {
-                   log_error(NO_EXIT,
+                   log_error(0,
                        _("%s owned by uid %u, should be uid %u"),
                        timestampfile, (unsigned int) sb.st_uid,
                        (unsigned int) timestamp_uid);
                    (void) unlink(timestampfile);
                } else if ((sb.st_mode & 0000022)) {
-                   log_error(NO_EXIT,
+                   log_error(0,
                        _("%s writable by non-owner (0%o), should be mode 0600"),
                        timestampfile, (unsigned int) sb.st_mode);
                    (void) unlink(timestampfile);
@@ -610,7 +610,7 @@ timestamp_status(char *timestampdir, char *timestampfile, char *user, int flags)
                }
            }
        } else if (errno != ENOENT) {
-           log_error(NO_EXIT|USE_ERRNO, _("unable to stat %s"), timestampfile);
+           log_error(USE_ERRNO, _("unable to stat %s"), timestampfile);
            status = TS_ERROR;
        }
     }
@@ -633,7 +633,7 @@ timestamp_status(char *timestampdir, char *timestampfile, char *user, int flags)
                 */
                if (mtime.tv_sec > now + 60 * def_timestamp_timeout * 2) {
                    time_t tv_sec = (time_t)mtime.tv_sec;
-                   log_error(NO_EXIT,
+                   log_error(0,
                        _("timestamp too far in the future: %20.20s"),
                        4 + ctime(&tv_sec));
                    if (timestampfile)
@@ -680,7 +680,7 @@ remove_timestamp(bool remove)
            else
                status = rmdir(timestampdir);
            if (status == -1 && errno != ENOENT) {
-               log_error(NO_EXIT,
+               log_error(0,
                    _("unable to remove %s (%s), will reset to the epoch"),
                    path, strerror(errno));
                remove = false;
@@ -699,9 +699,9 @@ remove_timestamp(bool remove)
 }
 
 /*
- * Returns true if tty lives on a devpts or /devices filesystem, else false.
- * Unlike most filesystems, the ctime of devpts nodes is not updated when
- * the device node is written to, only when the inode's status changes,
+ * Returns true if tty lives on a devpts, /dev or /devices filesystem, else
+ * false.  Unlike most filesystems, the ctime of devpts nodes is not updated
+ * when the device node is written to, only when the inode's status changes,
  * typically via the chmod, chown, link, rename, or utimes system calls.
  * Since the ctime is "stable" in this case, we can stash it the tty ticket
  * file and use it to determine whether the tty ticket file is stale.
@@ -727,7 +727,7 @@ tty_is_devpts(const char *tty)
     debug_decl(tty_is_devpts, SUDO_DEBUG_PTY)
 
     if (statvfs(tty, &sfs) == 0) {
-       if (strcmp(sfs.f_fstr, "devices") == 0)
+       if (strcmp(sfs.f_fstr, "dev") == 0 || strcmp(sfs.f_fstr, "devices") == 0)
            retval = true;
     }
 #else
@@ -749,13 +749,13 @@ get_authpw(void)
 
     if (def_rootpw) {
        if ((pw = sudo_getpwuid(ROOT_UID)) == NULL)
-           log_error(0, _("unknown uid: %u"), ROOT_UID);
+           log_fatal(0, _("unknown uid: %u"), ROOT_UID);
     } else if (def_runaspw) {
        if ((pw = sudo_getpwnam(def_runas_default)) == NULL)
-           log_error(0, _("unknown user: %s"), def_runas_default);
+           log_fatal(0, _("unknown user: %s"), def_runas_default);
     } else if (def_targetpw) {
        if (runas_pw->pw_name == NULL)
-           log_error(NO_MAIL|MSG_ONLY, _("unknown uid: %u"),
+           log_fatal(NO_MAIL|MSG_ONLY, _("unknown uid: %u"),
                (unsigned int) runas_pw->pw_uid);
        pw_addref(runas_pw);
        pw = runas_pw;