From 96eddddc12cacc0f5cd767431ae8e1436559bb94 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 19 Feb 2015 09:59:25 -0700 Subject: [PATCH] Almost no systems actually define OPEN_MAX since it is dynamic on modern OSes. If sysconf(_SC_OPEN_MAX) ever fails, fall back on _POSIX_OPEN_MAX instead. We can assume modern systems have sysconf(). Also remove checks for strrchr() and strtoll() for which the HAVE_* defines are no longer used. --- config.h.in | 7 ------- configure | 17 ----------------- configure.ac | 4 ++-- include/sudo_compat.h | 4 ---- lib/util/closefrom.c | 14 +++++++------- lib/util/setgroups.c | 2 -- plugins/sudoers/pwutil_impl.c | 4 +--- src/sudo.c | 2 -- 8 files changed, 10 insertions(+), 44 deletions(-) diff --git a/config.h.in b/config.h.in index 83534da00..5d36f60d6 100644 --- a/config.h.in +++ b/config.h.in @@ -117,10 +117,6 @@ don't. */ #undef HAVE_DECL_LLONG_MIN -/* Define to 1 if you have the declaration of `OPEN_MAX', and to 0 if you - don't. */ -#undef HAVE_DECL_OPEN_MAX - /* Define to 1 if you have the declaration of `PATH_MAX', and to 0 if you don't. */ #undef HAVE_DECL_PATH_MAX @@ -754,9 +750,6 @@ /* Define to 1 if your struct stat uses an st__tim union. */ #undef HAVE_ST__TIM -/* Define to 1 if you have the `sysconf' function. */ -#undef HAVE_SYSCONF - /* Define to 1 if you have the `sysctl' function. */ #undef HAVE_SYSCTL diff --git a/configure b/configure index 85108fbf8..b12ca34bf 100755 --- a/configure +++ b/configure @@ -2833,7 +2833,6 @@ as_fn_append ac_header_list " sys/sysmacros.h" as_fn_append ac_func_list " killpg" as_fn_append ac_func_list " nl_langinfo" as_fn_append ac_func_list " strftime" -as_fn_append ac_func_list " sysconf" as_fn_append ac_func_list " tzset" as_fn_append ac_func_list " seteuid" # Check that the precious variables saved in the cache have kept the same @@ -18381,8 +18380,6 @@ done - - for ac_func in getgrouplist do : ac_fn_c_check_func "$LINENO" "getgrouplist" "ac_cv_func_getgrouplist" @@ -21284,20 +21281,6 @@ _ACEOF _CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $OSDEFS" -ac_fn_c_check_decl "$LINENO" "OPEN_MAX" "ac_cv_have_decl_OPEN_MAX" " -#include -#include - -" -if test "x$ac_cv_have_decl_OPEN_MAX" = xyes; then : - ac_have_decl=1 -else - ac_have_decl=0 -fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_OPEN_MAX $ac_have_decl -_ACEOF ac_fn_c_check_decl "$LINENO" "LLONG_MAX" "ac_cv_have_decl_LLONG_MAX" " #include #include diff --git a/configure.ac b/configure.ac index 416e2b2ff..e0a4063cd 100644 --- a/configure.ac +++ b/configure.ac @@ -2349,7 +2349,7 @@ dnl dnl Function checks dnl AC_FUNC_GETGROUPS -AC_CHECK_FUNCS_ONCE([killpg nl_langinfo strftime sysconf tzset]) +AC_CHECK_FUNCS_ONCE([killpg nl_langinfo strftime tzset]) AC_CHECK_FUNCS([getgrouplist], [], [ case "$host_os" in aix*) @@ -3010,7 +3010,7 @@ dnl We need to add OSDEFS to CFLAGS to expose LLONG_MAX et al on glibc. dnl _CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $OSDEFS" -AC_CHECK_DECLS([OPEN_MAX, LLONG_MAX, LLONG_MIN, ULLONG_MAX, PATH_MAX, HOST_NAME_MAX], [], [], [ +AC_CHECK_DECLS([LLONG_MAX, LLONG_MIN, ULLONG_MAX, PATH_MAX, HOST_NAME_MAX], [], [], [ #include #include ]) diff --git a/include/sudo_compat.h b/include/sudo_compat.h index f20513dcc..0f649e9c5 100644 --- a/include/sudo_compat.h +++ b/include/sudo_compat.h @@ -120,10 +120,6 @@ /* * Some systems lack full limit definitions. */ -#if defined(HAVE_DECL_OPEN_MAX) && !HAVE_DECL_OPEN_MAX -# define OPEN_MAX 256 -#endif - #if defined(HAVE_DECL_LLONG_MAX) && !HAVE_DECL_LLONG_MAX # if defined(HAVE_DECL_QUAD_MAX) && HAVE_DECL_QUAD_MAX # define LLONG_MAX QUAD_MAX diff --git a/lib/util/closefrom.c b/lib/util/closefrom.c index 625c48eb3..27c01d22b 100644 --- a/lib/util/closefrom.c +++ b/lib/util/closefrom.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2005, 2007, 2010, 2012-2014 + * Copyright (c) 2004-2005, 2007, 2010, 2012-2015 * Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any @@ -55,6 +55,10 @@ #include "sudo_compat.h" +#ifndef _POSIX_OPEN_MAX +# define _POSIX_OPEN_MAX 20 +#endif + #if defined(HAVE_FCNTL_CLOSEM) && !defined(HAVE_DIRFD) # define sudo_closefrom closefrom_fallback #endif @@ -69,17 +73,13 @@ closefrom_fallback(int lowfd) long fd, maxfd; /* - * Fall back on sysconf() or getdtablesize(). We avoid checking + * Fall back on sysconf(_SC_OPEN_MAX). We avoid checking * resource limits since it is possible to open a file descriptor * and then drop the rlimit such that it is below the open fd. */ -#ifdef HAVE_SYSCONF maxfd = sysconf(_SC_OPEN_MAX); -#else - maxfd = getdtablesize(); -#endif /* HAVE_SYSCONF */ if (maxfd < 0) - maxfd = OPEN_MAX; + maxfd = _POSIX_OPEN_MAX; for (fd = lowfd; fd < maxfd; fd++) { #ifdef __APPLE__ diff --git a/lib/util/setgroups.c b/lib/util/setgroups.c index 82dc77d47..18843b39c 100644 --- a/lib/util/setgroups.c +++ b/lib/util/setgroups.c @@ -48,10 +48,8 @@ sudo_setgroups_v1(int ngids, const GETGROUPS_T *gids) rval = setgroups(ngids, (GETGROUPS_T *)gids); if (rval == -1 && errno == EINVAL) { /* Too many groups, try again with fewer. */ -#if defined(HAVE_SYSCONF) && defined(_SC_NGROUPS_MAX) maxgids = (int)sysconf(_SC_NGROUPS_MAX); if (maxgids == -1) -#endif maxgids = NGROUPS_MAX; if (ngids > maxgids) rval = setgroups(maxgids, (GETGROUPS_T *)gids); diff --git a/plugins/sudoers/pwutil_impl.c b/plugins/sudoers/pwutil_impl.c index ab3731306..4e50d0342 100644 --- a/plugins/sudoers/pwutil_impl.c +++ b/plugins/sudoers/pwutil_impl.c @@ -248,10 +248,8 @@ sudo_make_grlist_item(const struct passwd *pw, char * const *unused1, gids = sudo_emallocarray(ngids, sizeof(GETGROUPS_T)); (void)getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids); } else { -#if defined(HAVE_SYSCONF) && defined(_SC_NGROUPS_MAX) ngids = (int)sysconf(_SC_NGROUPS_MAX) * 2; if (ngids < 0) -#endif ngids = NGROUPS_MAX * 2; gids = sudo_emallocarray(ngids, sizeof(GETGROUPS_T)); if (getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids) == -1) { @@ -271,7 +269,7 @@ sudo_make_grlist_item(const struct passwd *pw, char * const *unused1, aix_setauthdb((char *) pw->pw_name); #endif -#if defined(HAVE_SYSCONF) && defined(_SC_LOGIN_NAME_MAX) +#ifdef _SC_LOGIN_NAME_MAX groupname_len = MAX((int)sysconf(_SC_LOGIN_NAME_MAX), 32); #else groupname_len = MAX(LOGIN_NAME_MAX, 32); diff --git a/src/sudo.c b/src/sudo.c index 438a10ab0..fdcb941f2 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -397,10 +397,8 @@ get_user_groups(struct user_details *ud) int i, len, maxgroups, group_source; debug_decl(get_user_groups, SUDO_DEBUG_UTIL) -#if defined(HAVE_SYSCONF) && defined(_SC_NGROUPS_MAX) maxgroups = (int)sysconf(_SC_NGROUPS_MAX); if (maxgroups < 0) -#endif maxgroups = NGROUPS_MAX; ud->groups = NULL; -- 2.40.0