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