diff --git a/autologin/autologin.c b/autologin/autologin.c index fcc2a7d..ccf8a88 100644 --- a/autologin/autologin.c +++ b/autologin/autologin.c @@ -206,9 +206,13 @@ Process(void) /* Close open files */ +#if HAVE_CLOSEFROM + closefrom((char *)0 == pcTty ? 3 : 0); +#else for (i = (char *)0 == pcTty ? 3 : 0; i < getdtablesize(); ++i) { (void)close(i); } +#endif /* Make us a session leader so that when we open /dev/tty * it will become our controlling terminal. diff --git a/conserver/consent.c b/conserver/consent.c index fc0d045..e37e226 100644 --- a/conserver/consent.c +++ b/conserver/consent.c @@ -454,11 +454,19 @@ StartInit(CONSENT *pCE) /* setup new process with clean file descriptors */ +#if HAVE_CLOSEFROM + for (i = 3; i <= pout[0] || i <= pin[1]; i++) { + if (i != pout[0] && i != pin[1]) + close(i); + } + closefrom(i); +#else i = GetMaxFiles(); for ( /* i above */ ; --i > 2;) { if (i != pout[0] && i != pin[1]) close(i); } +#endif /* leave 2 until we have to close it */ close(1); close(0); @@ -592,11 +600,18 @@ VirtDev(CONSENT *pCE) /* setup new process with clean filew descriptors */ +#if HAVE_CLOSEFROM + for (i = 3; i < pCE->execSlaveFD; i++) + close(i); + i++; + closefrom(i); +#else i = GetMaxFiles(); for ( /* i above */ ; --i > 2;) { if (i != pCE->execSlaveFD) close(i); } +#endif /* leave 2 until we *have to close it* */ close(1); diff --git a/conserver/group.c b/conserver/group.c index b89897c..8307c02 100644 --- a/conserver/group.c +++ b/conserver/group.c @@ -1810,10 +1810,14 @@ StartTask(CONSENT *pCE, char *cmd, uid_t uid, gid_t gid) /* setup new process with clean file descriptors */ +#if HAVE_CLOSEFROM + closefrom(3); +#else i = GetMaxFiles(); for ( /* i above */ ; --i > 2;) { close(i); } +#endif if (geteuid() == 0) { if (gid != 0) diff --git a/console/console.c b/console/console.c index e900c2e..3af1e4f 100644 --- a/console/console.c +++ b/console/console.c @@ -910,11 +910,19 @@ ExecCmd(void) /* setup new process with clean file descriptors * stderr still goes to stderr...so user sees it */ +#ifdef HAVE_CLOSEFROM + for (i = 3; i <= pout[0] || i <= pin[1]; i++) { + if (i != pout[0] && i != pin[1]) + close(i); + } + closefrom(i); +#else i = GetMaxFiles(); for ( /* i above */ ; --i > 3;) { if (i != pout[0] && i != pin[1]) close(i); } +#endif close(1); close(0);