Annotation of libwww/Library/src/HTTelnet.c, revision 1.1

1.1     ! timbl       1: /*             Telnet Acees, Roligin, etc                      HTAccess.c
        !             2: **             ==========================
        !             3: **
        !             4: ** Authors
        !             5: **     TBL     Tim Berners-Lee timbl@info.cern.ch
        !             6: **     JFG     Jean-Francois Groff jgh@next.com
        !             7: **     DD      Denis DeLaRoca (310) 825-4580  <CSP1DWD@mvs.oac.ucla.edu>
        !             8: ** History
        !             9: **       8 Jun 92 Telnet hopping prohibited as telnet is not secure (TBL)
        !            10: **     26 Jun 92 When over DECnet, suppressed FTP, Gopher and News. (JFG)
        !            11: **      6 Oct 92 Moved HTClientHost and logfile into here. (TBL)
        !            12: **     17 Dec 92 Tn3270 added, bug fix. (DD)
        !            13: **      2 Feb 93 Split from HTAccess.c. Registration.(TBL)
        !            14: */
        !            15: 
        !            16: /* Implements:
        !            17: */
        !            18: #include HTTelnet.h
        !            19: 
        !            20: #include "HTParse.h"
        !            21: #include "HTUtils.h"
        !            22: #include "WWW.h"
        !            23: #include "HTAnchor.h"
        !            24: #include "HTTP.h"
        !            25: #include "HTFile.h"
        !            26: #include <errno.h>
        !            27: #include <stdio.h>
        !            28: 
        !            29: #include "tcp.h"
        !            30: #include "HText.h"
        !            31: 
        !            32: #include "HTAccess.h"
        !            33: 
        !            34: #define HT_NO_DATA -9999
        !            35: 
        !            36: 
        !            37: /*     Telnet or "rlogin" access
        !            38: **     -------------------------
        !            39: */
        !            40: PRIVATE int remote_session ARGS2(char *, access, char *, host)
        !            41: {
        !            42:        char * user = host;
        !            43:        char * hostname = strchr(host, '@');
        !            44:        char * port = strchr(host, ':');
        !            45:        char   command[256];
        !            46:        enum _login_protocol { telnet, rlogin, tn3270 } login_protocol =
        !            47:                strcmp(access, "rlogin") == 0 ? rlogin :
        !            48:                strcmp(access, "tn3270") == 0 ? tn3270 : telnet;
        !            49:        
        !            50:        if (hostname) {
        !            51:            *hostname++ = 0;    /* Split */
        !            52:        } else {
        !            53:            hostname = host;
        !            54:            user = 0;           /* No user specified */
        !            55:        }
        !            56:        if (port) *port++ = 0;  /* Split */
        !            57: 
        !            58: 
        !            59: /* If the person is already telnetting etc, forbid hopping */
        !            60: /* This is a security precaution, for us and remote site */
        !            61: 
        !            62:        if (HTClientHost) {
        !            63: 
        !            64: #ifdef TELNETHOPPER_MAIL
        !            65:            sprintf(command, 
        !            66:              "finger @%s | mail -s \"**telnethopper %s\" tbl@dxcern.cern.ch",
        !            67:               HTClientHost, HTClientHost);
        !            68:            system(command);
        !            69: #endif
        !            70:            printf("\n\nSorry, but the service you have selected is one\n");
        !            71:            printf("to which you have to log in.  If you were running www\n");
        !            72:            printf("on your own computer, you would be automatically connected.\n");
        !            73:            printf("For security reasons, this is not allowed when\n");
        !            74:            printf("you log in to this information service remotely.\n\n");
        !            75: 
        !            76:            printf("You can manually connect to this service using %s\n",
        !            77:                   access);
        !            78:            printf("to host %s", hostname);
        !            79:            if (user) printf(", user name %s", user);
        !            80:            if (port) printf(", port %s", port);
        !            81:            printf(".\n\n");
        !            82:            return HT_NO_DATA;
        !            83:        }
        !            84: 
        !            85: /* Not all telnet servers get it even if user name is specified
        !            86: ** so we always tell the guy what to log in as
        !            87: */
        !            88:         if (user) printf("When you are connected, log in as %s\n", user);
        !            89:        
        !            90: #ifdef NeXT
        !            91: #define TELNET_MINUS_L
        !            92: #endif
        !            93: #ifdef ultrix
        !            94: #define TELNET_MINUS_L
        !            95: #endif
        !            96: 
        !            97: #ifdef TELNET_MINUS_L
        !            98: #endif
        !            99:        sprintf(command, "%s%s%s %s %s", access,
        !           100:                user ? " -l " : "",
        !           101:                user ? user : "",
        !           102:                hostname,
        !           103:                port ? port : "");
        !           104: 
        !           105:        if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
        !           106:        system(command);
        !           107:        return HT_NO_DATA;              /* Ok - it was done but no data */
        !           108: #define TELNET_DONE
        !           109: 
        !           110: /* Most unix machines suppport username only with rlogin */
        !           111: #ifdef unix
        !           112: #ifndef TELNET_DONE
        !           113:        if (login_protocol != rlogin) {
        !           114:            sprintf(command, "%s %s %s", access,
        !           115:                hostname,
        !           116:                port ? port : "");
        !           117:        } else {
        !           118:            sprintf(command, "%s%s%s %s %s", access,
        !           119:                user ? " -l " : "",
        !           120:                user ? user : "",
        !           121:                hostname,
        !           122:                port ? port : "");
        !           123:        }
        !           124:        if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
        !           125:        system(command);
        !           126:        return HT_NO_DATA;              /* Ok - it was done but no data */
        !           127: #define TELNET_DONE
        !           128: #endif
        !           129: #endif
        !           130: 
        !           131: #ifdef MULTINET                                /* VMS varieties */
        !           132:        if (login_protocol == telnet) {
        !           133:            sprintf(command, "TELNET %s%s %s",
        !           134:                port ? "/PORT=" : "",
        !           135:                port ? port : "",
        !           136:                hostname);
        !           137:        } else if (login_protocol == tn3270) {
        !           138:            sprintf(command, "TN3270 %s%s %s",
        !           139:                port ? "/PORT=" : "",
        !           140:                port ? port : "",
        !           141:                hostname);
        !           142:        } else {
        !           143:            sprintf(command, "RLOGIN%s%s%s%s %s", access,
        !           144:                user ? "/USERNAME=" : "",
        !           145:                user ? user : "",
        !           146:                port ? "/PORT=" : "",
        !           147:                port ? port : "",
        !           148:                hostname);
        !           149:        }
        !           150:        if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
        !           151:        system(command);
        !           152:        return HT_NO_DATA;              /* Ok - it was done but no data */
        !           153: #define TELNET_DONE
        !           154: #endif
        !           155: 
        !           156: #ifdef UCX
        !           157: #define SIMPLE_TELNET
        !           158: #endif
        !           159: #ifdef VM
        !           160: #define SIMPLE_TELNET
        !           161: #endif
        !           162: #ifdef SIMPLE_TELNET
        !           163:        if (login_protocol == telnet) {                 /* telnet only */
        !           164:            sprintf(command, "TELNET  %s",      /* @@ Bug: port ignored */
        !           165:                hostname);
        !           166:            if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
        !           167:            system(command);
        !           168:            return HT_NO_DATA;          /* Ok - it was done but no data */
        !           169:        }
        !           170: #endif
        !           171: 
        !           172: #ifndef TELNET_DONE
        !           173:        fprintf(stderr,
        !           174:        "Sorry, this browser was compiled without the %s access option.\n",
        !           175:                access);
        !           176:        fprintf(stderr,
        !           177:        "\nTo access the information you must %s to %s", access, hostname);
        !           178:        if (port) fprintf(stderr," (port %s)", port);
        !           179:        if (user) fprintf(stderr," logging in with username %s", user);
        !           180:        fprintf(stderr, ".\n");
        !           181:        return -1;
        !           182: #endif
        !           183: }
        !           184: 
        !           185: /*     "Load a document" -- establishes a session
        !           186: **     ------------------------------------------
        !           187: **
        !           188: ** On entry,
        !           189: **     addr            must point to the fully qualified hypertext reference.
        !           190: **
        !           191: ** On exit,
        !           192: **     returns         <0      Error has occured.
        !           193: **                     >=0     Value of file descriptor or socket to be used
        !           194: **                              to read data.
        !           195: **     *pFormat        Set to the format of the file, if known.
        !           196: **                     (See WWW.h)
        !           197: **
        !           198: */
        !           199: PRIVATE int HTLoadTelnet
        !           200: ARGS3
        !           201: (
        !           202:  CONST char *,         addr,
        !           203:  HTParentAnchor *,     anchor,
        !           204:  int,                  diagnostic
        !           205: )
        !           206: {
        !           207:     char * access =  HTParse(addr, "file:", PARSE_ACCESS);
        !           208:     
        !           209:     char * host = HTParse(addr, "", PARSE_HOST);
        !           210:     int status = remote_session(access, host);
        !           211: 
        !           212:     free(host);        
        !           213:     free(access);
        !           214:     return status;
        !           215: }
        !           216: 
        !           217: 
        !           218: PUBLIC HTAccessMethod HTTelnet = { "telnet", HTLoadTelnet, NULL };
        !           219: PUBLIC HTAccessMethod HTRlogin = { "rlogin", HTLoadTelnet, NULL };
        !           220: PUBLIC HTAccessMethod HTTn3270 = { "tn3270", HTLoadTelnet, NULL };
        !           221: 
        !           222: 

Webmaster