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 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. 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.
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
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
38 static const char copyright[] =
39 "@(#) Copyright (c) 1992, 1993\n\
40 The Regents of the University of California. All rights reserved.\n";
45 static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93";
46 static const char rcsid[] = "$OpenBSD: remote.c,v 1.16 2006/06/06 23:24:52 deraadt Exp $";
53 #include "pathnames.h"
57 * Attributes to be gleened from remote host description
60 static char **caps[] = {
61 &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI,
62 &ES, &EX, &FO, &RC, &RE, &PA
65 static char *capstrings[] = {
66 "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr",
67 "di", "es", "ex", "fo", "rc", "re", "pa", 0
70 static char *db_array[3] = { _PATH_REMOTE, 0, 0 };
72 #define cgetflag(f) (cgetcap(bp, f, ':') != NULL)
74 static void getremcap(char *);
79 char **p, ***q, *bp, *rempath;
82 rempath = getenv("REMOTE");
83 if (rempath != NULL) {
85 /* we have an entry */
87 else { /* we have a path */
88 db_array[1] = rempath;
89 db_array[2] = _PATH_REMOTE;
93 if ((stat = cgetent(&bp, db_array, host)) < 0) {
95 (host[0] == '/' && access(DV = host, R_OK | W_OK) == 0)) {
107 fprintf(stderr, "%s: unknown host %s\n", __progname,
112 "%s: can't open host description file\n",
117 "%s: possible reference loop in host description file\n", __progname);
123 for (p = capstrings, q = caps; *p != NULL; p++, q++)
126 if (!BR && (cgetnum(bp, "br", &BR) == -1))
128 if (!LD && (cgetnum(bp, "ld", &LD) == -1))
130 if (cgetnum(bp, "fs", &FS) == -1)
137 fprintf(stderr, "%s: missing device spec\n", host);
140 if (DU && CU == NOSTR)
142 if (DU && PN == NOSTR) {
143 fprintf(stderr, "%s: missing phone number\n", host);
146 if (DU && AT == NOSTR) {
147 fprintf(stderr, "%s: missing acu type\n", host);
154 * This effectively eliminates the "hw" attribute
155 * from the description file
158 HW = (CU == NOSTR) || (DU && equal(DV, CU));
161 * see if uppercase mode should be turned on initially
164 setboolean(value(RAISE), 1);
166 setboolean(value(ECHOCHECK), 1);
168 setboolean(value(BEAUTIFY), 1);
170 setboolean(value(BEAUTIFY), 0);
172 setboolean(value(SCRIPT), 1);
174 setboolean(value(TABEXPAND), 1);
176 setboolean(value(VERBOSE), 1);
178 setboolean(value(VERBOSE), 0);
180 setboolean(value(TAND), 1);
182 setboolean(value(TAND), 0);
184 setboolean(value(RAWFTP), 1);
186 setboolean(value(HALFDUPLEX), 1);
188 setboolean(value(DC), 1);
190 setboolean(value(HARDWAREFLOW), 1);
192 RE = (char *)"tip.record";
194 EX = (char *)"\t\n\b\f";
203 if (cgetnum(bp, "dl", &DL) == -1)
205 if (cgetnum(bp, "cl", &CL) == -1)
207 if (cgetnum(bp, "et", &ET) == -1)
212 getremote(char *host)
216 static int lookedup = 0;
219 if (host == NOSTR && (host = getenv("HOST")) == NOSTR) {
220 fprintf(stderr, "%s: no host specified\n", __progname);
228 * We return a new device each time we're called (to allow
229 * a rotary action to be simulated)
233 if ((cp = strchr(next, ',')) == NULL) {