From: Todd C. Miller Date: Fri, 1 Mar 2013 16:17:31 +0000 (-0500) Subject: Use pstat() on HP-UX to determine the tty device. X-Git-Tag: SUDO_1_7_10p8~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=94ba63b75d4c09d16b71f6d6e071864766d62cce;p=sudo Use pstat() on HP-UX to determine the tty device. --HG-- branch : 1.7 --- diff --git a/config.h.in b/config.h.in index 7ddd83257..34462cd54 100644 --- a/config.h.in +++ b/config.h.in @@ -401,6 +401,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_PROJECT_H +/* Define to 1 if you have the `pstat_getproc' function. */ +#undef HAVE_PSTAT_GETPROC + /* Define to 1 if you have the header file. */ #undef HAVE_PTY_H diff --git a/configure b/configure index d47b32a02..4c1547222 100755 --- a/configure +++ b/configure @@ -14087,6 +14087,17 @@ $as_echo "$sudo_cv_var_daportable" >&6; } test -z "$with_pam" && AUTH_EXCL_DEF="PAM" ;; esac + for ac_func in pstat_getproc +do : + ac_fn_c_check_func "$LINENO" "pstat_getproc" "ac_cv_func_pstat_getproc" +if test "x$ac_cv_func_pstat_getproc" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_PSTAT_GETPROC 1 +_ACEOF + +fi +done + ;; *-dec-osf*) # ignore envariables wrt dynamic lib path diff --git a/configure.in b/configure.in index ebee280eb..d88721237 100644 --- a/configure.in +++ b/configure.in @@ -1647,6 +1647,7 @@ case "$host" in test -z "$with_pam" && AUTH_EXCL_DEF="PAM" ;; esac + AC_CHECK_FUNCS(pstat_getproc) ;; *-dec-osf*) # ignore envariables wrt dynamic lib path diff --git a/ttyname.c b/ttyname.c index fa67d39a2..a634d302a 100644 --- a/ttyname.c +++ b/ttyname.c @@ -81,6 +81,10 @@ #elif defined(HAVE_SYS_PROCFS_H) # include #endif +#ifdef HAVE_PSTAT_GETPROC +# include +# include +#endif #include "sudo.h" @@ -334,7 +338,6 @@ sudo_ttyname_dev(rdev) * 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 * parent). First tries sysctl using the current pid, then the parent's pid. - * Falls back on ttyname of std{in,out,err} if that fails. */ char * get_process_ttyname() @@ -375,7 +378,6 @@ get_process_ttyname() * 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 * parent). First tries /proc/pid/psinfo, then /proc/ppid/psinfo. - * Falls back on ttyname of std{in,out,err} if that fails. */ char * get_process_ttyname() @@ -406,7 +408,6 @@ get_process_ttyname() * 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 * parent). First tries field 7 in /proc/pid/stat, then /proc/ppid/stat. - * Falls back on ttyname of std{in,out,err} if that fails. */ char * get_process_ttyname() @@ -446,6 +447,31 @@ get_process_ttyname() return tty; } +#elif HAVE_PSTAT_GETPROC +/* + * 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 + * parent). + */ +char * +get_process_ttyname(void) +{ + struct pst_status pstat; + char *tty = NULL; + int i; + + /* Try to determine the tty from psdev in struct pst_status. */ + for (i = 0; tty == NULL && i < 2; i++) { + const int pid = i ? (int)getppid() : (int)getpid(); + if (pstat_getproc(&pstat, sizeof(pstat), 0, pid) != -1) { + if (pstat.pst_term.psd_major != -1 && pstat.pst_term.psd_minor != -1) { + tty = sudo_ttyname_dev(makedev(pstat.pst_term.psd_major, + pstat.pst_term.psd_minor)); + } + } + } + return tty; +} #else /* * Return a string from ttyname() containing the tty to which the process is