From 217e0a9b4baad9915f3ed583887d5f07edbb4d5e Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 5 Mar 2018 17:35:02 -0700 Subject: [PATCH] Less confusing sysctl checks for kinfo_proc. --- config.h.in | 24 ++++++++-------- configure | 43 ++++++++++------------------- configure.ac | 13 +++++---- plugins/sudoers/starttime.c | 14 +++++----- plugins/sudoers/sudoers.c | 2 +- src/regress/ttyname/check_ttyname.c | 8 +++--- src/tgetpass.c | 2 +- src/ttyname.c | 12 ++++---- 8 files changed, 54 insertions(+), 64 deletions(-) diff --git a/config.h.in b/config.h.in index 3bbd6ee27..e728a3d72 100644 --- a/config.h.in +++ b/config.h.in @@ -367,6 +367,18 @@ /* Define to 1 if you have the `killpg' function. */ #undef HAVE_KILLPG +/* Define to 1 if your system has a NetBSD-style kinfo_proc2 struct. */ +#undef HAVE_KINFO_PROC2_NETBSD + +/* Define to 1 if your system has a 4.4BSD-style kinfo_proc struct. */ +#undef HAVE_KINFO_PROC_44BSD + +/* Define to 1 if your system has a FreeBSD-style kinfo_proc struct. */ +#undef HAVE_KINFO_PROC_FREEBSD + +/* Define to 1 if your system has an OpenBSD-style kinfo_proc struct. */ +#undef HAVE_KINFO_PROC_OPENBSD + /* Define to 1 if you have the `krb5_get_init_creds_opt_alloc' function. */ #undef HAVE_KRB5_GET_INIT_CREDS_OPT_ALLOC @@ -699,18 +711,6 @@ /* Define to 1 if the system has the type `struct in6_addr'. */ #undef HAVE_STRUCT_IN6_ADDR -/* Define to 1 if `p_tdev' is a member of `struct kinfo_proc2'. */ -#undef HAVE_STRUCT_KINFO_PROC2_P_TDEV - -/* Define to 1 if `ki_tdev' is a member of `struct kinfo_proc'. */ -#undef HAVE_STRUCT_KINFO_PROC_KI_TDEV - -/* Define to 1 if `kp_eproc.e_tdev' is a member of `struct kinfo_proc'. */ -#undef HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV - -/* Define to 1 if `p_tdev' is a member of `struct kinfo_proc'. */ -#undef HAVE_STRUCT_KINFO_PROC_P_TDEV - /* Define to 1 if `pr_ttydev' is a member of `struct psinfo'. */ #undef HAVE_STRUCT_PSINFO_PR_TTYDEV diff --git a/configure b/configure index 6af6c983b..aad6822cf 100755 --- a/configure +++ b/configure @@ -19235,60 +19235,44 @@ _ACEOF fi done - ac_fn_c_check_member "$LINENO" "struct kinfo_proc" "ki_tdev" "ac_cv_member_struct_kinfo_proc_ki_tdev" " + ac_fn_c_check_member "$LINENO" "struct kinfo_proc" "ki_structsize" "ac_cv_member_struct_kinfo_proc_ki_structsize" " # include # include # include " -if test "x$ac_cv_member_struct_kinfo_proc_ki_tdev" = xyes; then : - -cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_KINFO_PROC_KI_TDEV 1 -_ACEOF - +if test "x$ac_cv_member_struct_kinfo_proc_ki_structsize" = xyes; then : + $as_echo "#define HAVE_KINFO_PROC_FREEBSD 1" >>confdefs.h else - ac_fn_c_check_member "$LINENO" "struct kinfo_proc2" "p_tdev" "ac_cv_member_struct_kinfo_proc2_p_tdev" " + ac_fn_c_check_member "$LINENO" "struct kinfo_proc2" "p_paddr" "ac_cv_member_struct_kinfo_proc2_p_paddr" " # include # include " -if test "x$ac_cv_member_struct_kinfo_proc2_p_tdev" = xyes; then : - -cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_KINFO_PROC2_P_TDEV 1 -_ACEOF - +if test "x$ac_cv_member_struct_kinfo_proc2_p_paddr" = xyes; then : + $as_echo "#define HAVE_KINFO_PROC2_NETBSD 1" >>confdefs.h else - ac_fn_c_check_member "$LINENO" "struct kinfo_proc" "p_tdev" "ac_cv_member_struct_kinfo_proc_p_tdev" " + ac_fn_c_check_member "$LINENO" "struct kinfo_proc" "p_paddr" "ac_cv_member_struct_kinfo_proc_p_paddr" " # include # include " -if test "x$ac_cv_member_struct_kinfo_proc_p_tdev" = xyes; then : - -cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_KINFO_PROC_P_TDEV 1 -_ACEOF - +if test "x$ac_cv_member_struct_kinfo_proc_p_paddr" = xyes; then : + $as_echo "#define HAVE_KINFO_PROC_OPENBSD 1" >>confdefs.h else - ac_fn_c_check_member "$LINENO" "struct kinfo_proc" "kp_eproc.e_tdev" "ac_cv_member_struct_kinfo_proc_kp_eproc_e_tdev" " + ac_fn_c_check_member "$LINENO" "struct kinfo_proc" "kp_proc" "ac_cv_member_struct_kinfo_proc_kp_proc" " # include # include " -if test "x$ac_cv_member_struct_kinfo_proc_kp_eproc_e_tdev" = xyes; then : - -cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV 1 -_ACEOF - +if test "x$ac_cv_member_struct_kinfo_proc_kp_proc" = xyes; then : + $as_echo "#define HAVE_KINFO_PROC_44BSD 1" >>confdefs.h fi @@ -28792,6 +28776,9 @@ fi + + + diff --git a/configure.ac b/configure.ac index 8d5c8685b..310bb206a 100644 --- a/configure.ac +++ b/configure.ac @@ -2532,10 +2532,10 @@ if test "$utmp_style" = "LEGACY"; then fi AC_CHECK_FUNCS([sysctl], [AC_CHECK_FUNCS([devname]) - AC_CHECK_MEMBERS([struct kinfo_proc.ki_tdev], [], [ - AC_CHECK_MEMBERS([struct kinfo_proc2.p_tdev], [], [ - AC_CHECK_MEMBERS([struct kinfo_proc.p_tdev], [], [ - AC_CHECK_MEMBERS([struct kinfo_proc.kp_eproc.e_tdev], [], [], [ + AC_CHECK_MEMBER([struct kinfo_proc.ki_structsize], [AC_DEFINE(HAVE_KINFO_PROC_FREEBSD)], [ + AC_CHECK_MEMBER([struct kinfo_proc2.p_paddr], [AC_DEFINE(HAVE_KINFO_PROC2_NETBSD)], [ + AC_CHECK_MEMBER([struct kinfo_proc.p_paddr], [AC_DEFINE(HAVE_KINFO_PROC_OPENBSD)], [ + AC_CHECK_MEMBER([struct kinfo_proc.kp_proc], [AC_DEFINE(HAVE_KINFO_PROC_44BSD)], [], [ # include # include ]) @@ -4505,7 +4505,10 @@ AH_TEMPLATE(HAVE___NSS_XBYY_BUF_ALLOC, [Define to 1 if you have the `__nss_XbyY_ AH_TEMPLATE(NEED_RESOLV_H, [Define to 1 if resolv.h must be included to get the `inet_ntop' or `inet_pton' function prototypes.]) AH_TEMPLATE(HAVE_STRNLEN, [Define to 1 if you have the `strnlen' function.]) AH_TEMPLATE(PAM_SUN_CODEBASE, [Define to 1 if your system uses a Solaris-derived PAM and not Linux-PAM or OpenPAM.]) - +AH_TEMPLATE(HAVE_KINFO_PROC_44BSD, [Define to 1 if your system has a 4.4BSD-style kinfo_proc struct.]) +AH_TEMPLATE(HAVE_KINFO_PROC_FREEBSD, [Define to 1 if your system has a FreeBSD-style kinfo_proc struct.]) +AH_TEMPLATE(HAVE_KINFO_PROC2_NETBSD, [Define to 1 if your system has a NetBSD-style kinfo_proc2 struct.]) +AH_TEMPLATE(HAVE_KINFO_PROC_OPENBSD, [Define to 1 if your system has an OpenBSD-style kinfo_proc struct.]) dnl dnl Bits to copy verbatim into config.h.in dnl diff --git a/plugins/sudoers/starttime.c b/plugins/sudoers/starttime.c index 112a20bbd..4c0f2ec46 100644 --- a/plugins/sudoers/starttime.c +++ b/plugins/sudoers/starttime.c @@ -24,9 +24,9 @@ #include #include -#if defined(HAVE_STRUCT_KINFO_PROC_P_TDEV) || defined (HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV) || defined(HAVE_STRUCT_KINFO_PROC2_P_TDEV) +#if defined(HAVE_44BSD_KINFO_PROC) || defined (HAVE_OPENBSD_KINFO_PROC) || defined(HAVE_NETBSD_KINFO_PROC2) # include -#elif defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV) +#elif defined(HAVE_FREEBSD_KINFO_PROC) # include # include #endif @@ -59,15 +59,15 @@ /* * Arguments for sysctl(2) when reading the process start time. */ -#if defined(HAVE_STRUCT_KINFO_PROC2_P_TDEV) +#if defined(HAVE_NETBSD_KINFO_PROC) # define SUDO_KERN_PROC KERN_PROC2 # define sudo_kinfo_proc kinfo_proc2 # define sudo_kp_namelen 6 -#elif defined(HAVE_STRUCT_KINFO_PROC_P_TDEV) +#elif defined(HAVE_OPENBSD_KINFO_PROC) # define SUDO_KERN_PROC KERN_PROC # define sudo_kinfo_proc kinfo_proc # define sudo_kp_namelen 6 -#elif defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV) +#elif defined(HAVE_FREEBSD_KINFO_PROC) || defined(HAVE_44BSD_KINFO_PROC) # define SUDO_KERN_PROC KERN_PROC # define sudo_kinfo_proc kinfo_proc # define sudo_kp_namelen 4 @@ -107,11 +107,11 @@ get_starttime(pid_t pid, struct timespec *starttime) rc = sysctl(mib, sudo_kp_namelen, ki_proc, &size, NULL, 0); } while (rc == -1 && errno == ENOMEM); if (rc != -1) { -#if defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV) +#if defined(HAVE_FREEBSD_KINFO_PROC) /* FreeBSD and Dragonfly */ starttime->tv_sec = ki_proc->ki_start.tv_sec; starttime->tv_nsec = ki_proc->ki_start.tv_usec / 1000; -#elif defined(HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV) +#elif defined(HAVE_44BSD_KINFO_PROC) /* 4.4BSD and macOS */ starttime->tv_sec = ki_proc->kp_proc.p_starttime.tv_sec; starttime->tv_nsec = ki_proc->kp_proc.p_starttime.tv_usec / 1000; diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index 3cc114788..16ef7e1ae 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -1298,7 +1298,7 @@ create_admin_success_flag(void) static bool tty_present(void) { -#if defined(HAVE_STRUCT_KINFO_PROC2_P_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_P_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV) || defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || defined(HAVE_PSTAT_GETPROC) || defined(__linux__) +#if defined(HAVE_KINFO_PROC2_NETBSD) || defined(HAVE_KINFO_PROC_OPENBSD) || defined(HAVE_KINFO_PROC_FREEBSD) || defined(HAVE_KINFO_PROC_44BSD) || defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || defined(HAVE_PSTAT_GETPROC) || defined(__linux__) return user_ttypath != NULL; #else int fd = open(_PATH_TTY, O_RDWR); diff --git a/src/regress/ttyname/check_ttyname.c b/src/regress/ttyname/check_ttyname.c index 6b0c0c2db..1609cd096 100644 --- a/src/regress/ttyname/check_ttyname.c +++ b/src/regress/ttyname/check_ttyname.c @@ -52,10 +52,10 @@ main(int argc, char *argv[]) if (get_process_ttyname(pathbuf, sizeof(pathbuf)) != NULL) tty_sudo = pathbuf; -#if defined(HAVE_STRUCT_KINFO_PROC2_P_TDEV) || \ - defined(HAVE_STRUCT_KINFO_PROC_P_TDEV) || \ - defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV) || \ - defined(HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV) || \ +#if defined(HAVE_KINFO_PROC2_NETBSD) || \ + defined(HAVE_KINFO_PROC_OPENBSD) || \ + defined(HAVE_KINFO_PROC_FREEBSD) || \ + defined(HAVE_KINFO_PROC_44BSD) || \ defined(HAVE__TTYNAME_DEV) || defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || \ defined(HAVE_PSTAT_GETPROC) || defined(__linux__) diff --git a/src/tgetpass.c b/src/tgetpass.c index 85fc98cab..6956c0590 100644 --- a/src/tgetpass.c +++ b/src/tgetpass.c @@ -367,7 +367,7 @@ tgetpass_handler(int s) static bool tty_present(void) { -#if defined(HAVE_STRUCT_KINFO_PROC2_P_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_P_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV) || defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || defined(HAVE_PSTAT_GETPROC) || defined(__linux__) +#if defined(HAVE_KINFO_PROC2_NETBSD) || defined(HAVE_KINFO_PROC_OPENBSD) || defined(HAVE_KINFO_PROC_FREEBSD) || defined(HAVE_KINFO_PROC_44BSD) || defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || defined(HAVE_PSTAT_GETPROC) || defined(__linux__) debug_decl(tty_present, SUDO_DEBUG_UTIL) debug_return_bool(user_details.tty != NULL); #else diff --git a/src/ttyname.c b/src/ttyname.c index a87e6b6f5..13f0276fd 100644 --- a/src/ttyname.c +++ b/src/ttyname.c @@ -42,9 +42,9 @@ #include #include #include -#if defined(HAVE_STRUCT_KINFO_PROC_P_TDEV) || defined (HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV) || defined(HAVE_STRUCT_KINFO_PROC2_P_TDEV) +#if defined(HAVE_KINFO_PROC2_NETBSD) || defined (HAVE_KINFO_PROC_OPENBSD) || defined(HAVE_KINFO_PROC_44BSD) # include -#elif defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV) +#elif defined(HAVE_KINFO_PROC_FREEBSD) # include # include #endif @@ -62,22 +62,22 @@ /* * How to access the tty device number in struct kinfo_proc. */ -#if defined(HAVE_STRUCT_KINFO_PROC2_P_TDEV) +#if defined(HAVE_KINFO_PROC2_NETBSD) # define SUDO_KERN_PROC KERN_PROC2 # define sudo_kinfo_proc kinfo_proc2 # define sudo_kp_tdev p_tdev # define sudo_kp_namelen 6 -#elif defined(HAVE_STRUCT_KINFO_PROC_P_TDEV) +#elif defined(HAVE_KINFO_PROC_OPENBSD) # define SUDO_KERN_PROC KERN_PROC # define sudo_kinfo_proc kinfo_proc # define sudo_kp_tdev p_tdev # define sudo_kp_namelen 6 -#elif defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV) +#elif defined(HAVE_KINFO_PROC_FREEBSD) # define SUDO_KERN_PROC KERN_PROC # define sudo_kinfo_proc kinfo_proc # define sudo_kp_tdev ki_tdev # define sudo_kp_namelen 4 -#elif defined(HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV) +#elif defined(HAVE_KINFO_PROC_44BSD) # define SUDO_KERN_PROC KERN_PROC # define sudo_kinfo_proc kinfo_proc # define sudo_kp_tdev kp_eproc.e_tdev -- 2.40.0