home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume30 / log_tcp / part02 / miscd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-20  |  2.7 KB  |  100 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.   * Compile with -DDAEMON_UMASK=nnn if daemons should run with a non-default
  19.   * umask value (the system default is 000, resulting in world-writable
  20.   * files).
  21.   * 
  22.   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  23.   */
  24.  
  25. #ifndef lint
  26. static char sccsid[] = "@(#) miscd.c 1.3 92/06/11 22:21:20";
  27. #endif
  28.  
  29. /* System libraries. */
  30.  
  31. #include <sys/types.h>
  32. #include <sys/param.h>
  33. #include <sys/stat.h>
  34. #include <stdio.h>
  35. #include <syslog.h>
  36.  
  37. /* Local stuff. */
  38.  
  39. #include "log_tcp.h"
  40.  
  41. /* The following specifies where the vendor-provided daemon should go. */
  42.  
  43. #define REAL_DAEMON    "/usr/etc/.../miscd"
  44.  
  45. main(argc, argv)
  46. int     argc;
  47. char  **argv;
  48. {
  49.     struct from_host from;
  50.     int     from_stat;
  51.  
  52.     /* Attempt to prevent the creation of world-writable files. */
  53.  
  54. #ifdef DAEMON_UMASK
  55.     umask(DAEMON_UMASK);
  56. #endif
  57.  
  58.     /*
  59.      * Open a channel to the syslog daemon. Older versions of openlog()
  60.      * require only two arguments.
  61.      */
  62.  
  63. #ifdef LOG_MAIL
  64.     (void) openlog(argv[0], LOG_PID, FACILITY);
  65. #else
  66.     (void) openlog(argv[0], LOG_PID);
  67. #endif
  68.  
  69.     /*
  70.      * Find out and verify the remote host name. Sites concerned with
  71.      * security may choose to refuse connections from hosts that pretend to
  72.      * have someone elses host name.
  73.      */
  74.  
  75.     from_stat = fromhost(&from);
  76. #ifdef PARANOID
  77.     if (from_stat == -1)
  78.     refuse(&from);
  79. #endif
  80.  
  81.     /*
  82.      * Check whether this host can access the service in argv[0]. The
  83.      * access-control code invokes optional shell commands as specified in
  84.      * the access-control tables.
  85.      */
  86.  
  87. #ifdef HOSTS_ACCESS
  88.     if (!hosts_access(argv[0], &from))
  89.     refuse(&from);
  90. #endif
  91.  
  92.     /* Report remote client and invoke the real daemon program. */
  93.  
  94.     syslog(LOG_INFO, "connect from %s", hosts_info(&from));
  95.     (void) execv(REAL_DAEMON, argv);
  96.     syslog(LOG_ERR, "%s: %m", REAL_DAEMON);
  97.     clean_exit(&from);
  98.     /* NOTREACHED */
  99. }
  100.