home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / www / library / implemen / httelnet.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  6.3 KB  |  242 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. /* Implements:
  17. */
  18. #include"capalloc.h"
  19. #include "HTTelnet.h"
  20. #include"capstdio.h"
  21.  
  22. #include "HTParse.h"
  23. #include "HTUtils.h"
  24. #include "HTAnchor.h"
  25. #include "HTTP.h"
  26. #include "HTFile.h"
  27. #include <errno.h>
  28. #include <stdio.h>
  29.  
  30. #include "tcp.h"
  31. #include "HText.h"
  32.  
  33. #include "HTAccess.h"
  34. #include "HTAlert.h"
  35.  
  36. #define HT_NO_DATA -9999
  37.  
  38.  
  39. /*    Telnet or "rlogin" access
  40. **    -------------------------
  41. */
  42. PRIVATE int remote_session ARGS2(char *, access, char *, host)
  43. {
  44.     char * user = host;
  45.     char * hostname = strchr(host, '@');
  46.     char * port = strchr(host, ':');
  47.     char   command[256];
  48.     enum _login_protocol { telnet, rlogin, tn3270 } login_protocol =
  49.         strcmp(access, "rlogin") == 0 ? rlogin :
  50.         strcmp(access, "tn3270") == 0 ? tn3270 : telnet;
  51.     
  52.     if (hostname) {
  53.         *hostname++ = 0;    /* Split */
  54.     } else {
  55.         hostname = host;
  56.         user = 0;        /* No user specified */
  57.     }
  58.     if (port) *port++ = 0;    /* Split */
  59.  
  60.  
  61. /* If the person is already telnetting etc, forbid hopping */
  62. /* This is a security precaution, for us and remote site */
  63.  
  64.     if (HTSecure) {
  65.  
  66. #ifdef TELNETHOPPER_MAIL
  67.         sprintf(command, 
  68.           "finger @%s | mail -s \"**telnethopper %s\" tbl@dxcern.cern.ch",
  69.            HTClientHost, HTClientHost);
  70.         system(command);
  71. #endif
  72.         printf("\n\nSorry, but the service you have selected is one\n");
  73.         printf("to which you have to log in.  If you were running www\n");
  74.         printf("on your own computer, you would be automatically connected.\n");
  75.         printf("For security reasons, this is not allowed when\n");
  76.         printf("you log in to this information service remotely.\n\n");
  77.  
  78.         printf("You can manually connect to this service using %s\n",
  79.            access);
  80.         printf("to host %s", hostname);
  81.         if (user) printf(", user name %s", user);
  82.         if (port) printf(", port %s", port);
  83.         printf(".\n\n");
  84.         return HT_NO_DATA;
  85.     }
  86.  
  87. /* Not all telnet servers get it even if user name is specified
  88. ** so we always tell the guy what to log in as
  89. */
  90.         if (user) printf("When you are connected, log in as %s\n", user);
  91.     
  92. #ifdef NeXT
  93. #define TELNET_MINUS_L
  94. #endif
  95. #ifdef ultrix
  96. #define TELNET_MINUS_L
  97. #endif
  98.  
  99. #ifdef TELNET_MINUS_L
  100.     sprintf(command, "%s%s%s %s %s", access,
  101.         user ? " -l " : "",
  102.         user ? user : "",
  103.         hostname,
  104.         port ? port : "");
  105. #ifndef RELEASE
  106.     if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
  107. #endif /* RELEASE */
  108.     system(command);
  109.     return HT_NO_DATA;        /* Ok - it was done but no data */
  110. #define TELNET_DONE
  111. #endif
  112.  
  113. /* Most unix machines suppport username only with rlogin */
  114. #ifdef unix
  115. #ifndef TELNET_DONE
  116.     if (login_protocol != rlogin) {
  117.         sprintf(command, "%s %s %s", access,
  118.         hostname,
  119.         port ? port : "");
  120.     } else {
  121.         sprintf(command, "%s%s%s %s %s", access,
  122.         user ? " -l " : "",
  123.         user ? user : "",
  124.         hostname,
  125.         port ? port : "");
  126.     }
  127. #ifndef RELEASE
  128.     if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
  129. #endif /* RELEASE */
  130.     system(command);
  131.     return HT_NO_DATA;        /* Ok - it was done but no data */
  132. #define TELNET_DONE
  133. #endif
  134. #endif
  135.  
  136. #ifdef MULTINET                /* VMS varieties */
  137.     if (login_protocol == telnet) {
  138.         sprintf(command, "TELNET %s%s %s",
  139.         port ? "/PORT=" : "",
  140.         port ? port : "",
  141.         hostname);
  142.     } else if (login_protocol == tn3270) {
  143.         sprintf(command, "TELNET/TN3270 %s%s %s",
  144.         port ? "/PORT=" : "",
  145.         port ? port : "",
  146.         hostname);
  147.     } else {
  148.         sprintf(command, "RLOGIN%s%s%s%s %s",  /*lm 930713 */
  149.         user ? "/USERNAME=" : "",
  150.         user ? user : "",
  151.         port ? "/PORT=" : "",
  152.         port ? port : "",
  153.         hostname);
  154.     }
  155. #ifndef RELEASE
  156.     if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
  157. #endif /* RELEASE */
  158.     system(command);
  159.     return HT_NO_DATA;        /* Ok - it was done but no data */
  160. #define TELNET_DONE
  161. #endif
  162.  
  163. #ifdef UCX
  164. #define SIMPLE_TELNET
  165. #endif
  166. #ifdef VM
  167. #define SIMPLE_TELNET
  168. #endif
  169. #ifdef SIMPLE_TELNET
  170.     if (login_protocol == telnet) {            /* telnet only */
  171.         sprintf(command, "TELNET  %s",    /* @@ Bug: port ignored */
  172.         hostname);
  173. #ifndef RELEASE
  174.         if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
  175. #endif /* RELEASE */
  176.         system(command);
  177.         return HT_NO_DATA;        /* Ok - it was done but no data */
  178.     }
  179. #endif
  180.  
  181. #ifndef TELNET_DONE
  182.     fprintf(stderr,
  183.     "Sorry, DosLynx was compiled without the %s access option.\n",
  184.         access);
  185.     fprintf(stderr,
  186.     "\nTo access the information:\n  %s to %s", access, hostname);
  187.     if (port) fprintf(stderr," (port %s)\n", port);
  188.     if (user) fprintf(stderr," Log in with username %s", user);
  189.     fprintf(stderr, ".\n");
  190.     return -1;
  191. #endif
  192. }
  193.  
  194. /*    "Load a document" -- establishes a session
  195. **    ------------------------------------------
  196. **
  197. ** On entry,
  198. **    addr        must point to the fully qualified hypertext reference.
  199. **
  200. ** On exit,
  201. **    returns        <0    Error has occured.
  202. **            >=0    Value of file descriptor or socket to be used
  203. **                 to read data.
  204. **    *pFormat    Set to the format of the file, if known.
  205. **            (See WWW.h)
  206. **
  207. */
  208. PRIVATE int HTLoadTelnet
  209. ARGS4
  210. (
  211.  CONST char *,        addr,
  212.  HTParentAnchor *,    anchor,
  213.  HTFormat,        format_out,
  214.  HTStream *,        sink            /* Ignored */
  215. )
  216. {
  217.     char * access;
  218.     
  219.     char * host;
  220.     int status;
  221.     
  222.     if (sink) {
  223.         HTAlert("Can't output a live session -- it has to be interactive");
  224.     return HT_NO_ACCESS;
  225.     }
  226.     access =  HTParse(addr, "file:", PARSE_ACCESS);
  227.     
  228.     host = HTParse(addr, "", PARSE_HOST);
  229.     status = remote_session(access, host);
  230.  
  231.     free(host);    
  232.     free(access);
  233.     return status;
  234. }
  235.  
  236.  
  237. GLOBALDEF PUBLIC HTProtocol HTTelnet = { "telnet", HTLoadTelnet, NULL };
  238. GLOBALDEF PUBLIC HTProtocol HTRlogin = { "rlogin", HTLoadTelnet, NULL };
  239. GLOBALDEF PUBLIC HTProtocol HTTn3270 = { "tn3270", HTLoadTelnet, NULL };
  240.  
  241.  
  242.