mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 18:08:23 +00:00
get_process_ttyname: always return the terminal device if we find one.
If sudo cannot map the device number to a device file, set name to the empty string. The caller now checks for an empty name and only passes the tty path to the plugin if it is non-empty. This allows sudo to run without warnings in a chroot() jail where the terminal device files are not present. GitHub issue #421.
This commit is contained in:
parent
abc0baffc4
commit
7e8f006888
11
src/sudo.c
11
src/sudo.c
@ -622,10 +622,13 @@ get_user_info(struct user_details *ud)
|
|||||||
if (ttydev != (dev_t)-1) {
|
if (ttydev != (dev_t)-1) {
|
||||||
if (asprintf(&info[++i], "ttydev=%lld", (long long)ttydev) == -1)
|
if (asprintf(&info[++i], "ttydev=%lld", (long long)ttydev) == -1)
|
||||||
goto oom;
|
goto oom;
|
||||||
info[++i] = sudo_new_key_val("tty", path);
|
/* The terminal device file may be missing in a chroot() jail. */
|
||||||
if (info[i] == NULL)
|
if (path[0] != '\0') {
|
||||||
goto oom;
|
info[++i] = sudo_new_key_val("tty", path);
|
||||||
ud->tty = info[i] + sizeof("tty=") - 1;
|
if (info[i] == NULL)
|
||||||
|
goto oom;
|
||||||
|
ud->tty = info[i] + sizeof("tty=") - 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* tty may not always be present */
|
/* tty may not always be present */
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
|
@ -94,8 +94,10 @@
|
|||||||
|
|
||||||
#if defined(sudo_kp_tdev)
|
#if defined(sudo_kp_tdev)
|
||||||
/*
|
/*
|
||||||
* Store the name of the tty to which the process is attached in name.
|
* Look up terminal device that the process is attached to and
|
||||||
* Returns name on success and NULL on failure, setting errno.
|
* fill in its name, if available. Sets name to the empty string
|
||||||
|
* if the device number cannot be mapped to a device name.
|
||||||
|
* Returns the tty device number on success and -1 on failure, setting errno.
|
||||||
*/
|
*/
|
||||||
dev_t
|
dev_t
|
||||||
get_process_ttyname(char *name, size_t namelen)
|
get_process_ttyname(char *name, size_t namelen)
|
||||||
@ -135,10 +137,11 @@ get_process_ttyname(char *name, size_t namelen)
|
|||||||
errno = serrno;
|
errno = serrno;
|
||||||
ttydev = (dev_t)ki_proc->sudo_kp_tdev;
|
ttydev = (dev_t)ki_proc->sudo_kp_tdev;
|
||||||
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
|
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
|
||||||
sudo_warnx(
|
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
|
||||||
U_("unable to find terminal name for device %u, %u"),
|
"unable to find terminal name for device %u, %u",
|
||||||
(unsigned int)major(ttydev), (unsigned int)minor(ttydev));
|
(unsigned int)major(ttydev), (unsigned int)minor(ttydev));
|
||||||
ttydev = (dev_t)-1;
|
if (namelen != 0)
|
||||||
|
*name = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -151,8 +154,10 @@ get_process_ttyname(char *name, size_t namelen)
|
|||||||
}
|
}
|
||||||
#elif defined(HAVE_STRUCT_PSINFO_PR_TTYDEV)
|
#elif defined(HAVE_STRUCT_PSINFO_PR_TTYDEV)
|
||||||
/*
|
/*
|
||||||
* Store the name of the tty to which the process is attached in name.
|
* Look up terminal device that the process is attached to and
|
||||||
* Returns name on success and NULL on failure, setting errno.
|
* fill in its name, if available. Sets name to the empty string
|
||||||
|
* if the device number cannot be mapped to a device name.
|
||||||
|
* Returns the tty device number on success and -1 on failure, setting errno.
|
||||||
*/
|
*/
|
||||||
dev_t
|
dev_t
|
||||||
get_process_ttyname(char *name, size_t namelen)
|
get_process_ttyname(char *name, size_t namelen)
|
||||||
@ -179,10 +184,11 @@ get_process_ttyname(char *name, size_t namelen)
|
|||||||
if (ttydev != 0 && ttydev != (dev_t)-1) {
|
if (ttydev != 0 && ttydev != (dev_t)-1) {
|
||||||
errno = serrno;
|
errno = serrno;
|
||||||
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
|
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
|
||||||
sudo_warnx(
|
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
|
||||||
U_("unable to find terminal name for device %u, %u"),
|
"unable to find terminal name for device %u, %u",
|
||||||
(unsigned int)major(ttydev), (unsigned int)minor(ttydev));
|
(unsigned int)major(ttydev), (unsigned int)minor(ttydev));
|
||||||
ttydev = (dev_t)-1;
|
if (namelen != 0)
|
||||||
|
*name = '\0';
|
||||||
}
|
}
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -197,10 +203,11 @@ get_process_ttyname(char *name, size_t namelen)
|
|||||||
if (sudo_isatty(i, &sb)) {
|
if (sudo_isatty(i, &sb)) {
|
||||||
ttydev = sb.st_rdev;
|
ttydev = sb.st_rdev;
|
||||||
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
|
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
|
||||||
sudo_warnx(
|
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
|
||||||
U_("unable to find terminal name for device %u, %u"),
|
"unable to find terminal name for device %u, %u",
|
||||||
(unsigned int)major(ttydev), (unsigned int)minor(ttydev));
|
(unsigned int)major(ttydev), (unsigned int)minor(ttydev));
|
||||||
ttydev = (dev_t)-1;
|
if (namelen != 0)
|
||||||
|
*name = '\0';
|
||||||
}
|
}
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -217,8 +224,10 @@ done:
|
|||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
/*
|
/*
|
||||||
* Store the name of the tty to which the process is attached in name.
|
* Look up terminal device that the process is attached to and
|
||||||
* Returns name on success and NULL on failure, setting errno.
|
* fill in its name, if available. Sets name to the empty string
|
||||||
|
* if the device number cannot be mapped to a device name.
|
||||||
|
* Returns the tty device number on success and -1 on failure, setting errno.
|
||||||
*/
|
*/
|
||||||
dev_t
|
dev_t
|
||||||
get_process_ttyname(char *name, size_t namelen)
|
get_process_ttyname(char *name, size_t namelen)
|
||||||
@ -282,10 +291,11 @@ get_process_ttyname(char *name, size_t namelen)
|
|||||||
ttydev = (unsigned int)tty_nr;
|
ttydev = (unsigned int)tty_nr;
|
||||||
errno = serrno;
|
errno = serrno;
|
||||||
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
|
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
|
||||||
sudo_warnx(
|
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
|
||||||
U_("unable to find terminal name for device %u, %u"),
|
"unable to find terminal name for device %u, %u",
|
||||||
(unsigned int)major(ttydev), (unsigned int)minor(ttydev));
|
(unsigned int)major(ttydev), (unsigned int)minor(ttydev));
|
||||||
ttydev = (dev_t)-1;
|
if (namelen != 0)
|
||||||
|
*name = '\0';
|
||||||
}
|
}
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -310,10 +320,11 @@ get_process_ttyname(char *name, size_t namelen)
|
|||||||
if (sudo_isatty(i, &sb)) {
|
if (sudo_isatty(i, &sb)) {
|
||||||
ttydev = sb.st_rdev;
|
ttydev = sb.st_rdev;
|
||||||
if (sudo_ttyname_dev(sb.st_rdev, name, namelen) == NULL) {
|
if (sudo_ttyname_dev(sb.st_rdev, name, namelen) == NULL) {
|
||||||
sudo_warnx(
|
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
|
||||||
U_("unable to find terminal name for device %u, %u"),
|
"unable to find terminal name for device %u, %u",
|
||||||
(unsigned int)major(ttydev), (unsigned int)minor(ttydev));
|
(unsigned int)major(ttydev), (unsigned int)minor(ttydev));
|
||||||
ttydev = (dev_t)-1;
|
if (namelen != 0)
|
||||||
|
*name = '\0';
|
||||||
}
|
}
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -332,8 +343,10 @@ done:
|
|||||||
}
|
}
|
||||||
#elif defined(HAVE_PSTAT_GETPROC)
|
#elif defined(HAVE_PSTAT_GETPROC)
|
||||||
/*
|
/*
|
||||||
* Store the name of the tty to which the process is attached in name.
|
* Look up terminal device that the process is attached to and
|
||||||
* Returns name on success and NULL on failure, setting errno.
|
* fill in its name, if available. Sets name to the empty string
|
||||||
|
* if the device number cannot be mapped to a device name.
|
||||||
|
* Returns the tty device number on success and -1 on failure, setting errno.
|
||||||
*/
|
*/
|
||||||
dev_t
|
dev_t
|
||||||
get_process_ttyname(char *name, size_t namelen)
|
get_process_ttyname(char *name, size_t namelen)
|
||||||
@ -354,11 +367,12 @@ get_process_ttyname(char *name, size_t namelen)
|
|||||||
errno = serrno;
|
errno = serrno;
|
||||||
ttydev = makedev(pst.pst_term.psd_major, pst.pst_term.psd_minor);
|
ttydev = makedev(pst.pst_term.psd_major, pst.pst_term.psd_minor);
|
||||||
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
|
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
|
||||||
sudo_warnx(
|
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
|
||||||
U_("unable to find terminal name for device %u, %u"),
|
"unable to find terminal name for device %u, %u",
|
||||||
(unsigned int)pst.pst_term.psd_major,
|
(unsigned int)pst.pst_term.psd_major,
|
||||||
(unsigned int)pst.pst_term.psd_minor);
|
(unsigned int)pst.pst_term.psd_minor);
|
||||||
ttydev = (dev_t)-1;
|
if (namelen != 0)
|
||||||
|
*name = '\0';
|
||||||
}
|
}
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -373,8 +387,8 @@ done:
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/*
|
/*
|
||||||
* Store the name of the tty to which the process is attached in name.
|
* Look up terminal device that the process is attached to and fill in name.
|
||||||
* Returns name on success and NULL on failure, setting errno.
|
* Returns the tty device number on success and -1 on failure, setting errno.
|
||||||
*/
|
*/
|
||||||
dev_t
|
dev_t
|
||||||
get_process_ttyname(char *name, size_t namelen)
|
get_process_ttyname(char *name, size_t namelen)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user