1 /* $NetBSD: remote.c,v 1.17 2006/12/14 17:09:43 christos Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
35 __COPYRIGHT("@(#) Copyright (c) 1992, 1993\
36 The Regents of the University of California. All rights reserved.");
41 static char sccsid
[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93";
43 __RCSID("$NetBSD: remote.c,v 1.17 2006/12/14 17:09:43 christos Exp $");
46 #include "pathnames.h"
50 * Attributes to be gleened from remote host description
53 static char **caps
[] = {
54 &AT
, &DV
, &CM
, &CU
, &EL
, &IE
, &OE
, &PN
, &PR
, &DI
,
55 &ES
, &EX
, &FO
, &RC
, &RE
, &PA
58 static const char *capstrings
[] = {
59 "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr",
60 "di", "es", "ex", "fo", "rc", "re", "pa", 0
63 static const char *db_array
[3] = { _PATH_REMOTE
, 0, 0 };
65 #define cgetflag(f) (cgetcap(bp, f, ':') != NULL)
67 static void getremcap(char *);
69 static char tiprecord
[] = "tip.record";
70 static char wspace
[] = "\t\n\b\f";
81 rempath
= getenv("REMOTE");
82 if (rempath
!= NULL
) {
84 /* we have an entry */
85 (void)cgetset(rempath
);
86 else { /* we have a path */
87 db_array
[1] = rempath
;
88 db_array
[2] = _PATH_REMOTE
;
91 if ((status
= cgetent(&bp
, db_array
, host
)) < 0) {
93 (host
[0] == '/' && access(DV
= host
, R_OK
| W_OK
) == 0)) {
105 warnx("unknown host %s", host
);
108 warnx("can't open host description file");
111 warnx("possible reference loop in host "
119 for (p
= capstrings
, q
= caps
; *p
!= NULL
; p
++, q
++)
121 (void)cgetstr(bp
, *p
, *q
);
122 if (!BR
&& (cgetnum(bp
, "br", &BR
) == -1))
124 if (cgetnum(bp
, "fs", &FS
) == -1)
131 errx(3, "%s: missing device spec\n", host
);
133 if (DU
&& CU
== NULL
)
135 if (DU
&& PN
== NULL
) {
136 errx(3, "%s: missing phone number\n", host
);
142 * This effectively eliminates the "hw" attribute
143 * from the description file
146 HW
= (CU
== NULL
) || (DU
&& equal(DV
, CU
));
149 * see if uppercase mode should be turned on initially
152 setboolean(value(RAISE
), 1);
154 setboolean(value(ECHOCHECK
), 1);
156 setboolean(value(BEAUTIFY
), 1);
158 setboolean(value(BEAUTIFY
), 0);
160 setboolean(value(SCRIPT
), 1);
162 setboolean(value(TABEXPAND
), 1);
164 setboolean(value(VERBOSE
), 1);
166 setboolean(value(VERBOSE
), 0);
168 setboolean(value(TAND
), 1);
170 setboolean(value(TAND
), 0);
172 setboolean(value(RAWFTP
), 1);
174 setboolean(value(HALFDUPLEX
), 1);
178 setboolean(value(HARDWAREFLOW
), 1);
184 (void)vstring("es", ES
);
186 (void)vstring("fo", FO
);
188 (void)vstring("pr", PR
);
190 (void)vstring("rc", RC
);
191 if (cgetnum(bp
, "dl", &DL
) == -1)
193 if (cgetnum(bp
, "cl", &CL
) == -1)
195 if (cgetnum(bp
, "et", &ET
) == -1)
200 getremote(char *host
)
204 static int lookedup
= 0;
207 if (host
== NULL
&& (host
= getenv("HOST")) == NULL
) {
208 errx(3, "no host specified");
215 * We return a new device each time we're called (to allow
216 * a rotary action to be simulated)
220 if ((cp
= strchr(next
, ',')) == NULL
) {