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.
This commit is contained in:
Todd C. Miller
2015-02-19 09:59:25 -07:00
parent 7d1ee77136
commit 96eddddc12
8 changed files with 10 additions and 44 deletions

View File

@@ -117,10 +117,6 @@
don't. */ don't. */
#undef HAVE_DECL_LLONG_MIN #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 /* Define to 1 if you have the declaration of `PATH_MAX', and to 0 if you
don't. */ don't. */
#undef HAVE_DECL_PATH_MAX #undef HAVE_DECL_PATH_MAX
@@ -754,9 +750,6 @@
/* Define to 1 if your struct stat uses an st__tim union. */ /* Define to 1 if your struct stat uses an st__tim union. */
#undef HAVE_ST__TIM #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. */ /* Define to 1 if you have the `sysctl' function. */
#undef HAVE_SYSCTL #undef HAVE_SYSCTL

17
configure vendored
View File

@@ -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 " killpg"
as_fn_append ac_func_list " nl_langinfo" as_fn_append ac_func_list " nl_langinfo"
as_fn_append ac_func_list " strftime" 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 " tzset"
as_fn_append ac_func_list " seteuid" as_fn_append ac_func_list " seteuid"
# Check that the precious variables saved in the cache have kept the same # Check that the precious variables saved in the cache have kept the same
@@ -18381,8 +18380,6 @@ done
for ac_func in getgrouplist for ac_func in getgrouplist
do : do :
ac_fn_c_check_func "$LINENO" "getgrouplist" "ac_cv_func_getgrouplist" ac_fn_c_check_func "$LINENO" "getgrouplist" "ac_cv_func_getgrouplist"
@@ -21284,20 +21281,6 @@ _ACEOF
_CFLAGS="$CFLAGS" _CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $OSDEFS" CFLAGS="$CFLAGS $OSDEFS"
ac_fn_c_check_decl "$LINENO" "OPEN_MAX" "ac_cv_have_decl_OPEN_MAX" "
#include <sys/types.h>
#include <limits.h>
"
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" " ac_fn_c_check_decl "$LINENO" "LLONG_MAX" "ac_cv_have_decl_LLONG_MAX" "
#include <sys/types.h> #include <sys/types.h>
#include <limits.h> #include <limits.h>

View File

@@ -2349,7 +2349,7 @@ dnl
dnl Function checks dnl Function checks
dnl dnl
AC_FUNC_GETGROUPS 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], [], [ AC_CHECK_FUNCS([getgrouplist], [], [
case "$host_os" in case "$host_os" in
aix*) aix*)
@@ -3010,7 +3010,7 @@ dnl We need to add OSDEFS to CFLAGS to expose LLONG_MAX et al on glibc.
dnl dnl
_CFLAGS="$CFLAGS" _CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $OSDEFS" 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 <sys/types.h> #include <sys/types.h>
#include <limits.h> #include <limits.h>
]) ])

View File

@@ -120,10 +120,6 @@
/* /*
* Some systems lack full limit definitions. * 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_LLONG_MAX) && !HAVE_DECL_LLONG_MAX
# if defined(HAVE_DECL_QUAD_MAX) && HAVE_DECL_QUAD_MAX # if defined(HAVE_DECL_QUAD_MAX) && HAVE_DECL_QUAD_MAX
# define LLONG_MAX QUAD_MAX # define LLONG_MAX QUAD_MAX

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004-2005, 2007, 2010, 2012-2014 * Copyright (c) 2004-2005, 2007, 2010, 2012-2015
* Todd C. Miller <Todd.Miller@courtesan.com> * Todd C. Miller <Todd.Miller@courtesan.com>
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
@@ -55,6 +55,10 @@
#include "sudo_compat.h" #include "sudo_compat.h"
#ifndef _POSIX_OPEN_MAX
# define _POSIX_OPEN_MAX 20
#endif
#if defined(HAVE_FCNTL_CLOSEM) && !defined(HAVE_DIRFD) #if defined(HAVE_FCNTL_CLOSEM) && !defined(HAVE_DIRFD)
# define sudo_closefrom closefrom_fallback # define sudo_closefrom closefrom_fallback
#endif #endif
@@ -69,17 +73,13 @@ closefrom_fallback(int lowfd)
long fd, maxfd; 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 * resource limits since it is possible to open a file descriptor
* and then drop the rlimit such that it is below the open fd. * and then drop the rlimit such that it is below the open fd.
*/ */
#ifdef HAVE_SYSCONF
maxfd = sysconf(_SC_OPEN_MAX); maxfd = sysconf(_SC_OPEN_MAX);
#else
maxfd = getdtablesize();
#endif /* HAVE_SYSCONF */
if (maxfd < 0) if (maxfd < 0)
maxfd = OPEN_MAX; maxfd = _POSIX_OPEN_MAX;
for (fd = lowfd; fd < maxfd; fd++) { for (fd = lowfd; fd < maxfd; fd++) {
#ifdef __APPLE__ #ifdef __APPLE__

View File

@@ -48,10 +48,8 @@ sudo_setgroups_v1(int ngids, const GETGROUPS_T *gids)
rval = setgroups(ngids, (GETGROUPS_T *)gids); rval = setgroups(ngids, (GETGROUPS_T *)gids);
if (rval == -1 && errno == EINVAL) { if (rval == -1 && errno == EINVAL) {
/* Too many groups, try again with fewer. */ /* Too many groups, try again with fewer. */
#if defined(HAVE_SYSCONF) && defined(_SC_NGROUPS_MAX)
maxgids = (int)sysconf(_SC_NGROUPS_MAX); maxgids = (int)sysconf(_SC_NGROUPS_MAX);
if (maxgids == -1) if (maxgids == -1)
#endif
maxgids = NGROUPS_MAX; maxgids = NGROUPS_MAX;
if (ngids > maxgids) if (ngids > maxgids)
rval = setgroups(maxgids, (GETGROUPS_T *)gids); rval = setgroups(maxgids, (GETGROUPS_T *)gids);

View File

@@ -248,10 +248,8 @@ sudo_make_grlist_item(const struct passwd *pw, char * const *unused1,
gids = sudo_emallocarray(ngids, sizeof(GETGROUPS_T)); gids = sudo_emallocarray(ngids, sizeof(GETGROUPS_T));
(void)getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids); (void)getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids);
} else { } else {
#if defined(HAVE_SYSCONF) && defined(_SC_NGROUPS_MAX)
ngids = (int)sysconf(_SC_NGROUPS_MAX) * 2; ngids = (int)sysconf(_SC_NGROUPS_MAX) * 2;
if (ngids < 0) if (ngids < 0)
#endif
ngids = NGROUPS_MAX * 2; ngids = NGROUPS_MAX * 2;
gids = sudo_emallocarray(ngids, sizeof(GETGROUPS_T)); gids = sudo_emallocarray(ngids, sizeof(GETGROUPS_T));
if (getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids) == -1) { 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); aix_setauthdb((char *) pw->pw_name);
#endif #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); groupname_len = MAX((int)sysconf(_SC_LOGIN_NAME_MAX), 32);
#else #else
groupname_len = MAX(LOGIN_NAME_MAX, 32); groupname_len = MAX(LOGIN_NAME_MAX, 32);

View File

@@ -397,10 +397,8 @@ get_user_groups(struct user_details *ud)
int i, len, maxgroups, group_source; int i, len, maxgroups, group_source;
debug_decl(get_user_groups, SUDO_DEBUG_UTIL) debug_decl(get_user_groups, SUDO_DEBUG_UTIL)
#if defined(HAVE_SYSCONF) && defined(_SC_NGROUPS_MAX)
maxgroups = (int)sysconf(_SC_NGROUPS_MAX); maxgroups = (int)sysconf(_SC_NGROUPS_MAX);
if (maxgroups < 0) if (maxgroups < 0)
#endif
maxgroups = NGROUPS_MAX; maxgroups = NGROUPS_MAX;
ud->groups = NULL; ud->groups = NULL;