From: Todd C. Miller Date: Fri, 16 Aug 2013 19:50:48 +0000 (-0600) Subject: Don't redefine opterr, optind, optopt, optarg in getopt_long.c. X-Git-Tag: SUDO_1_8_8^2~43 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c2a9b9948118dcdcf3f10036bd8c3b9fed402fc;p=sudo Don't redefine opterr, optind, optopt, optarg in getopt_long.c. Add a check for optreset which is a BSD extension and provide a definition in getopt_long.c if it is not present. --- diff --git a/compat/getopt_long.c b/compat/getopt_long.c index f01f41fe4..8357a66fb 100644 --- a/compat/getopt_long.c +++ b/compat/getopt_long.c @@ -76,11 +76,20 @@ #define GNU_COMPATIBLE /* Be more compatible with GNU getopt. */ +#ifdef REPLACE_GETOPT int opterr = 1; /* if error message should be printed */ int optind = 1; /* index into parent argv vector */ int optopt = '?'; /* character checked for validity */ -int optreset; /* reset getopt */ char *optarg; /* argument associated with option */ +#else +extern int opterr; /* if error message should be printed */ +extern int optind; /* index into parent argv vector */ +extern int optopt; /* character checked for validity */ +extern char *optarg; /* argument associated with option */ +#endif +#if !defined(REPLACE_GETOPT) && !defined(HAVE_OPTRESET) +int optreset; /* reset getopt */ +#endif #define PRINT_ERROR ((opterr) && (*options != ':')) diff --git a/config.h.in b/config.h.in index 483d76f9c..a28142c9a 100644 --- a/config.h.in +++ b/config.h.in @@ -412,6 +412,9 @@ /* Define to 1 if you use NRL OPIE. */ #undef HAVE_OPIE +/* Define to 1 if you have the `optreset' symbol. */ +#undef HAVE_OPTRESET + /* Define to 1 if you use PAM authentication. */ #undef HAVE_PAM diff --git a/configure b/configure index 0670c67dd..1f5757563 100755 --- a/configure +++ b/configure @@ -17566,19 +17566,6 @@ esac fi -ac_fn_c_check_func "$LINENO" "getopt_long" "ac_cv_func_getopt_long" -if test "x$ac_cv_func_getopt_long" = xyes; then : - $as_echo "#define HAVE_GETOPT_LONG 1" >>confdefs.h - -else - case " $LIBOBJS " in - *" getopt_long.$ac_objext "* ) ;; - *) LIBOBJS="$LIBOBJS getopt_long.$ac_objext" - ;; -esac - -fi - ac_fn_c_check_func "$LINENO" "memrchr" "ac_cv_func_memrchr" if test "x$ac_cv_func_memrchr" = xyes; then : $as_echo "#define HAVE_MEMRCHR 1" >>confdefs.h @@ -17704,6 +17691,57 @@ esac fi +fi +done + +for ac_func in getopt_long +do : + ac_fn_c_check_func "$LINENO" "getopt_long" "ac_cv_func_getopt_long" +if test "x$ac_cv_func_getopt_long" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_GETOPT_LONG 1 +_ACEOF + +else + case " $LIBOBJS " in + *" getopt_long.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS getopt_long.$ac_objext" + ;; +esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for optreset" >&5 +$as_echo_n "checking for optreset... " >&6; } + if ${sudo_cv_optreset+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +extern int optreset; optreset = 1; return optreset; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + sudo_cv_optreset=yes +else + sudo_cv_optreset=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi + + if test "$sudo_cv_optreset" = "yes"; then + $as_echo "#define HAVE_OPTRESET 1" >>confdefs.h + + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $sudo_cv_optreset" >&5 +$as_echo "$sudo_cv_optreset" >&6; } + fi done @@ -23932,5 +23970,6 @@ fi + diff --git a/configure.in b/configure.in index 83c2761c3..e7a15a5ff 100644 --- a/configure.in +++ b/configure.in @@ -2355,11 +2355,20 @@ SUDO_FUNC_FNMATCH([AC_DEFINE(HAVE_FNMATCH)], [AC_LIBOBJ(fnmatch) COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }fnm_test" ]) SUDO_FUNC_ISBLANK -AC_REPLACE_FUNCS(getopt_long memrchr memset_s pw_dup strlcpy strlcat) +AC_REPLACE_FUNCS(memrchr memset_s pw_dup strlcpy strlcat) AC_CHECK_FUNCS(nanosleep, [], [ # On Solaris, nanosleep is in librt AC_CHECK_LIB(rt, nanosleep, [REPLAY_LIBS="${REPLAY_LIBS} -lrt"], [AC_LIBOBJ(nanosleep)]) ]) +AC_CHECK_FUNCS(getopt_long, [], [AC_LIBOBJ(getopt_long) + AC_MSG_CHECKING([for optreset]) + AC_CACHE_VAL(sudo_cv_optreset, [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[extern int optreset; optreset = 1; return optreset;]])], [sudo_cv_optreset=yes], [sudo_cv_optreset=no])]) + if test "$sudo_cv_optreset" = "yes"; then + AC_DEFINE(HAVE_OPTRESET) + fi + AC_MSG_RESULT($sudo_cv_optreset) +]) AC_CHECK_FUNCS(closefrom, [], [AC_LIBOBJ(closefrom) AC_CHECK_DECL(F_CLOSEM, AC_DEFINE(HAVE_FCNTL_CLOSEM), [], [ #include @@ -3714,6 +3723,7 @@ AH_TEMPLATE(HAVE_LIBINTL_H, [Define to 1 if you have the header file AH_TEMPLATE(HAVE_LINUX_AUDIT, [Define to 1 to enable Linux audit support.]) AH_TEMPLATE(HAVE_SSSD, [Define to 1 to enable SSSD support.]) AH_TEMPLATE(HAVE_OPIE, [Define to 1 if you use NRL OPIE.]) +AH_TEMPLATE(HAVE_OPTRESET, [Define to 1 if you have the `optreset' symbol.]) AH_TEMPLATE(HAVE_PAM, [Define to 1 if you use PAM authentication.]) AH_TEMPLATE(HAVE_PAM_LOGIN, [Define to 1 if you use a specific PAM session for sudo -i.]) AH_TEMPLATE(HAVE_PROJECT_H, [Define to 1 if you have the header file.])