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 */ 65 EXTERN char *DV; /* UNIX device(s) to open */ 66 EXTERN char *EL; /* chars marking an EOL */ 67 EXTERN char *CM; /* initial connection message */ 68 EXTERN char *IE; /* EOT to expect on input */ 69 EXTERN char *OE; /* EOT to send to complete FT */ 70 EXTERN char *CU; /* call unit if making a phone call */ 71 EXTERN char *AT; /* acu type */ 72 EXTERN char *PN; /* phone number(s) */ 73 EXTERN char *DI; /* disconnect string */ 74 EXTERN char *PA; /* parity to be generated */ 75 76 EXTERN char *PH; /* phone number file */ 77 EXTERN char *RM; /* remote file name */ 78 EXTERN char *HO; /* host name */ 79 80 EXTERN long BR; /* line speed for conversation */ 81 EXTERN long FS; /* frame size for transfers */ 82 83 EXTERN short DU; /* this host is dialed up */ 84 EXTERN short HW; /* this device is hardwired, see hunt.c */ 85 EXTERN char *ES; /* escape character */ 86 EXTERN char *EX; /* exceptions */ 87 EXTERN char *FO; /* force (literal next) char*/ 88 EXTERN char *RC; /* raise character */ 89 EXTERN char *RE; /* script record file */ 90 EXTERN char *PR; /* remote prompt */ 91 EXTERN long DL; /* line delay for file transfers to remote */ 92 EXTERN long CL; /* char delay for file transfers to remote */ 93 EXTERN long ET; /* echocheck timeout */ 94 EXTERN long LD; /* line disc */ 95 EXTERN short HD; /* this host is half duplex - do local echo */ 96 97 /* 98 * String value table 99 */ 100 typedef 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 */ 134 typedef 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 169 typedef 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 182 extern int vflag; /* verbose during reading of .tiprc file */ 183 extern int noesc; /* no escape `~' char */ 184 extern 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 239 EXTERN struct termios term; /* current mode of terminal */ 240 EXTERN struct termios defterm; /* initial mode of terminal */ 241 EXTERN struct termios defchars; /* current mode with initial chars */ 242 EXTERN int gotdefterm; 243 244 EXTERN FILE *fscript; /* FILE for scripting */ 245 246 EXTERN int fildes[2]; /* file transfer synchronization channel */ 247 EXTERN int repdes[2]; /* read process synchronization channel */ 248 EXTERN int FD; /* open file descriptor to remote host */ 249 EXTERN int AC; /* open file descriptor to dialer (v831 only) */ 250 EXTERN int vflag; /* print .tiprc initialization sequence */ 251 EXTERN int noesc; /* no `~' escape char */ 252 EXTERN int sfd; /* for ~< operation */ 253 EXTERN pid_t tipin_pid; /* pid of tipin */ 254 EXTERN pid_t tipout_pid; /* pid of tipout */ 255 EXTERN uid_t uid, euid; /* real and effective user id's */ 256 EXTERN gid_t gid, egid; /* real and effective group id's */ 257 EXTERN int stop; /* stop transfer session flag */ 258 EXTERN int quit; /* same; but on other end */ 259 EXTERN int intflag; /* recognized interrupt */ 260 EXTERN int stoprompt; /* for interrupting a prompt session */ 261 EXTERN int timedout; /* ~> transfer timedout */ 262 EXTERN int cumode; /* simulating the "cu" program */ 263 EXTERN int bits8; /* terminal is 8-bit mode */ 264 #define STRIP_PAR (bits8 ? 0377 : 0177) 265 266 EXTERN char fname[PATH_MAX]; /* file name buffer for ~< */ 267 EXTERN char copyname[PATH_MAX]; /* file name buffer for ~> */ 268 EXTERN char ccc; /* synchronization character */ 269 EXTERN char *uucplock; /* name of lock file for uucp's */ 270 271 EXTERN int odisc; /* initial tty line discipline */ 272 extern int disc; /* current tty discpline */ 273 274 extern char *__progname; /* program name */ 275 276 char *con(void); 277 char *ctrl(char); 278 char *expand(char *); 279 char *getremote(char *); 280 char *interp(char *); 281 int any(int, char *); 282 int biz22w_dialer(char *, char *); 283 int biz22f_dialer(char *, char *); 284 int biz31w_dialer(char *, char *); 285 int biz31f_dialer(char *, char *); 286 int cour_dialer(char *, char *); 287 int df02_dialer(char *, char *); 288 int df03_dialer(char *, char *); 289 int dn_dialer(char *, char *); 290 int hay_dialer(char *, char *); 291 int prompt(char *, char *, size_t); 292 size_t size(char *); 293 int t3000_dialer(char *, char *); 294 int ttysetup(int); 295 int uu_lock(char *); 296 int uu_unlock(char *); 297 int v3451_dialer(char *, char *); 298 int v831_dialer(char *, char *); 299 int ven_dialer(char *, char *); 300 int vstring(char *, char *); 301 long hunt(char *); 302 void biz22_disconnect(void); 303 void biz22_abort(void); 304 void biz31_disconnect(void); 305 void biz31_abort(void); 306 void chdirectory(int); 307 void cleanup(int); 308 void consh(int); 309 void cour_abort(void); 310 void cour_disconnect(void); 311 void cu_put(int); 312 void cu_take(int); 313 void cumain(int, char **); 314 void daemon_uid(void); 315 void df_abort(void); 316 void df_disconnect(void); 317 void disconnect(char *); 318 void dn_abort(void); 319 void dn_disconnect(void); 320 void finish(int); 321 void genbrk(int); 322 void getfl(int); 323 void hay_abort(void); 324 void hay_disconnect(void); 325 void help(int); 326 void listvariables(int); 327 void logent(char *, char *, char *, char *); 328 void loginit(void); 329 void parwrite(int, char *, size_t); 330 void pipefile(int); 331 void pipeout(int); 332 void raw(void); 333 void sendfile(int); 334 void setparity(char *); 335 void setscript(void); 336 void shell(int); 337 void shell_uid(void); 338 void suspend(int); 339 void t3000_disconnect(void); 340 void t3000_abort(void); 341 void timeout(int); 342 void tipabort(char *); 343 void tipout(void); 344 void user_uid(void); 345 void unexcl(void); 346 void unraw(void); 347 void v3451_abort(void); 348 void v3451_disconnect(void); 349 void v831_disconnect(void); 350 void v831_abort(void); 351 void variable(int); 352 void ven_disconnect(void); 353 void ven_abort(void); 354 void vinit(void); 355 void vlex(char *); 356