From owner-p4-projects@FreeBSD.ORG Mon Jul 14 05:17:52 2003 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 82FE137B404; Mon, 14 Jul 2003 05:17:50 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D074437B401 for ; Mon, 14 Jul 2003 05:17:49 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 62FA743F75 for ; Mon, 14 Jul 2003 05:17:49 -0700 (PDT) (envelope-from des@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.6/8.12.6) with ESMTP id h6ECHn0U058047 for ; Mon, 14 Jul 2003 05:17:49 -0700 (PDT) (envelope-from des@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.6/8.12.6/Submit) id h6ECHmnu058044 for perforce@freebsd.org; Mon, 14 Jul 2003 05:17:48 -0700 (PDT) Date: Mon, 14 Jul 2003 05:17:48 -0700 (PDT) Message-Id: <200307141217.h6ECHmnu058044@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to des@freebsd.org using -f From: Dag-Erling Smorgrav To: Perforce Change Reviews Subject: PERFORCE change 34469 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jul 2003 12:17:53 -0000 http://perforce.freebsd.org/chv.cgi?CH=34469 Change 34469 by des@des.at.des.thinksec.com on 2003/07/14 05:17:47 Use read(2) on fileno(stdin) rather than fgets(3). This make timeout handling considerably simpler, eliminating the need for setjmp(3) and evil global variables. Portions submitted by: Dmitry V. Levin Affected files ... .. //depot/projects/openpam/configure.in#3 edit .. //depot/projects/openpam/include/security/openpam.h#25 edit .. //depot/projects/openpam/lib/openpam_ttyconv.c#22 edit Differences ... ==== //depot/projects/openpam/configure.in#3 (text+ko) ==== @@ -1,4 +1,4 @@ -dnl $P4: //depot/projects/openpam/configure.in#2 $ +dnl $P4: //depot/projects/openpam/configure.in#3 $ AC_PREREQ(2.53) AC_INIT([OpenPAM],[YYYYMMDD],[des@freebsd.org]) @@ -6,6 +6,7 @@ AM_CONFIG_HEADER([config.h]) AC_CANONICAL_SYSTEM +AC_C_VOLATILE AC_DISABLE_STATIC AC_PROG_LIBTOOL AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) @@ -63,9 +64,11 @@ AM_CONDITIONAL(WITH_PAM_SU, test "x$with_pam_su" = "xyes") AM_CONDITIONAL(WITH_PAM_UNIX, test "x$with_pam_unix" = "xyes") +AC_PROG_INSTALL + AC_CHECK_HEADERS(crypt.h) -AC_PROG_INSTALL +AC_CHECK_FUNCS(fpurge) DL_LIBS= AC_CHECK_LIB(dl, dlopen, DL_LIBS=-ldl) ==== //depot/projects/openpam/include/security/openpam.h#25 (text+ko) ==== @@ -31,7 +31,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $P4: //depot/projects/openpam/include/security/openpam.h#24 $ + * $P4: //depot/projects/openpam/include/security/openpam.h#25 $ */ #ifndef _SECURITY_OPENPAM_H_INCLUDED @@ -178,6 +178,8 @@ struct pam_response **_resp, void *_data); +extern int openpam_ttyconv_timeout; + /* * Null conversation function */ ==== //depot/projects/openpam/lib/openpam_ttyconv.c#22 (text+ko) ==== @@ -31,12 +31,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $P4: //depot/projects/openpam/lib/openpam_ttyconv.c#21 $ + * $P4: //depot/projects/openpam/lib/openpam_ttyconv.c#22 $ */ #include #include +#include #include #include #include @@ -50,14 +51,12 @@ #include "openpam_impl.h" int openpam_ttyconv_timeout = 0; -static jmp_buf jmpenv; -static int timed_out; static void timeout(int sig) { - timed_out = 1; - longjmp(jmpenv, sig); + + (void)sig; } static char * @@ -67,8 +66,10 @@ struct sigaction action, saved_action; sigset_t saved_sigset, sigset; unsigned int saved_alarm; + int eof, error, fd, timed_out; size_t len; char *retval; + char ch; sigemptyset(&sigset); sigaddset(&sigset, SIGINT); @@ -79,18 +80,40 @@ sigemptyset(&action.sa_mask); sigaction(SIGALRM, &action, &saved_action); fputs(msg, stdout); + fflush(stdout); +#ifdef HAVE_FPURGE + fpurge(stdin); +#endif + fd = fileno(stdin); buf[0] = '\0'; timed_out = 0; + eof = error = timed_out = 0; saved_alarm = alarm(openpam_ttyconv_timeout); - if (setjmp(jmpenv) == 0) - fgets(buf, sizeof buf, stdin); - else - fputs(" timeout!\n", stderr); + ch = '\0'; + for (len = 0; ch != '\n' && !eof && !error; ++len) { + switch (read(fd, &ch, 1)) { + case 1: + if (len < PAM_MAX_RESP_SIZE - 1) { + buf[len + 1] = '\0'; + buf[len] = ch; + } + break; + case 0: + eof = 1; + break; + default: + error = errno; + break; + } + } alarm(0); sigaction(SIGALRM, &saved_action, NULL); sigprocmask(SIG_SETMASK, &saved_sigset, NULL); alarm(saved_alarm); - if (timed_out || ferror(stdin) || feof(stdin)) { + if (error == EINTR) + fputs(" timeout!", stderr); + if (error || eof) { + fputs("\n", stderr); memset(buf, 0, sizeof(buf)); return (NULL); }