[BACK]Return to main.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / telnet

Annotation of src/usr.bin/telnet/main.c, Revision 1.2

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