This patch will upgrade Sudo version 1.8.4 patchlevel 2 to Sudo version 1.8.4 patchlevel 3. To apply: $ cd sudo-1.8.4p2 $ patch -p1 < sudo-1.8.4p3.patch diff -urNa sudo-1.8.4p2/ChangeLog sudo-1.8.4p3/ChangeLog --- sudo-1.8.4p2/ChangeLog Mon Feb 27 14:59:37 2012 +++ sudo-1.8.4p3/ChangeLog Mon Mar 12 14:13:50 2012 @@ -1,8 +1,83 @@ +2012-03-12 Todd C. Miller + + * .hgtags: + Added tag SUDO_1_8_4p3 for changeset 3093c8558862 + [b82d3b208a4d] [tip] <1.8> + + * NEWS, configure, configure.in: + Update for sudo 1.8.4p3 + [3093c8558862] [SUDO_1_8_4p3] <1.8> + + * plugins/sudoers/env.c: + matches_env_check() returns int, not boolean + [110f954181e1] <1.8> + + * src/ttyname.c: + Simply move the free of ki_proc outside the realloc() loop. + [18209f1ff9f7] <1.8> + + * src/ttyname.c: + Bring back the erealloc() for the ENOMEM loop and just zero the + pointer after we free it. + [83a1c1ec6b03] <1.8> + + * doc/visudo.cat, doc/visudo.man.in: + regen + [04ea41a8657c] <1.8> + + * src/ttyname.c: + Don't try to erealloc() a potentially freed pointer; Mateusz Guzik + [cca8a33ed286] <1.8> + +2012-03-09 Todd C. Miller + + * src/exec_pty.c, src/ttyname.c: + Fix format string warning on Solaris with gcc 3.4.3. + [45322f41e677] <1.8> + + * src/Makefile.in: + Honor LDFLAGS when linking sesh; from Vita Cizek + [349b3c929637] <1.8> + + * src/sesh.c: + Include alloc.h for estrdup() prototype; from Vita Cizek + [f5ed422a6553] <1.8> + +2012-03-08 Todd C. Miller + + * INSTALL: + Fix editor goof. + [574f0b17a91f] <1.8> + +2012-03-01 Todd C. Miller + + * configure, configure.in: + Add check for variadic macro support in cpp. + [1ce59ac2e4f9] <1.8> + +2012-02-28 Todd C. Miller + + * doc/visudo.pod, plugins/sudoers/visudo.c: + Check the owner and mode in -c (check) mode unless the -f option is + specified. Previously, the owner and mode were checked on the main + sudoers file when the -s (strict) option was given, but this was not + documented. + [dff2805fc49e] <1.8> + + * config.h.in, configure, configure.in, src/ttyname.c: + Prefer KERN_PROC2 over KERN_PROC. Fixes compilation on some + versions of OpenBSD versions that have KERN_PROC2 but not KERN_PROC. + [dceb6078cda5] <1.8> + 2012-02-27 Todd C. Miller + * .hgtags: + Added tag SUDO_1_8_4p2 for changeset db564e1c02cf + [52638c160a4b] <1.8> + * NEWS, configure, configure.in: bump version to 1.8.4p2 - [db564e1c02cf] [tip] <1.8> + [db564e1c02cf] [SUDO_1_8_4p2] <1.8> * src/exec_pty.c: Fix typo in safe_close() made while converting to debug framework diff -urNa sudo-1.8.4p2/INSTALL sudo-1.8.4p3/INSTALL --- sudo-1.8.4p2/INSTALL Fri Jan 6 13:25:53 2012 +++ sudo-1.8.4p3/INSTALL Mon Mar 12 14:02:01 2012 @@ -286,7 +286,7 @@ older PAM implementations or on operating systems where opening a PAM session changes the utmp or wtmp files. If PAM session support is disabled, resource limits may not - be updatedin for command being run. + be updated for the command being run. --disable-root-mailer By default sudo will run the mailer as root when tattling diff -urNa sudo-1.8.4p2/NEWS sudo-1.8.4p3/NEWS --- sudo-1.8.4p2/NEWS Mon Feb 27 14:57:34 2012 +++ sudo-1.8.4p3/NEWS Mon Mar 12 14:07:14 2012 @@ -1,3 +1,15 @@ +What's new in Sudo 1.8.4p3? + + * Fixed a crash on FreeBSD when no tty is present. + + * Fixed a bug introduced in Sudo 1.8.4 that allowed users to + specify environment variables to set on the command line without + having sudo "ALL" permissions or the "SETENV" tag. + + * When visudo is run with the -c (check) option, the sudoers + file(s) owner and mode are now also checked unless the -f option + was specified. + What's new in Sudo 1.8.4p2? * Fixed a bug introduced in Sudo 1.8.4 where insufficient space diff -urNa sudo-1.8.4p2/config.h.in sudo-1.8.4p3/config.h.in --- sudo-1.8.4p2/config.h.in Mon Feb 6 13:36:48 2012 +++ sudo-1.8.4p3/config.h.in Mon Mar 12 14:02:06 2012 @@ -505,6 +505,9 @@ /* 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 diff -urNa sudo-1.8.4p2/configure sudo-1.8.4p3/configure --- sudo-1.8.4p2/configure Mon Feb 27 14:46:52 2012 +++ sudo-1.8.4p3/configure Mon Mar 12 14:07:32 2012 @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.68 for sudo 1.8.4p2. +# Generated by GNU Autoconf 2.68 for sudo 1.8.4p3. # # Report bugs to . # @@ -570,8 +570,8 @@ # Identity of this package. PACKAGE_NAME='sudo' PACKAGE_TARNAME='sudo' -PACKAGE_VERSION='1.8.4p2' -PACKAGE_STRING='sudo 1.8.4p2' +PACKAGE_VERSION='1.8.4p3' +PACKAGE_STRING='sudo 1.8.4p3' PACKAGE_BUGREPORT='http://www.sudo.ws/bugs/' PACKAGE_URL='' @@ -1447,7 +1447,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures sudo 1.8.4p2 to adapt to many kinds of systems. +\`configure' configures sudo 1.8.4p3 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1512,7 +1512,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of sudo 1.8.4p2:";; + short | recursive ) echo "Configuration of sudo 1.8.4p3:";; esac cat <<\_ACEOF @@ -1730,7 +1730,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -sudo configure 1.8.4p2 +sudo configure 1.8.4p3 generated by GNU Autoconf 2.68 Copyright (C) 2010 Free Software Foundation, Inc. @@ -2434,7 +2434,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by sudo $as_me 1.8.4p2, which was +It was created by sudo $as_me 1.8.4p3, which was generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -14538,6 +14538,31 @@ fi +# Check for variadic macro support in cpp +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +$ac_includes_default +#if defined(__GNUC__) && __GNUC__ == 2 +# define sudo_fprintf(fp, fmt...) fprintf((fp), (fmt)) +#else +# define sudo_fprintf(fp, ...) fprintf((fp), __VA_ARGS__) +#endif + +int +main () +{ +sudo_fprintf(stderr, "a %s", "test"); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + as_fn_error $? "Your C compiler doesn't support variadic macros, try building with gcc instead" "$LINENO" 5 +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test X"$with_gnu_ld" != "yes" -a -n "$GCC"; then _CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -static-libgcc" @@ -16452,15 +16477,15 @@ 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_proc2" "p_tdev" "ac_cv_member_struct_kinfo_proc2_p_tdev" " #include #include " -if test "x$ac_cv_member_struct_kinfo_proc_kp_eproc_e_tdev" = xyes; then : +if test "x$ac_cv_member_struct_kinfo_proc2_p_tdev" = xyes; then : cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV 1 +#define HAVE_STRUCT_KINFO_PROC2_P_TDEV 1 _ACEOF @@ -16478,6 +16503,20 @@ _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 + #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 + + fi @@ -16488,6 +16527,9 @@ fi + + +fi done @@ -20506,7 +20548,7 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by sudo $as_me 1.8.4p2, which was +This file was extended by sudo $as_me 1.8.4p3, which was generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -20572,7 +20614,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -sudo config.status 1.8.4p2 +sudo config.status 1.8.4p3 configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" diff -urNa sudo-1.8.4p2/configure.in sudo-1.8.4p3/configure.in --- sudo-1.8.4p2/configure.in Mon Feb 27 14:46:46 2012 +++ sudo-1.8.4p3/configure.in Mon Mar 12 14:07:24 2012 @@ -3,7 +3,7 @@ dnl dnl Copyright (c) 1994-1996,1998-2012 Todd C. Miller dnl -AC_INIT([sudo], [1.8.4p2], [http://www.sudo.ws/bugs/], [sudo]) +AC_INIT([sudo], [1.8.4p3], [http://www.sudo.ws/bugs/], [sudo]) AC_CONFIG_HEADER([config.h pathnames.h]) dnl dnl Note: this must come after AC_INIT @@ -1913,6 +1913,15 @@ AC_PROG_GCC_TRADITIONAL AC_C_CONST AC_C_VOLATILE +# Check for variadic macro support in cpp +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ +AC_INCLUDES_DEFAULT +#if defined(__GNUC__) && __GNUC__ == 2 +# define sudo_fprintf(fp, fmt...) fprintf((fp), (fmt)) +#else +# define sudo_fprintf(fp, ...) fprintf((fp), __VA_ARGS__) +#endif +], [sudo_fprintf(stderr, "a %s", "test");])], [], [AC_MSG_ERROR([Your C compiler doesn't support variadic macros, try building with gcc instead])]) if test X"$with_gnu_ld" != "yes" -a -n "$GCC"; then _CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -static-libgcc" @@ -2102,11 +2111,15 @@ AC_CHECK_FUNCS(getttyent ttyslot, [break]) fi -AC_CHECK_FUNCS(sysctl, [AC_CHECK_MEMBERS([struct kinfo_proc.ki_tdev], - [], +AC_CHECK_FUNCS(sysctl, [AC_CHECK_MEMBERS([struct kinfo_proc.ki_tdev], [], [ - AC_CHECK_MEMBERS([struct kinfo_proc.kp_eproc.e_tdev], [], [ - AC_CHECK_MEMBERS([struct kinfo_proc.p_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], [], [], [ + #include + #include + ]) + ], [ #include #include ]) diff -urNa sudo-1.8.4p2/doc/visudo.cat sudo-1.8.4p3/doc/visudo.cat --- sudo-1.8.4p2/doc/visudo.cat Fri Jan 6 15:28:30 2012 +++ sudo-1.8.4p3/doc/visudo.cat Mon Mar 12 14:02:08 2012 @@ -42,11 +42,12 @@ vviissuuddoo accepts the following command line options: -c Enable cchheecckk--oonnllyy mode. The existing _s_u_d_o_e_r_s file will be - checked for syntax and a message will be printed to the - standard output detailing the status of _s_u_d_o_e_r_s. If the - syntax check completes successfully, vviissuuddoo will exit with - a value of 0. If a syntax error is encountered, vviissuuddoo - will exit with a value of 1. + checked for syntax errors, owner and mode. A message will + be printed to the standard output describing the status of + _s_u_d_o_e_r_s unless the --qq option was specified. If the check + completes successfully, vviissuuddoo will exit with a value of 0. + If an error is encountered, vviissuuddoo will exit with a value + of 1. -f _s_u_d_o_e_r_s Specify and alternate _s_u_d_o_e_r_s file location. With this option vviissuuddoo will edit (or check) the _s_u_d_o_e_r_s file of your @@ -150,4 +151,4 @@ -1.8.4 January 6, 2012 VISUDO(1m) +1.8.4 March 12, 2012 VISUDO(1m) diff -urNa sudo-1.8.4p2/doc/visudo.man.in sudo-1.8.4p3/doc/visudo.man.in --- sudo-1.8.4p2/doc/visudo.man.in Fri Jan 6 15:28:30 2012 +++ sudo-1.8.4p3/doc/visudo.man.in Mon Mar 12 14:02:08 2012 @@ -144,7 +144,7 @@ .\" ======================================================================== .\" .IX Title "VISUDO @mansectsu@" -.TH VISUDO @mansectsu@ "January 6, 2012" "1.8.4" "MAINTENANCE COMMANDS" +.TH VISUDO @mansectsu@ "March 12, 2012" "1.8.4" "MAINTENANCE COMMANDS" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -192,10 +192,10 @@ .IP "\-c" 12 .IX Item "-c" Enable \fBcheck-only\fR mode. The existing \fIsudoers\fR file will be -checked for syntax and a message will be printed to the -standard output detailing the status of \fIsudoers\fR. -If the syntax check completes successfully, \fBvisudo\fR will -exit with a value of 0. If a syntax error is encountered, +checked for syntax errors, owner and mode. A message will be printed +to the standard output describing the status of \fIsudoers\fR unless +the \fB\-q\fR option was specified. If the check completes successfully, +\&\fBvisudo\fR will exit with a value of 0. If an error is encountered, \&\fBvisudo\fR will exit with a value of 1. .IP "\-f \fIsudoers\fR" 12 .IX Item "-f sudoers" diff -urNa sudo-1.8.4p2/doc/visudo.pod sudo-1.8.4p3/doc/visudo.pod --- sudo-1.8.4p2/doc/visudo.pod Fri Jan 6 15:28:26 2012 +++ sudo-1.8.4p3/doc/visudo.pod Mon Mar 12 14:02:08 2012 @@ -70,10 +70,10 @@ =item -c Enable B mode. The existing I file will be -checked for syntax and a message will be printed to the -standard output detailing the status of I. -If the syntax check completes successfully, B will -exit with a value of 0. If a syntax error is encountered, +checked for syntax errors, owner and mode. A message will be printed +to the standard output describing the status of I unless +the B<-q> option was specified. If the check completes successfully, +B will exit with a value of 0. If an error is encountered, B will exit with a value of 1. =item -f I diff -urNa sudo-1.8.4p2/plugins/sudoers/env.c sudo-1.8.4p3/plugins/sudoers/env.c --- sudo-1.8.4p2/plugins/sudoers/env.c Wed Jan 4 13:01:21 2012 +++ sudo-1.8.4p3/plugins/sudoers/env.c Mon Mar 12 14:03:48 2012 @@ -666,7 +666,7 @@ char * const *ep; char *eq, *bad = NULL; size_t len, blen = 0, bsize = 0; - bool okvar; + int okvar; if (env_vars == NULL) return; diff -urNa sudo-1.8.4p2/plugins/sudoers/visudo.c sudo-1.8.4p3/plugins/sudoers/visudo.c --- sudo-1.8.4p2/plugins/sudoers/visudo.c Wed Jan 11 16:26:52 2012 +++ sudo-1.8.4p3/plugins/sudoers/visudo.c Mon Mar 12 14:02:14 2012 @@ -105,7 +105,7 @@ static void get_hostname(void); static int whatnow(void); static int check_aliases(bool, bool); -static bool check_syntax(char *, bool, bool); +static bool check_syntax(char *, bool, bool, bool); static bool edit_sudoers(struct sudoersfile *, char *, char *, int); static bool install_sudoers(struct sudoersfile *, bool); static int print_unused(void *, void *); @@ -225,7 +225,7 @@ init_defaults(); if (checkonly) { - exitcode = check_syntax(sudoers_path, quiet, strict) ? 0 : 1; + exitcode = check_syntax(sudoers_path, quiet, strict, oldperms) ? 0 : 1; goto done; } @@ -776,9 +776,35 @@ } static bool -check_syntax(char *sudoers_path, bool quiet, bool strict) +check_owner(const char *path, bool quiet) { struct stat sb; + bool ok = true; + debug_decl(check_owner, SUDO_DEBUG_UTIL) + + if (stat(path, &sb) == 0) { + if (sb.st_uid != SUDOERS_UID || sb.st_gid != SUDOERS_GID) { + ok = false; + if (!quiet) { + fprintf(stderr, + _("%s: wrong owner (uid, gid) should be (%u, %u)\n"), + path, SUDOERS_UID, SUDOERS_GID); + } + } + if ((sb.st_mode & 07777) != SUDOERS_MODE) { + ok = false; + if (!quiet) { + fprintf(stderr, _("%s: bad permissions, should be mode 0%o\n"), + path, SUDOERS_MODE); + } + } + } + debug_return_bool(ok); +} + +static bool +check_syntax(char *sudoers_path, bool quiet, bool strict, bool oldperms) +{ bool ok = false; debug_decl(check_syntax, SUDO_DEBUG_UTIL) @@ -802,37 +828,28 @@ errorfile = sudoers_path; } ok = !parse_error; - if (!quiet) { - if (parse_error) { + + if (parse_error) { + if (!quiet) { if (errorlineno != -1) (void) printf(_("parse error in %s near line %d\n"), errorfile, errorlineno); else (void) printf(_("parse error in %s\n"), errorfile); - } else { - struct sudoersfile *sp; - (void) printf(_("%s: parsed OK\n"), sudoers_path); - tq_foreach_fwd(&sudoerslist, sp) { - (void) printf(_("%s: parsed OK\n"), sp->path); - } } - } - /* Check mode and owner in strict mode. */ - if (strict && yyin != stdin && fstat(fileno(yyin), &sb) == 0) { - if (sb.st_uid != SUDOERS_UID || sb.st_gid != SUDOERS_GID) { + } else { + struct sudoersfile *sp; + + /* Parsed OK, check mode and owner. */ + if (oldperms || check_owner(sudoers_path, quiet)) + (void) printf(_("%s: parsed OK\n"), sudoers_path); + else ok = false; - if (!quiet) { - fprintf(stderr, - _("%s: wrong owner (uid, gid) should be (%u, %u)\n"), - sudoers_path, SUDOERS_UID, SUDOERS_GID); - } - } - if ((sb.st_mode & 07777) != SUDOERS_MODE) { - ok = false; - if (!quiet) { - fprintf(stderr, _("%s: bad permissions, should be mode 0%o\n"), - sudoers_path, SUDOERS_MODE); - } + tq_foreach_fwd(&sudoerslist, sp) { + if (oldperms || check_owner(sp->path, quiet)) + (void) printf(_("%s: parsed OK\n"), sp->path); + else + ok = false; } } diff -urNa sudo-1.8.4p2/src/Makefile.in sudo-1.8.4p3/src/Makefile.in --- sudo-1.8.4p2/src/Makefile.in Fri Feb 10 12:46:59 2012 +++ sudo-1.8.4p3/src/Makefile.in Mon Mar 12 14:02:15 2012 @@ -100,7 +100,7 @@ $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) $(LTLDFLAGS) -o $@ sudo_noexec.lo -avoid-version -rpath $(noexecdir) sesh: sesh.o error.o exec_common.o @LIBINTL@ $(LT_LIBS) - $(LIBTOOL) --mode=link $(CC) -o $@ sesh.o error.o exec_common.o @LIBINTL@ $(LIBS) -static-libtool-libs + $(LIBTOOL) --mode=link $(CC) -o $@ sesh.o error.o exec_common.o $(LDFLAGS) @LIBINTL@ $(LIBS) -static-libtool-libs pre-install: diff -urNa sudo-1.8.4p2/src/exec_pty.c sudo-1.8.4p3/src/exec_pty.c --- sudo-1.8.4p2/src/exec_pty.c Mon Feb 27 14:46:29 2012 +++ sudo-1.8.4p3/src/exec_pty.c Mon Mar 12 14:02:15 2012 @@ -378,20 +378,20 @@ * Note that SIGCHLD will interrupt the sleep() */ if (use_pgrp) { - sudo_debug_printf(SUDO_DEBUG_INFO, "killpg %d SIGHUP", pid); + sudo_debug_printf(SUDO_DEBUG_INFO, "killpg %d SIGHUP", (int)pid); killpg(pid, SIGHUP); - sudo_debug_printf(SUDO_DEBUG_INFO, "killpg %d SIGTERM", pid); + sudo_debug_printf(SUDO_DEBUG_INFO, "killpg %d SIGTERM", (int)pid); killpg(pid, SIGTERM); sleep(2); - sudo_debug_printf(SUDO_DEBUG_INFO, "killpg %d SIGKILL", pid); + sudo_debug_printf(SUDO_DEBUG_INFO, "killpg %d SIGKILL", (int)pid); killpg(pid, SIGKILL); } else { - sudo_debug_printf(SUDO_DEBUG_INFO, "kill %d SIGHUP", pid); + sudo_debug_printf(SUDO_DEBUG_INFO, "kill %d SIGHUP", (int)pid); kill(pid, SIGHUP); - sudo_debug_printf(SUDO_DEBUG_INFO, "kill %d SIGTERM", pid); + sudo_debug_printf(SUDO_DEBUG_INFO, "kill %d SIGTERM", (int)pid); kill(pid, SIGTERM); sleep(2); - sudo_debug_printf(SUDO_DEBUG_INFO, "kill %d SIGKILL", pid); + sudo_debug_printf(SUDO_DEBUG_INFO, "kill %d SIGKILL", (int)pid); kill(pid, SIGKILL); } diff -urNa sudo-1.8.4p2/src/sesh.c sudo-1.8.4p3/src/sesh.c --- sudo-1.8.4p2/src/sesh.c Wed Jan 25 14:58:28 2012 +++ sudo-1.8.4p3/src/sesh.c Mon Mar 12 14:02:16 2012 @@ -34,8 +34,9 @@ #endif /* HAVE_STDBOOL_H */ #include "missing.h" -#include "gettext.h" +#include "alloc.h" #include "error.h" +#include "gettext.h" #include "sudo_conf.h" #include "sudo_debug.h" #include "sudo_exec.h" diff -urNa sudo-1.8.4p2/src/ttyname.c sudo-1.8.4p3/src/ttyname.c --- sudo-1.8.4p2/src/ttyname.c Fri Jan 13 09:07:09 2012 +++ sudo-1.8.4p3/src/ttyname.c Mon Mar 12 14:03:43 2012 @@ -42,7 +42,7 @@ #endif /* HAVE_UNISTD_H */ #include #include -#if defined(HAVE_STRUCT_KINFO_PROC_P_TDEV) || defined (HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV) +#if defined(HAVE_STRUCT_KINFO_PROC_P_TDEV) || defined (HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV) || defined(HAVE_STRUCT_KINFO_PROC2_P_TDEV) # include #elif defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV) # include @@ -54,15 +54,26 @@ /* * 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 +#if defined(HAVE_STRUCT_KINFO_PROC2_P_TDEV) +# 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) +# 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) +# 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) +# define SUDO_KERN_PROC KERN_PROC +# define sudo_kinfo_proc kinfo_proc +# define sudo_kp_tdev kp_eproc.e_tdev +# define sudo_kp_namelen 4 #endif #ifdef sudo_kp_tdev @@ -76,7 +87,7 @@ get_process_ttyname(void) { char *tty = NULL; - struct kinfo_proc *ki_proc = NULL; + struct sudo_kinfo_proc *ki_proc = NULL; size_t size = sizeof(*ki_proc); int i, mib[6], rc; debug_decl(get_process_ttyname, SUDO_DEBUG_UTIL) @@ -87,7 +98,7 @@ */ for (i = 0; tty == NULL && i < 2; i++) { mib[0] = CTL_KERN; - mib[1] = KERN_PROC; + mib[1] = SUDO_KERN_PROC; mib[2] = KERN_PROC_PID; mib[3] = i ? (int)getppid() : (int)getpid(); mib[4] = sizeof(*ki_proc); @@ -118,8 +129,8 @@ sudo_debug_printf(SUDO_DEBUG_WARN, "unable to resolve tty via KERN_PROC: %s", strerror(errno)); } - efree(ki_proc); } + efree(ki_proc); /* If all else fails, fall back on ttyname(). */ if (tty == NULL) { @@ -153,7 +164,7 @@ /* No tty for child, check the parent via /proc. */ ppid = getppid(); for (i = STDIN_FILENO; i < STDERR_FILENO && tty == NULL; i++) { - snprintf(path, sizeof(path), "/proc/%d/fd/%d", ppid, i); + snprintf(path, sizeof(path), "/proc/%d/fd/%d", (int)ppid, i); fd = open(path, O_RDONLY|O_NOCTTY, 0); if (fd != -1) { tty = ttyname(fd);