1 /* 2 * Copyright (c) 1983 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 #ifndef lint 35 static char sccsid[] = "@(#)remote.c 5.6 (Berkeley) 8/6/92"; 36 #endif /* not lint */ 37 38 #include <stdlib.h> 39 #include <stdio.h> 40 #include "pathnames.h" 41 #include "tip.h" 42 43 /* 44 * Attributes to be gleened from remote host description 45 * data base. 46 */ 47 static char **caps[] = { 48 &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI, 49 &ES, &EX, &FO, &RC, &RE, &PA 50 }; 51 52 static char *capstrings[] = { 53 "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr", 54 "di", "es", "ex", "fo", "rc", "re", "pa", 0 55 }; 56 57 static char *db_array[3] = { _PATH_REMOTE, 0, 0 }; 58 59 #define cgetflag(f) (cgetcap(bp, f, ':') != NULL) 60 61 static 62 getremcap(host) 63 register char *host; 64 { 65 register char **p, ***q; 66 char *bp; 67 char *rempath; 68 int stat; 69 70 rempath = getenv("REMOTE"); 71 if (rempath != NULL) 72 if (*rempath != '/') 73 /* we have an entry */ 74 cgetset(rempath); 75 else { /* we have a path */ 76 db_array[1] = rempath; 77 db_array[2] = _PATH_REMOTE; 78 } 79 80 if ((stat = cgetent(&bp, db_array, host)) < 0) { 81 if (DV || 82 host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) { 83 CU = DV; 84 HO = host; 85 HW = 1; 86 DU = 0; 87 if (!BR) 88 BR = DEFBR; 89 FS = DEFFS; 90 return; 91 } 92 switch(stat) { 93 case -1: 94 fprintf(stderr, "tip: unknown host %s\n", host); 95 break; 96 case -2: 97 fprintf(stderr, 98 "tip: can't open host description file\n"); 99 break; 100 case -3: 101 fprintf(stderr, 102 "tip: possible reference loop in host description file\n"); 103 break; 104 } 105 exit(3); 106 } 107 108 for (p = capstrings, q = caps; *p != NULL; p++, q++) 109 if (**q == NULL) 110 cgetstr(bp, *p, *q); 111 if (!BR && (cgetnum(bp, "br", &BR) == -1)) 112 BR = DEFBR; 113 if (cgetnum(bp, "fs", &FS) == -1) 114 FS = DEFFS; 115 if (DU < 0) 116 DU = 0; 117 else 118 DU = cgetflag("du"); 119 if (DV == NOSTR) { 120 fprintf(stderr, "%s: missing device spec\n", host); 121 exit(3); 122 } 123 if (DU && CU == NOSTR) 124 CU = DV; 125 if (DU && PN == NOSTR) { 126 fprintf(stderr, "%s: missing phone number\n", host); 127 exit(3); 128 } 129 130 HD = cgetflag("hd"); 131 132 /* 133 * This effectively eliminates the "hw" attribute 134 * from the description file 135 */ 136 if (!HW) 137 HW = (CU == NOSTR) || (DU && equal(DV, CU)); 138 HO = host; 139 /* 140 * see if uppercase mode should be turned on initially 141 */ 142 if (cgetflag("ra")) 143 boolean(value(RAISE)) = 1; 144 if (cgetflag("ec")) 145 boolean(value(ECHOCHECK)) = 1; 146 if (cgetflag("be")) 147 boolean(value(BEAUTIFY)) = 1; 148 if (cgetflag("nb")) 149 boolean(value(BEAUTIFY)) = 0; 150 if (cgetflag("sc")) 151 boolean(value(SCRIPT)) = 1; 152 if (cgetflag("tb")) 153 boolean(value(TABEXPAND)) = 1; 154 if (cgetflag("vb")) 155 boolean(value(VERBOSE)) = 1; 156 if (cgetflag("nv")) 157 boolean(value(VERBOSE)) = 0; 158 if (cgetflag("ta")) 159 boolean(value(TAND)) = 1; 160 if (cgetflag("nt")) 161 boolean(value(TAND)) = 0; 162 if (cgetflag("rw")) 163 boolean(value(RAWFTP)) = 1; 164 if (cgetflag("hd")) 165 boolean(value(HALFDUPLEX)) = 1; 166 if (RE == NOSTR) 167 RE = (char *)"tip.record"; 168 if (EX == NOSTR) 169 EX = (char *)"\t\n\b\f"; 170 if (ES != NOSTR) 171 vstring("es", ES); 172 if (FO != NOSTR) 173 vstring("fo", FO); 174 if (PR != NOSTR) 175 vstring("pr", PR); 176 if (RC != NOSTR) 177 vstring("rc", RC); 178 if (cgetnum(bp, "dl", &DL) == -1) 179 DL = 0; 180 if (cgetnum(bp, "cl", &CL) == -1) 181 CL = 0; 182 if (cgetnum(bp, "et", &ET) == -1) 183 ET = 10; 184 } 185 186 char * 187 getremote(host) 188 char *host; 189 { 190 register char *cp; 191 static char *next; 192 static int lookedup = 0; 193 194 if (!lookedup) { 195 if (host == NOSTR && (host = getenv("HOST")) == NOSTR) { 196 fprintf(stderr, "tip: no host specified\n"); 197 exit(3); 198 } 199 getremcap(host); 200 next = DV; 201 lookedup++; 202 } 203 /* 204 * We return a new device each time we're called (to allow 205 * a rotary action to be simulated) 206 */ 207 if (next == NOSTR) 208 return (NOSTR); 209 if ((cp = index(next, ',')) == NULL) { 210 DV = next; 211 next = NOSTR; 212 } else { 213 *cp++ = '\0'; 214 DV = next; 215 next = cp; 216 } 217 return (DV); 218 } 219