xref: /dflybsd-src/contrib/tcp_wrappers/miscd.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino  /*
2*86d7f5d3SJohn Marino   * Front end to the ULTRIX miscd service. The front end logs the remote host
3*86d7f5d3SJohn Marino   * name and then invokes the real miscd daemon. Install as "/usr/etc/miscd",
4*86d7f5d3SJohn Marino   * after renaming the real miscd daemon to the name defined with the
5*86d7f5d3SJohn Marino   * REAL_MISCD macro.
6*86d7f5d3SJohn Marino   *
7*86d7f5d3SJohn Marino   * Connections and diagnostics are logged through syslog(3).
8*86d7f5d3SJohn Marino   *
9*86d7f5d3SJohn Marino   * The Ultrix miscd program implements (among others) the systat service, which
10*86d7f5d3SJohn Marino   * pipes the output from who(1) to stdout. This information is potentially
11*86d7f5d3SJohn Marino   * useful to systems crackers.
12*86d7f5d3SJohn Marino   *
13*86d7f5d3SJohn Marino   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
14*86d7f5d3SJohn Marino   */
15*86d7f5d3SJohn Marino 
16*86d7f5d3SJohn Marino #ifndef lint
17*86d7f5d3SJohn Marino static char sccsid[] = "@(#) miscd.c 1.10 96/02/11 17:01:30";
18*86d7f5d3SJohn Marino #endif
19*86d7f5d3SJohn Marino 
20*86d7f5d3SJohn Marino /* System libraries. */
21*86d7f5d3SJohn Marino 
22*86d7f5d3SJohn Marino #include <sys/types.h>
23*86d7f5d3SJohn Marino #include <sys/param.h>
24*86d7f5d3SJohn Marino #include <sys/stat.h>
25*86d7f5d3SJohn Marino #include <sys/socket.h>
26*86d7f5d3SJohn Marino #include <netinet/in.h>
27*86d7f5d3SJohn Marino #include <stdio.h>
28*86d7f5d3SJohn Marino #include <syslog.h>
29*86d7f5d3SJohn Marino 
30*86d7f5d3SJohn Marino #ifndef MAXPATHNAMELEN
31*86d7f5d3SJohn Marino #define MAXPATHNAMELEN	BUFSIZ
32*86d7f5d3SJohn Marino #endif
33*86d7f5d3SJohn Marino 
34*86d7f5d3SJohn Marino #ifndef STDIN_FILENO
35*86d7f5d3SJohn Marino #define STDIN_FILENO	0
36*86d7f5d3SJohn Marino #endif
37*86d7f5d3SJohn Marino 
38*86d7f5d3SJohn Marino /* Local stuff. */
39*86d7f5d3SJohn Marino 
40*86d7f5d3SJohn Marino #include "patchlevel.h"
41*86d7f5d3SJohn Marino #include "tcpd.h"
42*86d7f5d3SJohn Marino 
43*86d7f5d3SJohn Marino int     allow_severity = SEVERITY;	/* run-time adjustable */
44*86d7f5d3SJohn Marino int     deny_severity = LOG_WARNING;	/* ditto */
45*86d7f5d3SJohn Marino 
main(argc,argv)46*86d7f5d3SJohn Marino main(argc, argv)
47*86d7f5d3SJohn Marino int     argc;
48*86d7f5d3SJohn Marino char  **argv;
49*86d7f5d3SJohn Marino {
50*86d7f5d3SJohn Marino     struct request_info request;
51*86d7f5d3SJohn Marino     char    path[MAXPATHNAMELEN];
52*86d7f5d3SJohn Marino 
53*86d7f5d3SJohn Marino     /* Attempt to prevent the creation of world-writable files. */
54*86d7f5d3SJohn Marino 
55*86d7f5d3SJohn Marino #ifdef DAEMON_UMASK
56*86d7f5d3SJohn Marino     umask(DAEMON_UMASK);
57*86d7f5d3SJohn Marino #endif
58*86d7f5d3SJohn Marino 
59*86d7f5d3SJohn Marino     /*
60*86d7f5d3SJohn Marino      * Open a channel to the syslog daemon. Older versions of openlog()
61*86d7f5d3SJohn Marino      * require only two arguments.
62*86d7f5d3SJohn Marino      */
63*86d7f5d3SJohn Marino 
64*86d7f5d3SJohn Marino #ifdef LOG_MAIL
65*86d7f5d3SJohn Marino     (void) openlog(argv[0], LOG_PID, FACILITY);
66*86d7f5d3SJohn Marino #else
67*86d7f5d3SJohn Marino     (void) openlog(argv[0], LOG_PID);
68*86d7f5d3SJohn Marino #endif
69*86d7f5d3SJohn Marino 
70*86d7f5d3SJohn Marino     /*
71*86d7f5d3SJohn Marino      * Find out the endpoint addresses of this conversation. Host name
72*86d7f5d3SJohn Marino      * lookups and double checks will be done on demand.
73*86d7f5d3SJohn Marino      */
74*86d7f5d3SJohn Marino 
75*86d7f5d3SJohn Marino     request_init(&request, RQ_DAEMON, argv[0], RQ_FILE, STDIN_FILENO, 0);
76*86d7f5d3SJohn Marino     fromhost(&request);
77*86d7f5d3SJohn Marino 
78*86d7f5d3SJohn Marino     /*
79*86d7f5d3SJohn Marino      * Optionally look up and double check the remote host name. Sites
80*86d7f5d3SJohn Marino      * concerned with security may choose to refuse connections from hosts
81*86d7f5d3SJohn Marino      * that pretend to have someone elses host name.
82*86d7f5d3SJohn Marino      */
83*86d7f5d3SJohn Marino 
84*86d7f5d3SJohn Marino #ifdef PARANOID
85*86d7f5d3SJohn Marino     if (STR_EQ(eval_hostname(request.client), paranoid))
86*86d7f5d3SJohn Marino 	refuse(&request);
87*86d7f5d3SJohn Marino #endif
88*86d7f5d3SJohn Marino 
89*86d7f5d3SJohn Marino     /*
90*86d7f5d3SJohn Marino      * The BSD rlogin and rsh daemons that came out after 4.3 BSD disallow
91*86d7f5d3SJohn Marino      * socket options at the IP level. They do so for a good reason.
92*86d7f5d3SJohn Marino      * Unfortunately, we cannot use this with SunOS 4.1.x because the
93*86d7f5d3SJohn Marino      * getsockopt() system call can panic the system.
94*86d7f5d3SJohn Marino      */
95*86d7f5d3SJohn Marino 
96*86d7f5d3SJohn Marino #ifdef KILL_IP_OPTIONS
97*86d7f5d3SJohn Marino     fix_options(&request);
98*86d7f5d3SJohn Marino #endif
99*86d7f5d3SJohn Marino 
100*86d7f5d3SJohn Marino     /*
101*86d7f5d3SJohn Marino      * Check whether this host can access the service in argv[0]. The
102*86d7f5d3SJohn Marino      * access-control code invokes optional shell commands as specified in
103*86d7f5d3SJohn Marino      * the access-control tables.
104*86d7f5d3SJohn Marino      */
105*86d7f5d3SJohn Marino 
106*86d7f5d3SJohn Marino #ifdef HOSTS_ACCESS
107*86d7f5d3SJohn Marino     if (!hosts_access(&request))
108*86d7f5d3SJohn Marino 	refuse(&request);
109*86d7f5d3SJohn Marino #endif
110*86d7f5d3SJohn Marino 
111*86d7f5d3SJohn Marino     /* Report request and invoke the real daemon program. */
112*86d7f5d3SJohn Marino 
113*86d7f5d3SJohn Marino     syslog(allow_severity, "connect from %s", eval_client(&request));
114*86d7f5d3SJohn Marino     sprintf(path, "%s/miscd", REAL_DAEMON_DIR);
115*86d7f5d3SJohn Marino     closelog();
116*86d7f5d3SJohn Marino     (void) execv(path, argv);
117*86d7f5d3SJohn Marino     syslog(LOG_ERR, "error: cannot execute %s: %m", path);
118*86d7f5d3SJohn Marino     clean_exit(&request);
119*86d7f5d3SJohn Marino     /* NOTREACHED */
120*86d7f5d3SJohn Marino }
121