Add support for determining tty via sysctl on other BSD variants.
This commit is contained in:
@@ -502,9 +502,15 @@
|
||||
/* Define to 1 if the system has the type `struct in6_addr'. */
|
||||
#undef HAVE_STRUCT_IN6_ADDR
|
||||
|
||||
/* Define if your struct kinfo_proc has a ki_tdev field. */
|
||||
/* 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 if your struct sockadr has an sa_len field. */
|
||||
#undef HAVE_STRUCT_SOCKADDR_SA_LEN
|
||||
|
||||
|
44
configure
vendored
44
configure
vendored
@@ -16317,16 +16317,56 @@ if test "x$ac_cv_func_sysctl" = xyes; then :
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_SYSCTL 1
|
||||
_ACEOF
|
||||
ac_fn_c_check_member "$LINENO" "struct kinfo_proc" "ki_tdev" "ac_cv_member_struct_kinfo_proc_ki_tdev" " #include <sys/param.h>
|
||||
ac_fn_c_check_member "$LINENO" "struct kinfo_proc" "ki_tdev" "ac_cv_member_struct_kinfo_proc_ki_tdev" "
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/user.h>
|
||||
|
||||
"
|
||||
if test "x$ac_cv_member_struct_kinfo_proc_ki_tdev" = xyes; then :
|
||||
|
||||
$as_echo "#define HAVE_STRUCT_KINFO_PROC_KI_TDEV 1" >>confdefs.h
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_STRUCT_KINFO_PROC_KI_TDEV 1
|
||||
_ACEOF
|
||||
|
||||
|
||||
else
|
||||
|
||||
ac_fn_c_check_member "$LINENO" "struct kinfo_proc" "kp_eproc.e_tdev" "ac_cv_member_struct_kinfo_proc_kp_eproc_e_tdev" "
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
"
|
||||
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
|
||||
|
||||
|
||||
else
|
||||
|
||||
ac_fn_c_check_member "$LINENO" "struct kinfo_proc" "p_tdev" "ac_cv_member_struct_kinfo_proc_p_tdev" "
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
"
|
||||
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
|
||||
|
||||
|
||||
fi
|
||||
|
||||
|
||||
fi
|
||||
|
||||
|
||||
fi
|
||||
|
||||
|
||||
fi
|
||||
done
|
||||
|
||||
|
24
configure.in
24
configure.in
@@ -2090,12 +2090,26 @@ if test "$utmp_style" = "LEGACY"; then
|
||||
AC_CHECK_FUNCS(getttyent ttyslot, [break])
|
||||
fi
|
||||
|
||||
AC_CHECK_FUNCS(sysctl, [AC_CHECK_MEMBER([struct kinfo_proc.ki_tdev],
|
||||
[AC_DEFINE(HAVE_STRUCT_KINFO_PROC_KI_TDEV, 1, [Define if your struct kinfo_proc has a ki_tdev field.])],
|
||||
AC_CHECK_FUNCS(sysctl, [AC_CHECK_MEMBERS([struct kinfo_proc.ki_tdev],
|
||||
[],
|
||||
[ #include <sys/param.h>
|
||||
#include <sys/user.h>]
|
||||
)])
|
||||
[
|
||||
AC_CHECK_MEMBERS([struct kinfo_proc.kp_eproc.e_tdev], [], [
|
||||
AC_CHECK_MEMBERS([struct kinfo_proc.p_tdev], [], [], [
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
])
|
||||
],
|
||||
[
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
])
|
||||
],
|
||||
[
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/user.h>
|
||||
])
|
||||
])
|
||||
|
||||
AC_CHECK_FUNCS(openpty, [AC_CHECK_HEADERS(libutil.h util.h pty.h, [break])], [
|
||||
AC_CHECK_LIB(util, openpty, [
|
||||
|
28
src/sudo.c
28
src/sudo.c
@@ -89,7 +89,9 @@
|
||||
#ifdef HAVE_PRIV_SET
|
||||
# include <priv.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRUCT_KINFO_PROC_KI_TDEV
|
||||
#if defined(HAVE_STRUCT_KINFO_PROC_P_TDEV) || defined (HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV)
|
||||
# include <sys/sysctl.h>
|
||||
#elif defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV)
|
||||
# include <sys/sysctl.h>
|
||||
# include <sys/user.h>
|
||||
#endif
|
||||
@@ -424,7 +426,21 @@ get_user_groups(struct user_details *ud)
|
||||
debug_return_str(gid_list);
|
||||
}
|
||||
|
||||
#ifdef HAVE_STRUCT_KINFO_PROC_KI_TDEV
|
||||
/*
|
||||
* How to access the tty device number in struct kinfo_proc.
|
||||
*/
|
||||
#if defined(HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV)
|
||||
# define sudo_kp_tdev kp_eproc.e_tdev
|
||||
# define sudo_kp_namelen 4
|
||||
#elif defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV)
|
||||
# define sudo_kp_tdev ki_tdev
|
||||
# define sudo_kp_namelen 4
|
||||
#elif defined(HAVE_STRUCT_KINFO_PROC_P_TDEV)
|
||||
# define sudo_kp_tdev p_tdev
|
||||
# define sudo_kp_namelen 6
|
||||
#endif
|
||||
|
||||
#ifdef sudo_kp_tdev
|
||||
/*
|
||||
* Return a string from ttyname() containing the tty to which the process is
|
||||
* attached or NULL if there is no tty associated with the process (or its
|
||||
@@ -437,7 +453,7 @@ get_process_tty(void)
|
||||
char *tty = NULL;
|
||||
struct kinfo_proc *ki_proc = NULL;
|
||||
size_t size = sizeof(*ki_proc);
|
||||
int i, mib[4], rc;
|
||||
int i, mib[6], rc;
|
||||
debug_decl(get_process_tty, SUDO_DEBUG_UTIL)
|
||||
|
||||
/*
|
||||
@@ -449,13 +465,15 @@ get_process_tty(void)
|
||||
mib[1] = KERN_PROC;
|
||||
mib[2] = KERN_PROC_PID;
|
||||
mib[3] = i ? (int)getppid() : (int)getpid();
|
||||
mib[4] = sizeof(*ki_proc);
|
||||
mib[5] = 1;
|
||||
do {
|
||||
size += size / 10;
|
||||
ki_proc = erealloc(ki_proc, size);
|
||||
rc = sysctl(mib, 4, ki_proc, &size, NULL, 0);
|
||||
rc = sysctl(mib, sudo_kp_namelen, ki_proc, &size, NULL, 0);
|
||||
} while (rc == -1 && errno == ENOMEM);
|
||||
if (rc != -1)
|
||||
tty = devname(ki_proc->ki_tdev, S_IFCHR);
|
||||
tty = devname(ki_proc->sudo_kp_tdev, S_IFCHR);
|
||||
}
|
||||
|
||||
/* If all else fails, fall back on ttyname(). */
|
||||
|
Reference in New Issue
Block a user