home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / lynx-2.4 / WWW / Library / Implementation / HTTelnet.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-28  |  9.2 KB  |  358 lines

  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. #include "HTUtils.h"
  17. #include "tcp.h"
  18.  
  19. /* Implements:
  20. */
  21. #include "HTTelnet.h"
  22.  
  23. #include "HTParse.h"
  24. #include "HTAnchor.h"
  25. #include "HTTP.h"
  26. #include "HTFile.h"
  27. /*#include <errno.h> included by tcp.h -- FM */
  28. /*#include <stdio.h> included by HTUtils.h -- FM */
  29.  
  30. #include "HText.h"
  31.  
  32. #include "HTAccess.h"
  33. #include "HTAlert.h"
  34. #ifndef VMS
  35. #include "../../../userdefs.h"  /* for TELNET_COMMAND and RLOGIN_COMMAND */
  36. #endif /* not VMS */
  37.  
  38. #include "LYLeaks.h"
  39.  
  40. #define HT_NO_DATA -9999
  41.  
  42.  
  43. /*    Telnet or "rlogin" access
  44. **    -------------------------
  45. */
  46. PRIVATE int remote_session ARGS2(char *, access, char *, host)
  47. {
  48.     char * user = host;
  49.      char * cp;
  50.     char * hostname;
  51.     char * port;
  52.     char   command[256];
  53.     enum _login_protocol { telnet, rlogin, tn3270 } login_protocol =
  54.         strcmp(access, "rlogin") == 0 ? rlogin :
  55.         strcmp(access, "tn3270") == 0 ? tn3270 : telnet;
  56. #ifdef VMS
  57.     extern int DCLsystem PARAMS((char *command));
  58. #define system(a) DCLsystem(a) /* use LYCurses.c routines for spawns */
  59. #endif /* VMS */
  60.  
  61.     /*
  62.      *    Modified to allow for odd chars in a username only if exists.
  63.      *    05-28-94 Lynx 2-3-1 Garrett Arch Blythe
  64.      */
  65.     /* prevent telnet://hostname;rm -rf *  URL's (VERY BAD) 
  66.      *  *cp=0;  /* terminate at any ;,<,>,`,|,",' or space or return
  67.      *  or tab to prevent security whole 
  68.      */
  69.     for(cp = (strchr(host, '@') ? strchr(host, '@') : host); *cp != '\0';
  70.         cp++)    {
  71.         if(!isalnum(*cp) && *cp != '_' && *cp != '-' &&
  72.                 *cp != ':' && *cp != '.' && *cp != '@') {
  73.             *cp = '\0';
  74.             break;
  75.         }
  76.     }
  77.  
  78.     hostname = strchr(host, '@');
  79.     port = strchr(host, ':');
  80.  
  81.     if (hostname) {
  82.         *hostname++ = 0;    /* Split */
  83.     } else {
  84.         hostname = host;
  85.         user = 0;        /* No user specified */
  86.     }
  87.  
  88.     if (port) *port++ = 0;    /* Split */
  89.  
  90.  
  91. /* If the person is already telnetting etc, forbid hopping */
  92. /* This is a security precaution, for us and remote site */
  93.  
  94.     if (HTSecure) {
  95.  
  96. #ifdef TELNETHOPPER_MAIL
  97.         sprintf(command, 
  98.           "finger @%s | mail -s \"**telnethopper %s\" tbl@dxcern.cern.ch",
  99.            HTClientHost, HTClientHost);
  100.         system(command);
  101. #endif
  102.         printf("\n\nSorry, but the service you have selected is one\n");
  103.         printf("to which you have to log in.  If you were running www\n");
  104.         printf("on your own computer, you would be automatically connected.\n");
  105.         printf("For security reasons, this is not allowed when\n");
  106.         printf("you log in to this information service remotely.\n\n");
  107.  
  108.         printf("You can manually connect to this service using %s\n",
  109.            access);
  110.         printf("to host %s", hostname);
  111.         if (user) printf(", user name %s", user);
  112.         if (port) printf(", port %s", port);
  113.         printf(".\n\n");
  114.         return HT_NO_DATA;
  115.     }
  116.  
  117. /* Not all telnet servers get it even if user name is specified
  118. ** so we always tell the guy what to log in as
  119. */
  120.         if (user && login_protocol != rlogin) 
  121.         printf("When you are connected, log in as %s\n", user);
  122.  
  123. /*
  124.  *    NeXTSTEP is the implied version of the NeXT operating system.
  125.  *        You may need to define this yourself.
  126.  */
  127. #if     defined(NeXT) && defined(NeXTSTEP) && NeXTSTEP<=20100
  128.     sprintf(command, "%s%s%s %s %s", TELNET_COMMAND,
  129.         user ? " -l " : "",
  130.         user ? user : "",
  131.         hostname,
  132.         port ? port : "");
  133.  
  134.     if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
  135.     system(command);
  136.     return HT_NO_DATA;        /* Ok - it was done but no data */
  137. #define TELNET_DONE
  138. #endif
  139.  
  140. /* Most unix machines suppport username only with rlogin */
  141. #if defined(unix)
  142. #ifndef TELNET_DONE
  143.     if (login_protocol == rlogin) {
  144.         sprintf(command, "%s %s%s%s", RLOGIN_COMMAND,
  145.         hostname,
  146.         user ? " -l " : "",
  147.         user ? user : "");
  148.  
  149.     } else if (login_protocol == tn3270) {
  150.         sprintf(command, "%s %s %s", TN3270_COMMAND,
  151.         hostname,
  152.         port ? port : "");
  153.  
  154.     } else {  /* TELNET */
  155.         sprintf(command, "%s %s %s", TELNET_COMMAND,
  156.         hostname,
  157.         port ? port : "");
  158.     }
  159.  
  160.     if (TRACE) fprintf(stderr, "HTaccess: Normal: Command is: %s\n", command);
  161.     system(command);
  162.     return HT_NO_DATA;        /* Ok - it was done but no data */
  163. #define TELNET_DONE
  164. #endif
  165. #endif
  166.  
  167. /* VMS varieties */
  168. #if defined(MULTINET)
  169.     if (login_protocol == rlogin) {
  170.         sprintf(command, "RLOGIN%s%s%s%s %s",  /*lm 930713 */
  171.         user ? "/USERNAME=" : "",
  172.         user ? user : "",
  173.         port ? "/PORT=" : "",
  174.         port ? port : "",
  175.         hostname);
  176.  
  177.     } else if (login_protocol == tn3270) {
  178.         sprintf(command, "TELNET/TN3270 %s%s %s",
  179.         port ? "/PORT=" : "",
  180.         port ? port : "",
  181.         hostname);
  182.  
  183.     } else {  /* TELNET */
  184.         sprintf(command, "TELNET %s%s %s",
  185.         port ? "/PORT=" : "",
  186.         port ? port : "",
  187.         hostname);
  188.     }
  189.  
  190.     if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
  191.     system(command);
  192.     return HT_NO_DATA;        /* Ok - it was done but no data */
  193. #define TELNET_DONE
  194. #endif /* MULTINET */
  195.  
  196. #if defined(WIN_TCP)
  197.         {
  198.             char *cp;
  199.     
  200.         if ((cp=getenv("WINTCP_COMMAND_STYLE")) != NULL &&
  201.                 0==strncasecomp(cp, "VMS", 3)) { /* VMS command syntax */ 
  202.             if (login_protocol == rlogin) {
  203.                 sprintf(command, "RLOGIN%s%s%s%s %s",  /*lm 930713 */
  204.                 user ? "/USERNAME=" : "",
  205.                 user ? user : "",
  206.                 port ? "/PORT=" : "",
  207.                 port ? port : "",
  208.                 hostname);
  209.  
  210.             } else if (login_protocol == tn3270) {
  211.                 sprintf(command, "TELNET/TN3270 %s%s %s",
  212.                 port ? "/PORT=" : "",
  213.                 port ? port : "",
  214.                 hostname);
  215.  
  216.             } else {  /* TELNET */
  217.                 sprintf(command, "TELNET %s%s %s",
  218.                 port ? "/PORT=" : "",
  219.                 port ? port : "",
  220.                 hostname);
  221.             }
  222.  
  223.             } else { /* UNIX command syntax */
  224.            if (login_protocol == rlogin) {
  225.                sprintf(command, "RLOGIN %s%s%s", 
  226.                hostname,
  227.                user ? " -l " : "",
  228.                user ? user : "");
  229.  
  230.             } else if (login_protocol == tn3270) {
  231.                 sprintf(command, "TN3270 %s %s",
  232.                 hostname,
  233.                 port ? port : "");
  234.  
  235.             } else {  /* TELNET */
  236.                 sprintf(command, "TELNET %s %s",
  237.                 hostname,
  238.                 port ? port : "");
  239.             }
  240.             }
  241.  
  242.         if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
  243.         system(command);
  244.         return HT_NO_DATA;        /* Ok - it was done but no data */
  245.         }
  246. #define TELNET_DONE
  247. #endif /* WIN_TCP */
  248.  
  249. #ifdef UCX
  250.     if (login_protocol == rlogin) {
  251.         sprintf(command, "RLOGIN%s%s %s %s",
  252.         user ? "/USERNAME=" : "",
  253.         user ? user : "",
  254.         hostname,
  255.         port ? port : "");
  256.  
  257.     } else if (login_protocol == tn3270) {
  258.         sprintf(command, "TN3270 %s %s",
  259.         hostname,
  260.         port ? port : "");
  261.  
  262.     } else {  /* TELNET */
  263.         sprintf(command, "TELNET %s %s",
  264.         hostname,
  265.         port ? port : "");
  266.     }
  267.  
  268.     if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
  269.     system(command);
  270.     return HT_NO_DATA;        /* Ok - it was done but no data */
  271. #define TELNET_DONE
  272. #endif /* UCX */
  273.  
  274. #ifdef VM
  275. #define SIMPLE_TELNET
  276. #endif
  277. #ifdef SIMPLE_TELNET
  278.     if (login_protocol == telnet) {            /* telnet only */
  279.         sprintf(command, "TELNET  %s",    /* @@ Bug: port ignored */
  280.         hostname);
  281.         if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
  282.         system(command);
  283.         return HT_NO_DATA;        /* Ok - it was done but no data */
  284.     }
  285. #endif
  286.  
  287. #ifndef TELNET_DONE
  288.     fprintf(stderr,
  289.     "\nSorry, this browser was compiled without the %s access option.\n",
  290.         access);
  291.     fprintf(stderr,
  292.     "\nTo access the information you must %s to %s", access, hostname);
  293.     if (port) fprintf(stderr," (port %s)", port);
  294.     if (user) fprintf(stderr,"\nlogging in with username %s", user);
  295.     fprintf(stderr, ".\n");
  296. #ifdef VMS
  297.     {
  298.         extern int LYgetch NOPARAMS;
  299.  
  300.         fprintf(stderr, "\nPress <return> to return to Lynx.");
  301.         LYgetch();
  302.     }
  303. #else
  304.     sleep(2);
  305. #endif /* VMS */
  306.     return HT_NO_DATA;
  307. #endif /* !TELNET_DONE */
  308. }
  309.  
  310. /*    "Load a document" -- establishes a session
  311. **    ------------------------------------------
  312. **
  313. ** On entry,
  314. **    addr        must point to the fully qualified hypertext reference.
  315. **
  316. ** On exit,
  317. **    returns        <0    Error has occured.
  318. **            >=0    Value of file descriptor or socket to be used
  319. **                 to read data.
  320. **    *pFormat    Set to the format of the file, if known.
  321. **            (See WWW.h)
  322. **
  323. */
  324. PRIVATE int HTLoadTelnet
  325. ARGS4
  326. (
  327.  CONST char *,        addr,
  328.  HTParentAnchor *,    anchor,
  329.  HTFormat,        format_out,
  330.  HTStream *,        sink            /* Ignored */
  331. )
  332. {
  333.     char * access;
  334.     
  335.     char * host;
  336.     int status;
  337.     
  338.     if (sink) {
  339.         HTAlert("Can't output a live session -- it has to be interactive");
  340.     return HT_NO_ACCESS;
  341.     }
  342.     access =  HTParse(addr, "file:", PARSE_ACCESS);
  343.     
  344.     host = HTParse(addr, "", PARSE_HOST);
  345.     status = remote_session(access, host);
  346.  
  347.     free(host);    
  348.     free(access);
  349.     return status;
  350. }
  351.  
  352.  
  353. GLOBALDEF PUBLIC HTProtocol HTTelnet = { "telnet", HTLoadTelnet, NULL };
  354. GLOBALDEF PUBLIC HTProtocol HTRlogin = { "rlogin", HTLoadTelnet, NULL };
  355. GLOBALDEF PUBLIC HTProtocol HTTn3270 = { "tn3270", HTLoadTelnet, NULL };
  356.  
  357.  
  358.