1 /* $OpenBSD: remote.c,v 1.16 2006/06/06 23:24:52 deraadt Exp $ */
2 /* $NetBSD: remote.c,v 1.5 1997/04/20 00:02:45 mellon Exp $ */
5 * SPDX-License-Identifier: BSD-3-Clause
7 * Copyright (c) 1992, 1993
8 * The Regents of the University of California. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
40 static const char copyright[] =
41 "@(#) Copyright (c) 1992, 1993\n\
42 The Regents of the University of California. All rights reserved.\n";
47 static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93";
48 static const char rcsid[] = "$OpenBSD: remote.c,v 1.16 2006/06/06 23:24:52 deraadt Exp $";
55 #include "pathnames.h"
59 * Attributes to be gleened from remote host description
62 static char **caps[] = {
63 &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI,
64 &ES, &EX, &FO, &RC, &RE, &PA
67 static char *capstrings[] = {
68 "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr",
69 "di", "es", "ex", "fo", "rc", "re", "pa", 0
72 static char *db_array[3] = { _PATH_REMOTE, 0, 0 };
74 #define cgetflag(f) (cgetcap(bp, f, ':') != NULL)
76 static void getremcap(char *);
81 char **p, ***q, *bp, *rempath;
84 rempath = getenv("REMOTE");
85 if (rempath != NULL) {
87 /* we have an entry */
89 else { /* we have a path */
90 db_array[1] = rempath;
91 db_array[2] = _PATH_REMOTE;
95 if ((stat = cgetent(&bp, db_array, host)) < 0) {
97 (host[0] == '/' && access(DV = host, R_OK | W_OK) == 0)) {
109 fprintf(stderr, "%s: unknown host %s\n", __progname,
114 "%s: can't open host description file\n",
119 "%s: possible reference loop in host description file\n", __progname);
125 for (p = capstrings, q = caps; *p != NULL; p++, q++)
128 if (!BR && (cgetnum(bp, "br", &BR) == -1))
130 if (!LD && (cgetnum(bp, "ld", &LD) == -1))
132 if (cgetnum(bp, "fs", &FS) == -1)
139 fprintf(stderr, "%s: missing device spec\n", host);
142 if (DU && CU == NOSTR)
144 if (DU && PN == NOSTR) {
145 fprintf(stderr, "%s: missing phone number\n", host);
148 if (DU && AT == NOSTR) {
149 fprintf(stderr, "%s: missing acu type\n", host);
156 * This effectively eliminates the "hw" attribute
157 * from the description file
160 HW = (CU == NOSTR) || (DU && equal(DV, CU));
163 * see if uppercase mode should be turned on initially
166 setboolean(value(RAISE), 1);
168 setboolean(value(ECHOCHECK), 1);
170 setboolean(value(BEAUTIFY), 1);
172 setboolean(value(BEAUTIFY), 0);
174 setboolean(value(SCRIPT), 1);
176 setboolean(value(TABEXPAND), 1);
178 setboolean(value(VERBOSE), 1);
180 setboolean(value(VERBOSE), 0);
182 setboolean(value(TAND), 1);
184 setboolean(value(TAND), 0);
186 setboolean(value(RAWFTP), 1);
188 setboolean(value(HALFDUPLEX), 1);
190 setboolean(value(DC), 1);
192 setboolean(value(HARDWAREFLOW), 1);
194 RE = (char *)"tip.record";
196 EX = (char *)"\t\n\b\f";
205 if (cgetnum(bp, "dl", &DL) == -1)
207 if (cgetnum(bp, "cl", &CL) == -1)
209 if (cgetnum(bp, "et", &ET) == -1)
214 getremote(char *host)
218 static int lookedup = 0;
221 if (host == NOSTR && (host = getenv("HOST")) == NOSTR) {
222 fprintf(stderr, "%s: no host specified\n", __progname);
230 * We return a new device each time we're called (to allow
231 * a rotary action to be simulated)
235 if ((cp = strchr(next, ',')) == NULL) {