char *get_tty_password(const char *opt_message) { #ifdef HAVE_GETPASS char *passbuff; #else /* ! HAVE_GETPASS */ TERMIO org,tmp; #endif /* HAVE_GETPASS */ char buff[80]; DBUG_ENTER("get_tty_password"); #ifdef HAVE_GETPASS passbuff = getpass(opt_message ? opt_message : "Enter password: "******"Enter password: ",stdout); fflush(stdout); } #if defined(HAVE_TERMIOS_H) tcgetattr(fileno(stdin), &org); tmp = org; tmp.c_lflag &= ~(ECHO | ISIG | ICANON); tmp.c_cc[VMIN] = 1; tmp.c_cc[VTIME] = 0; tcsetattr(fileno(stdin), TCSADRAIN, &tmp); get_password(buff, sizeof(buff)-1, fileno(stdin), isatty(fileno(stdout))); tcsetattr(fileno(stdin), TCSADRAIN, &org); #elif defined(HAVE_TERMIO_H) ioctl(fileno(stdin), (int) TCGETA, &org); tmp=org; tmp.c_lflag &= ~(ECHO | ISIG | ICANON); tmp.c_cc[VMIN] = 1; tmp.c_cc[VTIME]= 0; ioctl(fileno(stdin),(int) TCSETA, &tmp); get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stdout))); ioctl(fileno(stdin),(int) TCSETA, &org); #else gtty(fileno(stdin), &org); tmp=org; tmp.sg_flags &= ~ECHO; tmp.sg_flags |= RAW; stty(fileno(stdin), &tmp); get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stdout))); stty(fileno(stdin), &org); #endif if (isatty(fileno(stdout))) fputc('\n',stdout); #endif /* HAVE_GETPASS */ DBUG_RETURN(my_strdup(buff,MYF(MY_FAE))); }
init_tty() { bcopy(&tty_state, &tty_new, sizeof(tty_new)) ; tty_new.sg_flags |= RAW ; tty_new.sg_flags &= ~(TANDEM|CBREAK|LCASE|ECHO|CRMOD) ; stty(1,&tty_new) ; }
int getty(char *tty, speed_t speed, char *term, char *user) { int fd; char name[30]; /* Detach from initial controlling TTY */ vhangup(); fd = open(tty, O_RDWR); if (fd < 0) err(1, "Failed opening %s", tty); dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); if (ioctl(STDIN_FILENO, TIOCSCTTY, 1) < 0) warn("Failed TIOCSCTTY"); /* The getty process is responsible for the UTMP login record */ utmp_set_login(tty, NULL); if (!user) do_getty(tty, name, sizeof(name)); else strlcpy(name, user, sizeof(name)); /* Set up TTY, re-enabling ISIG et al. */ stty(fd, speed); close(fd); if (term && term[0]) setenv("TERM", term, 1); return do_login(name); }
static void init_tty() { if (gtty(1, &tty_state) < 0) { fprintf(stderr, "gtty failed\n"); exit(-1); } memcpy(&tty_new, &tty_state, sizeof(tty_new)); //#ifdef LINUX tty_new.c_lflag &= ~(ICANON | ECHO | ISIG); tcsetattr(1, TCSANOW, &tty_new); restore_tty(); //#else // tty_new.sg_flags |= RAW; //#ifdef HP_UX // tty_new.sg_flags &= ~(O_HUPCL | O_XTABS | LCASE | ECHO | CRMOD); //#else // tty_new.sg_flags &= ~(TANDEM | CBREAK | LCASE | ECHO | CRMOD); //#endif stty(1, &tty_new); //#endif }
static void set_tty(void) { otty.c_lflag &= ~(ICANON | ECHO); otty.c_cc[VMIN] = 1; /* read at least 1 char */ otty.c_cc[VTIME] = 0; /* no timeout */ stty(fileno(stderr), &otty); }
void openpl(void) { if ( isatty(fileno( stdout )) ) { shakehands = TRUE; fildes = open(TERMINAL, 0); gtty(fildes, &sarg); sarg.sg_flags = sarg.sg_flags | RAW; stty(fildes, &sarg); sarg.sg_flags = sarg.sg_flags & ~RAW; } else { shakehands = FALSE; } buffcount = 0; currentx = 0; currenty = 0; buffready(8); putchar(ESC); putchar(GRAPHIC); putchar(DISPLAY); putchar('c'); putchar(ESC); putchar(GRAPHIC); putchar(PLOT); putchar(BINARY); space(0,0,720,360); }
int raw() { T(("raw() called")); SP->_raw = TRUE; SP->_cbreak = TRUE; SP->_nlmapping = TRUE; #ifdef TERMIOS if(iexten == 0) iexten = cur_term->Nttyb.c_lflag & IEXTEN; cur_term->Nttyb.c_lflag &= ~(ICANON|ISIG|iexten); cur_term->Nttyb.c_iflag &= ~(INPCK|ISTRIP|IXON); cur_term->Nttyb.c_oflag &= ~(OPOST); cur_term->Nttyb.c_cc[VMIN] = 1; cur_term->Nttyb.c_cc[VTIME] = 0; if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) return ERR; else return OK; #else cur_term->Nttyb.sg_flags |= RAW; stty(cur_term->Filedes, &cur_term->Nttyb); return OK; #endif }
void restore_tty (void) /*restore tty settings from beginning*/ { if (ttysave[0] != -1) { #ifdef USG ttys.c_lflag = ttysave[0]; tcsetattr(0, TCSADRAIN, &ttys); #else ttys[0].sg_flags = ttysave[0]; stty(0, &ttys[0]); } if (ttysave[1] != -1) { ttys[1].sg_flags = ttysave[1]; stty(1, &ttys[1]); #endif /* USG */ } }
void testValues() { f = 2; struct sgttyb p; stty(anyint(), &p); //@ assert f == 2; //@ assert vacuous: \false; }
outplot() { spew(ESC); spew(ACK); spew(ESC); spew(ACK); fflush(stdout); stty (OUTF, &ITTY); }
void closepl(void) { putchar('Z'); fflush(stdout); if ( shakehands == TRUE ) { stty(fildes, &sarg); close(fildes); } }
static void set_raw_tty(int mode) { Terminal in_raw; if(mode != tty_mode && mode != -1) { if(!handlerIsSet) { /* Determine existing TTY settings */ gtty (STDIN, &in_orig); need_tty_reset = 1; /* Restore original TTY settings on exit */ atexit(cleanup_tty); handlerIsSet = 1; } setup_signal(); signal (SIGALRM, (SIG_CAST) tty_time_out); /* Change STDIN settings to raw */ gtty (STDIN, &in_raw); if(mode) { #ifdef USE_SGTTY in_raw.sg_flags |= CBREAK; #else in_raw.c_lflag &= ~ICANON; in_raw.c_cc[VMIN]=1; in_raw.c_cc[VTIME]=0; #endif stty (STDIN, &in_raw); } else { #ifdef USE_SGTTY in_raw.sg_flags &= ~CBREAK; #else in_raw.c_lflag |= ICANON; #endif stty (STDIN, &in_raw); } tty_mode = mode; discard_input(STDIN); } }
gettmode() { if (gtty(_tty_ch, &_tty) < 0) return; savetty(); if (stty(_tty_ch, &_tty) < 0) _tty.sg_flags = _res_flg; ospeed = _tty.sg_ospeed; _res_flg = _tty.sg_flags; UPPERCASE = (_tty.sg_flags & LCASE) != 0; GT = ((_tty.sg_flags & XTABS) == 0); NONL = ((_tty.sg_flags & CRMOD) == 0); _tty.sg_flags &= ~XTABS; stty(_tty_ch, &_tty); # ifdef DEBUG fprintf(outf, "GETTMODE: UPPERCASE = %s\n", UPPERCASE ? "TRUE":"FALSE"); fprintf(outf, "GETTMODE: GT = %s\n", GT ? "TRUE" : "FALSE"); fprintf(outf, "GETTMODE: NONL = %s\n", NONL ? "TRUE" : "FALSE"); fprintf(outf, "GETTMODE: ospeed = %d\n", ospeed); # endif }
int sh(char *tty) { int fd; char *arg0; char *args[2] = { NULL, NULL }; size_t len; struct termios term; /* Detach from initial controlling TTY */ vhangup(); fd = open(tty, O_RDWR); if (fd < 0) err(1, "Failed opening %s", tty); dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); if (ioctl(STDIN_FILENO, TIOCSCTTY, 1) < 0) warn("Failed TIOCSCTTY"); /* The getty process is usually responsible for the UTMP login record */ utmp_set_login(tty, NULL); /* Set up TTY, re-enabling ISIG et al. */ stty(fd, B0); close(fd); /* Start /bin/sh as a login shell, i.e. with a prefix '-' */ len = strlen(_PATH_BSHELL) + 2; arg0 = malloc(len); if (!arg0) err(1, "Failed allocating memory"); snprintf(arg0, len, "-%s", _PATH_BSHELL); args[0] = arg0; /* Reenable Ctrl-D and Ctrl-C, and ... */ if (!tcgetattr(STDIN_FILENO, &term)) { term.c_lflag |= ISIG; term.c_cc[VEOF] = CTL('D'); term.c_cc[VINTR] = CTL('C'); tcsetattr(STDIN_FILENO, TCSANOW, &term); } /* ... unblock signals in general */ sig_unblock(); return execv(_PATH_BSHELL, args); }
ttclose() { #if USG | HPUX | XENIX ioctl(0, TCSETA, &otermio); /* restore terminal settings */ fcntl(0, F_SETFL, kbdflgs); #endif #if V7 | BSD | SUN stty(0, &ostate); ioctl(0, TIOCSETC, &otchars); /* Place old character into K */ #endif }
twdone(){ obufp = obuf; oputs(t.twrest); flusho(); if(pipeflg){ close(ptid); wait(&waitf); } if(ttysave != -1) { ttys.sg_flags = ttysave; stty(1, &ttys); } }
static void set_ttymodes(TTY *modes) { # if USE_POSIX_TERMIOS fflush(stdout); tcsetattr(0, TCSAFLUSH, modes); # else # if USE_TERMIO tcsetattr(0, TCSETAF, modes); # else /* USE_SGTTY */ stty(0, modes); # endif # endif }
void set_tty (void) /*this replaces the use of bset and breset*/ { #ifndef USG /*for research/BSD only, reset CRMOD*/ if (ttysave[1] == -1) save_tty(); if (ttysave[1] != -1) { ttys[1].sg_flags &= ~CRMOD; stty(1, &ttys[1]); } #endif /* USG */ }
void echo_on (void) /*restore ECHO after .rd in "-q" mode*/ { if (ttysave[0] == -1) return; #ifdef USG ttys.c_lflag |= ECHO_USG; tcsetattr(0, TCSADRAIN, &ttys); #else ttys[0].sg_flags |= ECHO; stty(0, &ttys[0]); #endif /* USG */ }
void echo_off (void) /*turn off ECHO for .rd in "-q" mode*/ { if (ttysave[0] == -1) return; #ifdef USG ttys.c_lflag &= ~ECHO_USG; tcsetattr(0, TCSADRAIN, &ttys); #else ttys[0].sg_flags &= ~ECHO; stty(0, &ttys[0]); #endif /* USG */ }
static void reset_tty(void) { if (no_tty) return; if (pstate) { /* putchar - if that isn't a macro */ tputs(ULexit, fileno(stdout), ourputch); fflush(stdout); pstate = 0; } otty.c_lflag |= ICANON | ECHO; otty.c_cc[VMIN] = savetty0.c_cc[VMIN]; otty.c_cc[VTIME] = savetty0.c_cc[VTIME]; stty(fileno(stderr), &savetty0); }
static void disable_tty_echo(void) { /* turn off echo on the tty */ #if defined(HAVE_TCSETATTR) termb.c_lflag &= ~ECHO; tcsetattr(ttyfd, TCSAFLUSH, &termb); #else #if defined(HAVE_TERMIO_H) termb.c_lflag &= ~ECHO; ioctl(ttyfd, TCSETA, (char *) &termb); #else /* we HAVE_STTY */ ttyb.sg_flags &= ~ECHO; stty(ttyfd, &ttyb); #endif #endif }
static void restore_tty_state(void) { /* restore previous tty echo state */ #if defined(HAVE_TCSETATTR) termb.c_lflag = flags; tcsetattr(ttyfd, TCSAFLUSH, &termb); #else #if defined(HAVE_TERMIO_H) termb.c_lflag = flags; ioctl(ttyfd, TCSETA, (char *) &termb); #else /* we HAVE_STTY */ ttyb.sg_flags = flags; stty(ttyfd, &ttyb); #endif #endif }
openpl () { int reset(); xnow = ynow = 0; OUTF = 1; printf("\r"); gtty(OUTF, &ITTY); signal (2, reset); PTTY = ITTY; PTTY.sg_flags &= ~CRMOD; /* don't map lf */ stty(OUTF,&PTTY); /* initialize constants */ xscale = 4096./(HORZRESP * WIDTH); yscale = 4096 /(VERTRESP * HEIGHT); xoffset = OFFSET * HORZRESP; return; }
int noecho() { T(("noecho() called")); SP->_echo = FALSE; #ifdef TERMIOS cur_term->Nttyb.c_lflag &= ~(ECHO); if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) return ERR; else return OK; #else cur_term->Nttyb.sg_flags &= ~ECHO; stty(cur_term->Filedes, &cur_term->Nttyb); return OK; #endif }
/* [...] * control terminal: * -- checks for STTY | GTTY error; * -- checks for !(STTY | GTTY) error; * -- clears STTY/GTTY before calling stty/gtty; */ static int ctltty(short mn, unsigned rq, unsigned arg) { if (rq & STTY) { /* error -- cann't set & get */ if (rq & GTTY) /* avoid 2-check STTY && GTTY */ return -1; /* set param */ rq &= ~STTY; return stty(mn, rq, arg); } if (rq & GTTY) { /* get param */ rq &= ~GTTY; return gtty(mn, rq, arg); } /* set/get not specified */ return -1; }
int nocbreak() { T(("nocbreak() called")); SP->_cbreak = 0; #ifdef TERMIOS cur_term->Nttyb.c_lflag |= ICANON; if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) return ERR; else return OK; #else cur_term->Nttyb.sg_flags &= ~CBREAK; stty(cur_term->Filedes, &cur_term->Nttyb); return OK; #endif }
int echo() { T(("echo() called")); SP->_echo = TRUE; #ifdef TERMIOS cur_term->Nttyb.c_lflag |= ECHO; if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) return ERR; else return OK; #else cur_term->Nttyb.sg_flags |= ECHO; stty(cur_term->Filedes, &cur_term->Nttyb); return OK; #endif }
int nonl() { T(("nonl() called")); SP->_nl = SP->_nlmapping = FALSE; #ifdef TERMIOS cur_term->Nttyb.c_iflag &= ~ICRNL; cur_term->Nttyb.c_oflag &= ~ONLCR; if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) return ERR; else return OK; #else cur_term->Nttyb.sg_flags &= ~CRMOD; stty(cur_term->Filedes, &cur_term->Nttyb); return OK; #endif }
int nl() { T(("nl() called")); SP->_nl = TRUE; SP->_nlmapping = ! SP->_raw; #ifdef TERMIOS cur_term->Nttyb.c_iflag |= IXON|ICRNL|IXOFF; cur_term->Nttyb.c_oflag |= OPOST|ONLCR; if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) return ERR; else return OK; #else cur_term->Nttyb.sg_flags |= CRMOD; stty(cur_term->Filedes, &cur_term->Nttyb); return OK; #endif }