home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume20 / log_tcp / part01 / tcpd.c < prev   
Encoding:
C/C++ Source or Header  |  1991-05-22  |  1.8 KB  |  69 lines

  1.  /*
  2.   * General front end for connection-oriented tcp/ip services. This program
  3.   * logs the remote host name and then invokes the real daemon. For example,
  4.   * install as /usr/etc/{fingerd,telnetd,ftpd,rlogind,rshd,rexecd}, after
  5.   * saving the real daemons in the directory "/usr/etc/...". This arrangement
  6.   * requires that the network daemons are started by inetd or something
  7.   * similar. Connections and diagnostics are logged through syslog(3).
  8.   * 
  9.   * Compile with -DHOSTS_ACCESS in order to enable access control. See the
  10.   * hosts_access(5) manual page for details.
  11.   * 
  12.   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  13.   */
  14.  
  15. #ifndef lint
  16. static char sccsid[] = "@(#) tcpd.c 1.1 91/01/06 22:30:36";
  17. #endif
  18.  
  19. #include <stdio.h>
  20. #include <syslog.h>
  21. #include <sys/types.h>
  22. #include <sys/param.h>
  23. #ifndef MAXPATHNAMELEN
  24. #define MAXPATHNAMELEN    BUFSIZ
  25. #endif
  26.  
  27. /* The following specifies where the vendor-provided daemons should go. */
  28.  
  29. #define REAL_DAEMON_DIR    "/usr/etc/..."
  30.  
  31. main(argc, argv)
  32. int     argc;
  33. char  **argv;
  34. {
  35.     char   *fromhost();
  36.     char   *host_name;
  37.     char    path[MAXPATHNAMELEN];
  38.  
  39.     /*
  40.      * Open a channel to the syslog daemon. Older versions of openlog()
  41.      * require only two arguments.
  42.      */
  43.  
  44. #ifdef LOG_MAIL
  45.     (void) openlog(argv[0], LOG_PID, LOG_MAIL);
  46. #else
  47.     (void) openlog(argv[0], LOG_PID);
  48. #endif
  49.  
  50.     /* Find out and report the remote host name. */
  51.  
  52.     if ((host_name = fromhost()) == 0)
  53.     host_name = "unknown";
  54.     syslog(LOG_INFO, "connect from %s", host_name);
  55.  
  56.     /* Check whether this host can access the service in argv[0]. */
  57.  
  58. #ifdef HOSTS_ACCESS
  59.     hosts_access(argv[0], host_name);
  60. #endif
  61.  
  62.     /* Invoke the real daemon program. */
  63.  
  64.     (void) sprintf(path, "%s/%s", REAL_DAEMON_DIR, argv[0]);
  65.     (void) execv(path, argv);
  66.     syslog(LOG_ERR, "%s: %m", path);
  67.     return (1);
  68. }
  69.