diff --git a/usr.bin/tip/tip/tip.h b/usr.bin/tip/tip/tip.h index 6bf94521cdfd..298b08cb6692 100644 --- a/usr.bin/tip/tip/tip.h +++ b/usr.bin/tip/tip/tip.h @@ -1,360 +1,358 @@ /* $OpenBSD: tip.h,v 1.27 2006/08/18 03:06:18 jason Exp $ */ /* $NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $ */ /* $FreeBSD$ */ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)tip.h 8.1 (Berkeley) 6/6/93 */ /* * tip - terminal interface program */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef EXTERN #define EXTERN extern #endif /* * Remote host attributes */ EXTERN char *DV; /* UNIX device(s) to open */ EXTERN char *EL; /* chars marking an EOL */ EXTERN char *CM; /* initial connection message */ EXTERN char *IE; /* EOT to expect on input */ EXTERN char *OE; /* EOT to send to complete FT */ EXTERN char *CU; /* call unit if making a phone call */ EXTERN char *AT; /* acu type */ EXTERN char *PN; /* phone number(s) */ EXTERN char *DI; /* disconnect string */ EXTERN char *PA; /* parity to be generated */ EXTERN char *PH; /* phone number file */ EXTERN char *RM; /* remote file name */ EXTERN char *HO; /* host name */ EXTERN long BR; /* line speed for conversation */ EXTERN long FS; /* frame size for transfers */ EXTERN short DU; /* this host is dialed up */ EXTERN short HW; /* this device is hardwired, see hunt.c */ EXTERN char *ES; /* escape character */ EXTERN char *EX; /* exceptions */ EXTERN char *FO; /* force (literal next) char*/ EXTERN char *RC; /* raise character */ EXTERN char *RE; /* script record file */ EXTERN char *PR; /* remote prompt */ EXTERN long DL; /* line delay for file transfers to remote */ EXTERN long CL; /* char delay for file transfers to remote */ EXTERN long ET; /* echocheck timeout */ EXTERN long LD; /* line disc */ EXTERN short HD; /* this host is half duplex - do local echo */ /* * String value table */ typedef struct { char *v_name; /* whose name is it */ char v_type; /* for interpreting set's */ char v_access; /* protection of touchy ones */ char *v_abrev; /* possible abbreviation */ char *v_value; /* casted to a union later */ } value_t; #define STRING 01 /* string valued */ #define BOOL 02 /* true-false value */ #define NUMBER 04 /* numeric value */ #define CHAR 010 /* character value */ #define WRITE 01 /* write access to variable */ #define READ 02 /* read access */ #define CHANGED 01 /* low bit is used to show modification */ #define PUBLIC 1 /* public access rights */ #define PRIVATE 03 /* private to definer */ #define ROOT 05 /* root defined */ #define TRUE 1 #define FALSE 0 #define ENVIRON 020 /* initialize out of the environment */ #define IREMOTE 040 /* initialize out of remote structure */ #define INIT 0100 /* static data space used for initialization */ #define TMASK 017 /* * Definition of ACU line description */ typedef struct { char *acu_name; int (*acu_dialer)(char *, char *); void (*acu_disconnect)(void); void (*acu_abort)(void); } acu_t; #define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */ /* * variable manipulation stuff -- * if we defined the value entry in value_t, then we couldn't * initialize it in vars.c, so we cast it as needed to keep lint * happy. */ #define value(v) vtable[v].v_value #define lvalue(v) (long)(intptr_t)vtable[v].v_value #define number(v) ((long)(intptr_t)(v)) #define boolean(v) ((short)(intptr_t)(v)) #define character(v) ((char)(intptr_t)(v)) -#define address(v) ((long *)(v)) #define setnumber(v,n) do { (v) = (char *)(intptr_t)(n); } while (0) #define setboolean(v,n) do { (v) = (char *)(intptr_t)(n); } while (0) #define setcharacter(v,n) do { (v) = (char *)(intptr_t)(n); } while (0) -#define setaddress(v,n) do { (v) = (char *)(n); } while (0) /* * Escape command table definitions -- * lookup in this table is performed when ``escapec'' is recognized * at the beginning of a line (as defined by the eolmarks variable). */ typedef struct { char e_char; /* char to match on */ char e_flags; /* experimental, privileged */ char *e_help; /* help string */ void (*e_func)(int); /* command */ } esctable_t; #define NORM 00 /* normal protection, execute anyone */ #define EXP 01 /* experimental, mark it with a `*' on help */ #define PRIV 02 /* privileged, root execute only */ extern int vflag; /* verbose during reading of .tiprc file */ extern int noesc; /* no escape `~' char */ extern value_t vtable[]; /* variable table */ #ifndef ACULOG #define logent(a, b, c, d) #define loginit() #endif /* * Definition of indices into variable table so * value(DEFINE) turns into a static address. */ #define BEAUTIFY 0 #define BAUDRATE 1 #define DIALTIMEOUT 2 #define EOFREAD 3 #define EOFWRITE 4 #define EOL 5 #define ESCAPE 6 #define EXCEPTIONS 7 #define FORCE 8 #define FRAMESIZE 9 #define HOST 10 #define LOG 11 #define PHONES 12 #define PROMPT 13 #define RAISE 14 #define RAISECHAR 15 #define RECORD 16 #define REMOTE 17 #define SCRIPT 18 #define TABEXPAND 19 #define VERBOSE 20 #define SHELL 21 #define HOME 22 #define ECHOCHECK 23 #define DISCONNECT 24 #define TAND 25 #define LDELAY 26 #define CDELAY 27 #define ETIMEOUT 28 #define RAWFTP 29 #define HALFDUPLEX 30 #define LECHO 31 #define PARITY 32 #define HARDWAREFLOW 33 #define LINEDISC 34 #define DC 35 #define NOVAL ((value_t *)NULL) #define NOACU ((acu_t *)NULL) #define NOSTR ((char *)NULL) #define NOFILE ((FILE *)NULL) #define NOPWD ((struct passwd *)0) EXTERN struct termios term; /* current mode of terminal */ EXTERN struct termios defterm; /* initial mode of terminal */ EXTERN struct termios defchars; /* current mode with initial chars */ EXTERN int gotdefterm; EXTERN FILE *fscript; /* FILE for scripting */ EXTERN int fildes[2]; /* file transfer synchronization channel */ EXTERN int repdes[2]; /* read process sychronization channel */ EXTERN int FD; /* open file descriptor to remote host */ EXTERN int AC; /* open file descriptor to dialer (v831 only) */ EXTERN int vflag; /* print .tiprc initialization sequence */ EXTERN int noesc; /* no `~' escape char */ EXTERN int sfd; /* for ~< operation */ EXTERN pid_t tipin_pid; /* pid of tipin */ EXTERN pid_t tipout_pid; /* pid of tipout */ EXTERN uid_t uid, euid; /* real and effective user id's */ EXTERN gid_t gid, egid; /* real and effective group id's */ EXTERN int stop; /* stop transfer session flag */ EXTERN int quit; /* same; but on other end */ EXTERN int intflag; /* recognized interrupt */ EXTERN int stoprompt; /* for interrupting a prompt session */ EXTERN int timedout; /* ~> transfer timedout */ EXTERN int cumode; /* simulating the "cu" program */ EXTERN int bits8; /* terminal is 8-bit mode */ #define STRIP_PAR (bits8 ? 0377 : 0177) EXTERN char fname[PATH_MAX]; /* file name buffer for ~< */ EXTERN char copyname[PATH_MAX]; /* file name buffer for ~> */ EXTERN char ccc; /* synchronization character */ EXTERN char *uucplock; /* name of lock file for uucp's */ EXTERN int odisc; /* initial tty line discipline */ extern int disc; /* current tty discpline */ extern char *__progname; /* program name */ char *con(void); char *ctrl(char); char *expand(char *); char *getremote(char *); char *interp(char *); int any(int, char *); int biz22w_dialer(char *, char *); int biz22f_dialer(char *, char *); int biz31w_dialer(char *, char *); int biz31f_dialer(char *, char *); int cour_dialer(char *, char *); int df02_dialer(char *, char *); int df03_dialer(char *, char *); int dn_dialer(char *, char *); int hay_dialer(char *, char *); int prompt(char *, char *, size_t); size_t size(char *); int t3000_dialer(char *, char *); int ttysetup(int); int uu_lock(char *); int uu_unlock(char *); int v3451_dialer(char *, char *); int v831_dialer(char *, char *); int ven_dialer(char *, char *); int vstring(char *, char *); long hunt(char *); void biz22_disconnect(void); void biz22_abort(void); void biz31_disconnect(void); void biz31_abort(void); void chdirectory(int); void cleanup(int); void consh(int); void cour_abort(void); void cour_disconnect(void); void cu_put(int); void cu_take(int); void cumain(int, char **); void daemon_uid(void); void df_abort(void); void df_disconnect(void); void disconnect(char *); void dn_abort(void); void dn_disconnect(void); void finish(int); void genbrk(int); void getfl(int); void hay_abort(void); void hay_disconnect(void); void help(int); void listvariables(int); void logent(char *, char *, char *, char *); void loginit(void); void parwrite(int, char *, size_t); void pipefile(int); void pipeout(int); void raw(void); void sendfile(int); void setparity(char *); void setscript(void); void shell(int); void shell_uid(void); void suspend(int); void t3000_disconnect(void); void t3000_abort(void); void timeout(int); void tipabort(char *); void tipout(void); void user_uid(void); void unexcl(void); void unraw(void); void v3451_abort(void); void v3451_disconnect(void); void v831_disconnect(void); void v831_abort(void); void variable(int); void ven_disconnect(void); void ven_abort(void); void vinit(void); void vlex(char *); diff --git a/usr.bin/tip/tip/value.c b/usr.bin/tip/tip/value.c index a4776b80d35d..9cf1052d3ea2 100644 --- a/usr.bin/tip/tip/value.c +++ b/usr.bin/tip/tip/value.c @@ -1,351 +1,365 @@ /* $OpenBSD: value.c,v 1.14 2006/03/17 22:02:58 moritz Exp $ */ /* $NetBSD: value.c,v 1.6 1997/02/11 09:24:09 mrg Exp $ */ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #ifndef lint #if 0 static char sccsid[] = "@(#)value.c 8.1 (Berkeley) 6/6/93"; static const char rcsid[] = "$OpenBSD: value.c,v 1.14 2006/03/17 22:02:58 moritz Exp $"; #endif #endif /* not lint */ #include "tip.h" #define MIDDLE 35 static value_t *vlookup(char *); static void vassign(value_t *, char *); static void vtoken(char *); static void vprint(value_t *); static int vaccess(unsigned int, unsigned int); static char *vinterp(char *, int); static size_t col = 0; /* * Variable manipulation */ void vinit(void) { char file[FILENAME_MAX], *cp; value_t *p; FILE *fp; for (p = vtable; p->v_name != NULL; p++) { if (p->v_type&ENVIRON) if ((cp = getenv(p->v_name))) p->v_value = cp; - if (p->v_type&IREMOTE) - setnumber(p->v_value, *address(p->v_value)); + if (p->v_type&IREMOTE) { + switch (p->v_type&TMASK) { + case STRING: + p->v_value = *(char **)p->v_value; + break; + case NUMBER: + setnumber(p->v_value, *(long *)p->v_value); + break; + case BOOL: + setboolean(p->v_value, *(short *)p->v_value); + break; + case CHAR: + setcharacter(p->v_value, *(char *)p->v_value); + break; + } + } } /* * Read the .tiprc file in the HOME directory * for sets */ cp = value(HOME); if (cp == NULL) { (void)fprintf(stderr, "$HOME not set. Skipping check for ~/.tiprc\n"); } else if (strlen(cp) + sizeof("/.tiprc") > sizeof(file)) { (void)fprintf(stderr, "Home directory path too long: %s\n", value(HOME)); } else { snprintf(file, sizeof file, "%s/.tiprc", value(HOME)); if ((fp = fopen(file, "r")) != NULL) { char *tp; while (fgets(file, sizeof(file)-1, fp) != NULL) { if (vflag) printf("set %s", file); if ((tp = strrchr(file, '\n'))) *tp = '\0'; vlex(file); } fclose(fp); } } /* * To allow definition of exception prior to fork */ vtable[EXCEPTIONS].v_access &= ~(WRITE<v_access, WRITE)) { printf("access denied\r\n"); return; } switch (p->v_type&TMASK) { case STRING: if (p->v_value && equal(p->v_value, v)) return; if (!(p->v_type&(ENVIRON|INIT))) free(p->v_value); if ((p->v_value = strdup(v)) == NOSTR) { printf("out of core\r\n"); return; } p->v_type &= ~(ENVIRON|INIT); break; case NUMBER: if (number(p->v_value) == number(v)) return; setnumber(p->v_value, number(v)); break; case BOOL: if (boolean(p->v_value) == (*v != '!')) return; setboolean(p->v_value, (*v != '!')); break; case CHAR: if (character(p->v_value) == *v) return; setcharacter(p->v_value, *v); } p->v_access |= CHANGED; } void vlex(char *s) { value_t *p; char *cp; if (equal(s, "all")) { for (p = vtable; p->v_name; p++) if (vaccess(p->v_access, READ)) vprint(p); } else { do { if ((cp = vinterp(s, ' '))) cp++; vtoken(s); s = cp; } while (s); } if (col > 0) { printf("\r\n"); col = 0; } } static void vtoken(char *s) { value_t *p; char *cp; if ((cp = strchr(s, '='))) { *cp = '\0'; if ((p = vlookup(s))) { cp++; if (p->v_type&NUMBER) vassign(p, (char *)(intptr_t)atoi(cp)); else { if (strcmp(s, "record") == 0) cp = expand(cp); vassign(p, cp); } return; } } else if ((cp = strchr(s, '?'))) { *cp = '\0'; if ((p = vlookup(s)) && vaccess(p->v_access, READ)) { vprint(p); return; } } else { if (*s != '!') p = vlookup(s); else p = vlookup(s+1); if (p != NOVAL) { vassign(p, s); return; } } printf("%s: unknown variable\r\n", s); } static void vprint(value_t *p) { char *cp; if (col > 0 && col < MIDDLE) while (col++ < MIDDLE) putchar(' '); col += size(p->v_name); switch (p->v_type&TMASK) { case BOOL: if (boolean(p->v_value) == FALSE) { col++; putchar('!'); } printf("%s", p->v_name); break; case STRING: printf("%s=", p->v_name); col++; if (p->v_value) { cp = interp(p->v_value); col += size(cp); printf("%s", cp); } break; case NUMBER: col += 6; printf("%s=%-5ld", p->v_name, number(p->v_value)); break; case CHAR: printf("%s=", p->v_name); col++; if (p->v_value) { cp = ctrl(character(p->v_value)); col += size(cp); printf("%s", cp); } break; } if (col >= MIDDLE) { col = 0; printf("\r\n"); return; } } static int vaccess(unsigned int mode, unsigned int rw) { if (mode & (rw<v_name; p++) if (equal(p->v_name, s) || (p->v_abrev && equal(p->v_abrev, s))) return (p); return (NULL); } static char * vinterp(char *s, int stop) { char *p = s, c; int num; while ((c = *s++) && c != stop) { switch (c) { case '^': if (*s) *p++ = *s++ - 0100; else *p++ = c; break; case '\\': num = 0; c = *s++; if (c >= '0' && c <= '7') num = (num<<3)+(c-'0'); else { char *q = "n\nr\rt\tb\bf\f"; for (; *q; q++) if (c == *q++) { *p++ = *q; goto cont; } *p++ = c; cont: break; } if ((c = *s++) >= '0' && c <= '7') { num = (num<<3)+(c-'0'); if ((c = *s++) >= '0' && c <= '7') num = (num<<3)+(c-'0'); else s--; } else s--; *p++ = num; break; default: *p++ = c; } } *p = '\0'; return (c == stop ? s-1 : NULL); } /* * assign variable s with value v (for NUMBER or STRING or CHAR types) */ int vstring(char *s, char *v) { value_t *p; p = vlookup(s); if (p == 0) return (1); if (p->v_type&NUMBER) vassign(p, (char *)(intptr_t)atoi(v)); else { if (strcmp(s, "record") == 0) v = expand(v); vassign(p, v); } return (0); }