mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 01:49:11 +00:00
Use NODEV macro instead of explicit (dev_t)-1.
Also fix an assignment of dev_t to -1 that should be NODEV. Bug #1074.
This commit is contained in:
parent
73cbe4e7e1
commit
d5028a00c0
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: ISC
|
||||
*
|
||||
* Copyright (c) 1996, 1998-2005, 2008, 2009-2023
|
||||
* Copyright (c) 1996, 1998-2005, 2008, 2009-2024
|
||||
* Todd C. Miller <Todd.Miller@sudo.ws>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
@ -40,6 +40,10 @@
|
||||
* Macros and functions that may be missing on some operating systems.
|
||||
*/
|
||||
|
||||
#ifndef NODEV
|
||||
# define NODEV ((dev_t)-1) /* non-existent device */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Given the pointer x to the member m of the struct s, return
|
||||
* a pointer to the containing structure.
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: ISC
|
||||
*
|
||||
* Copyright (c) 2012-2018 Todd C. Miller <Todd.Miller@sudo.ws>
|
||||
* Copyright (c) 2012-2018, 2024 Todd C. Miller <Todd.Miller@sudo.ws>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -398,7 +398,7 @@ sudoers_policy_deserialize_info(struct sudoers_context *ctx, void *v,
|
||||
ctx->user.gid = (gid_t)-1;
|
||||
ctx->user.uid = (gid_t)-1;
|
||||
ctx->user.umask = (mode_t)-1;
|
||||
ctx->user.ttydev = (dev_t)-1;
|
||||
ctx->user.ttydev = NODEV;
|
||||
for (cur = info->user_info; *cur != NULL; cur++) {
|
||||
if (MATCHES(*cur, "user=")) {
|
||||
CHECK(*cur, "user=");
|
||||
@ -597,7 +597,7 @@ sudoers_policy_deserialize_info(struct sudoers_context *ctx, void *v,
|
||||
}
|
||||
|
||||
/* ttydev is only set in user_info[] for API 1.22 and above. */
|
||||
if (ctx->user.ttydev == (dev_t)-1 && ctx->user.ttypath != NULL) {
|
||||
if (ctx->user.ttydev == NODEV && ctx->user.ttypath != NULL) {
|
||||
struct stat sb;
|
||||
if (stat(ctx->user.ttypath, &sb) == 0)
|
||||
ctx->user.ttydev = sb.st_rdev;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: ISC
|
||||
*
|
||||
* Copyright (c) 2014-2023 Todd C. Miller <Todd.Miller@sudo.ws>
|
||||
* Copyright (c) 2014-2024 Todd C. Miller <Todd.Miller@sudo.ws>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -397,7 +397,7 @@ ts_init_key(const struct sudoers_context *ctx,
|
||||
sudo_warnx("unknown time stamp ticket type %d", ticket_type);
|
||||
FALLTHROUGH;
|
||||
case tty:
|
||||
if (ctx->user.ttydev != (dev_t)-1) {
|
||||
if (ctx->user.ttydev != NODEV) {
|
||||
/* tty-based time stamp */
|
||||
entry->type = TS_TTY;
|
||||
entry->u.ttydev = ctx->user.ttydev;
|
||||
|
@ -69,7 +69,7 @@ main(int argc, char *argv[])
|
||||
char *tty_libc = NULL, *tty_sudo = NULL;
|
||||
char pathbuf[PATH_MAX];
|
||||
bool verbose = false;
|
||||
dev_t ttydev = -1;
|
||||
dev_t ttydev = NODEV;
|
||||
int ch, errors = 0, ntests = 1;
|
||||
|
||||
initprogname(argc > 0 ? argv[0] : "check_ttyname");
|
||||
@ -87,7 +87,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Lookup tty name using kernel info if possible. */
|
||||
ttydev = get_process_ttyname(pathbuf, sizeof(pathbuf));
|
||||
if (ttydev != (dev_t)-1) {
|
||||
if (ttydev != NODEV) {
|
||||
char numbuf[STRLEN_MAX_SIGNED(long long) + 1];
|
||||
const char *errstr;
|
||||
dev_t newdev;
|
||||
|
@ -619,7 +619,7 @@ get_user_info(struct user_details *ud)
|
||||
}
|
||||
|
||||
ttydev = get_process_ttyname(path, sizeof(path));
|
||||
if (ttydev != (dev_t)-1) {
|
||||
if (ttydev != NODEV) {
|
||||
if (asprintf(&info[++i], "ttydev=%lld", (long long)ttydev) == -1)
|
||||
goto oom;
|
||||
/* The terminal device file may be missing in a chroot() jail. */
|
||||
|
@ -105,7 +105,7 @@ get_process_ttyname(char *name, size_t namelen)
|
||||
struct sudo_kinfo_proc *ki_proc = NULL;
|
||||
size_t size = sizeof(*ki_proc);
|
||||
int mib[6], rc, serrno = errno;
|
||||
dev_t ttydev = (dev_t)-1;
|
||||
dev_t ttydev = NODEV;
|
||||
debug_decl(get_process_ttyname, SUDO_DEBUG_UTIL);
|
||||
|
||||
/*
|
||||
@ -133,7 +133,7 @@ get_process_ttyname(char *name, size_t namelen)
|
||||
}
|
||||
errno = ENOENT;
|
||||
if (rc != -1) {
|
||||
if ((dev_t)ki_proc->sudo_kp_tdev != (dev_t)-1) {
|
||||
if ((dev_t)ki_proc->sudo_kp_tdev != NODEV) {
|
||||
errno = serrno;
|
||||
ttydev = (dev_t)ki_proc->sudo_kp_tdev;
|
||||
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
|
||||
@ -162,7 +162,7 @@ get_process_ttyname(char *name, size_t namelen)
|
||||
dev_t
|
||||
get_process_ttyname(char *name, size_t namelen)
|
||||
{
|
||||
dev_t ttydev = (dev_t)-1;
|
||||
dev_t ttydev = NODEV;
|
||||
struct psinfo psinfo;
|
||||
char path[PATH_MAX];
|
||||
ssize_t nread;
|
||||
@ -181,7 +181,7 @@ get_process_ttyname(char *name, size_t namelen)
|
||||
ttydev = makedev(major64(psinfo.pr_ttydev), minor64(psinfo.pr_ttydev));
|
||||
#endif
|
||||
/* On AIX, pr_ttydev is 0 (not -1) when no terminal is present. */
|
||||
if (ttydev != 0 && ttydev != (dev_t)-1) {
|
||||
if (ttydev != 0 && ttydev != NODEV) {
|
||||
errno = serrno;
|
||||
if (sudo_ttyname_dev(ttydev, name, namelen) == NULL) {
|
||||
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
|
||||
@ -192,7 +192,7 @@ get_process_ttyname(char *name, size_t namelen)
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
ttydev = (dev_t)-1;
|
||||
ttydev = NODEV;
|
||||
}
|
||||
} else {
|
||||
struct stat sb;
|
||||
@ -216,7 +216,7 @@ get_process_ttyname(char *name, size_t namelen)
|
||||
errno = ENOENT;
|
||||
|
||||
done:
|
||||
if (ttydev == (dev_t)-1)
|
||||
if (ttydev == NODEV)
|
||||
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
|
||||
"unable to resolve tty via %s", path);
|
||||
|
||||
@ -233,7 +233,7 @@ dev_t
|
||||
get_process_ttyname(char *name, size_t namelen)
|
||||
{
|
||||
const char path[] = "/proc/self/stat";
|
||||
dev_t ttydev = (dev_t)-1;
|
||||
dev_t ttydev = NODEV;
|
||||
char *cp, buf[1024];
|
||||
int serrno = errno;
|
||||
pid_t ppid = 0;
|
||||
@ -335,7 +335,7 @@ get_process_ttyname(char *name, size_t namelen)
|
||||
done:
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
if (ttydev == (dev_t)-1)
|
||||
if (ttydev == NODEV)
|
||||
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
|
||||
"unable to resolve tty via %s", path);
|
||||
|
||||
@ -351,7 +351,7 @@ done:
|
||||
dev_t
|
||||
get_process_ttyname(char *name, size_t namelen)
|
||||
{
|
||||
dev_t ttydev = (dev_t)-1;
|
||||
dev_t ttydev = NODEV;
|
||||
int rc, serrno = errno;
|
||||
struct pst_status pst;
|
||||
debug_decl(get_process_ttyname, SUDO_DEBUG_UTIL);
|
||||
@ -418,6 +418,6 @@ get_process_ttyname(char *name, size_t namelen)
|
||||
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
|
||||
"unable to resolve tty via ttyname");
|
||||
errno = ENOENT;
|
||||
debug_return_dev_t((dev_t)-1);
|
||||
debug_return_dev_t(NODEV);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user