Annotation of libwww/Library/src/HTTelnet.c, revision 1.3
1.1 timbl 1: /* Telnet Acees, Roligin, etc HTAccess.c
2: ** ==========================
3: **
4: ** Authors
5: ** TBL Tim Berners-Lee timbl@info.cern.ch
6: ** JFG Jean-Francois Groff jgh@next.com
7: ** DD Denis DeLaRoca (310) 825-4580 <CSP1DWD@mvs.oac.ucla.edu>
8: ** History
9: ** 8 Jun 92 Telnet hopping prohibited as telnet is not secure (TBL)
10: ** 26 Jun 92 When over DECnet, suppressed FTP, Gopher and News. (JFG)
11: ** 6 Oct 92 Moved HTClientHost and logfile into here. (TBL)
12: ** 17 Dec 92 Tn3270 added, bug fix. (DD)
13: ** 2 Feb 93 Split from HTAccess.c. Registration.(TBL)
14: */
15:
16: /* Implements:
17: */
1.2 timbl 18: #include "HTTelnet.h"
1.1 timbl 19:
20: #include "HTParse.h"
21: #include "HTUtils.h"
22: #include "WWW.h"
23: #include "HTAnchor.h"
24: #include "HTTP.h"
25: #include "HTFile.h"
26: #include <errno.h>
27: #include <stdio.h>
28:
29: #include "tcp.h"
30: #include "HText.h"
31:
32: #include "HTAccess.h"
1.3 ! timbl 33: #include "HTAlert.h"
1.1 timbl 34:
35: #define HT_NO_DATA -9999
36:
37:
38: /* Telnet or "rlogin" access
39: ** -------------------------
40: */
41: PRIVATE int remote_session ARGS2(char *, access, char *, host)
42: {
43: char * user = host;
44: char * hostname = strchr(host, '@');
45: char * port = strchr(host, ':');
46: char command[256];
47: enum _login_protocol { telnet, rlogin, tn3270 } login_protocol =
48: strcmp(access, "rlogin") == 0 ? rlogin :
49: strcmp(access, "tn3270") == 0 ? tn3270 : telnet;
50:
51: if (hostname) {
52: *hostname++ = 0; /* Split */
53: } else {
54: hostname = host;
55: user = 0; /* No user specified */
56: }
57: if (port) *port++ = 0; /* Split */
58:
59:
60: /* If the person is already telnetting etc, forbid hopping */
61: /* This is a security precaution, for us and remote site */
62:
63: if (HTClientHost) {
64:
65: #ifdef TELNETHOPPER_MAIL
66: sprintf(command,
67: "finger @%s | mail -s \"**telnethopper %s\" tbl@dxcern.cern.ch",
68: HTClientHost, HTClientHost);
69: system(command);
70: #endif
71: printf("\n\nSorry, but the service you have selected is one\n");
72: printf("to which you have to log in. If you were running www\n");
73: printf("on your own computer, you would be automatically connected.\n");
74: printf("For security reasons, this is not allowed when\n");
75: printf("you log in to this information service remotely.\n\n");
76:
77: printf("You can manually connect to this service using %s\n",
78: access);
79: printf("to host %s", hostname);
80: if (user) printf(", user name %s", user);
81: if (port) printf(", port %s", port);
82: printf(".\n\n");
83: return HT_NO_DATA;
84: }
85:
86: /* Not all telnet servers get it even if user name is specified
87: ** so we always tell the guy what to log in as
88: */
89: if (user) printf("When you are connected, log in as %s\n", user);
90:
91: #ifdef NeXT
92: #define TELNET_MINUS_L
93: #endif
94: #ifdef ultrix
95: #define TELNET_MINUS_L
96: #endif
97:
98: #ifdef TELNET_MINUS_L
99: sprintf(command, "%s%s%s %s %s", access,
100: user ? " -l " : "",
101: user ? user : "",
102: hostname,
103: port ? port : "");
104:
105: if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
106: system(command);
107: return HT_NO_DATA; /* Ok - it was done but no data */
108: #define TELNET_DONE
1.2 timbl 109: #endif
1.1 timbl 110:
111: /* Most unix machines suppport username only with rlogin */
112: #ifdef unix
113: #ifndef TELNET_DONE
114: if (login_protocol != rlogin) {
115: sprintf(command, "%s %s %s", access,
116: hostname,
117: port ? port : "");
118: } else {
119: sprintf(command, "%s%s%s %s %s", access,
120: user ? " -l " : "",
121: user ? user : "",
122: hostname,
123: port ? port : "");
124: }
125: if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
126: system(command);
127: return HT_NO_DATA; /* Ok - it was done but no data */
128: #define TELNET_DONE
129: #endif
130: #endif
131:
132: #ifdef MULTINET /* VMS varieties */
133: if (login_protocol == telnet) {
134: sprintf(command, "TELNET %s%s %s",
135: port ? "/PORT=" : "",
136: port ? port : "",
137: hostname);
138: } else if (login_protocol == tn3270) {
139: sprintf(command, "TN3270 %s%s %s",
140: port ? "/PORT=" : "",
141: port ? port : "",
142: hostname);
143: } else {
144: sprintf(command, "RLOGIN%s%s%s%s %s", access,
145: user ? "/USERNAME=" : "",
146: user ? user : "",
147: port ? "/PORT=" : "",
148: port ? port : "",
149: hostname);
150: }
151: if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
152: system(command);
153: return HT_NO_DATA; /* Ok - it was done but no data */
154: #define TELNET_DONE
155: #endif
156:
157: #ifdef UCX
158: #define SIMPLE_TELNET
159: #endif
160: #ifdef VM
161: #define SIMPLE_TELNET
162: #endif
163: #ifdef SIMPLE_TELNET
164: if (login_protocol == telnet) { /* telnet only */
165: sprintf(command, "TELNET %s", /* @@ Bug: port ignored */
166: hostname);
167: if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
168: system(command);
169: return HT_NO_DATA; /* Ok - it was done but no data */
170: }
171: #endif
172:
173: #ifndef TELNET_DONE
174: fprintf(stderr,
175: "Sorry, this browser was compiled without the %s access option.\n",
176: access);
177: fprintf(stderr,
178: "\nTo access the information you must %s to %s", access, hostname);
179: if (port) fprintf(stderr," (port %s)", port);
180: if (user) fprintf(stderr," logging in with username %s", user);
181: fprintf(stderr, ".\n");
182: return -1;
183: #endif
184: }
185:
186: /* "Load a document" -- establishes a session
187: ** ------------------------------------------
188: **
189: ** On entry,
190: ** addr must point to the fully qualified hypertext reference.
191: **
192: ** On exit,
193: ** returns <0 Error has occured.
194: ** >=0 Value of file descriptor or socket to be used
195: ** to read data.
196: ** *pFormat Set to the format of the file, if known.
197: ** (See WWW.h)
198: **
199: */
200: PRIVATE int HTLoadTelnet
1.2 timbl 201: ARGS4
1.1 timbl 202: (
203: CONST char *, addr,
204: HTParentAnchor *, anchor,
1.3 ! timbl 205: HTFormat, format_out,
1.2 timbl 206: HTStream *, sink /* Ignored */
1.1 timbl 207: )
208: {
1.2 timbl 209: char * access;
210:
211: char * host;
212: int status;
213:
214: if (sink) {
215: HTAlert("Can't output a live session -- it has to be interactive");
216: return HT_NO_ACCESS;
217: }
218: access = HTParse(addr, "file:", PARSE_ACCESS);
1.1 timbl 219:
1.2 timbl 220: host = HTParse(addr, "", PARSE_HOST);
221: status = remote_session(access, host);
1.1 timbl 222:
223: free(host);
224: free(access);
225: return status;
226: }
227:
228:
1.2 timbl 229: PUBLIC HTProtocol HTTelnet = { "telnet", HTLoadTelnet, NULL };
230: PUBLIC HTProtocol HTRlogin = { "rlogin", HTLoadTelnet, NULL };
231: PUBLIC HTProtocol HTTn3270 = { "tn3270", HTLoadTelnet, NULL };
1.1 timbl 232:
233:
Webmaster