]> granicus.if.org Git - sudo/commitdiff
Use closefrom() instead of doing the equivalent inline.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 12 Jan 2004 19:03:54 +0000 (19:03 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 12 Jan 2004 19:03:54 +0000 (19:03 +0000)
Makefile.in
config.h.in
configure
configure.in
sudo.c
sudo.h

index f81c20b274dc9f924ad47606c14b70bd360f8a53..23402b235b1e6858dfc34c7562d5e1ac73bf5e8c 100644 (file)
@@ -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)
index 9943f4baf6faed122562047af1cbb9c059c3b84d..6bb3eb295fc3294ee5d3462fb202b1b19cf1d8fe 100644 (file)
@@ -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
 
index 882890bfd4f89745740d1e317715b60ebf5f7a1b..65ab8ddf9f107b1bf728b8b31ac72702f3a13ef0 100755 (executable)
--- 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
index 1aa699eb009d08ad1dab6942b8dbb16fd6dd7b53..75fce58b77cd6fd2acec34e29984c3c2ad6256d7 100644 (file)
@@ -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 dcce57fac86b9f84ed1458fc807feeada0e6ac14..21ac19c791f5003ac837875ed54ad550569d341b 100644 (file)
--- 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 2316682955f4171be9703e20447f0310cb97dc19..cc919d79b73db17c3f0dcbb3be612961612e7e2c 100644 (file)
--- 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