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