2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * @(#) Copyright (c) 1992, 1993 The Regents of the University of California. All rights reserved.
31 * @(#)remote.c 8.1 (Berkeley) 6/6/93
32 * $FreeBSD: src/usr.bin/tip/tip/remote.c,v 1.4 1999/08/28 01:06:35 peter Exp $
40 #include "pathnames.h"
43 * Attributes to be gleened from remote host description
46 static char **caps
[] = {
47 &AT
, &DV
, &CM
, &CU
, &EL
, &IE
, &OE
, &PN
, &PR
, &DI
,
48 &ES
, &EX
, &FO
, &RC
, &RE
, &PA
, &LI
, &LO
51 static char *capstrings
[] = {
52 "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr",
53 "di", "es", "ex", "fo", "rc", "re", "pa", "li", "lo", 0
56 static char *db_array
[3] = { _PATH_REMOTE
, 0, 0 };
58 #define cgetflag(f) (cgetcap(bp, f, ':') != NULL)
60 static void getremcap(char *);
63 Expand the start tilde sequence at the start of the
64 specified path. Optionally, free space allocated to
65 path before reinitializing it.
68 expand_tilde (char **path
, void (*free
) (char *p
))
71 char buffer
[PATH_MAX
];
73 if ((tailp
= strchr (*path
+ 1, '/')) != NULL
)
77 if (*(*path
+ 1) == '\0')
78 strcpy (buffer
, getlogin ());
80 strcpy (buffer
, *path
+ 1);
81 if ((pwd
= getpwnam (buffer
)) != NULL
)
83 strcpy (buffer
, pwd
->pw_dir
);
85 strcat (buffer
, tailp
);
88 *path
= strdup (buffer
);
104 rempath
= getenv("REMOTE");
105 if (rempath
!= NULL
) {
107 /* we have an entry */
109 else { /* we have a path */
110 db_array
[1] = rempath
;
111 db_array
[2] = _PATH_REMOTE
;
115 if ((stat
= cgetent(&bp
, db_array
, host
)) < 0) {
117 (host
[0] == '/' && access(DV
= host
, R_OK
| W_OK
) == 0)) {
129 warnx("unknown host %s", host
);
132 warnx("can't open host description file");
135 warnx("possible reference loop in host description file");
141 for (p
= capstrings
, q
= caps
; *p
!= NULL
; p
++, q
++)
144 if (!BR
&& (cgetnum(bp
, "br", &BR
) == -1))
146 if (cgetnum(bp
, "fs", &FS
) == -1)
153 fprintf(stderr
, "%s: missing device spec\n", host
);
156 if (DU
&& CU
== NULL
)
158 if (DU
&& PN
== NULL
) {
159 fprintf(stderr
, "%s: missing phone number\n", host
);
166 * This effectively eliminates the "hw" attribute
167 * from the description file
170 HW
= (CU
== NULL
) || (DU
&& equal(DV
, CU
));
174 If login script, verify access
178 (void) expand_tilde (&LI
, NULL
);
179 if (access (LI
, F_OK
| X_OK
) != 0) {
180 printf("tip (warning): can't open login script \"%s\"\n", LI
);
186 If logout script, verify access
190 (void) expand_tilde (&LO
, NULL
);
191 if (access (LO
, F_OK
| X_OK
) != 0) {
192 printf("tip (warning): can't open logout script \"%s\"\n", LO
);
198 * see if uppercase mode should be turned on initially
201 boolean(value(RAISE
)) = 1;
203 boolean(value(ECHOCHECK
)) = 1;
205 boolean(value(BEAUTIFY
)) = 1;
207 boolean(value(BEAUTIFY
)) = 0;
209 boolean(value(SCRIPT
)) = 1;
211 boolean(value(TABEXPAND
)) = 1;
213 boolean(value(VERBOSE
)) = 1;
215 boolean(value(VERBOSE
)) = 0;
217 boolean(value(TAND
)) = 1;
219 boolean(value(TAND
)) = 0;
221 boolean(value(RAWFTP
)) = 1;
223 boolean(value(HALFDUPLEX
)) = 1;
225 RE
= (char *)"tip.record";
227 EX
= (char *)"\t\n\b\f";
236 if (cgetnum(bp
, "dl", &DL
) == -1)
238 if (cgetnum(bp
, "cl", &CL
) == -1)
240 if (cgetnum(bp
, "et", &ET
) == -1)
245 getremote(char *host
)
249 static int lookedup
= 0;
252 if (host
== NULL
&& (host
= getenv("HOST")) == NULL
)
253 errx(3, "no host specified");
259 * We return a new device each time we're called (to allow
260 * a rotary action to be simulated)
264 if ((cp
= index(next
, ',')) == NULL
) {