nmh-workers
[Top] [All Lists]

[Nmh-workers] inc bug

2005-02-21 07:39:54
A little while back, I noticed that inc crashes if I have logged in
using su from another user. Having investigated, it is the code which
reopens the terminal to read the password. When logged in using su, this
is still owned by the original user so the fopen fails. It ought to be
opening /dev/tty instead of whatever ttyname() returns for stdin. Fix is
below.

Oliver

Index: sbr/getpass.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/getpass.c,v
retrieving revision 1.4
diff -u -r1.4 getpass.c
--- sbr/getpass.c       9 May 2000 21:44:16 -0000       1.4
+++ sbr/getpass.c       21 Feb 2005 14:05:26 -0000
@@ -35,7 +35,7 @@
 
 #include <stdio.h>
 #include <termios.h>
-#include <unistd.h>   /* for ttyname() */
+#include <unistd.h>   /* for isatty() */
 #include "h/mh.h"     /* for adios() */
 
 /* We don't use MAX_PASS here because the maximum password length on a remote
@@ -52,21 +52,21 @@
 {
   struct termios oterm, term;
   int ch;
-  char *p, *ttystring;
+  char *p;
   FILE *fout, *fin;
   static char  buf[MAX_PASSWORD_LEN + 1];
+  int istty = isatty(fileno(stdin));
 
   /* Find if stdin is connect to a terminal. If so, read directly from
    * the terminal, and turn off echo. Otherwise read from stdin.
    */
 
-  if((ttystring = (char *)ttyname(fileno(stdin))) == NULL) {
+  if (!istty || !(fout = fin = fopen("/dev/tty", "w+"))) {
     fout = stderr;
     fin = stdin;
   }
   else /* Reading directly from terminal here */
     {
-      fout = fin = fopen(ttystring, "w+");
       (void)tcgetattr(fileno(fin), &oterm);
       term = oterm; /* Save original info */
       term.c_lflag &= ~ECHO;
@@ -81,7 +81,7 @@
     *p++ = ch;
   *p = '\0';
 
-  if(ttystring != NULL) {
+  if (istty) {
     (void)tcsetattr(fileno(fin), TCSANOW, &oterm);
     rewind(fout);
     (void)fputc('\n', fout);


_______________________________________________
Nmh-workers mailing list
Nmh-workers(_at_)nongnu(_dot_)org
http://lists.nongnu.org/mailman/listinfo/nmh-workers

<Prev in Thread] Current Thread [Next in Thread>
  • [Nmh-workers] inc bug, Oliver Kiddle <=