Ultrix3.1 bug in ioctl(2)?

Piet Tutelaers rcpt at tuegate.tue.nl
Tue May 29 07:14:09 AEST 1990


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 at urc.tue.nl

------------------------------------noecho.c---------------------------
#include <errno.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/sgtty.h>
#include <stdio.h>
#include  <fcntl.h>
#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);
}



More information about the Comp.unix.ultrix mailing list