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

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