static void checkpath(char *name) { /* restrict pathnames to current tree or uucppublic */ if (strstr(name, "../")) { canit(); fprintf(stderr, "\r\nlrz:\tSecurity Violation\r\n"); bibi(-1); } if (name[0] == '.' || strstr(name, "/.")) { canit(); fprintf(stderr, "\r\nlrz:\tSecurity Violation\r\n"); bibi(-1); } }
/* * mode(n) * 3: save old tty stat, set raw mode with flow control * 2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g * 1: save old tty stat, set raw mode * 0: restore original tty mode */ int io_mode(int fd, int n) { static int did0 = FALSE; vfile("Setting iode:%d", n); /* fprintf(stderr,"TEST BUILD: ignoring all terminal mode changes"); return 0 ; */ switch(n) { #ifdef USE_TERMIOS case 2: /* Un-raw mode used by sz, sb when -g detected */ if(!did0) { did0 = TRUE; tcgetattr(fd,&oldtty); } tty = oldtty; tty.c_iflag = BRKINT|IXON; tty.c_oflag = 0; /* Transparent output */ tty.c_cflag &= ~PARENB; /* Disable parity */ tty.c_cflag |= CS8; /* Set character size = 8 */ if (Twostop) tty.c_cflag |= CSTOPB; /* Set two stop bits */ #ifdef READCHECK tty.c_lflag = protocol==ZM_ZMODEM ? 0 : ISIG; tty.c_cc[VINTR] = protocol==ZM_ZMODEM ? -1 : 030; /* Interrupt char */ #else tty.c_lflag = 0; tty.c_cc[VINTR] = protocol==ZM_ZMODEM ? 03 : 030; /* Interrupt char */ #endif #ifdef _POSIX_VDISABLE if (((int) _POSIX_VDISABLE)!=(-1)) { tty.c_cc[VQUIT] = _POSIX_VDISABLE; /* Quit char */ } else { tty.c_cc[VQUIT] = -1; /* Quit char */ } #else tty.c_cc[VQUIT] = -1; /* Quit char */ #endif #ifdef NFGVMIN tty.c_cc[VMIN] = 1; #else tty.c_cc[VMIN] = 3; /* This many chars satisfies reads */ #endif tty.c_cc[VTIME] = 1; /* or in this many tenths of seconds */ tcsetattr(fd,TCSADRAIN,&tty); return OK; case 1: case 3: if(!did0) { did0 = TRUE; tcgetattr(fd,&oldtty); } tty = oldtty; tty.c_iflag = IGNBRK; if (n==3) /* with flow control */ tty.c_iflag |= IXOFF; /* No echo, crlf mapping, INTR, QUIT, delays, no erase/kill */ tty.c_lflag &= ~(ECHO | ICANON | ISIG); tty.c_oflag = 0; /* Transparent output */ tty.c_cflag &= ~(PARENB); /* Same baud rate, disable parity */ /* Set character size = 8 */ tty.c_cflag &= ~(CSIZE); tty.c_cflag |= CS8; if (Twostop) tty.c_cflag |= CSTOPB; /* Set two stop bits */ #ifdef NFGVMIN tty.c_cc[VMIN] = 1; /* This many chars satisfies reads */ #else tty.c_cc[VMIN] = HOWMANY; /* This many chars satisfies reads */ #endif tty.c_cc[VTIME] = 1; /* or in this many tenths of seconds */ tcsetattr(fd,TCSADRAIN,&tty); Baudrate = getspeed(cfgetospeed(&tty)); return OK; case 0: if(!did0) return ERROR; tcdrain (fd); /* wait until everything is sent */ tcflush (fd,TCIOFLUSH); /* flush input queue */ tcsetattr (fd,TCSADRAIN,&oldtty); tcflow (fd,TCOON); /* restart output */ return OK; #endif #ifdef USE_TERMIO case 2: /* Un-raw mode used by sz, sb when -g detected */ if(!did0) (void) ioctl(fd, TCGETA, &oldtty); tty = oldtty; tty.c_iflag = BRKINT|IXON; tty.c_oflag = 0; /* Transparent output */ tty.c_cflag &= ~PARENB; /* Disable parity */ tty.c_cflag |= CS8; /* Set character size = 8 */ if (Twostop) tty.c_cflag |= CSTOPB; /* Set two stop bits */ #ifdef READCHECK tty.c_lflag = protocol==ZM_ZMODEM ? 0 : ISIG; tty.c_cc[VINTR] = protocol==ZM_ZMODEM ? -1 : 030; /* Interrupt char */ #else tty.c_lflag = 0; tty.c_cc[VINTR] = protocol==ZM_ZMODEM ? 03 : 030; /* Interrupt char */ #endif tty.c_cc[VQUIT] = -1; /* Quit char */ #ifdef NFGVMIN tty.c_cc[VMIN] = 1; #else tty.c_cc[VMIN] = 3; /* This many chars satisfies reads */ #endif tty.c_cc[VTIME] = 1; /* or in this many tenths of seconds */ (void) ioctl(fd, TCSETAW, &tty); did0 = TRUE; return OK; case 1: case 3: if(!did0) (void) ioctl(fd, TCGETA, &oldtty); tty = oldtty; tty.c_iflag = n==3 ? (IGNBRK|IXOFF) : IGNBRK; /* No echo, crlf mapping, delays, no erase/kill */ tty.c_lflag &= ~(ECHO | ICANON | ISIG); tty.c_oflag = 0; /* Transparent output */ tty.c_cflag &= ~PARENB; /* Same baud rate, disable parity */ tty.c_cflag |= CS8; /* Set character size = 8 */ if (Twostop) tty.c_cflag |= CSTOPB; /* Set two stop bits */ #ifdef NFGVMIN tty.c_cc[VMIN] = 1; /* This many chars satisfies reads */ #else tty.c_cc[VMIN] = HOWMANY; /* This many chars satisfies reads */ #endif tty.c_cc[VTIME] = 1; /* or in this many tenths of seconds */ (void) ioctl(fd, TCSETAW, &tty); did0 = TRUE; Baudrate = getspeed(tty.c_cflag & CBAUD); return OK; case 0: if(!did0) return ERROR; (void) ioctl(fd, TCSBRK, 1); /* Wait for output to drain */ (void) ioctl(fd, TCFLSH, 0); /* Flush input queue */ (void) ioctl(fd, TCSETAW, &oldtty); /* Restore modes */ (void) ioctl(fd, TCXONC,1); /* Restart output */ return OK; #endif #ifdef USE_SGTTY /* * NOTE: this should transmit all 8 bits and at the same time * respond to XOFF/XON flow control. If no FIONREAD or other * READCHECK alternative, also must respond to INTRRUPT char * This doesn't work with V7. It should work with LLITOUT, * but LLITOUT was broken on the machine I tried it on. */ case 2: /* Un-raw mode used by sz, sb when -g detected */ if(!did0) { ioctl(fd, TIOCEXCL, 0); ioctl(fd, TIOCGETP, &oldtty); ioctl(fd, TIOCGETC, &oldtch); #ifdef LLITOUT ioctl(fd, TIOCLGET, &Locmode); #endif } tty = oldtty; tch = oldtch; #ifdef READCHECK tch.t_intrc = Zmodem ? -1:030; /* Interrupt char */ #else tch.t_intrc = Zmodem ? 03:030; /* Interrupt char */ #endif tty.sg_flags |= (ODDP|EVENP|CBREAK); tty.sg_flags &= ~(ALLDELAY|CRMOD|ECHO|LCASE); ioctl(fd, TIOCSETP, &tty); ioctl(fd, TIOCSETC, &tch); #ifdef LLITOUT ioctl(fd, TIOCLBIS, &Locbit); #else bibi(99); /* un-raw doesn't work w/o lit out */ #endif did0 = TRUE; return OK; case 1: case 3: if(!did0) { ioctl(fd, TIOCEXCL, 0); ioctl(fd, TIOCGETP, &oldtty); ioctl(fd, TIOCGETC, &oldtch); #ifdef LLITOUT ioctl(fd, TIOCLGET, &Locmode); #endif } tty = oldtty; tty.sg_flags |= RAW; tty.sg_flags &= ~ECHO; ioctl(fd, TIOCSETP, &tty); did0 = TRUE; Baudrate = getspeed(tty.sg_ospeed); return OK; case 0: if(!did0) return ERROR; ioctl(fd, TIOCSETP, &oldtty); ioctl(fd, TIOCSETC, &oldtch); ioctl(fd, TIOCNXCL, 0); #ifdef LLITOUT ioctl(fd, TIOCLSET, &Locmode); #endif #ifdef TIOCFLUSH { int x=1; ioctl(fd,TIOCFLUSH,&x); } #endif #endif return OK; default: return ERROR; } }