1/* $OpenBSD: tip.h,v 1.27 2006/08/18 03:06:18 jason Exp $ */ 2/* $NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $ */ 3/* $FreeBSD: stable/11/usr.bin/tip/tip/tip.h 359763 2020-04-10 00:27:19Z kevans $ */ 4 5/* 6 * Copyright (c) 1989, 1993 7 * The Regents of the University of California. All rights reserved. 8 * 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)tip.h 8.1 (Berkeley) 6/6/93 35 */ 36 37/* 38 * tip - terminal interface program 39 */ 40 41#include <sys/types.h> 42#include <sys/file.h> 43#include <sys/time.h> 44#include <sys/wait.h> 45#include <sys/ioctl.h> 46 47#include <termios.h> 48#include <signal.h> 49#include <stdio.h> 50#include <stdlib.h> 51#include <string.h> 52#include <pwd.h> 53#include <ctype.h> 54#include <setjmp.h> 55#include <unistd.h> 56#include <errno.h> 57#include <limits.h> 58 59#ifndef EXTERN 60#define EXTERN extern 61#endif 62 63/* 64 * Remote host attributes 65 */ 66EXTERN char *DV; /* UNIX device(s) to open */ 67EXTERN char *EL; /* chars marking an EOL */ 68EXTERN char *CM; /* initial connection message */ 69EXTERN char *IE; /* EOT to expect on input */ 70EXTERN char *OE; /* EOT to send to complete FT */ 71EXTERN char *CU; /* call unit if making a phone call */ 72EXTERN char *AT; /* acu type */ 73EXTERN char *PN; /* phone number(s) */ 74EXTERN char *DI; /* disconnect string */ 75EXTERN char *PA; /* parity to be generated */ 76 77EXTERN char *PH; /* phone number file */ 78EXTERN char *RM; /* remote file name */ 79EXTERN char *HO; /* host name */ 80 81EXTERN long BR; /* line speed for conversation */ 82EXTERN long FS; /* frame size for transfers */ 83 84EXTERN short DU; /* this host is dialed up */ 85EXTERN short HW; /* this device is hardwired, see hunt.c */ 86EXTERN char *ES; /* escape character */ 87EXTERN char *EX; /* exceptions */ 88EXTERN char *FO; /* force (literal next) char*/ 89EXTERN char *RC; /* raise character */ 90EXTERN char *RE; /* script record file */ 91EXTERN char *PR; /* remote prompt */ 92EXTERN long DL; /* line delay for file transfers to remote */ 93EXTERN long CL; /* char delay for file transfers to remote */ 94EXTERN long ET; /* echocheck timeout */ 95EXTERN long LD; /* line disc */ 96EXTERN short HD; /* this host is half duplex - do local echo */ 97 98/* 99 * String value table 100 */ 101typedef 102 struct { 103 char *v_name; /* whose name is it */ 104 char v_type; /* for interpreting set's */ 105 char v_access; /* protection of touchy ones */ 106 char *v_abrev; /* possible abbreviation */ 107 char *v_value; /* casted to a union later */ 108 } 109 value_t; 110 111#define STRING 01 /* string valued */ 112#define BOOL 02 /* true-false value */ 113#define NUMBER 04 /* numeric value */ 114#define CHAR 010 /* character value */ 115 116#define WRITE 01 /* write access to variable */ 117#define READ 02 /* read access */ 118 119#define CHANGED 01 /* low bit is used to show modification */ 120#define PUBLIC 1 /* public access rights */ 121#define PRIVATE 03 /* private to definer */ 122#define ROOT 05 /* root defined */ 123 124#define TRUE 1 125#define FALSE 0 126 127#define ENVIRON 020 /* initialize out of the environment */ 128#define IREMOTE 040 /* initialize out of remote structure */ 129#define INIT 0100 /* static data space used for initialization */ 130#define TMASK 017 131 132/* 133 * Definition of ACU line description 134 */ 135typedef 136 struct { 137 char *acu_name; 138 int (*acu_dialer)(char *, char *); 139 void (*acu_disconnect)(void); 140 void (*acu_abort)(void); 141 } 142 acu_t; 143 144#define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */ 145 146/* 147 * variable manipulation stuff -- 148 * if we defined the value entry in value_t, then we couldn't 149 * initialize it in vars.c, so we cast it as needed to keep lint 150 * happy. 151 */ 152 153#define value(v) vtable[v].v_value 154#define lvalue(v) (long)vtable[v].v_value 155 156#define number(v) ((long)(v)) 157#define boolean(v) ((short)(long)(v)) 158#define character(v) ((char)(long)(v)) 159#define address(v) ((long *)(v)) 160 161#define setnumber(v,n) do { (v) = (char *)(long)(n); } while (0) 162#define setboolean(v,n) do { (v) = (char *)(long)(n); } while (0) 163#define setcharacter(v,n) do { (v) = (char *)(long)(n); } while (0) 164#define setaddress(v,n) do { (v) = (char *)(n); } while (0) 165 166/* 167 * Escape command table definitions -- 168 * lookup in this table is performed when ``escapec'' is recognized 169 * at the beginning of a line (as defined by the eolmarks variable). 170*/ 171 172typedef 173 struct { 174 char e_char; /* char to match on */ 175 char e_flags; /* experimental, privileged */ 176 char *e_help; /* help string */ 177 void (*e_func)(int); /* command */ 178 } 179 esctable_t; 180 181#define NORM 00 /* normal protection, execute anyone */ 182#define EXP 01 /* experimental, mark it with a `*' on help */ 183#define PRIV 02 /* privileged, root execute only */ 184 185extern int vflag; /* verbose during reading of .tiprc file */ 186extern int noesc; /* no escape `~' char */ 187extern value_t vtable[]; /* variable table */ 188 189#ifndef ACULOG 190#define logent(a, b, c, d) 191#define loginit() 192#endif 193 194/* 195 * Definition of indices into variable table so 196 * value(DEFINE) turns into a static address. 197 */ 198 199#define BEAUTIFY 0 200#define BAUDRATE 1 201#define DIALTIMEOUT 2 202#define EOFREAD 3 203#define EOFWRITE 4 204#define EOL 5 205#define ESCAPE 6 206#define EXCEPTIONS 7 207#define FORCE 8 208#define FRAMESIZE 9 209#define HOST 10 210#define LOG 11 211#define PHONES 12 212#define PROMPT 13 213#define RAISE 14 214#define RAISECHAR 15 215#define RECORD 16 216#define REMOTE 17 217#define SCRIPT 18 218#define TABEXPAND 19 219#define VERBOSE 20 220#define SHELL 21 221#define HOME 22 222#define ECHOCHECK 23 223#define DISCONNECT 24 224#define TAND 25 225#define LDELAY 26 226#define CDELAY 27 227#define ETIMEOUT 28 228#define RAWFTP 29 229#define HALFDUPLEX 30 230#define LECHO 31 231#define PARITY 32 232#define HARDWAREFLOW 33 233#define LINEDISC 34 234#define DC 35 235 236#define NOVAL ((value_t *)NULL) 237#define NOACU ((acu_t *)NULL) 238#define NOSTR ((char *)NULL) 239#define NOFILE ((FILE *)NULL) 240#define NOPWD ((struct passwd *)0) 241 242EXTERN struct termios term; /* current mode of terminal */ 243EXTERN struct termios defterm; /* initial mode of terminal */ 244EXTERN struct termios defchars; /* current mode with initial chars */ 245EXTERN int gotdefterm; 246 247EXTERN FILE *fscript; /* FILE for scripting */ 248 249EXTERN int fildes[2]; /* file transfer synchronization channel */ 250EXTERN int repdes[2]; /* read process sychronization channel */ 251EXTERN int FD; /* open file descriptor to remote host */ 252EXTERN int AC; /* open file descriptor to dialer (v831 only) */ 253EXTERN int vflag; /* print .tiprc initialization sequence */ 254EXTERN int noesc; /* no `~' escape char */ 255EXTERN int sfd; /* for ~< operation */ 256EXTERN pid_t tipin_pid; /* pid of tipin */ 257EXTERN pid_t tipout_pid; /* pid of tipout */ 258EXTERN uid_t uid, euid; /* real and effective user id's */ 259EXTERN gid_t gid, egid; /* real and effective group id's */ 260EXTERN int stop; /* stop transfer session flag */ 261EXTERN int quit; /* same; but on other end */ 262EXTERN int intflag; /* recognized interrupt */ 263EXTERN int stoprompt; /* for interrupting a prompt session */ 264EXTERN int timedout; /* ~> transfer timedout */ 265EXTERN int cumode; /* simulating the "cu" program */ 266EXTERN int bits8; /* terminal is 8-bit mode */ 267#define STRIP_PAR (bits8 ? 0377 : 0177) 268 269EXTERN char fname[PATH_MAX]; /* file name buffer for ~< */ 270EXTERN char copyname[PATH_MAX]; /* file name buffer for ~> */ 271EXTERN char ccc; /* synchronization character */ 272EXTERN char *uucplock; /* name of lock file for uucp's */ 273 274EXTERN int odisc; /* initial tty line discipline */ 275extern int disc; /* current tty discpline */ 276 277extern char *__progname; /* program name */ 278 279char *con(void); 280char *ctrl(char); 281char *expand(char *); 282char *getremote(char *); 283char *interp(char *); 284int any(int, char *); 285int biz22w_dialer(char *, char *); 286int biz22f_dialer(char *, char *); 287int biz31w_dialer(char *, char *); 288int biz31f_dialer(char *, char *); 289int cour_dialer(char *, char *); 290int df02_dialer(char *, char *); 291int df03_dialer(char *, char *); 292int dn_dialer(char *, char *); 293int hay_dialer(char *, char *); 294int prompt(char *, char *, size_t); 295size_t size(char *); 296int t3000_dialer(char *, char *); 297int ttysetup(int); 298int uu_lock(char *); 299int uu_unlock(char *); 300int v3451_dialer(char *, char *); 301int v831_dialer(char *, char *); 302int ven_dialer(char *, char *); 303int vstring(char *, char *); 304long hunt(char *); 305void biz22_disconnect(void); 306void biz22_abort(void); 307void biz31_disconnect(void); 308void biz31_abort(void); 309void chdirectory(int); 310void cleanup(int); 311void consh(int); 312void cour_abort(void); 313void cour_disconnect(void); 314void cu_put(int); 315void cu_take(int); 316void cumain(int, char **); 317void daemon_uid(void); 318void df_abort(void); 319void df_disconnect(void); 320void disconnect(char *); 321void dn_abort(void); 322void dn_disconnect(void); 323void finish(int); 324void genbrk(int); 325void getfl(int); 326void hay_abort(void); 327void hay_disconnect(void); 328void help(int); 329void listvariables(int); 330void logent(char *, char *, char *, char *); 331void loginit(void); 332void parwrite(int, char *, size_t); 333void pipefile(int); 334void pipeout(int); 335void raw(void); 336void sendfile(int); 337void setparity(char *); 338void setscript(void); 339void shell(int); 340void shell_uid(void); 341void suspend(int); 342void t3000_disconnect(void); 343void t3000_abort(void); 344void timeout(int); 345void tipabort(char *); 346void tipout(void); 347void user_uid(void); 348void unexcl(void); 349void unraw(void); 350void v3451_abort(void); 351void v3451_disconnect(void); 352void v831_disconnect(void); 353void v831_abort(void); 354void variable(int); 355void ven_disconnect(void); 356void ven_abort(void); 357void vinit(void); 358void vlex(char *); 359