home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume39 / tcp_wrappers / part03 / miscd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-29  |  2.7 KB  |  104 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 renaming the real miscd daemon to the name defined with the
  5.   * REAL_MISCD macro.
  6.   * 
  7.   * Connections and diagnostics are logged through syslog(3).
  8.   * 
  9.   * The Ultrix miscd program implements (among others) the systat service, which
  10.   * pipes the output from who(1) to stdout. This information is potentially
  11.   * useful to systems crackers.
  12.   * 
  13.   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  14.   */
  15.  
  16. #ifndef lint
  17. static char sccsid[] = "@(#) miscd.c 1.8 93/09/27 18:59:15";
  18. #endif
  19.  
  20. /* System libraries. */
  21.  
  22. #include <sys/types.h>
  23. #include <sys/param.h>
  24. #include <sys/stat.h>
  25. #include <sys/socket.h>
  26. #include <netinet/in.h>
  27. #include <stdio.h>
  28. #include <syslog.h>
  29.  
  30. /* Local stuff. */
  31.  
  32. #include "patchlevel.h"
  33. #include "log_tcp.h"
  34.  
  35. int     allow_severity = SEVERITY;    /* run-time adjustable */
  36. int     deny_severity = LOG_WARNING;    /* ditto */
  37.  
  38. main(argc, argv)
  39. int     argc;
  40. char  **argv;
  41. {
  42.     struct client_info client;
  43.     int     from_stat;
  44.  
  45.     /* Attempt to prevent the creation of world-writable files. */
  46.  
  47. #ifdef DAEMON_UMASK
  48.     umask(DAEMON_UMASK);
  49. #endif
  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(&client);
  69. #ifdef PARANOID
  70.     if (from_stat == -1)
  71.     refuse(&client);
  72. #endif
  73.  
  74.     /*
  75.      * The BSD rlogin and rsh daemons that came out after 4.3 BSD disallow
  76.      * socket options at the IP level. They do so for a good reason.
  77.      * Unfortunately, we cannot use this with SunOS 4.1.x because the
  78.      * getsockopt() system call can panic the system.
  79.      */
  80.  
  81. #ifdef KILL_IP_OPTIONS
  82.     fix_options(&client);
  83. #endif
  84.  
  85.     /*
  86.      * Check whether this host can access the service in argv[0]. The
  87.      * access-control code invokes optional shell commands as specified in
  88.      * the access-control tables.
  89.      */
  90.  
  91. #ifdef HOSTS_ACCESS
  92.     if (!hosts_access(argv[0], &client))
  93.     refuse(&client);
  94. #endif
  95.  
  96.     /* Report remote client and invoke the real daemon program. */
  97.  
  98.     syslog(allow_severity, "connect from %s", hosts_info(&client));
  99.     (void) execv(REAL_MISCD, argv);
  100.     syslog(LOG_ERR, "error: cannot execute %s: %m", REAL_MISCD);
  101.     clean_exit(&client);
  102.     /* NOTREACHED */
  103. }
  104.