From: Todd C. Miller Date: Wed, 14 Oct 2009 20:04:04 +0000 (+0000) Subject: Add check for strsignal() and a simple implementation if it is not there but sys_sigl... X-Git-Tag: SUDO_1_7_3~234 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=233377a8b7cc9935719e4333ac9177019ee2df55;p=sudo Add check for strsignal() and a simple implementation if it is not there but sys_siglist is --- diff --git a/Makefile.in b/Makefile.in index c995abaa5..da0b974c4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -110,10 +110,10 @@ SRCS = aix.c alias.c alloc.c audit.c bsm_audit.c check.c closefrom.c \ gram.y interfaces.c isblank.c lbuf.c ldap.c list.c logging.c match.c \ mkstemp.c memrchr.c nanosleep.c parse.c pwutil.c script.c set_perms.c \ sigaction.c snprintf.c strcasecmp.c strerror.c strlcat.c strlcpy.c \ - sudo.c sudo_noexec.c sudo_edit.c sudo_nss.c term.c testsudoers.c \ - tgetpass.c toke.c toke.l tsgetgrpw.c utimes.c vasgroups.c visudo.c \ - zero_bytes.c redblack.c selinux.c sesh.c sudoreplay.c getdate.c \ - getdate.y getline.c timestr.c $(AUTH_SRCS) + strsignal.c sudo.c sudo_noexec.c sudo_edit.c sudo_nss.c term.c \ + testsudoers.c tgetpass.c toke.c toke.l tsgetgrpw.c utimes.c \ + vasgroups.c visudo.c zero_bytes.c redblack.c selinux.c sesh.c \ + sudoreplay.c getdate.c getdate.y getline.c timestr.c $(AUTH_SRCS) AUTH_SRCS = auth/afs.c auth/aix_auth.c auth/bsdauth.c auth/dce.c auth/fwtk.c \ auth/kerb4.c auth/kerb5.c auth/pam.c auth/passwd.c auth/rfc1938.c \ @@ -327,6 +327,8 @@ strlcat.o: $(srcdir)/strlcat.c $(srcdir)/compat.h config.h $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(OPTIONS) $(srcdir)/strlcat.c strlcpy.o: $(srcdir)/strlcpy.c $(srcdir)/compat.h config.h $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(OPTIONS) $(srcdir)/strlcpy.c +strsignal.o: $(srcdir)/strsignal.c $(srcdir)/compat.h config.h + $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(OPTIONS) $(srcdir)/strsignal.c selinux.o: $(srcdir)/selinux.c $(SUDODEP) $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(OPTIONS) $(srcdir)/selinux.c sudo.o: $(srcdir)/sudo.c $(SUDODEP) sudo_usage.h $(srcdir)/interfaces.h diff --git a/config.h.in b/config.h.in index 6ea8c3867..b40c24765 100644 --- a/config.h.in +++ b/config.h.in @@ -453,6 +453,9 @@ /* Define to 1 if you have the `strrchr' function. */ #undef HAVE_STRRCHR +/* Define to 1 if you have the `strsignal' function. */ +#undef HAVE_STRSIGNAL + /* Define to 1 if your struct stat has an st_mtim member */ #undef HAVE_ST_MTIM @@ -479,6 +482,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_SELECT_H +/* Define to 1 if you have the 'sys_siglist' symbol in libc. */ +#undef HAVE_SYS_SIGLIST + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_SOCKIO_H diff --git a/configure b/configure index c13810ff6..1afae21e4 100755 --- a/configure +++ b/configure @@ -21130,6 +21130,173 @@ fi done + +for ac_func in strsignal +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 declares $ac_func. + For example, HP-UX 11i 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 to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#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 + +else + + { echo "$as_me:$LINENO: checking for sys_siglist" >&5 +echo $ECHO_N "checking for sys_siglist... $ECHO_C" >&6; } + if test "${sudo_cv_sys_siglist+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. */ + +int +main () +{ +extern char *sys_siglist; char *hup = sys_siglist[1]; + ; + 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 + sudo_cv_sys_siglist=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + sudo_cv_sys_siglist=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +fi + + if test "$sudo_cv_sys_siglist" = "yes"; then + case " $LIBOBJS " in + *" strsignal.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS strsignal.$ac_objext" + ;; +esac + + cat >>confdefs.h <<\_ACEOF +#define HAVE_SYS_SIGLIST 1 +_ACEOF + + cat >>confdefs.h <<\_ACEOF +#define HAVE_STRSIGNAL 1 +_ACEOF + + fi + { echo "$as_me:$LINENO: result: $sudo_cv_sys_siglist" >&5 +echo "${ECHO_T}$sudo_cv_sys_siglist" >&6; } + +fi +done + + netsvc_conf='/etc/netsvc.conf' nsswitch_conf='/etc/nsswitch.conf' if test ${with_netsvc-"no"} != "no"; then diff --git a/configure.in b/configure.in index 8a3938956..ace66a2b4 100644 --- a/configure.in +++ b/configure.in @@ -1965,6 +1965,21 @@ AC_CHECK_FUNCS(getprogname, , [ AC_MSG_RESULT($sudo_cv___progname) ]) +dnl +dnl Check for strsignal() or sys_siglist +dnl +AC_CHECK_FUNCS(strsignal, [], [ + AC_MSG_CHECKING([for sys_siglist]) + AC_CACHE_VAL(sudo_cv_sys_siglist, [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[extern char *sys_siglist; char *hup = sys_siglist[1];]])], [sudo_cv_sys_siglist=yes], [sudo_cv_sys_siglist=no])]) + if test "$sudo_cv_sys_siglist" = "yes"; then + AC_LIBOBJ(strsignal) + AC_DEFINE(HAVE_SYS_SIGLIST) + AC_DEFINE(HAVE_STRSIGNAL) + fi + AC_MSG_RESULT($sudo_cv_sys_siglist) +]) + dnl dnl nsswitch.conf and its equivalents dnl diff --git a/strsignal.c b/strsignal.c new file mode 100644 index 000000000..e83b4f0b7 --- /dev/null +++ b/strsignal.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2009 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +#include +#include + +#ifndef lint +__unused static const char rcsid[] = "$Sudo$"; +#endif /* lint */ + +/* + * Get signal description string + */ +char * +strsignal(signo) + int signo; +{ + extern const char *const sys_siglist[]; + + if (signo > 0 && signo < NSIG) + return((char *)sys_siglist[signo]); + return("Unknown signal"); +} diff --git a/sudo.h b/sudo.h index 0db98fa47..38f1a9610 100644 --- a/sudo.h +++ b/sudo.h @@ -246,6 +246,9 @@ int setenv __P((const char *, const char *, int)); #ifndef HAVE_UNSETENV int unsetenv __P((const char *)); #endif +#ifdef HAVE_SYS_SIGLIST +char *strsignal __P((int)); +#endif char *sudo_goodpath __P((const char *, struct stat *)); char *tgetpass __P((const char *, int, int)); int find_path __P((char *, char **, struct stat *, char *));