OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [userland/] [telnet/] [main.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 763 simons
/*
2
 * Copyright (c) 1988, 1990, 1993
3
 *      The Regents of the University of California.  All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. All advertising materials mentioning features or use of this software
14
 *    must display the following acknowledgement:
15
 *      This product includes software developed by the University of
16
 *      California, Berkeley and its contributors.
17
 * 4. Neither the name of the University nor the names of its contributors
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
#ifndef lint
35
static char copyright[] =
36
"@(#) Copyright (c) 1988, 1990, 1993\n\
37
        The Regents of the University of California.  All rights reserved.\n";
38
#endif /* not lint */
39
 
40
#ifndef lint
41
static char sccsid[] = "@(#)main.c      8.2 (Berkeley) 12/15/93";
42
#endif /* not lint */
43
 
44
#include <sys/types.h>
45
#include <stdlib.h>
46
#include <unistd.h>
47
 
48
#include "ring.h"
49
#include "externs.h"
50
#include "defines.h"
51
 
52
/* These values need to be the same as defined in libtelnet/kerberos5.c */
53
/* Either define them in both places, or put in some common header file. */
54
#define OPTS_FORWARD_CREDS           0x00000002
55
#define OPTS_FORWARDABLE_CREDS       0x00000001
56
 
57
#if 0
58
#define FORWARD
59
#endif
60
 
61
/*
62
 * Initialize variables.
63
 */
64
    void
65
tninit()
66
{
67
    init_terminal();
68
 
69
    init_network();
70
 
71
    init_telnet();
72
 
73
    init_sys();
74
 
75
#if defined(TN3270)
76
    init_3270();
77
#endif
78
}
79
 
80
        void
81
usage()
82
{
83
        fprintf(stderr, "Usage: %s %s%s%s%s\n",
84
            prompt,
85
#ifdef  AUTHENTICATION
86
            "[-8] [-E] [-K] [-L] [-S tos] [-X atype] [-a] [-c] [-d] [-e char]",
87
            "\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] ",
88
#else
89
            "[-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]",
90
            "\n\t[-n tracefile]",
91
#endif
92
#if defined(TN3270) && defined(unix)
93
# ifdef AUTHENTICATION
94
            "[-noasynch] [-noasynctty]\n\t[-noasyncnet] [-r] [-t transcom] ",
95
# else
96
            "[-noasynch] [-noasynctty] [-noasyncnet] [-r]\n\t[-t transcom]",
97
# endif
98
#else
99
            "[-r] ",
100
#endif
101
            "[host-name [port]]"
102
        );
103
        exit(1);
104
}
105
 
106
/*
107
 * main.  Parse arguments, invoke the protocol or command parser.
108
 */
109
 
110
 
111
main(argc, argv)
112
        int argc;
113
        char *argv[];
114
{
115
        extern char *optarg;
116
        extern int optind;
117
        int ch;
118
        char *user, *strrchr();
119
#ifdef  FORWARD
120
        extern int forward_flags;
121
#endif  /* FORWARD */
122
 
123
        tninit();               /* Clear out things */
124
#if     defined(CRAY) && !defined(__STDC__)
125
        _setlist_init();        /* Work around compiler bug */
126
#endif
127
 
128
        TerminalSaveState();
129
 
130
        if (prompt = strrchr(argv[0], '/'))
131
                ++prompt;
132
        else
133
                prompt = argv[0];
134
 
135
        user = NULL;
136
 
137
        rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
138
        autologin = -1;
139
 
140
        while ((ch = getopt(argc, argv, "8EKLNS:X:acde:fFk:l:n:rt:x")) != -1) {
141
                switch(ch) {
142
                case '8':
143
                        eight = 3;      /* binary output and input */
144
                        break;
145
                case 'E':
146
                        rlogin = escape = _POSIX_VDISABLE;
147
                        break;
148
                case 'K':
149
#ifdef  AUTHENTICATION
150
                        autologin = 0;
151
#endif
152
                        break;
153
                case 'L':
154
                        eight |= 2;     /* binary output only */
155
                        break;
156
                case 'N':
157
                        doaddrlookup = 0;
158
                        break;
159
                case 'S':
160
                    {
161
#ifdef  HAS_GETTOS
162
                        extern int tos;
163
 
164
                        if ((tos = parsetos(optarg, "tcp")) < 0)
165
                                fprintf(stderr, "%s%s%s%s\n",
166
                                        prompt, ": Bad TOS argument '",
167
                                        optarg,
168
                                        "; will try to use default TOS");
169
#else
170
                        fprintf(stderr,
171
                           "%s: Warning: -S ignored, no parsetos() support.\n",
172
                                                                prompt);
173
#endif
174
                    }
175
                        break;
176
                case 'X':
177
#ifdef  AUTHENTICATION
178
                        auth_disable_name(optarg);
179
#endif
180
                        break;
181
                case 'a':
182
                        autologin = 1;
183
                        break;
184
                case 'c':
185
                        skiprc = 1;
186
                        break;
187
                case 'd':
188
                        debug = 1;
189
                        break;
190
                case 'e':
191
                        set_escape_char(optarg);
192
                        break;
193
                case 'f':
194
#if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
195
                        if (forward_flags & OPTS_FORWARD_CREDS) {
196
                            fprintf(stderr,
197
                                    "%s: Only one of -f and -F allowed.\n",
198
                                    prompt);
199
                            usage();
200
                        }
201
                        forward_flags |= OPTS_FORWARD_CREDS;
202
#else
203
                        fprintf(stderr,
204
                         "%s: Warning: -f ignored, no Kerberos V5 support.\n",
205
                                prompt);
206
#endif
207
                        break;
208
                case 'F':
209
#if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
210
                        if (forward_flags & OPTS_FORWARD_CREDS) {
211
                            fprintf(stderr,
212
                                    "%s: Only one of -f and -F allowed.\n",
213
                                    prompt);
214
                            usage();
215
                        }
216
                        forward_flags |= OPTS_FORWARD_CREDS;
217
                        forward_flags |= OPTS_FORWARDABLE_CREDS;
218
#else
219
                        fprintf(stderr,
220
                         "%s: Warning: -F ignored, no Kerberos V5 support.\n",
221
                                prompt);
222
#endif
223
                        break;
224
                case 'k':
225
#if defined(AUTHENTICATION) && defined(KRB4)
226
                    {
227
                        extern char *dest_realm, dst_realm_buf[], dst_realm_sz;
228
                        dest_realm = dst_realm_buf;
229
                        (void)strncpy(dest_realm, optarg, dst_realm_sz);
230
                    }
231
#else
232
                        fprintf(stderr,
233
                           "%s: Warning: -k ignored, no Kerberos V4 support.\n",
234
                                                                prompt);
235
#endif
236
                        break;
237
                case 'l':
238
                        autologin = 1;
239
                        user = optarg;
240
                        break;
241
                case 'n':
242
#if defined(TN3270) && defined(unix)
243
                        /* distinguish between "-n oasynch" and "-noasynch" */
244
                        if (argv[optind - 1][0] == '-' && argv[optind - 1][1]
245
                            == 'n' && argv[optind - 1][2] == 'o') {
246
                                if (!strcmp(optarg, "oasynch")) {
247
                                        noasynchtty = 1;
248
                                        noasynchnet = 1;
249
                                } else if (!strcmp(optarg, "oasynchtty"))
250
                                        noasynchtty = 1;
251
                                else if (!strcmp(optarg, "oasynchnet"))
252
                                        noasynchnet = 1;
253
                        } else
254
#endif  /* defined(TN3270) && defined(unix) */
255
                                SetNetTrace(optarg);
256
                        break;
257
                case 'r':
258
                        rlogin = '~';
259
                        break;
260
                case 't':
261
#if defined(TN3270) && defined(unix)
262
                        transcom = tline;
263
                        (void)strcpy(transcom, optarg);
264
#else
265
                        fprintf(stderr,
266
                           "%s: Warning: -t ignored, no TN3270 support.\n",
267
                                                                prompt);
268
#endif
269
                        break;
270
                case 'x':
271
                        fprintf(stderr,
272
                            "%s: Warning: -x ignored, no ENCRYPT support.\n",
273
                                                                prompt);
274
                        break;
275
                case '?':
276
                default:
277
                        usage();
278
                        /* NOTREACHED */
279
                }
280
        }
281
        if (autologin == -1)
282
                autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
283
 
284
        argc -= optind;
285
        argv += optind;
286
 
287
        if (argc) {
288
                char *args[7], **argp = args;
289
 
290
                if (argc > 2)
291
                        usage();
292
                *argp++ = prompt;
293
                if (user) {
294
                        *argp++ = "-l";
295
                        *argp++ = user;
296
                }
297
                *argp++ = argv[0];               /* host */
298
                if (argc > 1)
299
                        *argp++ = argv[1];      /* port */
300
                *argp = 0;
301
 
302
#ifndef EMBED
303
                if (setjmp(toplevel) != 0)
304
                        Exit(0);
305
#endif
306
                if (tn(argp - args, args) == 1)
307
                        return (0);
308
                else
309
                        return (1);
310
        }
311
#ifndef EMBED
312
        (void)setjmp(toplevel);
313
#endif
314
        for (;;) {
315
#ifdef TN3270
316
                if (shell_active)
317
                        shell_continue();
318
                else
319
#endif
320
                        command(1, 0, 0);
321
        }
322
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.