From: Todd C. Miller Date: Mon, 12 Jan 2004 19:03:54 +0000 (+0000) Subject: Use closefrom() instead of doing the equivalent inline. X-Git-Tag: SUDO_1_6_8~245 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d55c3f63c751815e0b00c526261f4e0f952791ca;p=sudo Use closefrom() instead of doing the equivalent inline. --- diff --git a/Makefile.in b/Makefile.in index f81c20b27..23402b235 100644 --- a/Makefile.in +++ b/Makefile.in @@ -116,9 +116,9 @@ SHELL = /bin/sh PROGS = @PROGS@ -SRCS = alloc.c alloca.c check.c def_data.c defaults.c env.c err.c fileops.c \ - find_path.c fnmatch.c getcwd.c getprogname.c getspwuid.c goodpath.c \ - interfaces.c lex.yy.c lsearch.c logging.c parse.c parse.lex \ +SRCS = alloc.c alloca.c check.c closefrom.c def_data.c defaults.c env.c err.c \ + fileops.c find_path.c fnmatch.c getcwd.c getprogname.c getspwuid.c \ + goodpath.c interfaces.c lex.yy.c lsearch.c logging.c parse.c parse.lex \ parse.yacc set_perms.c sigaction.c snprintf.c strcasecmp.c strerror.c \ strlcat.c strlcpy.c sudo.c sudo.tab.c testsudoers.c tgetpass.c utime.c \ visudo.c zero_bytes.c $(AUTH_SRCS) @@ -219,6 +219,7 @@ sudo_noexec.la: sudo_noexec.lo # Dependencies (not counting auth functions) alloc.o: alloc.c $(SUDODEP) check.o: check.c $(SUDODEP) +closefrom.o: closefrom.c config.h env.o: env.c $(SUDODEP) err.o: err.c config.h compat.h emul/err.h fileops.o: fileops.c $(SUDODEP) diff --git a/config.h.in b/config.h.in index 9943f4baf..6bb3eb295 100644 --- a/config.h.in +++ b/config.h.in @@ -65,6 +65,9 @@ /* Define if you use BSD authentication. */ #undef HAVE_BSD_AUTH_H +/* Define to 1 if you have the `closefrom' function. */ +#undef HAVE_CLOSEFROM + /* Define if you use OSF DCE. */ #undef HAVE_DCE diff --git a/configure b/configure index 882890bfd..65ab8ddf9 100755 --- a/configure +++ b/configure @@ -26017,7 +26017,8 @@ _ACEOF -for ac_func in strerror strcasecmp sigaction strlcpy strlcat + +for ac_func in strerror strcasecmp sigaction strlcpy strlcat closefrom do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 diff --git a/configure.in b/configure.in index 1aa699eb0..75fce58b7 100644 --- a/configure.in +++ b/configure.in @@ -1687,7 +1687,7 @@ AC_CHECK_FUNCS(lsearch, , [AC_CHECK_LIB(compat, lsearch, AC_CHECK_HEADER(search. AC_CHECK_FUNCS(utime, [SUDO_FUNC_UTIME_POSIX], [AC_LIBOBJ(utime)]) SUDO_FUNC_FNMATCH(AC_DEFINE(HAVE_FNMATCH, 1, [Define if you have the `fnmatch' function.]), AC_LIBOBJ(fnmatch)) SUDO_FUNC_ISBLANK -AC_REPLACE_FUNCS(strerror strcasecmp sigaction strlcpy strlcat) +AC_REPLACE_FUNCS(strerror strcasecmp sigaction strlcpy strlcat closefrom) AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf, , [NEED_SNPRINTF=1]) dnl dnl If NEED_SNPRINTF is set, add snprintf.c to LIBOBJS diff --git a/sudo.c b/sudo.c index dcce57fac..21ac19c79 100644 --- a/sudo.c +++ b/sudo.c @@ -863,12 +863,9 @@ check_sudoers() static void initial_setup() { - int fd, maxfd; -#ifdef HAVE_SETRLIMIT +#if defined(RLIMIT_CORE) && !defined(SUDO_DEVEL) struct rlimit rl; -#endif -#if defined(RLIMIT_CORE) && !defined(SUDO_DEVEL) /* * Turn off core dumps. */ @@ -878,23 +875,7 @@ initial_setup() (void) setrlimit(RLIMIT_CORE, &rl); #endif /* RLIMIT_CORE && !SUDO_DEVEL */ - /* - * Close any open fd's other than stdin, stdout and stderr. - */ -#ifdef HAVE_SYSCONF - maxfd = sysconf(_SC_OPEN_MAX) - 1; -#else - maxfd = getdtablesize() - 1; -#endif /* HAVE_SYSCONF */ -#ifdef RLIMIT_NOFILE - if (getrlimit(RLIMIT_NOFILE, &rl) == 0) { - if (rl.rlim_max != RLIM_INFINITY && rl.rlim_max <= maxfd) - maxfd = rl.rlim_max - 1; - } -#endif /* RLIMIT_NOFILE */ - - for (fd = maxfd; fd > STDERR_FILENO; fd--) - (void) close(fd); + closefrom(STDERR_FILENO + 1); /* * Make set_perms point to the correct function. diff --git a/sudo.h b/sudo.h index 231668295..cc919d79b 100644 --- a/sudo.h +++ b/sudo.h @@ -172,6 +172,9 @@ struct sudo_user { */ #define YY_DECL int yylex __P((void)) +#ifndef HAVE_CLOSEFROM +void closefrom __P((int)); +#endif #ifndef HAVE_GETCWD char *getcwd __P((char *, size_t size)); #endif