1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate /* 6*7c478bd9Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 7*7c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 8*7c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 9*7c478bd9Sstevel@tonic-gate */ 10*7c478bd9Sstevel@tonic-gate 11*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 12*7c478bd9Sstevel@tonic-gate 13*7c478bd9Sstevel@tonic-gate /* 14*7c478bd9Sstevel@tonic-gate * tip - terminal interface program 15*7c478bd9Sstevel@tonic-gate */ 16*7c478bd9Sstevel@tonic-gate 17*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 18*7c478bd9Sstevel@tonic-gate #ifdef USG 19*7c478bd9Sstevel@tonic-gate #include <fcntl.h> /* for O_RDWR, etc. */ 20*7c478bd9Sstevel@tonic-gate #include <unistd.h> /* for R_OK, etc. */ 21*7c478bd9Sstevel@tonic-gate #else 22*7c478bd9Sstevel@tonic-gate #include <sys/file.h> 23*7c478bd9Sstevel@tonic-gate #endif 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate #include <sys/termios.h> 26*7c478bd9Sstevel@tonic-gate #include <sys/filio.h> /* XXX - for FIONREAD only */ 27*7c478bd9Sstevel@tonic-gate #include <signal.h> 28*7c478bd9Sstevel@tonic-gate #include <stdio.h> 29*7c478bd9Sstevel@tonic-gate #include <pwd.h> 30*7c478bd9Sstevel@tonic-gate #include <ctype.h> 31*7c478bd9Sstevel@tonic-gate #include <setjmp.h> 32*7c478bd9Sstevel@tonic-gate #include <errno.h> 33*7c478bd9Sstevel@tonic-gate #include <string.h> 34*7c478bd9Sstevel@tonic-gate #include <time.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> /* for ENDIAN defines */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #define _CTRL(c) (c&037) 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate #ifdef USG 40*7c478bd9Sstevel@tonic-gate #define signal(_sig_, _hdlr_) sigset((_sig_), (_hdlr_)) 41*7c478bd9Sstevel@tonic-gate #endif 42*7c478bd9Sstevel@tonic-gate typedef void (*sig_handler_t)(); /* works on BSD and SV */ 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate /* 45*7c478bd9Sstevel@tonic-gate * Remote host attributes 46*7c478bd9Sstevel@tonic-gate */ 47*7c478bd9Sstevel@tonic-gate char *DV; /* UNIX device(s) to open */ 48*7c478bd9Sstevel@tonic-gate char *EL; /* chars marking an EOL */ 49*7c478bd9Sstevel@tonic-gate char *CM; /* initial connection message */ 50*7c478bd9Sstevel@tonic-gate char *IE; /* EOT to expect on input */ 51*7c478bd9Sstevel@tonic-gate char *OE; /* EOT to send to complete FT */ 52*7c478bd9Sstevel@tonic-gate char *CU; /* call unit if making a phone call */ 53*7c478bd9Sstevel@tonic-gate char *AT; /* acu type */ 54*7c478bd9Sstevel@tonic-gate char *PN; /* phone number(s) */ 55*7c478bd9Sstevel@tonic-gate char *DI; /* disconnect string */ 56*7c478bd9Sstevel@tonic-gate char *PA; /* parity to be generated */ 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate char *PH; /* phone number file */ 59*7c478bd9Sstevel@tonic-gate char *RM; /* remote file name */ 60*7c478bd9Sstevel@tonic-gate char *HO; /* host name */ 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate int BR; /* line speed for conversation */ 63*7c478bd9Sstevel@tonic-gate int FS; /* frame size for transfers */ 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate signed char DU; /* this host is dialed up */ 66*7c478bd9Sstevel@tonic-gate char HW; /* this device is hardwired, see hunt.c */ 67*7c478bd9Sstevel@tonic-gate char *ES; /* escape character */ 68*7c478bd9Sstevel@tonic-gate char *EX; /* exceptions */ 69*7c478bd9Sstevel@tonic-gate char *FO; /* force (literal next) char */ 70*7c478bd9Sstevel@tonic-gate char *RC; /* raise character */ 71*7c478bd9Sstevel@tonic-gate char *RE; /* script record file */ 72*7c478bd9Sstevel@tonic-gate char *PR; /* remote prompt */ 73*7c478bd9Sstevel@tonic-gate int DL; /* line delay for file transfers to remote */ 74*7c478bd9Sstevel@tonic-gate int CL; /* char delay for file transfers to remote */ 75*7c478bd9Sstevel@tonic-gate int ET; /* echocheck timeout */ 76*7c478bd9Sstevel@tonic-gate int DB; /* dialback - ignore hangup */ 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate /* 79*7c478bd9Sstevel@tonic-gate * String value table 80*7c478bd9Sstevel@tonic-gate */ 81*7c478bd9Sstevel@tonic-gate typedef 82*7c478bd9Sstevel@tonic-gate struct { 83*7c478bd9Sstevel@tonic-gate char *v_name; /* whose name is it */ 84*7c478bd9Sstevel@tonic-gate char v_type; /* for interpreting set's */ 85*7c478bd9Sstevel@tonic-gate char v_access; /* protection of touchy ones */ 86*7c478bd9Sstevel@tonic-gate char *v_abrev; /* possible abreviation */ 87*7c478bd9Sstevel@tonic-gate char *v_value; /* casted to a union later */ 88*7c478bd9Sstevel@tonic-gate } 89*7c478bd9Sstevel@tonic-gate value_t; 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate #define STRING 01 /* string valued */ 92*7c478bd9Sstevel@tonic-gate #define BOOL 02 /* true-false value */ 93*7c478bd9Sstevel@tonic-gate #define NUMBER 04 /* numeric value */ 94*7c478bd9Sstevel@tonic-gate #define CHAR 010 /* character value */ 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate #define WRITE 01 /* write access to variable */ 97*7c478bd9Sstevel@tonic-gate #define READ 02 /* read access */ 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate #define CHANGED 01 /* low bit is used to show modification */ 100*7c478bd9Sstevel@tonic-gate #define PUBLIC 1 /* public access rights */ 101*7c478bd9Sstevel@tonic-gate #define PRIVATE 03 /* private to definer */ 102*7c478bd9Sstevel@tonic-gate #define ROOT 05 /* root defined */ 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate #define TRUE 1 105*7c478bd9Sstevel@tonic-gate #define FALSE 0 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate #define ENVIRON 020 /* initialize out of the environment */ 108*7c478bd9Sstevel@tonic-gate #define IREMOTE 040 /* initialize out of remote structure */ 109*7c478bd9Sstevel@tonic-gate #define INIT 0100 /* static data space used for initialization */ 110*7c478bd9Sstevel@tonic-gate #define TMASK 017 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate /* 113*7c478bd9Sstevel@tonic-gate * Definition of ACU line description 114*7c478bd9Sstevel@tonic-gate */ 115*7c478bd9Sstevel@tonic-gate typedef 116*7c478bd9Sstevel@tonic-gate struct { 117*7c478bd9Sstevel@tonic-gate char *acu_name; 118*7c478bd9Sstevel@tonic-gate int (*acu_dialer)(); 119*7c478bd9Sstevel@tonic-gate int (*acu_disconnect)(); 120*7c478bd9Sstevel@tonic-gate int (*acu_abort)(); 121*7c478bd9Sstevel@tonic-gate } 122*7c478bd9Sstevel@tonic-gate acu_t; 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate #define equal(a, b) (strcmp(a, b) == 0) /* A nice function to compare */ 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate /* 127*7c478bd9Sstevel@tonic-gate * variable manipulation stuff -- 128*7c478bd9Sstevel@tonic-gate * if we defined the value entry in value_t, then we couldn't 129*7c478bd9Sstevel@tonic-gate * initialize it in vars.c, so we cast it as needed to keep lint 130*7c478bd9Sstevel@tonic-gate * happy. 131*7c478bd9Sstevel@tonic-gate */ 132*7c478bd9Sstevel@tonic-gate typedef 133*7c478bd9Sstevel@tonic-gate union { 134*7c478bd9Sstevel@tonic-gate int zz_number; 135*7c478bd9Sstevel@tonic-gate int *zz_address; 136*7c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 137*7c478bd9Sstevel@tonic-gate short zz_boolean; 138*7c478bd9Sstevel@tonic-gate char zz_character; 139*7c478bd9Sstevel@tonic-gate #endif 140*7c478bd9Sstevel@tonic-gate #if defined(_BIG_ENDIAN) 141*7c478bd9Sstevel@tonic-gate int zz_boolean; 142*7c478bd9Sstevel@tonic-gate int zz_character; 143*7c478bd9Sstevel@tonic-gate #endif 144*7c478bd9Sstevel@tonic-gate } 145*7c478bd9Sstevel@tonic-gate zzhack; 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate #define value(v) vtable[v].v_value 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate #define boolean(v) ((((zzhack *)(&(v))))->zz_boolean) 150*7c478bd9Sstevel@tonic-gate #define number(v) ((((zzhack *)(&(v))))->zz_number) 151*7c478bd9Sstevel@tonic-gate #define character(v) ((((zzhack *)(&(v))))->zz_character) 152*7c478bd9Sstevel@tonic-gate #define address(v) ((((zzhack *)(&(v))))->zz_address) 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate /* 155*7c478bd9Sstevel@tonic-gate * Escape command table definitions -- 156*7c478bd9Sstevel@tonic-gate * lookup in this table is performed when ``escapec'' is recognized 157*7c478bd9Sstevel@tonic-gate * at the begining of a line (as defined by the eolmarks variable). 158*7c478bd9Sstevel@tonic-gate */ 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate typedef 161*7c478bd9Sstevel@tonic-gate struct { 162*7c478bd9Sstevel@tonic-gate char e_char; /* char to match on */ 163*7c478bd9Sstevel@tonic-gate char e_flags; /* experimental, priviledged */ 164*7c478bd9Sstevel@tonic-gate char *e_help; /* help string */ 165*7c478bd9Sstevel@tonic-gate int (*e_func)(); /* command */ 166*7c478bd9Sstevel@tonic-gate } 167*7c478bd9Sstevel@tonic-gate esctable_t; 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate #define NORM 00 /* normal protection, execute anyone */ 170*7c478bd9Sstevel@tonic-gate #define EXP 01 /* experimental, mark it with a `*' on help */ 171*7c478bd9Sstevel@tonic-gate #define PRIV 02 /* priviledged, root execute only */ 172*7c478bd9Sstevel@tonic-gate 173*7c478bd9Sstevel@tonic-gate extern int vflag; /* verbose during reading of .tiprc file */ 174*7c478bd9Sstevel@tonic-gate extern value_t vtable[]; /* variable table */ 175*7c478bd9Sstevel@tonic-gate extern int noparity; 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate #ifndef ACULOG 179*7c478bd9Sstevel@tonic-gate #define logent(a, b, c, d) 180*7c478bd9Sstevel@tonic-gate #define loginit() 181*7c478bd9Sstevel@tonic-gate #endif 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate /* 184*7c478bd9Sstevel@tonic-gate * Definition of indices into variable table so 185*7c478bd9Sstevel@tonic-gate * value(DEFINE) turns into a static address. 186*7c478bd9Sstevel@tonic-gate */ 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate #define BEAUTIFY 0 189*7c478bd9Sstevel@tonic-gate #define BAUDRATE 1 190*7c478bd9Sstevel@tonic-gate #define DIALTIMEOUT 2 191*7c478bd9Sstevel@tonic-gate #define EOFREAD 3 192*7c478bd9Sstevel@tonic-gate #define EOFWRITE 4 193*7c478bd9Sstevel@tonic-gate #define EOL 5 194*7c478bd9Sstevel@tonic-gate #define ESCAPE 6 195*7c478bd9Sstevel@tonic-gate #define EXCEPTIONS 7 196*7c478bd9Sstevel@tonic-gate #define FORCE 8 197*7c478bd9Sstevel@tonic-gate #define FRAMESIZE 9 198*7c478bd9Sstevel@tonic-gate #define HOST 10 199*7c478bd9Sstevel@tonic-gate #define LOG 11 200*7c478bd9Sstevel@tonic-gate #define PHONES 12 201*7c478bd9Sstevel@tonic-gate #define PROMPT 13 202*7c478bd9Sstevel@tonic-gate #define RAISE 14 203*7c478bd9Sstevel@tonic-gate #define RAISECHAR 15 204*7c478bd9Sstevel@tonic-gate #define RECORD 16 205*7c478bd9Sstevel@tonic-gate #define REMOTE 17 206*7c478bd9Sstevel@tonic-gate #define SCRIPT 18 207*7c478bd9Sstevel@tonic-gate #define TABEXPAND 19 208*7c478bd9Sstevel@tonic-gate #define VERBOSE 20 209*7c478bd9Sstevel@tonic-gate #define SHELL 21 210*7c478bd9Sstevel@tonic-gate #define HOME 22 211*7c478bd9Sstevel@tonic-gate #define ECHOCHECK 23 212*7c478bd9Sstevel@tonic-gate #define DISCONNECT 24 213*7c478bd9Sstevel@tonic-gate #define TAND 25 214*7c478bd9Sstevel@tonic-gate #define LDELAY 26 215*7c478bd9Sstevel@tonic-gate #define CDELAY 27 216*7c478bd9Sstevel@tonic-gate #define ETIMEOUT 28 217*7c478bd9Sstevel@tonic-gate #define RAWFTP 29 218*7c478bd9Sstevel@tonic-gate #define HALFDUPLEX 30 219*7c478bd9Sstevel@tonic-gate #define LECHO 31 220*7c478bd9Sstevel@tonic-gate #define PARITY 32 221*7c478bd9Sstevel@tonic-gate #define HARDWAREFLOW 33 222*7c478bd9Sstevel@tonic-gate 223*7c478bd9Sstevel@tonic-gate #define NOVAL ((value_t *)NULL) 224*7c478bd9Sstevel@tonic-gate #define NOACU ((acu_t *)NULL) 225*7c478bd9Sstevel@tonic-gate #define NOSTR ((char *)NULL) 226*7c478bd9Sstevel@tonic-gate #define NOFILE ((FILE *)NULL) 227*7c478bd9Sstevel@tonic-gate #define NOPWD ((struct passwd *)0) 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gate struct termios arg; /* current mode of local terminal */ 230*7c478bd9Sstevel@tonic-gate struct termios defarg; /* initial mode of local terminal */ 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate FILE *fscript; /* FILE for scripting */ 233*7c478bd9Sstevel@tonic-gate FILE *phfd; /* FILE for PHONES file */ 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate int fildes[2]; /* file transfer synchronization channel */ 236*7c478bd9Sstevel@tonic-gate int repdes[2]; /* read process sychronization channel */ 237*7c478bd9Sstevel@tonic-gate int FD; /* open file descriptor to remote host */ 238*7c478bd9Sstevel@tonic-gate int AC; /* open file descriptor to dialer (v831 only) */ 239*7c478bd9Sstevel@tonic-gate int vflag; /* print .tiprc initialization sequence */ 240*7c478bd9Sstevel@tonic-gate int sfd; /* for ~< operation */ 241*7c478bd9Sstevel@tonic-gate int pid; /* pid of tipout */ 242*7c478bd9Sstevel@tonic-gate int uid, euid; /* real and effective user id's */ 243*7c478bd9Sstevel@tonic-gate int gid, egid; /* real and effective group id's */ 244*7c478bd9Sstevel@tonic-gate int stoprompt; /* for interrupting a prompt session */ 245*7c478bd9Sstevel@tonic-gate int timedout; /* ~> transfer timedout */ 246*7c478bd9Sstevel@tonic-gate int cumode; /* simulating the "cu" program */ 247*7c478bd9Sstevel@tonic-gate 248*7c478bd9Sstevel@tonic-gate char fname[80]; /* file name buffer for ~< */ 249*7c478bd9Sstevel@tonic-gate char copyname[80]; /* file name buffer for ~> */ 250*7c478bd9Sstevel@tonic-gate char ccc; /* synchronization character */ 251*7c478bd9Sstevel@tonic-gate char ch; /* for tipout */ 252*7c478bd9Sstevel@tonic-gate char *uucplock; /* name of lock file for uucp's */ 253*7c478bd9Sstevel@tonic-gate extern int trusted_device; 254*7c478bd9Sstevel@tonic-gate 255*7c478bd9Sstevel@tonic-gate extern char *ctrl(); 256*7c478bd9Sstevel@tonic-gate extern char *ctime(); 257*7c478bd9Sstevel@tonic-gate extern struct passwd *getpwuid(); 258*7c478bd9Sstevel@tonic-gate extern char *getlogin(); 259*7c478bd9Sstevel@tonic-gate extern char *vinterp(); 260*7c478bd9Sstevel@tonic-gate extern char *getenv(); 261*7c478bd9Sstevel@tonic-gate extern char *malloc(); 262*7c478bd9Sstevel@tonic-gate extern char *connect(); 263