]> granicus.if.org Git - sudo/commitdiff
Add UNIX98 pty support.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 8 Aug 2009 00:26:13 +0000 (00:26 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 8 Aug 2009 00:26:13 +0000 (00:26 +0000)
configure
configure.in
script.c

index b15da746fd594f0ec8b783974e084a5d1fb811ca..b5ad3d62e1e2ed2dbc4c7affc85c5d85a20295bd 100755 (executable)
--- a/configure
+++ b/configure
@@ -15825,9 +15825,10 @@ LIBS=$ac_save_LIBS
 
 
 
+
 for ac_func in strchr strrchr memchr memcpy memset sysconf tzset \
               strftime setrlimit initgroups getgroups fstat gettimeofday \
-              setlocale getaddrinfo setsid setenv
+              setlocale getaddrinfo setsid setenv vhangup
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 { echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -16376,8 +16377,98 @@ _ACEOF
 else
 
 
+for ac_func in grantpt
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; }
+if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$ac_func || defined __stub___$ac_func
+choke me
+#endif
+
+int
+main ()
+{
+return $ac_func ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       eval "$as_ac_var=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+ac_res=`eval echo '${'$as_ac_var'}'`
+              { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
 
-for ac_func in revoke vhangup
+for ac_func in posix_openpt
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 { echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -16466,7 +16557,108 @@ if test `eval echo '${'$as_ac_var'}'` = yes; then
   cat >>confdefs.h <<_ACEOF
 #define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
 _ACEOF
- break
+
+fi
+done
+
+
+else
+
+
+for ac_func in revoke
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; }
+if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$ac_func || defined __stub___$ac_func
+choke me
+#endif
+
+int
+main ()
+{
+return $ac_func ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       eval "$as_ac_var=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+ac_res=`eval echo '${'$as_ac_var'}'`
+              { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
 fi
 done
 
index d7796e68f3a4a8d9b691a0388ab4896c7e46647b..7cfeeee6ee83a6d45f850da71401ff73900de524 100644 (file)
@@ -1836,14 +1836,18 @@ dnl
 AC_FUNC_GETGROUPS
 AC_CHECK_FUNCS(strchr strrchr memchr memcpy memset sysconf tzset \
               strftime setrlimit initgroups getgroups fstat gettimeofday \
-              setlocale getaddrinfo setsid setenv)
+              setlocale getaddrinfo setsid setenv vhangup)
 AC_CHECK_FUNCS(openpty, [AC_CHECK_HEADERS(util.h pty.h, [break])], [
     AC_CHECK_LIB(util, openpty, [
        AC_CHECK_HEADERS(util.h pty.h, [break])
        SUDO_LIBS="${SUDO_LIBS} -lutil"
        AC_DEFINE(HAVE_OPENPTY)
     ], [
-       AC_CHECK_FUNCS(revoke vhangup, [break])
+       AC_CHECK_FUNCS(grantpt, [
+           AC_CHECK_FUNCS(posix_openpt)
+       ], [
+           AC_CHECK_FUNCS(revoke)
+       ])
     ])
 ])
 AC_CHECK_FUNCS(unsetenv, SUDO_FUNC_UNSETENV_VOID)
index bba652e5fd482c9d681a01f3a160ceb1d48ce5fe..8a9f928b4c021d121028e5c6d218637911330aa9 100644 (file)
--- a/script.c
+++ b/script.c
@@ -87,12 +87,12 @@ static int get_pty __P((int *master, int *slave));
 
 /*
  * TODO: run monitor as root?
- *       get_pty for unix98 pty
  *       if stdin not tty, just use sane defaults
  *      fix sigchild
  */
 
-static int fdcompar(v1, v2)
+static int
+fdcompar(v1, v2)
     const void *v1;
     const void *v2;
 {
@@ -462,7 +462,8 @@ sigwinch(signo)
 }
 
 #ifdef HAVE_OPENPTY
-static int get_pty(master, slave)
+static int
+get_pty(master, slave)
     int *master;
     int *slave;
 {
@@ -480,9 +481,59 @@ static int get_pty(master, slave)
 }
 
 #else
+# ifdef HAVE_GRANTPT
+
+#  ifndef HAVE_POSIX_OPENPT
+static int
+posix_openpt(oflag)
+    int oflag;
+{
+    int fd;
+
+#   ifdef _AIX
+    fd = open("/dev/ptc", oflag);
+#   else
+    fd = open("/dev/ptmx", oflag);
+#   endif
+    return(fd);
+}
+#  endif HAVE_POSIX_OPENPT
+
+static int
+get_pty(master, slave)
+    int *master;
+    int *slave;
+{
+    char *line;
+
+    *master = posix_openpt(O_RDWR);
+    if (*master == -1)
+       return(0);
+
+    if (unlockpt(*master) != 0) {
+       close(*master);
+       return(0);
+    }
+    (void) grantpt(*master);
+    line = ptsname(*master);
+    if (line == NULL) {
+       close(*master);
+       return(0);
+    }
+    *slave = open(line, O_RDWR, 0);
+    if (*slave == -1) {
+       close(*master);
+       return(0);
+    }
+    (void) chown(line, runas_pw->pw_uid, -1);
+    return(1);
+}
+
+# else /* !HAVE_GRANTPT */
 
 static char line[] = "/dev/ptyXX";
-static int get_pty(master, slave)
+static int
+get_pty(master, slave)
     int *master;
     int *slave;
 {
@@ -504,18 +555,19 @@ static int get_pty(master, slave)
                continue; /* already in use */
            }
            line[sizeof("/dev/p") - 2] = 't';
-           (void)chown(line, runas_pw->pw_uid, ttygid);
-           (void)chmod(line, S_IRUSR|S_IWUSR|S_IWGRP);
-#ifdef HAVE_REVOKE
-           (void)revoke(line);
-#endif
+           (void) chown(line, runas_pw->pw_uid, ttygid);
+           (void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP);
+#  ifdef HAVE_REVOKE
+           (void) revoke(line);
+#  endif
            *slave = open(line, O_RDWR, 0);
            if (*slave != -1)
                    return(1); /* success */
-           (void)close(*master);
+           (void) close(*master);
        }
     }
     return(0);
 }
 
-#endif
+# endif /* HAVE_GRANTPT */
+#endif /* HAVE_OPENPTY */