Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!tuegate.tue.nl!rcpt From: rcpt@tuegate.tue.nl (Piet Tutelaers) Newsgroups: comp.unix.ultrix Subject: Ultrix3.1 bug in ioctl(2)? Keywords: bugreport Message-ID: <1768@tuegate.tue.nl> Date: 28 May 90 21:14:09 GMT Organization: Eindhoven University of Technology, The Netherlands Lines: 119 The next program shows a bug I encountered in ULTRIX 3.1 when I tried to install npasswd(1), a public replacement for passwd(1). The password should obviously not be echo'ed when typed in by the user. To realise this the program npasswd(1) uses ioctl() calls. The next program compiled with the compile time flag -DULTRIX_BUG shows the essential part of npasswd(1) that handles the disabling of the echoing. The program comes up with the next error message: getpass(save get): Not a typewriter By trial and error we find out that the old fashioned gtty() and stty() calls corrects the ill behaviour of the program (the shown message and no echoing if the errors are ignored). This can be demonstrated by compiling the program without the `-DULTRIX_BUG' option. I consider this as a BUG, perhaps a known one. I would like to know if ULTRIX 4.0 solves this problem? Who can test this? -- Piet rcpt@urc.tue.nl ------------------------------------noecho.c--------------------------- #include #include #include #include #include #include #include "version.h" char pbuf[16]; /* Password read buffer 1 */ /* * passwd - change the password for a user. * * This program impliments the 'passwd' command. */ main(argc, argv) int argc; char *argv[]; { void getpass(); getpass("New password: "); } struct sgttyb saved_tty_mode; #define ERR -1 /* * The system getpass() throws away all but the first 8 characters * of a password string. If this isn't enough for you, use this * routine instead. This code assumes that stdin is the terminal. */ void getpass(prompt) char *prompt; { struct sgttyb saved, /* Saved tty characteristics */ noecho; /* No-echo tty characteristics */ char *index(); int tp; static char ib[64]; /* Input buffer */ char *rc; /* Temp */ if ((tp = open("/dev/tty", O_RDONLY)) < 0) { perror("getpass(open)"); return; } #ifdef ULTRIX_BUG if (ioctl(tp, TIOCGETP, &saved)==ERR) { perror("getpass(save get)"); return; } #else gtty(tp, &saved); #endif #ifdef ULTRIX_BUG if (ioctl(tp, TIOCGETP, &noecho)==ERR) { perror("getpass(noechoget)"); return; } #else gtty(tp, &noecho); #endif noecho.sg_flags &= ~ECHO; #ifdef ULTRIX_BUG if (ioctl(tp, TIOCSETP, &noecho)==ERR) { perror("getpass(noecho set)"); return; } #else stty(tp, &noecho); #endif fputs(prompt, stderr); #ifdef ULTRIX_BUG rc = fgets(ib, sizeof(ib), stdin); #else rc = read(tp, (char *)ib, (int) sizeof(ib)); #endif putc('\n', stderr); #ifdef ULTRIX_BUG (void) ioctl(tp, TIOCSETP, &saved); #else stty(tp, &saved); #endif close(tp); fprintf(stderr, "password was:%s\n", ib); }