else name++;
main(argc, argv)	int argc;	char *argv[];{	int fd, s, ldisc, odisc;	char *name;#ifdef POSIX	struct termios tios, otios;#else	struct sgttyb tty, otty;#endif	char logincmd[2*BUFSIZ+32];	extern uid_t getuid();	environ = restricted_environ; /* minimal protection for system() */	if ((name = strrchr(argv[0], '/')) == NULL)		name = argv[0];	s = getdtablesize();	for (fd = 3 ; fd < s ; fd++)		(void) close(fd);	if (argc > 1 && strlen(argv[1]) > MAXLOGNAME)		errx(1, "login %s too long", argv[1]);	openlog(name, LOG_PID, LOG_DAEMON);	uid = getuid();	if (argc > 1) {		findid(argv[1]);		/*		 * Disassociate from current controlling terminal, if any,		 * and ensure that the slip line is our controlling terminal.		 */#ifdef POSIX		switch (fork()) {		case -1:			perror("fork");			exit(1);		case 0:			break;		default:			exit(0);		}		if (setsid() == -1)			perror("setsid");#else		if ((fd = open("/dev/tty", O_RDONLY, 0)) >= 0) {			extern char *ttyname();			(void) ioctl(fd, TIOCNOTTY, (caddr_t)0);			(void) close(fd);			/* open slip tty again to acquire as controlling tty? */			fd = open(ttyname(0), O_RDWR, 0);			if (fd >= 0)				(void) close(fd);		}		(void) setpgrp(0, getpid());#endif		if (argc > 2) {			if ((fd = open(argv[2], O_RDWR)) == -1) {				perror(argv[2]);				exit(2);			}			(void) dup2(fd, 0);			if (fd > 2)				close(fd);		}#ifdef TIOCSCTTY		if (ioctl(STDIN_FILENO, TIOCSCTTY, (caddr_t)0) != 0)			perror("ioctl (TIOCSCTTY)");#endif	} else {		extern char *getlogin();		if ((name = getlogin()) == NULL) {			syslog(LOG_ERR,			    "access denied - getlogin returned 0");			errx(1, "access denied - no username");		}		findid(name);	}	if (!isatty(STDIN_FILENO)) {		syslog(LOG_ERR, "stdin not a tty");		errx(1, "stdin not a tty");	}	(void) fchmod(STDIN_FILENO, 0600);	warnx("starting slip login for %s", loginname);#ifdef POSIX	/* set up the line parameters */	if (tcgetattr(STDIN_FILENO, &tios) < 0) {		syslog(LOG_ERR, "tcgetattr: %m");		exit(1);	}	otios = tios;	cfmakeraw(&tios);	tios.c_iflag &= ~IMAXBEL;	if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios) < 0) {		syslog(LOG_ERR, "tcsetattr: %m");		exit(1);	}	speed = cfgetispeed(&tios);#else	/* set up the line parameters */	if (ioctl(STDIN_FILENO, TIOCGETP, (caddr_t)&tty) < 0) {		syslog(LOG_ERR, "ioctl (TIOCGETP): %m");		exit(1);	}	otty = tty;	speed = tty.sg_ispeed;	tty.sg_flags = RAW | ANYP;	if (ioctl(STDIN_FILENO, TIOCSETP, (caddr_t)&tty) < 0) {		syslog(LOG_ERR, "ioctl (TIOCSETP): %m");		exit(1);	}#endif	/* find out what ldisc we started with */	if (ioctl(STDIN_FILENO, TIOCGETD, (caddr_t)&odisc) < 0) {		syslog(LOG_ERR, "ioctl(TIOCGETD) (1): %m");		exit(1);	}	ldisc = SLIPDISC;	if (ioctl(STDIN_FILENO, TIOCSETD, (caddr_t)&ldisc) < 0) {		syslog(LOG_ERR, "ioctl(TIOCSETD): %m");		exit(1);	}	/* find out what unit number we were assigned */	if (ioctl(STDIN_FILENO, SLIOCGUNIT, (caddr_t)&unit) < 0) {		syslog(LOG_ERR, "ioctl (SLIOCGUNIT): %m");		exit(1);	}	(void) signal(SIGHUP, hup_handler);	(void) signal(SIGTERM, hup_handler);	syslog(LOG_INFO, "attaching slip unit %d for %s", unit, loginname);	(void)snprintf(logincmd, sizeof(loginargs), "%s %d %d %s", loginfile,	    unit, speed, loginargs);	/*	 * aim stdout and errout at /dev/null so logincmd output won't	 * babble into the slip tty line.	 */	(void) close(1);	if ((fd = open(_PATH_DEVNULL, O_WRONLY)) != 1) {		if (fd < 0) {			syslog(LOG_ERR, "open /dev/null: %m");			exit(1);		}		(void) dup2(fd, 1);		(void) close(fd);	}	(void) dup2(1, 2);	/*	 * Run login and logout scripts as root (real and effective);	 * current route(8) is setuid root, and checks the real uid	 * to see whether changes are allowed (or just "route get").	 */	(void) setuid(0);	if (s = system(logincmd)) {		syslog(LOG_ERR, "%s login failed: exit status %d from %s",		       loginname, s, loginfile);		(void) ioctl(STDIN_FILENO, TIOCSETD, (caddr_t)&odisc);#ifdef POSIX		(void) tcsetattr(STDIN_FILENO, TCSAFLUSH, &otios);#else		(void) ioctl(STDIN_FILENO, TIOCSETP, (caddr_t)&otty);#endif		exit(6);	}	/* twiddle thumbs until we get a signal; allow user to kill */	seteuid(uid);	while (1)		sigpause(0);	/* NOTREACHED */}