Annotation of src/usr.bin/tip/remote.c, Revision 1.33
1.33 ! nicm 1: /* $OpenBSD: remote.c,v 1.32 2010/07/11 23:16:42 chl Exp $ */
1.5 millert 2: /* $NetBSD: remote.c,v 1.5 1997/04/20 00:02:45 mellon Exp $ */
1.1 deraadt 3:
4: /*
5: * Copyright (c) 1992, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: *
9: * Redistribution and use in source and binary forms, with or without
10: * modification, are permitted provided that the following conditions
11: * are met:
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.
1.12 millert 17: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 18: * may be used to endorse or promote products derived from this software
19: * without specific prior written permission.
20: *
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
31: * SUCH DAMAGE.
32: */
33:
34: #include <stdio.h>
35: #include <stdlib.h>
36:
37: #include "tip.h"
38:
39: static char *db_array[3] = { _PATH_REMOTE, 0, 0 };
40:
41: #define cgetflag(f) (cgetcap(bp, f, ':') != NULL)
42:
1.29 nicm 43: char *
44: getremote(char *host)
1.1 deraadt 45: {
1.26 chl 46: char *bp, *rempath, *strval;
1.22 nicm 47: int stat;
48: long val;
1.1 deraadt 49:
50: rempath = getenv("REMOTE");
1.8 deraadt 51: if (rempath != NULL) {
1.1 deraadt 52: if (*rempath != '/')
53: /* we have an entry */
54: cgetset(rempath);
55: else { /* we have a path */
56: db_array[1] = rempath;
57: db_array[2] = _PATH_REMOTE;
58: }
1.8 deraadt 59: }
1.1 deraadt 60:
61: if ((stat = cgetent(&bp, db_array, host)) < 0) {
1.27 nicm 62: if (vgetstr(DEVICE) != NULL ||
1.25 nicm 63: (host[0] == '/' && access(host, R_OK | W_OK) == 0)) {
1.29 nicm 64: if (vgetstr(DEVICE) == NULL)
65: vsetstr(DEVICE, host);
1.27 nicm 66: vsetstr(HOST, host);
67: if (!vgetnum(BAUDRATE))
68: vsetnum(BAUDRATE, DEFBR);
69: vsetnum(FRAMESIZE, DEFFS);
1.29 nicm 70: return (vgetstr(DEVICE));
1.1 deraadt 71: }
1.14 deraadt 72: switch (stat) {
1.1 deraadt 73: case -1:
1.9 millert 74: fprintf(stderr, "%s: unknown host %s\n", __progname,
75: host);
1.1 deraadt 76: break;
77: case -2:
1.14 deraadt 78: fprintf(stderr,
1.9 millert 79: "%s: can't open host description file\n",
80: __progname);
1.1 deraadt 81: break;
82: case -3:
1.14 deraadt 83: fprintf(stderr,
1.9 millert 84: "%s: possible reference loop in host description file\n", __progname);
1.1 deraadt 85: break;
86: }
87: exit(3);
88: }
89:
1.33 ! nicm 90: /* String options. Use if not already set. */
! 91: if (vgetstr(DEVICE) == NULL && cgetstr(bp, "dv", &strval) >= 0)
! 92: vsetstr(DEVICE, strval);
! 93: if (vgetstr(CONNECT) == NULL && cgetstr(bp, "cm", &strval) >= 0)
! 94: vsetstr(CONNECT, strval);
! 95: if (vgetstr(DISCONNECT) == NULL && cgetstr(bp, "di", &strval) >= 0)
! 96: vsetstr(DISCONNECT, strval);
! 97: if (vgetstr(EOL) == NULL && cgetstr(bp, "el", &strval) >= 0)
! 98: vsetstr(EOL, strval);
! 99: if (vgetstr(EOFREAD) == NULL && cgetstr(bp, "ie", &strval) >= 0)
! 100: vsetstr(EOFREAD, strval);
! 101: if (vgetstr(EOFWRITE) == NULL && cgetstr(bp, "oe", &strval) >= 0)
! 102: vsetstr(EOFWRITE, strval);
! 103: if (vgetstr(EXCEPTIONS) == NULL && cgetstr(bp, "ex", &strval) >= 0)
! 104: vsetstr(EXCEPTIONS, strval);
! 105: if (vgetstr(RECORD) == NULL && cgetstr(bp, "re", &strval) >= 0)
1.30 nicm 106: vsetstr(RECORD, strval);
1.33 ! nicm 107: if (vgetstr(PARITY) == NULL && cgetstr(bp, "pa", &strval) >= 0)
! 108: vsetstr(PARITY, strval);
1.27 nicm 109:
1.33 ! nicm 110: /* Numbers with default values. Set if currently zero (XXX ugh). */
! 111: if (vgetnum(BAUDRATE) == 0) {
! 112: if (cgetnum(bp, "br", &val) < 0)
1.27 nicm 113: vsetnum(BAUDRATE, DEFBR);
1.22 nicm 114: else
1.27 nicm 115: vsetnum(BAUDRATE, val);
1.22 nicm 116: }
1.33 ! nicm 117: if (vgetnum(LINEDISC) == 0) { /* XXX relies on TTYDISC == 0 */
! 118: if (cgetnum(bp, "ld", &val) < 0)
1.27 nicm 119: vsetnum(LINEDISC, TTYDISC);
1.22 nicm 120: else
1.27 nicm 121: vsetnum(LINEDISC, val);
1.22 nicm 122: }
1.33 ! nicm 123: if (vgetnum(FRAMESIZE) == 0) {
! 124: if (cgetnum(bp, "fs", &val) < 0)
! 125: vsetnum(FRAMESIZE, DEFFS);
! 126: else
! 127: vsetnum(FRAMESIZE, val);
! 128: }
! 129:
! 130: /* Numbers - default values already set in vinit() or zero. */
! 131: if (cgetnum(bp, "es", &val) >= 0)
! 132: vsetnum(ESCAPE, val);
! 133: if (cgetnum(bp, "fo", &val) >= 0)
! 134: vsetnum(FORCE, val);
! 135: if (cgetnum(bp, "pr", &val) >= 0)
! 136: vsetnum(PROMPT, val);
! 137: if (cgetnum(bp, "rc", &val) >= 0)
! 138: vsetnum(RAISECHAR, val);
! 139:
! 140: /* Numbers - default is zero. */
! 141: if (cgetnum(bp, "dl", &val) < 0)
! 142: vsetnum(LDELAY, 0);
! 143: else
! 144: vsetnum(LDELAY, val);
! 145: if (cgetnum(bp, "cl", &val) < 0)
! 146: vsetnum(CDELAY, 0);
1.22 nicm 147: else
1.33 ! nicm 148: vsetnum(CDELAY, val);
! 149: if (cgetnum(bp, "et", &val) < 0)
! 150: vsetnum(ETIMEOUT, 0);
! 151: else
! 152: vsetnum(ETIMEOUT, val);
1.1 deraadt 153:
1.33 ! nicm 154: /* Flag options. */
! 155: if (cgetflag("hd")) /* XXX overrides command line */
1.27 nicm 156: vsetnum(HALFDUPLEX, 1);
1.1 deraadt 157: if (cgetflag("ra"))
1.27 nicm 158: vsetnum(RAISE, 1);
1.1 deraadt 159: if (cgetflag("ec"))
1.27 nicm 160: vsetnum(ECHOCHECK, 1);
1.1 deraadt 161: if (cgetflag("be"))
1.27 nicm 162: vsetnum(BEAUTIFY, 1);
1.1 deraadt 163: if (cgetflag("nb"))
1.27 nicm 164: vsetnum(BEAUTIFY, 0);
1.1 deraadt 165: if (cgetflag("sc"))
1.27 nicm 166: vsetnum(SCRIPT, 1);
1.1 deraadt 167: if (cgetflag("tb"))
1.27 nicm 168: vsetnum(TABEXPAND, 1);
1.33 ! nicm 169: if (cgetflag("vb")) /* XXX overrides command line */
1.27 nicm 170: vsetnum(VERBOSE, 1);
1.33 ! nicm 171: if (cgetflag("nv")) /* XXX overrides command line */
1.27 nicm 172: vsetnum(VERBOSE, 0);
1.1 deraadt 173: if (cgetflag("ta"))
1.27 nicm 174: vsetnum(TAND, 1);
1.1 deraadt 175: if (cgetflag("nt"))
1.27 nicm 176: vsetnum(TAND, 0);
1.1 deraadt 177: if (cgetflag("rw"))
1.27 nicm 178: vsetnum(RAWFTP, 1);
1.1 deraadt 179: if (cgetflag("hd"))
1.27 nicm 180: vsetnum(HALFDUPLEX, 1);
1.5 millert 181: if (cgetflag("dc"))
1.27 nicm 182: vsetnum(DC, 1);
1.13 millert 183: if (cgetflag("hf"))
1.27 nicm 184: vsetnum(HARDWAREFLOW, 1);
1.33 ! nicm 185:
1.27 nicm 186: if (vgetstr(RECORD) == NULL)
187: vsetstr(RECORD, "tip.record");
188: if (vgetstr(EXCEPTIONS) == NULL)
189: vsetstr(EXCEPTIONS, "\t\n\b\f");
1.1 deraadt 190:
1.33 ! nicm 191: vsetstr(HOST, host);
! 192: if (vgetstr(DEVICE) == NULL) {
! 193: fprintf(stderr, "%s: missing device spec\n", host);
! 194: exit(3);
! 195: }
1.27 nicm 196: return (vgetstr(DEVICE));
1.1 deraadt 197: }