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

1.23    ! guenther    1: /*     $OpenBSD: main.c,v 1.22 2013/10/26 21:33:29 sthen 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.
1.14      millert    16:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  */
                     32:
1.5       art        33: #include "telnet_locl.h"
1.1       deraadt    34:
                     35: /* These values need to be the same as defined in libtelnet/kerberos5.c */
                     36: /* Either define them in both places, or put in some common header file. */
1.2       niklas     37: #define OPTS_FORWARD_CREDS     0x00000002
                     38: #define OPTS_FORWARDABLE_CREDS 0x00000001
1.1       deraadt    39:
1.15      otto       40: int family = AF_UNSPEC;
1.22      sthen      41: int rtableid = -1;
1.15      otto       42:
1.1       deraadt    43: /*
                     44:  * Initialize variables.
                     45:  */
                     46:     void
                     47: tninit()
                     48: {
                     49:     init_terminal();
                     50:
                     51:     init_network();
1.2       niklas     52:
1.1       deraadt    53:     init_telnet();
                     54:
                     55:     init_sys();
                     56: }
                     57:
                     58:        void
                     59: usage()
                     60: {
1.16      jmc        61:        extern char *__progname;
                     62:
                     63:        (void)fprintf(stderr,
1.23    ! guenther   64:            "usage: %s [-4678acDdEKLr] [-b hostalias] [-e escapechar] "
        !            65:            "[-l user]\n"
        !            66:            "\t[-n tracefile] [-V rtable] [host [port]]\n",
1.16      jmc        67:            __progname);
                     68:
1.1       deraadt    69:        exit(1);
                     70: }
                     71:
                     72: /*
                     73:  * main.  Parse arguments, invoke the protocol or command parser.
                     74:  */
                     75:
1.7       art        76:        int
1.1       deraadt    77: main(argc, argv)
                     78:        int argc;
                     79:        char *argv[];
                     80: {
                     81:        extern char *optarg;
                     82:        extern int optind;
                     83:        int ch;
1.5       art        84:        char *user, *alias;
1.17      claudio    85:        const char *errstr;
1.11      hin        86:
1.1       deraadt    87:        tninit();               /* Clear out things */
                     88:
                     89:        TerminalSaveState();
                     90:
1.5       art        91:        if ((prompt = strrchr(argv[0], '/')))
1.1       deraadt    92:                ++prompt;
                     93:        else
                     94:                prompt = argv[0];
                     95:
1.3       niklas     96:        user = alias = NULL;
1.1       deraadt    97:
                     98:        rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
1.5       art        99:
1.1       deraadt   100:        autologin = -1;
                    101:
1.23    ! guenther  102:        while ((ch = getopt(argc, argv, "4678ab:cDdEe:KLl:n:rV:"))
1.15      otto      103:            != -1) {
1.1       deraadt   104:                switch(ch) {
1.15      otto      105:                case '4':
                    106:                        family = AF_INET;
                    107:                        break;
                    108:                case '6':
                    109:                        family = AF_INET6;
                    110:                        break;
1.23    ! guenther  111:                case '7':
        !           112:                        eight = 0;
        !           113:                        break;
1.1       deraadt   114:                case '8':
                    115:                        eight = 3;      /* binary output and input */
                    116:                        break;
1.23    ! guenther  117:                case 'a':
        !           118:                        autologin = 1;
        !           119:                        break;
        !           120:                case 'b':
        !           121:                        alias = optarg;
        !           122:                        break;
        !           123:                case 'c':
        !           124:                        skiprc = 1;
1.5       art       125:                        break;
                    126:                case 'D': {
                    127:                        /* sometimes we don't want a mangled display */
                    128:                        char *p;
                    129:                        if((p = getenv("DISPLAY")))
                    130:                                env_define("DISPLAY", (unsigned char*)p);
                    131:                        break;
                    132:                }
1.23    ! guenther  133:                case 'd':
        !           134:                        debug = 1;
        !           135:                        break;
1.1       deraadt   136:                case 'E':
                    137:                        rlogin = escape = _POSIX_VDISABLE;
                    138:                        break;
1.23    ! guenther  139:                case 'e':
        !           140:                        set_escape_char(optarg);
        !           141:                        break;
1.1       deraadt   142:                case 'K':
                    143:                        autologin = 0;
                    144:                        break;
                    145:                case 'L':
                    146:                        eight |= 2;     /* binary output only */
                    147:                        break;
                    148:                case 'l':
1.6       art       149:                        autologin = -1;
1.1       deraadt   150:                        user = optarg;
                    151:                        break;
                    152:                case 'n':
1.23    ! guenther  153:                        SetNetTrace(optarg);
1.1       deraadt   154:                        break;
                    155:                case 'r':
                    156:                        rlogin = '~';
                    157:                        break;
1.17      claudio   158:                case 'V':
1.22      sthen     159:                        rtableid = (int)strtonum(optarg, 0,
1.17      claudio   160:                            RT_TABLEID_MAX, &errstr);
                    161:                        if (errstr) {
1.20      guenther  162:                                fprintf(stderr, "%s: Warning: "
                    163:                                    "-V ignored, rtable %s: %s\n",
1.17      claudio   164:                                    prompt, errstr, optarg);
                    165:                        }
1.1       deraadt   166:                        break;
                    167:                case '?':
                    168:                default:
                    169:                        usage();
                    170:                        /* NOTREACHED */
                    171:                }
                    172:        }
1.5       art       173:
1.1       deraadt   174:        if (autologin == -1)
                    175:                autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
                    176:
                    177:        argc -= optind;
                    178:        argv += optind;
                    179:
                    180:        if (argc) {
                    181:                char *args[7], **argp = args;
                    182:
                    183:                if (argc > 2)
                    184:                        usage();
                    185:                *argp++ = prompt;
                    186:                if (user) {
                    187:                        *argp++ = "-l";
                    188:                        *argp++ = user;
1.3       niklas    189:                }
                    190:                if (alias) {
                    191:                        *argp++ = "-b";
                    192:                        *argp++ = alias;
1.1       deraadt   193:                }
                    194:                *argp++ = argv[0];              /* host */
                    195:                if (argc > 1)
                    196:                        *argp++ = argv[1];      /* port */
                    197:                *argp = 0;
                    198:
                    199:                if (setjmp(toplevel) != 0)
                    200:                        Exit(0);
                    201:                if (tn(argp - args, args) == 1)
                    202:                        return (0);
                    203:                else
                    204:                        return (1);
                    205:        }
                    206:        (void)setjmp(toplevel);
                    207:        for (;;) {
1.23    ! guenther  208:                command(1, 0, 0);
1.1       deraadt   209:        }
1.7       art       210:        return 0;
1.1       deraadt   211: }