The device name returned by devname() does not include the /dev/
prefix so we need to add it ourselves.
This commit is contained in:
27
src/sudo.c
27
src/sudo.c
@@ -473,24 +473,32 @@ get_process_tty(void)
|
|||||||
rc = sysctl(mib, sudo_kp_namelen, ki_proc, &size, NULL, 0);
|
rc = sysctl(mib, sudo_kp_namelen, ki_proc, &size, NULL, 0);
|
||||||
} while (rc == -1 && errno == ENOMEM);
|
} while (rc == -1 && errno == ENOMEM);
|
||||||
if (rc != -1) {
|
if (rc != -1) {
|
||||||
tty = devname(ki_proc->sudo_kp_tdev, S_IFCHR);
|
char *dev = devname(ki_proc->sudo_kp_tdev, S_IFCHR);
|
||||||
if (*tty != '/') {
|
/* Some versions of devname() return NULL, others do not. */
|
||||||
|
if (dev == NULL || *dev == '?' || *dev == '#') {
|
||||||
sudo_debug_printf(SUDO_DEBUG_WARN,
|
sudo_debug_printf(SUDO_DEBUG_WARN,
|
||||||
"unable to map device number %u to name: %s",
|
"unable to map device number %u to name",
|
||||||
ki_proc->sudo_kp_tdev, tty);
|
ki_proc->sudo_kp_tdev);
|
||||||
tty = NULL;
|
} else {
|
||||||
|
/* devname() doesn't use the /dev/ prefix, add one... */
|
||||||
|
size_t len = sizeof(_PATH_DEV) + strlen(dev);
|
||||||
|
tty = emalloc(len);
|
||||||
|
strlcpy(tty, _PATH_DEV, len);
|
||||||
|
strlcat(tty, dev, len);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sudo_debug_printf(SUDO_DEBUG_WARN,
|
sudo_debug_printf(SUDO_DEBUG_WARN,
|
||||||
"unable to resolve tty via KERN_PROC: %s", strerror(errno));
|
"unable to resolve tty via KERN_PROC: %s", strerror(errno));
|
||||||
}
|
}
|
||||||
|
efree(ki_proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If all else fails, fall back on ttyname(). */
|
/* If all else fails, fall back on ttyname(). */
|
||||||
if (tty == NULL) {
|
if (tty == NULL) {
|
||||||
if ((tty = ttyname(STDIN_FILENO)) == NULL &&
|
if ((tty = ttyname(STDIN_FILENO)) != NULL ||
|
||||||
(tty = ttyname(STDOUT_FILENO)) == NULL)
|
(tty = ttyname(STDOUT_FILENO)) != NULL ||
|
||||||
tty = ttyname(STDERR_FILENO);
|
(tty = ttyname(STDERR_FILENO)) != NULL)
|
||||||
|
tty = estrdup(tty);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_return_str(tty);
|
debug_return_str(tty);
|
||||||
@@ -526,7 +534,7 @@ get_process_tty(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_return_str(tty);
|
debug_return_str(estrdup(tty));
|
||||||
}
|
}
|
||||||
#endif /* sudo_kp_tdev */
|
#endif /* sudo_kp_tdev */
|
||||||
|
|
||||||
@@ -585,6 +593,7 @@ get_user_info(struct user_details *ud)
|
|||||||
if (user_info[i] == NULL)
|
if (user_info[i] == NULL)
|
||||||
errorx(1, _("unable to allocate memory"));
|
errorx(1, _("unable to allocate memory"));
|
||||||
ud->tty = user_info[i] + sizeof("tty=") - 1;
|
ud->tty = user_info[i] + sizeof("tty=") - 1;
|
||||||
|
efree(cp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gethostname(host, sizeof(host)) == 0)
|
if (gethostname(host, sizeof(host)) == 0)
|
||||||
|
Reference in New Issue
Block a user