home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume23 / log_tcp / part01 / miscd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  2.4 KB  |  88 lines

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