From: Todd C. Miller Date: Mon, 6 Jun 1994 00:04:55 +0000 (+0000) Subject: uses sysconf() if available X-Git-Tag: SUDO_1_3_1~180 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=14ea471acdebf1611c3d598e4592477b1676173a;p=sudo uses sysconf() if available --- diff --git a/tgetpass.c b/tgetpass.c index e21bc7060..09b31ef5f 100644 --- a/tgetpass.c +++ b/tgetpass.c @@ -1,11 +1,38 @@ +/* + * CU sudo version 1.3.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Please send bugs, changes, problems to sudo-bugs.cs.colorado.edu + * + ******************************************************************* + * + * This module contains tgetpass(), getpass(3) with a timeout. + * + * Todd C. Miller Sun Jun 5 17:22:31 MDT 1994 + */ + #include "config.h" #include "pathnames.h" #include -#include -#include -#include +#ifdef HAVE_UNISTD_H +#include +#endif /* HAVE_UNISTD_H */ #include +#include #include #include #ifdef HAVE_TERMIOS_H @@ -24,6 +51,15 @@ #endif /* _PASSWD_LEN */ +/****************************************************************** + * + * tgetpass() + * + * this function prints a prompt and gets a password from /dev/tty + * or stdin. Echo is turned off (if possible) during password entry + * and input will time out based on the value of timeout. + */ + char * tgetpass(prompt, timeout) const char *prompt; int timeout; @@ -101,7 +137,11 @@ char * tgetpass(prompt, timeout) FD_SET(input, &readfds); tv.tv_sec = timeout; tv.tv_usec = 0; +#ifdef HAVE_SYSCONF + if (select(sysconf(_SC_OPEN_MAX), &readfds, NULL, NULL, &tv) <= 0) { +#else if (select(getdtablesize(), &readfds, NULL, NULL, &tv) <= 0) { +#endif /* HAVE_SYSCONF */ i = 0; break; }