1 /* $NetBSD: remote.c,v 1.3 1994/12/08 09:31:03 jtc Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. 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 37 #ifndef lint 38 static char copyright[] = 39 "@(#) Copyright (c) 1992, 1993\n\ 40 The Regents of the University of California. All rights reserved.\n"; 41 #endif /* not lint */ 42 43 #ifndef lint 44 #if 0 45 static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93"; 46 #endif 47 static char rcsid[] = "$NetBSD: remote.c,v 1.3 1994/12/08 09:31:03 jtc Exp $"; 48 #endif /* not lint */ 49 50 #include <stdio.h> 51 #include <stdlib.h> 52 53 #include "pathnames.h" 54 #include "tip.h" 55 56 /* 57 * Attributes to be gleened from remote host description 58 * data base. 59 */ 60 static char **caps[] = { 61 &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI, 62 &ES, &EX, &FO, &RC, &RE, &PA 63 }; 64 65 static char *capstrings[] = { 66 "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr", 67 "di", "es", "ex", "fo", "rc", "re", "pa", 0 68 }; 69 70 static char *db_array[3] = { _PATH_REMOTE, 0, 0 }; 71 72 #define cgetflag(f) (cgetcap(bp, f, ':') != NULL) 73 74 static 75 getremcap(host) 76 register char *host; 77 { 78 register char **p, ***q; 79 char *bp; 80 char *rempath; 81 int stat; 82 83 rempath = getenv("REMOTE"); 84 if (rempath != NULL) 85 if (*rempath != '/') 86 /* we have an entry */ 87 cgetset(rempath); 88 else { /* we have a path */ 89 db_array[1] = rempath; 90 db_array[2] = _PATH_REMOTE; 91 } 92 93 if ((stat = cgetent(&bp, db_array, host)) < 0) { 94 if (DV || 95 host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) { 96 CU = DV; 97 HO = host; 98 HW = 1; 99 DU = 0; 100 if (!BR) 101 BR = DEFBR; 102 FS = DEFFS; 103 return; 104 } 105 switch(stat) { 106 case -1: 107 fprintf(stderr, "tip: unknown host %s\n", host); 108 break; 109 case -2: 110 fprintf(stderr, 111 "tip: can't open host description file\n"); 112 break; 113 case -3: 114 fprintf(stderr, 115 "tip: possible reference loop in host description file\n"); 116 break; 117 } 118 exit(3); 119 } 120 121 for (p = capstrings, q = caps; *p != NULL; p++, q++) 122 if (**q == NULL) 123 cgetstr(bp, *p, *q); 124 if (!BR && (cgetnum(bp, "br", &BR) == -1)) 125 BR = DEFBR; 126 if (cgetnum(bp, "fs", &FS) == -1) 127 FS = DEFFS; 128 if (DU < 0) 129 DU = 0; 130 else 131 DU = cgetflag("du"); 132 if (DV == NOSTR) { 133 fprintf(stderr, "%s: missing device spec\n", host); 134 exit(3); 135 } 136 if (DU && CU == NOSTR) 137 CU = DV; 138 if (DU && PN == NOSTR) { 139 fprintf(stderr, "%s: missing phone number\n", host); 140 exit(3); 141 } 142 143 HD = cgetflag("hd"); 144 145 /* 146 * This effectively eliminates the "hw" attribute 147 * from the description file 148 */ 149 if (!HW) 150 HW = (CU == NOSTR) || (DU && equal(DV, CU)); 151 HO = host; 152 /* 153 * see if uppercase mode should be turned on initially 154 */ 155 if (cgetflag("ra")) 156 boolean(value(RAISE)) = 1; 157 if (cgetflag("ec")) 158 boolean(value(ECHOCHECK)) = 1; 159 if (cgetflag("be")) 160 boolean(value(BEAUTIFY)) = 1; 161 if (cgetflag("nb")) 162 boolean(value(BEAUTIFY)) = 0; 163 if (cgetflag("sc")) 164 boolean(value(SCRIPT)) = 1; 165 if (cgetflag("tb")) 166 boolean(value(TABEXPAND)) = 1; 167 if (cgetflag("vb")) 168 boolean(value(VERBOSE)) = 1; 169 if (cgetflag("nv")) 170 boolean(value(VERBOSE)) = 0; 171 if (cgetflag("ta")) 172 boolean(value(TAND)) = 1; 173 if (cgetflag("nt")) 174 boolean(value(TAND)) = 0; 175 if (cgetflag("rw")) 176 boolean(value(RAWFTP)) = 1; 177 if (cgetflag("hd")) 178 boolean(value(HALFDUPLEX)) = 1; 179 if (RE == NOSTR) 180 RE = (char *)"tip.record"; 181 if (EX == NOSTR) 182 EX = (char *)"\t\n\b\f"; 183 if (ES != NOSTR) 184 vstring("es", ES); 185 if (FO != NOSTR) 186 vstring("fo", FO); 187 if (PR != NOSTR) 188 vstring("pr", PR); 189 if (RC != NOSTR) 190 vstring("rc", RC); 191 if (cgetnum(bp, "dl", &DL) == -1) 192 DL = 0; 193 if (cgetnum(bp, "cl", &CL) == -1) 194 CL = 0; 195 if (cgetnum(bp, "et", &ET) == -1) 196 ET = 10; 197 } 198 199 char * 200 getremote(host) 201 char *host; 202 { 203 register char *cp; 204 static char *next; 205 static int lookedup = 0; 206 207 if (!lookedup) { 208 if (host == NOSTR && (host = getenv("HOST")) == NOSTR) { 209 fprintf(stderr, "tip: no host specified\n"); 210 exit(3); 211 } 212 getremcap(host); 213 next = DV; 214 lookedup++; 215 } 216 /* 217 * We return a new device each time we're called (to allow 218 * a rotary action to be simulated) 219 */ 220 if (next == NOSTR) 221 return (NOSTR); 222 if ((cp = index(next, ',')) == NULL) { 223 DV = next; 224 next = NOSTR; 225 } else { 226 *cp++ = '\0'; 227 DV = next; 228 next = cp; 229 } 230 return (DV); 231 } 232