summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2004-08-15 18:40:59 +1000
committerDamien Miller <djm@mindrot.org>2004-08-15 18:40:59 +1000
commit36f496502072d82dbb202b41a199eb6032557710 (patch)
tree439092c6479cb2fea8c09318b37a61370d860638
parent25f60a7ee780c2cd4a01e05698149d274821012f (diff)
- (djm) [acconfig.h configure.ac openbsd-compat/Makefile.in
openbsd-compat/bsd-closefrom.c openbsd-compat/bsd-misc.c openbsd-compat/bsd-misc.h openbsd-compat/openbsd-compat.h] Use smarter closefrom() replacement from sudo; ok dtucker@
-rw-r--r--ChangeLog6
-rw-r--r--acconfig.h5
-rw-r--r--configure.ac30
-rw-r--r--openbsd-compat/Makefile.in4
-rw-r--r--openbsd-compat/bsd-closefrom.c100
-rw-r--r--openbsd-compat/bsd-misc.c19
-rw-r--r--openbsd-compat/bsd-misc.h6
-rw-r--r--openbsd-compat/openbsd-compat.h6
8 files changed, 138 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index d1936ac1d..841c9e68f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,10 @@
120040815 120040815
2 - (dtucker) [Makefile.in ssh-keysign.c ssh.c] Use permanently_set_uid() since 2 - (dtucker) [Makefile.in ssh-keysign.c ssh.c] Use permanently_set_uid() since
3 it does the right thing on all platforms. ok djm@ 3 it does the right thing on all platforms. ok djm@
4 - (djm) [acconfig.h configure.ac openbsd-compat/Makefile.in
5 openbsd-compat/bsd-closefrom.c openbsd-compat/bsd-misc.c
6 openbsd-compat/bsd-misc.h openbsd-compat/openbsd-compat.h] Use smarter
7 closefrom() replacement from sudo; ok dtucker@
4 8
520040814 920040814
6 - (dtucker) [auth-krb5.c gss-serv-krb5.c openbsd-compat/xmmap.c] 10 - (dtucker) [auth-krb5.c gss-serv-krb5.c openbsd-compat/xmmap.c]
@@ -1635,4 +1639,4 @@
1635 - (djm) Trim deprecated options from INSTALL. Mention UsePAM 1639 - (djm) Trim deprecated options from INSTALL. Mention UsePAM
1636 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu 1640 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
1637 1641
1638$Id: ChangeLog,v 1.3509 2004/08/15 07:23:34 dtucker Exp $ 1642$Id: ChangeLog,v 1.3510 2004/08/15 08:40:59 djm Exp $
diff --git a/acconfig.h b/acconfig.h
index 4c655823f..bb069630d 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -1,4 +1,4 @@
1/* $Id: acconfig.h,v 1.178 2004/06/28 06:01:20 dtucker Exp $ */ 1/* $Id: acconfig.h,v 1.179 2004/08/15 08:40:59 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved. 4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved.
@@ -454,6 +454,9 @@
454/* Define if your resolver libs need this for getrrsetbyname */ 454/* Define if your resolver libs need this for getrrsetbyname */
455#undef BIND_8_COMPAT 455#undef BIND_8_COMPAT
456 456
457/* Define if you have /proc/$pid/fd */
458#undef HAVE_PROC_PID
459
457@BOTTOM@ 460@BOTTOM@
458 461
459/* ******************* Shouldn't need to edit below this line ************** */ 462/* ******************* Shouldn't need to edit below this line ************** */
diff --git a/configure.ac b/configure.ac
index 1579c8dd3..6954fb47e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
1# $Id: configure.ac,v 1.224 2004/07/19 17:19:27 tim Exp $ 1# $Id: configure.ac,v 1.225 2004/08/15 08:40:59 djm Exp $
2# 2#
3# Copyright (c) 1999-2004 Damien Miller 3# Copyright (c) 1999-2004 Damien Miller
4# 4#
@@ -517,16 +517,16 @@ int main(){exit(0);}
517) 517)
518 518
519# Checks for header files. 519# Checks for header files.
520AC_CHECK_HEADERS(bstring.h crypt.h endian.h features.h floatingpoint.h \ 520AC_CHECK_HEADERS(bstring.h crypt.h dirent.h endian.h features.h \
521 getopt.h glob.h ia.h lastlog.h limits.h login.h \ 521 floatingpoint.h getopt.h glob.h ia.h lastlog.h limits.h login.h \
522 login_cap.h maillock.h netdb.h netgroup.h \ 522 login_cap.h maillock.h ndir.h netdb.h netgroup.h \
523 netinet/in_systm.h pam/pam_appl.h paths.h pty.h readpassphrase.h \ 523 netinet/in_systm.h pam/pam_appl.h paths.h pty.h readpassphrase.h \
524 rpc/types.h security/pam_appl.h shadow.h stddef.h stdint.h \ 524 rpc/types.h security/pam_appl.h shadow.h stddef.h stdint.h \
525 strings.h sys/strtio.h sys/audit.h sys/bitypes.h sys/bsdtty.h \ 525 strings.h sys/dir.h sys/strtio.h sys/audit.h sys/bitypes.h \
526 sys/cdefs.h sys/mman.h sys/prctl.h sys/pstat.h sys/ptms.h \ 526 sys/bsdtty.h sys/cdefs.h sys/mman.h sys/ndir.h sys/prctl.h \
527 sys/select.h sys/stat.h sys/stream.h sys/stropts.h \ 527 sys/pstat.h sys/ptms.h sys/select.h sys/stat.h sys/stream.h \
528 sys/sysmacros.h sys/time.h sys/timers.h sys/un.h time.h tmpdir.h \ 528 sys/stropts.h sys/sysmacros.h sys/time.h sys/timers.h sys/un.h \
529 ttyent.h usersec.h util.h utime.h utmp.h utmpx.h vis.h) 529 time.h tmpdir.h ttyent.h usersec.h util.h utime.h utmp.h utmpx.h vis.h)
530 530
531# Checks for libraries. 531# Checks for libraries.
532AC_CHECK_FUNC(yp_match, , AC_CHECK_LIB(nsl, yp_match)) 532AC_CHECK_FUNC(yp_match, , AC_CHECK_LIB(nsl, yp_match))
@@ -731,6 +731,14 @@ int main(void){struct dirent d;exit(sizeof(d.d_name)<=sizeof(char));}
731 ] 731 ]
732) 732)
733 733
734AC_MSG_CHECKING([for /proc/pid/fd directory])
735if test -d "/proc/$$/fd" ; then
736 AC_DEFINE(HAVE_PROC_PID)
737 AC_MSG_RESULT(yes)
738else
739 AC_MSG_RESULT(no)
740fi
741
734# Check whether user wants S/Key support 742# Check whether user wants S/Key support
735SKEY_MSG="no" 743SKEY_MSG="no"
736AC_ARG_WITH(skey, 744AC_ARG_WITH(skey,
@@ -833,8 +841,8 @@ AC_ARG_WITH(tcp-wrappers,
833dnl Checks for library functions. Please keep in alphabetical order 841dnl Checks for library functions. Please keep in alphabetical order
834AC_CHECK_FUNCS(\ 842AC_CHECK_FUNCS(\
835 arc4random __b64_ntop b64_ntop __b64_pton b64_pton bcopy \ 843 arc4random __b64_ntop b64_ntop __b64_pton b64_pton bcopy \
836 bindresvport_sa clock closefrom fchmod fchown freeaddrinfo futimes \ 844 bindresvport_sa clock closefrom dirfd fchmod fchown freeaddrinfo \
837 getaddrinfo getcwd getgrouplist getnameinfo getopt \ 845 futimes getaddrinfo getcwd getgrouplist getnameinfo getopt \
838 getpeereid _getpty getrlimit getttyent glob inet_aton \ 846 getpeereid _getpty getrlimit getttyent glob inet_aton \
839 inet_ntoa inet_ntop innetgr login_getcapbool md5_crypt memmove \ 847 inet_ntoa inet_ntop innetgr login_getcapbool md5_crypt memmove \
840 mkdtemp mmap ngetaddrinfo nsleep ogetaddrinfo openlog_r openpty \ 848 mkdtemp mmap ngetaddrinfo nsleep ogetaddrinfo openlog_r openpty \
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index 5de20abbc..0f34f2240 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.30 2004/01/21 06:07:23 djm Exp $ 1# $Id: Makefile.in,v 1.31 2004/08/15 08:41:00 djm Exp $
2 2
3sysconfdir=@sysconfdir@ 3sysconfdir=@sysconfdir@
4piddir=@piddir@ 4piddir=@piddir@
@@ -18,7 +18,7 @@ LDFLAGS=-L. @LDFLAGS@
18 18
19OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtoul.o vis.o 19OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtoul.o vis.o
20 20
21COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-snprintf.o bsd-waitpid.o fake-rfc2553.o xmmap.o xcrypt.o 21COMPAT=bsd-arc4random.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-snprintf.o bsd-waitpid.o fake-rfc2553.o xmmap.o xcrypt.o
22 22
23PORTS=port-irix.o port-aix.o 23PORTS=port-irix.o port-aix.o
24 24
diff --git a/openbsd-compat/bsd-closefrom.c b/openbsd-compat/bsd-closefrom.c
new file mode 100644
index 000000000..61a9fa391
--- /dev/null
+++ b/openbsd-compat/bsd-closefrom.c
@@ -0,0 +1,100 @@
1/*
2 * Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "includes.h"
18
19#ifndef HAVE_CLOSEFROM
20
21#include <sys/types.h>
22#include <sys/param.h>
23#include <unistd.h>
24#include <stdio.h>
25#include <limits.h>
26#include <stdlib.h>
27#include <stddef.h>
28#ifdef HAVE_DIRENT_H
29# include <dirent.h>
30# define NAMLEN(dirent) strlen((dirent)->d_name)
31#else
32# define dirent direct
33# define NAMLEN(dirent) (dirent)->d_namlen
34# ifdef HAVE_SYS_NDIR_H
35# include <sys/ndir.h>
36# endif
37# ifdef HAVE_SYS_DIR_H
38# include <sys/dir.h>
39# endif
40# ifdef HAVE_NDIR_H
41# include <ndir.h>
42# endif
43#endif
44
45#ifndef OPEN_MAX
46# define OPEN_MAX 256
47#endif
48
49RCSID("$Id: bsd-closefrom.c,v 1.1 2004/08/15 08:41:00 djm Exp $");
50
51#ifndef lint
52static const char sudorcsid[] = "$Sudo: closefrom.c,v 1.6 2004/06/01 20:51:56 millert Exp $";
53#endif /* lint */
54
55/*
56 * Close all file descriptors greater than or equal to lowfd.
57 */
58void
59closefrom(int lowfd)
60{
61 long fd, maxfd;
62#if defined(HAVE_DIRFD) && defined(HAVE_PROC_PID)
63 char fdpath[PATH_MAX], *endp;
64 struct dirent *dent;
65 DIR *dirp;
66 int len;
67
68 /* Check for a /proc/$$/fd directory. */
69 len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid());
70 if (len != -1 && len <= sizeof(fdpath) && (dirp = opendir(fdpath))) {
71 while ((dent = readdir(dirp)) != NULL) {
72 fd = strtol(dent->d_name, &endp, 10);
73 if (dent->d_name != endp && *endp == '\0' &&
74 fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp))
75 (void) close((int) fd);
76 }
77 (void) closedir(dirp);
78 } else
79#endif
80 {
81 /*
82 * Fall back on sysconf() or getdtablesize(). We avoid checking
83 * resource limits since it is possible to open a file descriptor
84 * and then drop the rlimit such that it is below the open fd.
85 */
86#ifdef HAVE_SYSCONF
87 maxfd = sysconf(_SC_OPEN_MAX);
88#else
89 maxfd = getdtablesize();
90#endif /* HAVE_SYSCONF */
91 if (maxfd < 0)
92 maxfd = OPEN_MAX;
93
94 for (fd = lowfd; fd < maxfd; fd++)
95 (void) close((int) fd);
96 }
97}
98
99#endif /* HAVE_CLOSEFROM */
100
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c
index 3a30b6e4f..1b276b4f4 100644
--- a/openbsd-compat/bsd-misc.c
+++ b/openbsd-compat/bsd-misc.c
@@ -1,3 +1,4 @@
1
1/* 2/*
2 * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
3 * 4 *
@@ -17,7 +18,7 @@
17#include "includes.h" 18#include "includes.h"
18#include "xmalloc.h" 19#include "xmalloc.h"
19 20
20RCSID("$Id: bsd-misc.c,v 1.24 2004/08/13 08:37:21 dtucker Exp $"); 21RCSID("$Id: bsd-misc.c,v 1.25 2004/08/15 08:41:00 djm Exp $");
21 22
22#ifndef HAVE___PROGNAME 23#ifndef HAVE___PROGNAME
23char *__progname; 24char *__progname;
@@ -196,22 +197,6 @@ tcsendbreak(int fd, int duration)
196} 197}
197#endif /* HAVE_TCSENDBREAK */ 198#endif /* HAVE_TCSENDBREAK */
198 199
199#ifndef HAVE_CLOSEFROM
200int
201closefrom(int fd)
202{
203 int i, result = 0, err = 0;
204
205 for (i = fd; i < 128; i++)
206 if (close(i) != 0) {
207 err = errno;
208 result = -1;
209 }
210 errno = err;
211 return result;
212}
213#endif /* HAVE_CLOSEFROM */
214
215mysig_t 200mysig_t
216mysignal(int sig, mysig_t act) 201mysignal(int sig, mysig_t act)
217{ 202{
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h
index 7027815d6..33a1d707f 100644
--- a/openbsd-compat/bsd-misc.h
+++ b/openbsd-compat/bsd-misc.h
@@ -1,4 +1,4 @@
1/* $Id: bsd-misc.h,v 1.16 2004/06/25 04:03:34 dtucker Exp $ */ 1/* $Id: bsd-misc.h,v 1.17 2004/08/15 08:41:00 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org> 4 * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
@@ -93,10 +93,6 @@ int tcsendbreak(int, int);
93void unsetenv(const char *); 93void unsetenv(const char *);
94#endif 94#endif
95 95
96#ifndef HAVE_CLOSEFROM
97int closefrom(int);
98#endif
99
100/* wrapper for signal interface */ 96/* wrapper for signal interface */
101typedef void (*mysig_t)(int); 97typedef void (*mysig_t)(int);
102mysig_t mysignal(int sig, mysig_t act); 98mysig_t mysignal(int sig, mysig_t act);
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index 6be1bcda4..89d1454e0 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
1/* $Id: openbsd-compat.h,v 1.25 2004/01/21 06:07:23 djm Exp $ */ 1/* $Id: openbsd-compat.h,v 1.26 2004/08/15 08:41:00 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved. 4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved.
@@ -48,6 +48,10 @@ char *basename(const char *path);
48int bindresvport_sa(int sd, struct sockaddr *sa); 48int bindresvport_sa(int sd, struct sockaddr *sa);
49#endif 49#endif
50 50
51#ifndef HAVE_CLOSEFROM
52void closefrom(int);
53#endif
54
51#ifndef HAVE_GETCWD 55#ifndef HAVE_GETCWD
52char *getcwd(char *pt, size_t size); 56char *getcwd(char *pt, size_t size);
53#endif 57#endif