From 6d4d4594b7e8e545a0dfe5455450cd4a38f3a628 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 29 Jun 2017 18:10:53 -0600 Subject: [PATCH] Use _PATH_DEV consistently --- configure | 4 +++- configure.ac | 4 +++- lib/util/closefrom.c | 2 +- lib/util/mktemp.c | 5 +++-- pathnames.h.in | 4 ++-- src/exec_pty.c | 7 ++++--- src/get_pty.c | 12 ++++++------ src/ttyname.c | 18 +++++++++--------- 8 files changed, 31 insertions(+), 25 deletions(-) diff --git a/configure b/configure index 35f771853..3631e71d7 100755 --- a/configure +++ b/configure @@ -6679,11 +6679,13 @@ if test "${enable_devsearch+set}" = set; then : $as_echo "$as_me: WARNING: Ignoring attempt to disable the device search path" >&2;} ;; *) devsearch="$enableval" + ;; esac fi +ds="`echo \"$devsearch\"|sed 's@/dev/*\([^:]*:*\)@_PATH_DEV \"\1\" @g'`" cat >>confdefs.h < * * Permission to use, copy, modify, and distribute this software for any @@ -43,6 +43,7 @@ #endif #include "sudo_compat.h" +#include "pathnames.h" #define MKTEMP_FILE 1 #define MKTEMP_DIR 2 @@ -83,7 +84,7 @@ seed_random(void) /* * Seed from /dev/urandom if possible. */ - fd = open("/dev/urandom", O_RDONLY); + fd = open(_PATH_DEV "urandom", O_RDONLY); if (fd != -1) { ssize_t nread; diff --git a/pathnames.h.in b/pathnames.h.in index 7979f1129..e7f89ebff 100644 --- a/pathnames.h.in +++ b/pathnames.h.in @@ -36,11 +36,11 @@ #endif /* _PATH_DEV */ #ifndef _PATH_TTY -# define _PATH_TTY "/dev/tty" +# define _PATH_TTY _PATH_DEV "tty" #endif /* _PATH_TTY */ #ifndef _PATH_DEVNULL -# define _PATH_DEVNULL "/dev/null" +# define _PATH_DEVNULL _PATH_DEV "null" #endif /* _PATH_DEVNULL */ #ifndef _PATH_DEFPATH diff --git a/src/exec_pty.c b/src/exec_pty.c index 4d4811bf4..d8efb2979 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -145,8 +145,9 @@ pty_setup(uid_t uid, const char *tty) if (utmp_user != NULL) utmp_login(tty, slavename, io_fds[SFD_SLAVE], utmp_user); sudo_debug_printf(SUDO_DEBUG_INFO, - "%s: /dev/tty fd %d, pty master fd %d, pty slave fd %d", __func__, - io_fds[SFD_USERTTY], io_fds[SFD_MASTER], io_fds[SFD_SLAVE]); + "%s: %s fd %d, pty master fd %d, pty slave fd %d", + __func__, _PATH_TTY, io_fds[SFD_USERTTY], io_fds[SFD_MASTER], + io_fds[SFD_SLAVE]); } debug_return; @@ -1581,7 +1582,7 @@ safe_close(int fd) /* Avoid closing /dev/tty or std{in,out,err}. */ if (fd < 3 || fd == io_fds[SFD_USERTTY]) { sudo_debug_printf(SUDO_DEBUG_INFO, - "%s: not closing fd %d (/dev/tty)", __func__, fd); + "%s: not closing fd %d (%s)", __func__, fd, _PATH_TTY); errno = EINVAL; debug_return_int(-1); } diff --git a/src/get_pty.c b/src/get_pty.c index 78ea63dca..4cc25503e 100644 --- a/src/get_pty.c +++ b/src/get_pty.c @@ -99,9 +99,9 @@ posix_openpt(int oflag) int fd; # ifdef _AIX - fd = open("/dev/ptc", oflag); + fd = open(_PATH_DEV "ptc", oflag); # else - fd = open("/dev/ptmx", oflag); + fd = open(_PATH_DEV "ptmx", oflag); # endif return fd; } @@ -145,7 +145,7 @@ done: #else /* Old-style BSD ptys */ -static char line[] = "/dev/ptyXX"; +static char line[] = _PATH_DEV "ptyXX"; bool get_pty(int *master, int *slave, char *name, size_t namesz, uid_t ttyuid) @@ -160,16 +160,16 @@ get_pty(int *master, int *slave, char *name, size_t namesz, uid_t ttyuid) ttygid = gr->gr_gid; for (bank = "pqrs"; *bank != '\0'; bank++) { - line[sizeof("/dev/ptyX") - 2] = *bank; + line[sizeof(_PATH_DEV "ptyX") - 2] = *bank; for (cp = "0123456789abcdef"; *cp != '\0'; cp++) { - line[sizeof("/dev/ptyXX") - 2] = *cp; + line[sizeof(_PATH_DEV "ptyXX") - 2] = *cp; *master = open(line, O_RDWR|O_NOCTTY, 0); if (*master == -1) { if (errno == ENOENT) goto done; /* out of ptys */ continue; /* already in use */ } - line[sizeof("/dev/p") - 2] = 't'; + line[sizeof(_PATH_DEV "p") - 2] = 't'; (void) chown(line, ttyuid, ttygid); (void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP); # ifdef HAVE_REVOKE diff --git a/src/ttyname.c b/src/ttyname.c index f3a427c17..5fda11a6c 100644 --- a/src/ttyname.c +++ b/src/ttyname.c @@ -142,9 +142,9 @@ sudo_ttyname_dev(dev_t tdev, char *name, size_t namelen) * Device nodes to ignore. */ static const char *ignore_devs[] = { - "/dev/stdin", - "/dev/stdout", - "/dev/stderr", + _PATH_DEV "stdin", + _PATH_DEV "stdout", + _PATH_DEV "stderr", NULL }; @@ -305,7 +305,7 @@ sudo_ttyname_dev(dev_t rdev, char *buf, size_t buflen) /* * First, check /dev/console. */ - ret = sudo_dev_check(rdev, "/dev/console", buf, buflen); + ret = sudo_dev_check(rdev, _PATH_DEV "console", buf, buflen); if (ret != NULL) goto done; @@ -326,14 +326,14 @@ sudo_ttyname_dev(dev_t rdev, char *buf, size_t buflen) memcpy(path, cp, len); path[len] = '\0'; - if (strcmp(path, "/dev/pts") == 0) { + if (strcmp(path, _PATH_DEV "pts") == 0) { /* Special case /dev/pts */ - len = (size_t)snprintf(path, sizeof(path), "/dev/pts/%u", - (unsigned int)minor(rdev)); + len = (size_t)snprintf(path, sizeof(path), "%spts/%u", + _PATH_DEV, (unsigned int)minor(rdev)); if (len >= sizeof(path)) { sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, - "devsearch entry /dev/pts/%u too long", - (unsigned int)minor(rdev)); + "devsearch entry %spts/%u too long", + _PATH_DEV, (unsigned int)minor(rdev)); continue; } ret = sudo_dev_check(rdev, path, buf, buflen); -- 2.40.0