xref: /freebsd/contrib/tcp_wrappers/miscd.c (revision 911f0260390e18cf85f3dbf2c719b593efdc1e3c)
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.10 96/02/11 17:01:30";
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 #ifndef MAXPATHNAMELEN
31 #define MAXPATHNAMELEN	BUFSIZ
32 #endif
33 
34 #ifndef STDIN_FILENO
35 #define STDIN_FILENO	0
36 #endif
37 
38 /* Local stuff. */
39 
40 #include "patchlevel.h"
41 #include "tcpd.h"
42 
43 int     allow_severity = SEVERITY;	/* run-time adjustable */
44 int     deny_severity = LOG_WARNING;	/* ditto */
45 
46 main(int argc, char **argv)
47 {
48     struct request_info request;
49     char    path[MAXPATHNAMELEN];
50 
51     /* Attempt to prevent the creation of world-writable files. */
52 
53 #ifdef DAEMON_UMASK
54     umask(DAEMON_UMASK);
55 #endif
56 
57     /*
58      * Open a channel to the syslog daemon. Older versions of openlog()
59      * require only two arguments.
60      */
61 
62 #ifdef LOG_MAIL
63     (void) openlog(argv[0], LOG_PID, FACILITY);
64 #else
65     (void) openlog(argv[0], LOG_PID);
66 #endif
67 
68     /*
69      * Find out the endpoint addresses of this conversation. Host name
70      * lookups and double checks will be done on demand.
71      */
72 
73     request_init(&request, RQ_DAEMON, argv[0], RQ_FILE, STDIN_FILENO, 0);
74     fromhost(&request);
75 
76     /*
77      * Optionally look up and double check the remote host name. Sites
78      * concerned with security may choose to refuse connections from hosts
79      * that pretend to have someone elses host name.
80      */
81 
82 #ifdef PARANOID
83     if (STR_EQ(eval_hostname(request.client), paranoid))
84 	refuse(&request);
85 #endif
86 
87     /*
88      * The BSD rlogin and rsh daemons that came out after 4.3 BSD disallow
89      * socket options at the IP level. They do so for a good reason.
90      * Unfortunately, we cannot use this with SunOS 4.1.x because the
91      * getsockopt() system call can panic the system.
92      */
93 
94 #ifdef KILL_IP_OPTIONS
95     fix_options(&request);
96 #endif
97 
98     /*
99      * Check whether this host can access the service in argv[0]. The
100      * access-control code invokes optional shell commands as specified in
101      * the access-control tables.
102      */
103 
104 #ifdef HOSTS_ACCESS
105     if (!hosts_access(&request))
106 	refuse(&request);
107 #endif
108 
109     /* Report request and invoke the real daemon program. */
110 
111     syslog(allow_severity, "connect from %s", eval_client(&request));
112     sprintf(path, "%s/miscd", REAL_DAEMON_DIR);
113     closelog();
114     (void) execv(path, argv);
115     syslog(LOG_ERR, "error: cannot execute %s: %m", path);
116     clean_exit(&request);
117     /* NOTREACHED */
118 }
119