home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume23 / log_tcp / part01 / tcpd.c < prev    next >
C/C++ Source or Header  |  1991-10-19  |  3KB  |  93 lines

  1.  /*
  2.   * General front end for stream and datagram IP services. This program logs
  3.   * the remote host name and then invokes the real daemon. For example,
  4.   * install as /usr/etc/{tftpd,fingerd,telnetd,ftpd,rlogind,rshd,rexecd},
  5.   * after saving the real daemons in the directory "/usr/etc/...". This
  6.   * arrangement requires that the network daemons are started by inetd or
  7.   * something similar. Connections and diagnostics are logged through
  8.   * syslog(3).
  9.   * 
  10.   * Compile with -DHOSTS_ACCESS in order to enable access control. See the
  11.   * hosts_access(5) manual page for details.
  12.   * 
  13.   * Compile with -DPARANOID if service should be refused to hosts that pretend
  14.   * to have someone elses host name. This gives some protection against rsh
  15.   * and rlogin attacks that involve compromised domain name servers.
  16.   * 
  17.   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  18.   */
  19.  
  20. #ifndef lint
  21. static char sccsid[] = "@(#) tcpd.c 1.2 91/10/02 23:01:44";
  22. #endif
  23.  
  24. /* System libraries. */
  25.  
  26. #include <sys/types.h>
  27. #include <sys/param.h>
  28. #include <stdio.h>
  29. #include <syslog.h>
  30.  
  31. #ifndef MAXPATHNAMELEN
  32. #define MAXPATHNAMELEN    BUFSIZ
  33. #endif
  34.  
  35. /* Local stuff. */
  36.  
  37. #include "log_tcp.h"
  38.  
  39. /* The following specifies where the vendor-provided daemons should go. */
  40.  
  41. #define REAL_DAEMON_DIR    "/usr/etc/..."
  42.  
  43. main(argc, argv)
  44. int     argc;
  45. char  **argv;
  46. {
  47.     struct from_host from;
  48.     int     from_stat;
  49.     char    path[MAXPATHNAMELEN];
  50.  
  51.     /*
  52.      * Open a channel to the syslog daemon. Older versions of openlog()
  53.      * require only two arguments.
  54.      */
  55.  
  56. #ifdef LOG_MAIL
  57.     (void) openlog(argv[0], LOG_PID, FACILITY);
  58. #else
  59.     (void) openlog(argv[0], LOG_PID);
  60. #endif
  61.  
  62.     /*
  63.      * Find out and verify the remote host name. Sites concerned with
  64.      * security may choose to refuse connections from hosts that pretend to
  65.      * have someone elses host name.
  66.      */
  67.  
  68.     from_stat = fromhost(&from);
  69. #ifdef PARANOID
  70.     if (from_stat == -1)
  71.     refuse(&from);
  72. #endif
  73.  
  74.     /*
  75.      * Check whether this host can access the service in argv[0]. The
  76.      * access-control code invokes optional shell commands as specified in
  77.      * the access-control tables.
  78.      */
  79.  
  80. #ifdef HOSTS_ACCESS
  81.     if (!hosts_access(argv[0], from.source))
  82.     refuse(&from);
  83. #endif
  84.  
  85.     /* Report remote host name and invoke the real daemon program. */
  86.  
  87.     syslog(LOG_INFO, "connect from %s", from.source);
  88.     sprintf(path, "%s/%s", REAL_DAEMON_DIR, argv[0]);
  89.     (void) execv(path, argv);
  90.     syslog(LOG_ERR, "%s: %m", path);
  91.     return (1);
  92. }
  93.