[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.10

1.10    ! aaron       1: /*     $OpenBSD: main.c,v 1.9 1999/12/15 11:16:31 deraadt Exp $        */
1.2       niklas      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:
1.5       art        43: #include "telnet_locl.h"
1.1       deraadt    44:
                     45: /* These values need to be the same as defined in libtelnet/kerberos5.c */
                     46: /* Either define them in both places, or put in some common header file. */
1.2       niklas     47: #define OPTS_FORWARD_CREDS     0x00000002
                     48: #define OPTS_FORWARDABLE_CREDS 0x00000001
1.1       deraadt    49:
1.5       art        50: #if KRB5
1.1       deraadt    51: #define FORWARD
                     52: #endif
                     53:
1.6       art        54: #ifdef KRB4
                     55: #include <kerberosIV/krb.h>
                     56: #endif
                     57:
1.1       deraadt    58: /*
                     59:  * Initialize variables.
                     60:  */
                     61:     void
                     62: tninit()
                     63: {
                     64:     init_terminal();
                     65:
                     66:     init_network();
1.2       niklas     67:
1.1       deraadt    68:     init_telnet();
                     69:
                     70:     init_sys();
                     71:
                     72: #if defined(TN3270)
                     73:     init_3270();
                     74: #endif
                     75: }
                     76:
                     77:        void
                     78: usage()
                     79: {
                     80:        fprintf(stderr, "Usage: %s %s%s%s%s\n",
                     81:            prompt,
                     82: #ifdef AUTHENTICATION
1.2       niklas     83:            "[-8] [-E] [-K] [-L] [-S tos] [-X atype] [-a] [-c] [-d] [-e char]",
1.9       deraadt    84:            "\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] [-b hostalias ] ",
1.1       deraadt    85: #else
1.2       niklas     86:            "[-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]",
1.9       deraadt    87:            "\n\t[-n tracefile] [-b hostalias ] ",
1.1       deraadt    88: #endif
                     89: #if defined(TN3270) && defined(unix)
                     90: # ifdef AUTHENTICATION
1.2       niklas     91:            "[-noasynch] [-noasynctty]\n\t[-noasyncnet] [-r] [-t transcom] ",
1.1       deraadt    92: # else
1.2       niklas     93:            "[-noasynch] [-noasynctty] [-noasyncnet] [-r]\n\t[-t transcom]",
1.1       deraadt    94: # endif
                     95: #else
                     96:            "[-r] ",
                     97: #endif
1.9       deraadt    98:            "\n\t"
1.5       art        99: #ifdef ENCRYPTION
1.9       deraadt   100:            "[-x] "
1.5       art       101: #endif
1.9       deraadt   102:            "[host-name [port]]");
1.1       deraadt   103:        exit(1);
                    104: }
                    105:
                    106: /*
                    107:  * main.  Parse arguments, invoke the protocol or command parser.
                    108:  */
                    109:
1.7       art       110:        int
1.1       deraadt   111: main(argc, argv)
                    112:        int argc;
                    113:        char *argv[];
                    114: {
                    115:        extern char *optarg;
                    116:        extern int optind;
                    117:        int ch;
1.5       art       118:        char *user, *alias;
1.1       deraadt   119: #ifdef FORWARD
                    120:        extern int forward_flags;
                    121: #endif /* FORWARD */
                    122:
                    123:        tninit();               /* Clear out things */
                    124:
                    125:        TerminalSaveState();
                    126:
1.5       art       127:        if ((prompt = strrchr(argv[0], '/')))
1.1       deraadt   128:                ++prompt;
                    129:        else
                    130:                prompt = argv[0];
                    131:
1.3       niklas    132:        user = alias = NULL;
1.1       deraadt   133:
                    134:        rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
1.5       art       135:
                    136:        /*
                    137:         * if AUTHENTICATION and ENCRYPTION is set autologin will be
                    138:         * set to true after the getopt switch; unless the -K option is
                    139:         * passed
                    140:         */
1.1       deraadt   141:        autologin = -1;
                    142:
1.5       art       143:        while ((ch = getopt(argc, argv, "78DEKLS:X:ab:cde:fFk:l:n:rt:x")) != -1) {
1.1       deraadt   144:                switch(ch) {
                    145:                case '8':
                    146:                        eight = 3;      /* binary output and input */
                    147:                        break;
1.5       art       148:                case '7':
                    149:                        eight = 0;
                    150:                        break;
                    151:                case 'D': {
                    152:                        /* sometimes we don't want a mangled display */
                    153:                        char *p;
                    154:                        if((p = getenv("DISPLAY")))
                    155:                                env_define("DISPLAY", (unsigned char*)p);
                    156:                        break;
                    157:                }
                    158:
1.1       deraadt   159:                case 'E':
                    160:                        rlogin = escape = _POSIX_VDISABLE;
                    161:                        break;
                    162:                case 'K':
                    163: #ifdef AUTHENTICATION
                    164:                        autologin = 0;
                    165: #endif
                    166:                        break;
                    167:                case 'L':
                    168:                        eight |= 2;     /* binary output only */
                    169:                        break;
                    170:                case 'S':
                    171:                    {
                    172: #ifdef HAS_GETTOS
                    173:                        extern int tos;
                    174:
                    175:                        if ((tos = parsetos(optarg, "tcp")) < 0)
                    176:                                fprintf(stderr, "%s%s%s%s\n",
                    177:                                        prompt, ": Bad TOS argument '",
                    178:                                        optarg,
                    179:                                        "; will try to use default TOS");
                    180: #else
                    181:                        fprintf(stderr,
                    182:                           "%s: Warning: -S ignored, no parsetos() support.\n",
                    183:                                                                prompt);
                    184: #endif
                    185:                    }
                    186:                        break;
                    187:                case 'X':
                    188: #ifdef AUTHENTICATION
                    189:                        auth_disable_name(optarg);
                    190: #endif
                    191:                        break;
                    192:                case 'a':
                    193:                        autologin = 1;
                    194:                        break;
                    195:                case 'c':
                    196:                        skiprc = 1;
                    197:                        break;
                    198:                case 'd':
                    199:                        debug = 1;
                    200:                        break;
                    201:                case 'e':
                    202:                        set_escape_char(optarg);
                    203:                        break;
                    204:                case 'f':
                    205: #if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
                    206:                        if (forward_flags & OPTS_FORWARD_CREDS) {
1.2       niklas    207:                            fprintf(stderr,
1.1       deraadt   208:                                    "%s: Only one of -f and -F allowed.\n",
                    209:                                    prompt);
                    210:                            usage();
                    211:                        }
                    212:                        forward_flags |= OPTS_FORWARD_CREDS;
                    213: #else
                    214:                        fprintf(stderr,
1.2       niklas    215:                         "%s: Warning: -f ignored, no Kerberos V5 support.\n",
1.1       deraadt   216:                                prompt);
                    217: #endif
                    218:                        break;
                    219:                case 'F':
                    220: #if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
                    221:                        if (forward_flags & OPTS_FORWARD_CREDS) {
1.2       niklas    222:                            fprintf(stderr,
1.1       deraadt   223:                                    "%s: Only one of -f and -F allowed.\n",
                    224:                                    prompt);
                    225:                            usage();
                    226:                        }
                    227:                        forward_flags |= OPTS_FORWARD_CREDS;
                    228:                        forward_flags |= OPTS_FORWARDABLE_CREDS;
                    229: #else
                    230:                        fprintf(stderr,
1.2       niklas    231:                         "%s: Warning: -F ignored, no Kerberos V5 support.\n",
1.1       deraadt   232:                                prompt);
                    233: #endif
                    234:                        break;
                    235:                case 'k':
                    236: #if defined(AUTHENTICATION) && defined(KRB4)
                    237:                    {
1.5       art       238:                        extern char *dest_realm, dst_realm_buf[];
                    239:                        extern int dst_realm_sz;
1.1       deraadt   240:                        dest_realm = dst_realm_buf;
                    241:                        (void)strncpy(dest_realm, optarg, dst_realm_sz);
                    242:                    }
                    243: #else
                    244:                        fprintf(stderr,
                    245:                           "%s: Warning: -k ignored, no Kerberos V4 support.\n",
                    246:                                                                prompt);
                    247: #endif
                    248:                        break;
                    249:                case 'l':
1.6       art       250:                        autologin = -1;
1.1       deraadt   251:                        user = optarg;
                    252:                        break;
1.3       niklas    253:                case 'b':
                    254:                        alias = optarg;
                    255:                        break;
1.1       deraadt   256:                case 'n':
                    257: #if defined(TN3270) && defined(unix)
                    258:                        /* distinguish between "-n oasynch" and "-noasynch" */
                    259:                        if (argv[optind - 1][0] == '-' && argv[optind - 1][1]
                    260:                            == 'n' && argv[optind - 1][2] == 'o') {
                    261:                                if (!strcmp(optarg, "oasynch")) {
                    262:                                        noasynchtty = 1;
                    263:                                        noasynchnet = 1;
                    264:                                } else if (!strcmp(optarg, "oasynchtty"))
                    265:                                        noasynchtty = 1;
                    266:                                else if (!strcmp(optarg, "oasynchnet"))
                    267:                                        noasynchnet = 1;
                    268:                        } else
                    269: #endif /* defined(TN3270) && defined(unix) */
                    270:                                SetNetTrace(optarg);
                    271:                        break;
                    272:                case 'r':
                    273:                        rlogin = '~';
                    274:                        break;
                    275:                case 't':
                    276: #if defined(TN3270) && defined(unix)
1.10    ! aaron     277:                        (void)strlcpy(tline, optarg, sizeof tline);
1.1       deraadt   278:                        transcom = tline;
                    279: #else
                    280:                        fprintf(stderr,
                    281:                           "%s: Warning: -t ignored, no TN3270 support.\n",
                    282:                                                                prompt);
                    283: #endif
                    284:                        break;
                    285:                case 'x':
1.5       art       286: #ifdef ENCRYPTION
                    287:                        encrypt_auto(1);
                    288:                        decrypt_auto(1);
                    289:                        EncryptVerbose(1);
                    290: #else
1.1       deraadt   291:                        fprintf(stderr,
                    292:                            "%s: Warning: -x ignored, no ENCRYPT support.\n",
                    293:                                                                prompt);
1.5       art       294: #endif
1.1       deraadt   295:                        break;
                    296:                case '?':
                    297:                default:
                    298:                        usage();
                    299:                        /* NOTREACHED */
                    300:                }
                    301:        }
1.5       art       302:
1.6       art       303: #ifdef KRB4
                    304:        {
                    305:                char realm[REALM_SZ];
                    306:
                    307:                if (krb_get_lrealm(realm, 0) != KSUCCESS) {
                    308: #if defined(AUTHENTICATION)
                    309:                        auth_disable_name("KERBEROS_V4");
                    310: #endif
                    311:                } else if (autologin == -1) {
1.5       art       312: #if defined(AUTHENTICATION)
1.6       art       313:                        autologin = 1;
1.5       art       314: #endif
                    315: #if defined(ENCRYPTION)
1.6       art       316:                        encrypt_auto(1);
                    317:                        decrypt_auto(1);
1.5       art       318: #endif
1.6       art       319:                }
1.5       art       320:        }
1.6       art       321: #endif /* KRB4 */
1.5       art       322:
1.1       deraadt   323:        if (autologin == -1)
                    324:                autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
                    325:
                    326:        argc -= optind;
                    327:        argv += optind;
                    328:
                    329:        if (argc) {
                    330:                char *args[7], **argp = args;
                    331:
                    332:                if (argc > 2)
                    333:                        usage();
                    334:                *argp++ = prompt;
                    335:                if (user) {
                    336:                        *argp++ = "-l";
                    337:                        *argp++ = user;
1.3       niklas    338:                }
                    339:                if (alias) {
                    340:                        *argp++ = "-b";
                    341:                        *argp++ = alias;
1.1       deraadt   342:                }
                    343:                *argp++ = argv[0];              /* host */
                    344:                if (argc > 1)
                    345:                        *argp++ = argv[1];      /* port */
                    346:                *argp = 0;
                    347:
                    348:                if (setjmp(toplevel) != 0)
                    349:                        Exit(0);
                    350:                if (tn(argp - args, args) == 1)
                    351:                        return (0);
                    352:                else
                    353:                        return (1);
                    354:        }
                    355:        (void)setjmp(toplevel);
                    356:        for (;;) {
                    357: #ifdef TN3270
                    358:                if (shell_active)
                    359:                        shell_continue();
                    360:                else
                    361: #endif
                    362:                        command(1, 0, 0);
                    363:        }
1.7       art       364:        return 0;
1.1       deraadt   365: }