10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 30Sstevel@tonic-gate * Use is subject to license terms. 40Sstevel@tonic-gate */ 50Sstevel@tonic-gate /* 60Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 70Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 80Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 90Sstevel@tonic-gate */ 100Sstevel@tonic-gate 11*549Smuffin #ifndef _TIP_H 12*549Smuffin #define _TIP_H 13*549Smuffin 140Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 150Sstevel@tonic-gate 160Sstevel@tonic-gate /* 170Sstevel@tonic-gate * tip - terminal interface program 180Sstevel@tonic-gate */ 190Sstevel@tonic-gate 200Sstevel@tonic-gate #include <sys/types.h> 210Sstevel@tonic-gate #ifdef USG 220Sstevel@tonic-gate #include <fcntl.h> /* for O_RDWR, etc. */ 230Sstevel@tonic-gate #include <unistd.h> /* for R_OK, etc. */ 240Sstevel@tonic-gate #else 250Sstevel@tonic-gate #include <sys/file.h> 260Sstevel@tonic-gate #endif 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/termios.h> 290Sstevel@tonic-gate #include <sys/filio.h> /* XXX - for FIONREAD only */ 300Sstevel@tonic-gate #include <signal.h> 310Sstevel@tonic-gate #include <stdio.h> 320Sstevel@tonic-gate #include <pwd.h> 330Sstevel@tonic-gate #include <ctype.h> 340Sstevel@tonic-gate #include <setjmp.h> 350Sstevel@tonic-gate #include <errno.h> 360Sstevel@tonic-gate #include <string.h> 370Sstevel@tonic-gate #include <time.h> 380Sstevel@tonic-gate #include <sys/isa_defs.h> /* for ENDIAN defines */ 39*549Smuffin #include <stdlib.h> 40*549Smuffin #include <sys/wait.h> 410Sstevel@tonic-gate 420Sstevel@tonic-gate #define _CTRL(c) (c&037) 430Sstevel@tonic-gate 440Sstevel@tonic-gate #ifdef USG 450Sstevel@tonic-gate #define signal(_sig_, _hdlr_) sigset((_sig_), (_hdlr_)) 460Sstevel@tonic-gate #endif 47*549Smuffin typedef void (*sig_handler_t)(int); /* works on BSD and SV */ 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* 500Sstevel@tonic-gate * Remote host attributes 510Sstevel@tonic-gate */ 520Sstevel@tonic-gate char *DV; /* UNIX device(s) to open */ 530Sstevel@tonic-gate char *EL; /* chars marking an EOL */ 540Sstevel@tonic-gate char *CM; /* initial connection message */ 550Sstevel@tonic-gate char *IE; /* EOT to expect on input */ 560Sstevel@tonic-gate char *OE; /* EOT to send to complete FT */ 570Sstevel@tonic-gate char *CU; /* call unit if making a phone call */ 580Sstevel@tonic-gate char *AT; /* acu type */ 590Sstevel@tonic-gate char *PN; /* phone number(s) */ 600Sstevel@tonic-gate char *DI; /* disconnect string */ 610Sstevel@tonic-gate char *PA; /* parity to be generated */ 620Sstevel@tonic-gate 630Sstevel@tonic-gate char *PH; /* phone number file */ 640Sstevel@tonic-gate char *RM; /* remote file name */ 650Sstevel@tonic-gate char *HO; /* host name */ 660Sstevel@tonic-gate 670Sstevel@tonic-gate int BR; /* line speed for conversation */ 680Sstevel@tonic-gate int FS; /* frame size for transfers */ 690Sstevel@tonic-gate 700Sstevel@tonic-gate signed char DU; /* this host is dialed up */ 710Sstevel@tonic-gate char HW; /* this device is hardwired, see hunt.c */ 720Sstevel@tonic-gate char *ES; /* escape character */ 730Sstevel@tonic-gate char *EX; /* exceptions */ 740Sstevel@tonic-gate char *FO; /* force (literal next) char */ 750Sstevel@tonic-gate char *RC; /* raise character */ 760Sstevel@tonic-gate char *RE; /* script record file */ 770Sstevel@tonic-gate char *PR; /* remote prompt */ 780Sstevel@tonic-gate int DL; /* line delay for file transfers to remote */ 790Sstevel@tonic-gate int CL; /* char delay for file transfers to remote */ 800Sstevel@tonic-gate int ET; /* echocheck timeout */ 810Sstevel@tonic-gate int DB; /* dialback - ignore hangup */ 820Sstevel@tonic-gate 830Sstevel@tonic-gate /* 840Sstevel@tonic-gate * String value table 850Sstevel@tonic-gate */ 860Sstevel@tonic-gate typedef 870Sstevel@tonic-gate struct { 880Sstevel@tonic-gate char *v_name; /* whose name is it */ 890Sstevel@tonic-gate char v_type; /* for interpreting set's */ 900Sstevel@tonic-gate char v_access; /* protection of touchy ones */ 910Sstevel@tonic-gate char *v_abrev; /* possible abreviation */ 920Sstevel@tonic-gate char *v_value; /* casted to a union later */ 930Sstevel@tonic-gate } 940Sstevel@tonic-gate value_t; 950Sstevel@tonic-gate 960Sstevel@tonic-gate #define STRING 01 /* string valued */ 970Sstevel@tonic-gate #define BOOL 02 /* true-false value */ 980Sstevel@tonic-gate #define NUMBER 04 /* numeric value */ 990Sstevel@tonic-gate #define CHAR 010 /* character value */ 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate #define WRITE 01 /* write access to variable */ 1020Sstevel@tonic-gate #define READ 02 /* read access */ 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate #define CHANGED 01 /* low bit is used to show modification */ 1050Sstevel@tonic-gate #define PUBLIC 1 /* public access rights */ 1060Sstevel@tonic-gate #define PRIVATE 03 /* private to definer */ 1070Sstevel@tonic-gate #define ROOT 05 /* root defined */ 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate #define TRUE 1 1100Sstevel@tonic-gate #define FALSE 0 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate #define ENVIRON 020 /* initialize out of the environment */ 1130Sstevel@tonic-gate #define IREMOTE 040 /* initialize out of remote structure */ 1140Sstevel@tonic-gate #define INIT 0100 /* static data space used for initialization */ 1150Sstevel@tonic-gate #define TMASK 017 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* 1180Sstevel@tonic-gate * Definition of ACU line description 1190Sstevel@tonic-gate */ 1200Sstevel@tonic-gate typedef 1210Sstevel@tonic-gate struct { 1220Sstevel@tonic-gate char *acu_name; 123*549Smuffin int (*acu_dialer)(char *, char *); 124*549Smuffin void (*acu_disconnect)(void); 125*549Smuffin void (*acu_abort)(void); 1260Sstevel@tonic-gate } 1270Sstevel@tonic-gate acu_t; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate #define equal(a, b) (strcmp(a, b) == 0) /* A nice function to compare */ 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate /* 1320Sstevel@tonic-gate * variable manipulation stuff -- 1330Sstevel@tonic-gate * if we defined the value entry in value_t, then we couldn't 1340Sstevel@tonic-gate * initialize it in vars.c, so we cast it as needed to keep lint 1350Sstevel@tonic-gate * happy. 1360Sstevel@tonic-gate */ 1370Sstevel@tonic-gate typedef 1380Sstevel@tonic-gate union { 1390Sstevel@tonic-gate int zz_number; 1400Sstevel@tonic-gate int *zz_address; 1410Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 1420Sstevel@tonic-gate short zz_boolean; 1430Sstevel@tonic-gate char zz_character; 1440Sstevel@tonic-gate #endif 1450Sstevel@tonic-gate #if defined(_BIG_ENDIAN) 1460Sstevel@tonic-gate int zz_boolean; 1470Sstevel@tonic-gate int zz_character; 1480Sstevel@tonic-gate #endif 1490Sstevel@tonic-gate } 1500Sstevel@tonic-gate zzhack; 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate #define value(v) vtable[v].v_value 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate #define boolean(v) ((((zzhack *)(&(v))))->zz_boolean) 1550Sstevel@tonic-gate #define number(v) ((((zzhack *)(&(v))))->zz_number) 1560Sstevel@tonic-gate #define character(v) ((((zzhack *)(&(v))))->zz_character) 1570Sstevel@tonic-gate #define address(v) ((((zzhack *)(&(v))))->zz_address) 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate /* 1600Sstevel@tonic-gate * Escape command table definitions -- 1610Sstevel@tonic-gate * lookup in this table is performed when ``escapec'' is recognized 1620Sstevel@tonic-gate * at the begining of a line (as defined by the eolmarks variable). 1630Sstevel@tonic-gate */ 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate typedef 1660Sstevel@tonic-gate struct { 1670Sstevel@tonic-gate char e_char; /* char to match on */ 1680Sstevel@tonic-gate char e_flags; /* experimental, priviledged */ 1690Sstevel@tonic-gate char *e_help; /* help string */ 170*549Smuffin void (*e_func)(int); /* command */ 1710Sstevel@tonic-gate } 1720Sstevel@tonic-gate esctable_t; 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate #define NORM 00 /* normal protection, execute anyone */ 1750Sstevel@tonic-gate #define EXP 01 /* experimental, mark it with a `*' on help */ 1760Sstevel@tonic-gate #define PRIV 02 /* priviledged, root execute only */ 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate extern int vflag; /* verbose during reading of .tiprc file */ 1790Sstevel@tonic-gate extern value_t vtable[]; /* variable table */ 1800Sstevel@tonic-gate extern int noparity; 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate #ifndef ACULOG 1840Sstevel@tonic-gate #define logent(a, b, c, d) 1850Sstevel@tonic-gate #define loginit() 186*549Smuffin #else 187*549Smuffin extern void logent(char *, char *, char *, char *); 188*549Smuffin extern void loginit(void); 1890Sstevel@tonic-gate #endif 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate /* 1920Sstevel@tonic-gate * Definition of indices into variable table so 1930Sstevel@tonic-gate * value(DEFINE) turns into a static address. 1940Sstevel@tonic-gate */ 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate #define BEAUTIFY 0 1970Sstevel@tonic-gate #define BAUDRATE 1 1980Sstevel@tonic-gate #define DIALTIMEOUT 2 1990Sstevel@tonic-gate #define EOFREAD 3 2000Sstevel@tonic-gate #define EOFWRITE 4 2010Sstevel@tonic-gate #define EOL 5 2020Sstevel@tonic-gate #define ESCAPE 6 2030Sstevel@tonic-gate #define EXCEPTIONS 7 2040Sstevel@tonic-gate #define FORCE 8 2050Sstevel@tonic-gate #define FRAMESIZE 9 2060Sstevel@tonic-gate #define HOST 10 2070Sstevel@tonic-gate #define LOG 11 2080Sstevel@tonic-gate #define PHONES 12 2090Sstevel@tonic-gate #define PROMPT 13 2100Sstevel@tonic-gate #define RAISE 14 2110Sstevel@tonic-gate #define RAISECHAR 15 2120Sstevel@tonic-gate #define RECORD 16 2130Sstevel@tonic-gate #define REMOTE 17 2140Sstevel@tonic-gate #define SCRIPT 18 2150Sstevel@tonic-gate #define TABEXPAND 19 2160Sstevel@tonic-gate #define VERBOSE 20 2170Sstevel@tonic-gate #define SHELL 21 2180Sstevel@tonic-gate #define HOME 22 2190Sstevel@tonic-gate #define ECHOCHECK 23 2200Sstevel@tonic-gate #define DISCONNECT 24 2210Sstevel@tonic-gate #define TAND 25 2220Sstevel@tonic-gate #define LDELAY 26 2230Sstevel@tonic-gate #define CDELAY 27 2240Sstevel@tonic-gate #define ETIMEOUT 28 2250Sstevel@tonic-gate #define RAWFTP 29 2260Sstevel@tonic-gate #define HALFDUPLEX 30 2270Sstevel@tonic-gate #define LECHO 31 2280Sstevel@tonic-gate #define PARITY 32 2290Sstevel@tonic-gate #define HARDWAREFLOW 33 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate #define NOVAL ((value_t *)NULL) 2320Sstevel@tonic-gate #define NOACU ((acu_t *)NULL) 2330Sstevel@tonic-gate #define NOSTR ((char *)NULL) 2340Sstevel@tonic-gate #define NOFILE ((FILE *)NULL) 2350Sstevel@tonic-gate #define NOPWD ((struct passwd *)0) 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate struct termios arg; /* current mode of local terminal */ 2380Sstevel@tonic-gate struct termios defarg; /* initial mode of local terminal */ 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate FILE *fscript; /* FILE for scripting */ 2410Sstevel@tonic-gate FILE *phfd; /* FILE for PHONES file */ 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate int fildes[2]; /* file transfer synchronization channel */ 2440Sstevel@tonic-gate int repdes[2]; /* read process sychronization channel */ 2450Sstevel@tonic-gate int FD; /* open file descriptor to remote host */ 2460Sstevel@tonic-gate int AC; /* open file descriptor to dialer (v831 only) */ 2470Sstevel@tonic-gate int vflag; /* print .tiprc initialization sequence */ 2480Sstevel@tonic-gate int sfd; /* for ~< operation */ 2490Sstevel@tonic-gate int pid; /* pid of tipout */ 2500Sstevel@tonic-gate int uid, euid; /* real and effective user id's */ 2510Sstevel@tonic-gate int gid, egid; /* real and effective group id's */ 2520Sstevel@tonic-gate int stoprompt; /* for interrupting a prompt session */ 2530Sstevel@tonic-gate int timedout; /* ~> transfer timedout */ 2540Sstevel@tonic-gate int cumode; /* simulating the "cu" program */ 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate char fname[80]; /* file name buffer for ~< */ 2570Sstevel@tonic-gate char copyname[80]; /* file name buffer for ~> */ 2580Sstevel@tonic-gate char ccc; /* synchronization character */ 2590Sstevel@tonic-gate char ch; /* for tipout */ 2600Sstevel@tonic-gate char *uucplock; /* name of lock file for uucp's */ 2610Sstevel@tonic-gate extern int trusted_device; 2620Sstevel@tonic-gate 263*549Smuffin 264*549Smuffin extern char *connect(void); 265*549Smuffin extern char *ctrl(char); 266*549Smuffin extern char *getremote(char *); 267*549Smuffin extern char *expand(char []); 268*549Smuffin extern char *vinterp(char *, char); 269*549Smuffin extern void cumain(int, char *[]); 270*549Smuffin extern void delock(char *); 271*549Smuffin extern void disconnect(char *); 272*549Smuffin extern void myperm(void); 273*549Smuffin extern void parwrite(int, unsigned char *, int); 274*549Smuffin extern void raw(void); 275*549Smuffin extern void setparity(char *); 276*549Smuffin extern void setscript(void); 277*549Smuffin extern void tandem(char *); 278*549Smuffin extern void tip_abort(char *); 279*549Smuffin extern void ttysetup(int); 280*549Smuffin extern void unraw(void); 281*549Smuffin extern void userperm(void); 282*549Smuffin extern void vinit(void); 283*549Smuffin extern void vlex(char *); 284*549Smuffin extern int any(char, char *); 285*549Smuffin extern int hunt(char *); 286*549Smuffin extern int prompt(char *, char *, size_t); 287*549Smuffin extern int rgetent(char *, char *, int); 288*549Smuffin extern int rgetflag(char *); 289*549Smuffin extern int rgetnum(char *); 290*549Smuffin extern int speed(int); 291*549Smuffin extern int tip_mlock(char *); 292*549Smuffin extern int vstring(char *, char *); 293*549Smuffin 294*549Smuffin #endif /* _TIP_H */ 295