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