* prompter.c (krb5_prompter_posix, setup_tty, restore_tty): Fix to
authorTom Yu <tlyu@mit.edu>
Fri, 7 Feb 2003 04:15:22 +0000 (04:15 +0000)
committerTom Yu <tlyu@mit.edu>
Fri, 7 Feb 2003 04:15:22 +0000 (04:15 +0000)
use the actual file descriptor we dup()'ed to in case tcsetattr()
doesn't actually change the underlying device modes and instead
only affects the specific file descriptor.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15164 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/os/ChangeLog
src/lib/krb5/os/prompter.c

index 3ad433b12448feecbc3b33744de4813b40d503a4..53c7a3881612e39d8b06d9be9dd13370718cf011 100644 (file)
@@ -1,3 +1,10 @@
+2003-02-06  Tom Yu  <tlyu@mit.edu>
+
+       * prompter.c (krb5_prompter_posix, setup_tty, restore_tty): Fix to
+       use the actual file descriptor we dup()'ed to in case tcsetattr()
+       doesn't actually change the underlying device modes and instead
+       only affects the specific file descriptor.
+
 2003-02-06  Ken Raeburn  <raeburn@mit.edu>
 
        * locate_kdc.c (translate_ai_error): Handle EAI_ADDRFAMILY like
index 3e4503216d055ae8ce571fb8a5fb3007991346c6..81e0b78f0e31f212d70bdc839423c33f2b4badc0 100644 (file)
@@ -15,8 +15,8 @@ static void   catch_signals(void);
 static void    restore_signals(void);
 static krb5_sigtype    intrfunc(int sig);
 
-static krb5_error_code setup_tty(int);
-static krb5_error_code restore_tty(void);
+static krb5_error_code setup_tty(FILE*, int);
+static krb5_error_code restore_tty(FILE*);
 
 #ifdef POSIX_SIGNALS
 static struct sigaction osigint;
@@ -75,7 +75,7 @@ krb5_prompter_posix(
        (void)fflush(stdout);
        (void)memset(prompts[i].reply->data, 0, prompts[i].reply->length);
 
-       errcode = setup_tty(prompts[i].hidden);
+       errcode = setup_tty(fp, prompts[i].hidden);
        if (errcode) {
            if (prompts[i].hidden)
                putchar('\n');
@@ -91,7 +91,7 @@ krb5_prompter_posix(
                errcode = KRB5_LIBOS_PWDINTR;
            else
                errcode = KRB5_LIBOS_CANTREADPWD;
-           restore_tty();
+           restore_tty(fp);
            break;
        }
 
@@ -106,7 +106,7 @@ krb5_prompter_posix(
            } while (scratchchar != EOF && scratchchar != '\n');
        }
 
-       errcode = restore_tty();
+       errcode = restore_tty(fp);
        if (errcode)
            break;
        prompts[i].reply->length = strlen(prompts[i].reply->data);
@@ -153,19 +153,21 @@ restore_signals(void)
 static struct termios saveparm;
 
 static krb5_error_code
-setup_tty(int hidden)
+setup_tty(FILE *fp, int hidden)
 {
     krb5_error_code    ret;
+    int                        fd;
     struct termios     tparm;
 
     ret = KRB5_LIBOS_CANTREADPWD;
     catch_signals();
+    fd = fileno(fp);
     do {
-       if (!isatty(STDIN_FILENO)) {
+       if (!isatty(fd)) {
            ret = 0;
            break;
        }
-       if (tcgetattr(STDIN_FILENO, &tparm) < 0)
+       if (tcgetattr(fd, &tparm) < 0)
            break;
        saveparm = tparm;
 #ifndef ECHO_PASSWORD
@@ -184,13 +186,14 @@ setup_tty(int hidden)
 }
 
 static krb5_error_code
-restore_tty(void)
+restore_tty(FILE* fp)
 {
-    int ret;
+    int ret, fd;
 
     ret = 0;
-    if (isatty(STDIN_FILENO)) {
-       ret = tcsetattr(STDIN_FILENO, TCSANOW, &saveparm);
+    fd = fileno(fp);
+    if (isatty(fd)) {
+       ret = tcsetattr(fd, TCSANOW, &saveparm);
        if (ret < 0)
            ret = KRB5_LIBOS_CANTREADPWD;
        else