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