1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
6 /*
7 * Copyright (c) 1983 Regents of the University of California.
8 * All rights reserved. The Berkeley software License Agreement
9 * specifies the terms and conditions for redistribution.
10 */
11
12 #include "tip.h"
13
14 char *DV; /* UNIX device(s) to open */
15 char *EL; /* chars marking an EOL */
16 char *CM; /* initial connection message */
17 char *IE; /* EOT to expect on input */
18 char *OE; /* EOT to send to complete FT */
19 char *CU; /* call unit if making a phone call */
20 char *AT; /* acu type */
21 char *PN; /* phone number(s) */
22 char *DI; /* disconnect string */
23 char *PA; /* parity to be generated */
24
25 char *PH; /* phone number file */
26 char *RM; /* remote file name */
27 char *HO; /* host name */
28
29 int BR; /* line speed for conversation */
30 int FS; /* frame size for transfers */
31 char DU; /* this host is dialed up */
32 char HW; /* this device is hardwired, see hunt.c */
33 char *ES; /* escape character */
34 char *EX; /* exceptions */
35 char *FO; /* force (literal next) char */
36 char *RC; /* raise character */
37 char *RE; /* script record file */
38 char *PR; /* remote prompt */
39 int DL; /* line delay for file transfers to remote */
40 int CL; /* char delay for file transfers to remote */
41 int ET; /* echocheck timeout */
42 int DB; /* dialback - ignore hangup */
43
44 /*
45 * Attributes to be gleened from remote host description
46 * data base.
47 */
48 static char **caps[] = {
49 &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI,
50 &ES, &EX, &FO, &RC, &RE, &PA
51 };
52
53 static char *capstrings[] = {
54 "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr",
55 "di", "es", "ex", "fo", "rc", "re", "pa", 0
56 };
57
58 extern char *rgetstr(char *, char **);
59
60 static void
getremcap(char * host)61 getremcap(char *host)
62 {
63 int stat;
64 char tbuf[BUFSIZ];
65 static char buf[BUFSIZ/2];
66 char *bp = buf;
67 char **p, ***q;
68
69 if ((stat = rgetent(tbuf, host, sizeof (tbuf))) <= 0) {
70 if (DV ||
71 host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) {
72 /*
73 * If the user specifies a device on the commandline,
74 * don't trust it.
75 */
76 if (host[0] == '/')
77 trusted_device = 0;
78 CU = DV;
79 HO = host;
80 HW = 1;
81 DU = 0;
82 if (!BR)
83 BR = DEFBR;
84 FS = DEFFS;
85 RE = (char *)"tip.record";
86 EX = (char *)"\t\n\b\f";
87 DL = 0;
88 CL = 0;
89 ET = 10;
90 return;
91 }
92 (void) fprintf(stderr, stat == 0 ?
93 "tip: unknown host %s\n" :
94 "tip: can't open host description file\n", host);
95 exit(3);
96 }
97
98 for (p = capstrings, q = caps; *p != NULL; p++, q++)
99 if (**q == NULL)
100 **q = rgetstr(*p, &bp);
101 if (!BR && (BR = rgetnum("br")) < 0)
102 BR = DEFBR;
103 if ((FS = rgetnum("fs")) < 0)
104 FS = DEFFS;
105 if (DU < 0)
106 DU = 0;
107 else
108 DU = rgetflag("du");
109 if (DV == NOSTR) {
110 (void) fprintf(stderr, "%s: missing device spec\n", host);
111 exit(3);
112 }
113 if (DU && CU == NOSTR)
114 CU = DV;
115 if (DU && PN == NOSTR) {
116 (void) fprintf(stderr, "%s: missing phone number\n", host);
117 exit(3);
118 }
119 DB = rgetflag("db");
120
121 /*
122 * This effectively eliminates the "hw" attribute
123 * from the description file
124 */
125 if (!HW)
126 HW = (CU == NOSTR) || (DU && equal(DV, CU));
127 HO = host;
128 /*
129 * see if uppercase mode should be turned on initially
130 */
131 if (rgetflag("ra"))
132 boolean(value(RAISE)) = 1;
133 if (rgetflag("ec"))
134 boolean(value(ECHOCHECK)) = 1;
135 if (rgetflag("be"))
136 boolean(value(BEAUTIFY)) = 1;
137 if (rgetflag("nb"))
138 boolean(value(BEAUTIFY)) = 0;
139 if (rgetflag("sc"))
140 boolean(value(SCRIPT)) = 1;
141 if (rgetflag("tb"))
142 boolean(value(TABEXPAND)) = 1;
143 if (rgetflag("vb"))
144 boolean(value(VERBOSE)) = 1;
145 if (rgetflag("nv"))
146 boolean(value(VERBOSE)) = 0;
147 if (rgetflag("ta"))
148 boolean(value(TAND)) = 1;
149 if (rgetflag("nt"))
150 boolean(value(TAND)) = 0;
151 if (rgetflag("rw"))
152 boolean(value(RAWFTP)) = 1;
153 if (rgetflag("hd"))
154 boolean(value(HALFDUPLEX)) = 1;
155 if (rgetflag("hf"))
156 boolean(value(HARDWAREFLOW)) = 1;
157 if (RE == NULL)
158 RE = (char *)"tip.record";
159 if (EX == NULL)
160 EX = (char *)"\t\n\b\f";
161 if (ES != NOSTR)
162 (void) vstring("es", ES);
163 if (FO != NOSTR)
164 (void) vstring("fo", FO);
165 if (PR != NOSTR)
166 (void) vstring("pr", PR);
167 if (RC != NOSTR)
168 (void) vstring("rc", RC);
169 if ((DL = rgetnum("dl")) < 0)
170 DL = 0;
171 if ((CL = rgetnum("cl")) < 0)
172 CL = 0;
173 if ((ET = rgetnum("et")) < 0)
174 ET = 10;
175 }
176
177 char *
getremote(char * host)178 getremote(char *host)
179 {
180 char *cp;
181 static char *next;
182 static int lookedup = 0;
183
184 if (!lookedup) {
185 if (host == NOSTR && (host = getenv("HOST")) == NOSTR) {
186 (void) fprintf(stderr, "tip: no host specified\n");
187 exit(3);
188 }
189 getremcap(host);
190 next = DV;
191 lookedup++;
192 }
193 /*
194 * We return a new device each time we're called (to allow
195 * a rotary action to be simulated)
196 */
197 if (next == NOSTR)
198 return (NOSTR);
199 if ((cp = strchr(next, ',')) == NULL) {
200 DV = next;
201 next = NOSTR;
202 } else {
203 *cp++ = '\0';
204 DV = next;
205 next = cp;
206 }
207 return (DV);
208 }
209