int do_rlogin (const char *remote_host, char *name, int namelen, char *term, int termlen) { struct passwd *pwd; char remote_name[32]; char *cp; int remote_speed = 9600; int speed_name = B9600; int i; TERMIO termio; get_remote_string (remote_name, sizeof remote_name); get_remote_string (name, namelen); get_remote_string (term, termlen); if ((cp = strchr (term, '/'))) { *cp++ = '\0'; if (!(remote_speed = atoi (cp))) remote_speed = 9600; } for (i = 0; speed_table[i].spd_baud != remote_speed && speed_table[i].spd_name != -1; i++); if (speed_table[i].spd_name != -1) speed_name = speed_table[i].spd_name; /* * Put the terminal in cooked mode with echo turned on. */ GTTY (0, &termio); termio.c_iflag |= ICRNL | IXON; termio.c_oflag |= OPOST | ONLCR; termio.c_lflag |= ICANON | ECHO | ECHOE; #ifdef CBAUD termio.c_cflag = (termio.c_cflag & ~CBAUD) | speed_name; #else termio.c_cflag = (termio.c_cflag) | speed_name; #endif STTY (0, &termio); if (!(pwd = getpwnam (name))) return 0; /* * ruserok() returns 0 for success on modern systems, and 1 on * older ones. If you are having trouble with people logging * in without giving a required password, THIS is the culprit - * go fix the #define in config.h. */ #ifndef RUSEROK return 0; #else return ruserok (remote_host, pwd->pw_uid == 0, remote_name, name) == RUSEROK; #endif }
/* * set current tty */ setctty() { if (STTY(&curttyb) == -1 ) perror("setctty"); if (STTY2(&curttyb2) == -1) perror("setctty 2"); }
/* reset terminal to original state */ settty() { if (STTY(&inittyb) == -1) perror("settty"); if (STTY2(&inittyb2) == -1) perror("settty 2"); curttyb.inputflags |= STRIPHI; }
static void send_mesg_to_tty (int tty_fd) { TERMIO oldt, newt; FILE *mesg_file, *tty_file; bool is_tty; tty_file = fdopen (tty_fd, "w"); if (NULL == tty_file) { return; } is_tty = (GTTY (tty_fd, &oldt) == 0); if (is_tty) { /* Suggested by Ivan Nejgebauar <*****@*****.**>: set OPOST before writing the message. */ newt = oldt; newt.c_oflag |= OPOST; STTY (tty_fd, &newt); } mesg_file = fopen (HUP_MESG_FILE, "r"); if (NULL != mesg_file) { int c; while ((c = getc (mesg_file)) != EOF) { if (c == '\n') { putc ('\r', tty_file); } putc (c, tty_file); } fclose (mesg_file); } else { fputs (DEFAULT_HUP_MESG, tty_file); } fflush (tty_file); fclose (tty_file); if (is_tty) { STTY (tty_fd, &oldt); } }
static void setup_tty (void) { TERMIO termio; int erasechar; int killchar; if (GTTY (0, &termio) == 0) { /* get terminal characteristics */ /* * Add your favorite terminal modes here ... */ termio.c_lflag |= ISIG | ICANON | ECHO | ECHOE; termio.c_iflag |= ICRNL; #if defined(ECHOKE) && defined(ECHOCTL) termio.c_lflag |= ECHOKE | ECHOCTL; #endif #if defined(ECHOPRT) && defined(NOFLSH) && defined(TOSTOP) termio.c_lflag &= ~(ECHOPRT | NOFLSH | TOSTOP); #endif #ifdef ONLCR termio.c_oflag |= ONLCR; #endif /* leave these values unchanged if not specified in login.defs */ erasechar = getdef_num ("ERASECHAR", (int) termio.c_cc[VERASE]); killchar = getdef_num ("KILLCHAR", (int) termio.c_cc[VKILL]); termio.c_cc[VERASE] = (cc_t) erasechar; termio.c_cc[VKILL] = (cc_t) killchar; /* Make sure the values were valid. * getdef_num cannot validate this. */ if (erasechar != (int) termio.c_cc[VERASE]) { fprintf (stderr, _("configuration error - cannot parse %s value: '%d'"), "ERASECHAR", erasechar); exit (1); } if (killchar != (int) termio.c_cc[VKILL]) { fprintf (stderr, _("configuration error - cannot parse %s value: '%d'"), "KILLCHAR", killchar); exit (1); } /* * ttymon invocation prefers this, but these settings * won't come into effect after the first username login */ (void) STTY (0, &termio); } }
static void setup_tty() { TERMIO termio; GTTY (0, &termio); /* get terminal characteristics */ /* * Add your favorite terminal modes here ... */ #ifndef USE_SGTTY termio.c_lflag |= ISIG|ICANON|ECHO|ECHOE; termio.c_iflag |= ICRNL; #if defined(ECHOKE) && defined(ECHOCTL) termio.c_lflag |= ECHOKE|ECHOCTL; #endif #if defined(ECHOPRT) && defined(NOFLSH) && defined(TOSTOP) termio.c_lflag &= ~(ECHOPRT|NOFLSH|TOSTOP); #endif #ifdef ONLCR termio.c_oflag |= ONLCR; #endif #ifdef SUN4 /* * Terminal setup for SunOS 4.1 courtesy of Steve Allen * at UCO/Lick. */ termio.c_cc[VEOF] = '\04'; termio.c_cflag &= ~CSIZE; termio.c_cflag |= (PARENB|CS7); termio.c_lflag |= (ISIG|ICANON|ECHO|IEXTEN); termio.c_iflag |= (BRKINT|IGNPAR|ISTRIP|IMAXBEL|ICRNL|IXON); termio.c_iflag &= ~IXANY; termio.c_oflag |= (XTABS|OPOST|ONLCR); #endif termio.c_cc[VERASE] = getdef_num("ERASECHAR", '\b'); termio.c_cc[VKILL] = getdef_num("KILLCHAR", '\025'); /* * ttymon invocation prefers this, but these settings won't come into * effect after the first username login */ #else #endif /* !BSD */ STTY (0, &termio); }
static int cgetc(void){ Sgttyb *tty; int ch; #if !defined(__CYGWIN__) if( READYCC(stdin) || _PollIn1(fileno(stdin),1) == 0 ) #endif tty = STTY("-echo cbreak"); ch = getc(stdin); if( tty ) RTTY(tty); return ch; }
/* * die - set or reset termio modes. * * die() is called before processing begins. signal() is then called * with die() as the signal handler. If signal later calls die() with a * signal number, the terminal modes are then reset. */ static RETSIGTYPE die (int killed) { static TERMIO sgtty; if (killed != 0) { STTY (0, &sgtty); } else { GTTY (0, &sgtty); } if (killed != 0) { closelog (); exit (128+killed); } }
/* * catch_signals - set or reset termio modes. * * catch_signals() is called before processing begins. signal() is then * called with catch_signals() as the signal handler. If signal later * calls catch_signals() with a signal number, the terminal modes are * then reset. */ static RETSIGTYPE catch_signals (int killed) { static TERMIO sgtty; if (0 != killed) { STTY (0, &sgtty); } else { GTTY (0, &sgtty); } if (0 != killed) { (void) putchar ('\n'); (void) fflush (stdout); exit (killed); } }
static int cgetc_with_timeout(int sec,int usec){ Sgttyb *tty; int ch; struct timeval tv; tv.tv_sec = sec; tv.tv_usec = usec; tty = STTY("-echo cbreak"); if( _PollIn1(fileno(stdin),sec*1000+usec/1000) <= 0 ){ RTTY(tty); return -1; } ch = getc(stdin); RTTY(tty); return ch; }
static int TtyInputReady(int usec){ Sgttyb *tty = 0; int nready; int infd = fileno(stdin); nready = _PollIn1(infd,1); if( nready <= 0 ){ if( isatty(infd) ) tty = STTY("-echo cbreak"); nready = _PollIn1(infd,usec*1000); } if( tty ){ if( 0 < nready ) ungetc(getchar(),stdin); RTTY(tty); } if(nready<0){ nready = 0; } return nready; }
static char * prompt_password(const char *prompt, int with_echo) { static char nostring[1] = ""; static char *return_value; volatile int tty_opened; static FILE *ifp, *ofp; volatile int is_tty; #ifdef HAVE_SIGACTION struct sigaction old_sigact; #else RETSIGTYPE (*old_signal)(); #endif TERMIO old_modes; int max_asterisks = getdef_num("GETPASS_ASTERISKS", -1); /* * set a flag so the SIGINT signal can be re-sent if it * is caught */ sig_caught = 0; return_value = NULL; tty_opened = 0; /* * if /dev/tty can't be opened, getpass() needs to read * from stdin and write to stderr instead. */ if (!(ifp = fopen("/dev/tty", "r+"))) { ifp = stdin; ofp = stderr; } else { ofp = ifp; tty_opened = 1; } setbuf(ifp, (char *) 0); /* * the current tty modes must be saved so they can be * restored later on. echo will be turned off, except * for the newline character */ is_tty = 1; if (GTTY(fileno(ifp), &old_modes)) { is_tty = 0; #if 0 /* to make getpass work with redirected stdin */ return_value = NULL; goto out2; #endif } #ifdef USE_SETJMP /* * If we get a SIGINT, sig_catch() will jump here - * no need to press Enter after Ctrl-C. */ if (sigsetjmp(intr, 1)) goto out; #endif #ifdef HAVE_SIGACTION sigact.sa_handler = sig_catch; sigemptyset(&sigact.sa_mask); sigact.sa_flags = 0; sigaction(SIGINT, &sigact, &old_sigact); #else old_signal = signal(SIGINT, sig_catch); #endif if (is_tty) { TERMIO new_modes = old_modes; if (max_asterisks < 0) new_modes.c_lflag |= ICANON; else new_modes.c_lflag &= ~(ICANON); if (with_echo) new_modes.c_lflag |= (ECHO | ECHOE | ECHOK); else new_modes.c_lflag &= ~(ECHO | ECHOE | ECHOK); new_modes.c_lflag |= ECHONL; if (STTY(fileno(ifp), &new_modes)) goto out; } /* * the prompt is output, and the response read without * echoing. the trailing newline must be removed. if * the fgets() returns an error, a NULL pointer is * returned. */ if ((fputs(prompt, ofp) != EOF) && (fflush(ofp) != EOF)) return_value = readpass(ifp, ofp, with_echo, max_asterisks); out: /* * the old SIGINT handler is restored after the tty * modes. then /dev/tty is closed if it was opened in * the beginning. finally, if a signal was caught it * is sent to this process for normal processing. */ if (is_tty) { if (STTY(fileno(ifp), &old_modes)) return_value = NULL; } #ifdef HAVE_SIGACTION (void) sigaction (SIGINT, &old_sigact, NULL); #else (void) signal (SIGINT, old_signal); #endif #if 0 out2: #endif if (tty_opened) (void) fclose(ifp); if (sig_caught) { kill(getpid(), SIGINT); return_value = NULL; } if (!return_value) { nostring[0] = '\0'; return_value = nostring; } return return_value; }