From 536c83cec31f356f2817d25212cf6872c76a5a76 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 3 Feb 2015 07:33:24 -0700 Subject: [PATCH] Solaris uses sysinfo(SI_SRPC_DOMAIN) instead of getdomainname() to get the host's NIS domain. --- config.h.in | 6 ++++++ configure | 30 ++++++++++++++++++++++++++++-- configure.ac | 5 ++++- plugins/sudoers/match.c | 17 ++++++++++++++--- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/config.h.in b/config.h.in index 50280146d..c3479ffa8 100644 --- a/config.h.in +++ b/config.h.in @@ -741,6 +741,9 @@ /* Define to 1 if you have the `sysctl' function. */ #undef HAVE_SYSCTL +/* Define to 1 if you have the `sysinfo' function. */ +#undef HAVE_SYSINFO + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_BSDTYPES_H @@ -776,6 +779,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_SYSMACROS_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SYSTEMINFO_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H diff --git a/configure b/configure index 8b9ad558e..c94b6ca38 100755 --- a/configure +++ b/configure @@ -18653,7 +18653,11 @@ if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF - for ac_func in getdomainname + break +fi +done + +for ac_func in getdomainname do : ac_fn_c_check_func "$LINENO" "getdomainname" "ac_cv_func_getdomainname" if test "x$ac_cv_func_getdomainname" = xyes; then : @@ -18661,9 +18665,31 @@ if test "x$ac_cv_func_getdomainname" = xyes; then : #define HAVE_GETDOMAINNAME 1 _ACEOF +else + + for ac_func in sysinfo +do : + ac_fn_c_check_func "$LINENO" "sysinfo" "ac_cv_func_sysinfo" +if test "x$ac_cv_func_sysinfo" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_SYSINFO 1 +_ACEOF + for ac_header in sys/systeminfo.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "sys/systeminfo.h" "ac_cv_header_sys_systeminfo_h" "$ac_includes_default" +if test "x$ac_cv_header_sys_systeminfo_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_SYS_SYSTEMINFO_H 1 +_ACEOF + fi + done - break + +fi +done + + fi done diff --git a/configure.ac b/configure.ac index 6561ca6a8..9231065b0 100644 --- a/configure.ac +++ b/configure.ac @@ -2452,7 +2452,10 @@ if test X"$with_interfaces" != X"no"; then AC_CHECK_FUNCS([getifaddrs], [AC_CHECK_FUNCS([freeifaddrs])]) fi AC_CHECK_FUNCS([lockf flock], [break]) -AC_CHECK_FUNCS([innetgr _innetgr], [AC_CHECK_FUNCS([getdomainname]) [break]]) +AC_CHECK_FUNCS([innetgr _innetgr], [break]) +AC_CHECK_FUNCS([getdomainname], [], [ + AC_CHECK_FUNCS([sysinfo], [AC_CHECK_HEADERS([sys/systeminfo.h])]) +]) AC_CHECK_FUNCS([utimes], [ AC_CHECK_FUNCS([futimes futimesat], [break]) ], [ diff --git a/plugins/sudoers/match.c b/plugins/sudoers/match.c index 03c929302..59b1bfbbe 100644 --- a/plugins/sudoers/match.c +++ b/plugins/sudoers/match.c @@ -25,6 +25,9 @@ #include #include +#ifdef HAVE_SYS_SYSTEMINFO_H +# include +#endif #include #ifdef STDC_HEADERS # include @@ -912,12 +915,20 @@ const char * sudo_getdomainname(void) { char *domain = NULL; -#ifdef HAVE_GETDOMAINNAME +#if defined(HAVE_GETDOMAINNAME) || defined(SI_SRPC_DOMAIN) static char buf[HOST_NAME_MAX + 1]; static bool initialized; if (!initialized) { - if (getdomainname(buf, sizeof(buf)) == 0 && buf[0] != '\0') { + int rval; + +# ifdef SI_SRPC_DOMAIN + buf[0] = '\0'; + rval = sysinfo(SI_SRPC_DOMAIN, buf, sizeof(buf)); +# else + rval = getdomainname(buf, sizeof(buf)); +# endif + if (rval != -1 && buf[0] != '\0') { char *cp; domain = buf; @@ -931,7 +942,7 @@ sudo_getdomainname(void) } initialized = true; } -#endif /* HAVE_GETDOMAINNAME */ +#endif /* HAVE_GETDOMAINNAME || SI_SRPC_DOMAIN */ return domain; } -- 2.40.0