xref: /freebsd/contrib/tcp_wrappers/miscd.c (revision 14f102eacc8434a5a1f96466752578a4167140c9)
12aef6930SMark Murray  /*
22aef6930SMark Murray   * Front end to the ULTRIX miscd service. The front end logs the remote host
32aef6930SMark Murray   * name and then invokes the real miscd daemon. Install as "/usr/etc/miscd",
42aef6930SMark Murray   * after renaming the real miscd daemon to the name defined with the
52aef6930SMark Murray   * REAL_MISCD macro.
62aef6930SMark Murray   *
72aef6930SMark Murray   * Connections and diagnostics are logged through syslog(3).
82aef6930SMark Murray   *
92aef6930SMark Murray   * The Ultrix miscd program implements (among others) the systat service, which
102aef6930SMark Murray   * pipes the output from who(1) to stdout. This information is potentially
112aef6930SMark Murray   * useful to systems crackers.
122aef6930SMark Murray   *
132aef6930SMark Murray   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
142aef6930SMark Murray   */
152aef6930SMark Murray 
162aef6930SMark Murray #ifndef lint
172aef6930SMark Murray static char sccsid[] = "@(#) miscd.c 1.10 96/02/11 17:01:30";
182aef6930SMark Murray #endif
192aef6930SMark Murray 
202aef6930SMark Murray /* System libraries. */
212aef6930SMark Murray 
222aef6930SMark Murray #include <sys/types.h>
232aef6930SMark Murray #include <sys/param.h>
242aef6930SMark Murray #include <sys/stat.h>
252aef6930SMark Murray #include <sys/socket.h>
262aef6930SMark Murray #include <netinet/in.h>
272aef6930SMark Murray #include <stdio.h>
282aef6930SMark Murray #include <syslog.h>
292aef6930SMark Murray 
302aef6930SMark Murray #ifndef MAXPATHNAMELEN
312aef6930SMark Murray #define MAXPATHNAMELEN	BUFSIZ
322aef6930SMark Murray #endif
332aef6930SMark Murray 
342aef6930SMark Murray #ifndef STDIN_FILENO
352aef6930SMark Murray #define STDIN_FILENO	0
362aef6930SMark Murray #endif
372aef6930SMark Murray 
382aef6930SMark Murray /* Local stuff. */
392aef6930SMark Murray 
402aef6930SMark Murray #include "patchlevel.h"
412aef6930SMark Murray #include "tcpd.h"
422aef6930SMark Murray 
432aef6930SMark Murray int     allow_severity = SEVERITY;	/* run-time adjustable */
442aef6930SMark Murray int     deny_severity = LOG_WARNING;	/* ditto */
452aef6930SMark Murray 
main(int argc,char ** argv)46*14f102eaSEd Maste main(int argc, char **argv)
472aef6930SMark Murray {
482aef6930SMark Murray     struct request_info request;
492aef6930SMark Murray     char    path[MAXPATHNAMELEN];
502aef6930SMark Murray 
512aef6930SMark Murray     /* Attempt to prevent the creation of world-writable files. */
522aef6930SMark Murray 
532aef6930SMark Murray #ifdef DAEMON_UMASK
542aef6930SMark Murray     umask(DAEMON_UMASK);
552aef6930SMark Murray #endif
562aef6930SMark Murray 
572aef6930SMark Murray     /*
582aef6930SMark Murray      * Open a channel to the syslog daemon. Older versions of openlog()
592aef6930SMark Murray      * require only two arguments.
602aef6930SMark Murray      */
612aef6930SMark Murray 
622aef6930SMark Murray #ifdef LOG_MAIL
632aef6930SMark Murray     (void) openlog(argv[0], LOG_PID, FACILITY);
642aef6930SMark Murray #else
652aef6930SMark Murray     (void) openlog(argv[0], LOG_PID);
662aef6930SMark Murray #endif
672aef6930SMark Murray 
682aef6930SMark Murray     /*
692aef6930SMark Murray      * Find out the endpoint addresses of this conversation. Host name
702aef6930SMark Murray      * lookups and double checks will be done on demand.
712aef6930SMark Murray      */
722aef6930SMark Murray 
732aef6930SMark Murray     request_init(&request, RQ_DAEMON, argv[0], RQ_FILE, STDIN_FILENO, 0);
742aef6930SMark Murray     fromhost(&request);
752aef6930SMark Murray 
762aef6930SMark Murray     /*
772aef6930SMark Murray      * Optionally look up and double check the remote host name. Sites
782aef6930SMark Murray      * concerned with security may choose to refuse connections from hosts
792aef6930SMark Murray      * that pretend to have someone elses host name.
802aef6930SMark Murray      */
812aef6930SMark Murray 
822aef6930SMark Murray #ifdef PARANOID
832aef6930SMark Murray     if (STR_EQ(eval_hostname(request.client), paranoid))
842aef6930SMark Murray 	refuse(&request);
852aef6930SMark Murray #endif
862aef6930SMark Murray 
872aef6930SMark Murray     /*
882aef6930SMark Murray      * The BSD rlogin and rsh daemons that came out after 4.3 BSD disallow
892aef6930SMark Murray      * socket options at the IP level. They do so for a good reason.
902aef6930SMark Murray      * Unfortunately, we cannot use this with SunOS 4.1.x because the
912aef6930SMark Murray      * getsockopt() system call can panic the system.
922aef6930SMark Murray      */
932aef6930SMark Murray 
942aef6930SMark Murray #ifdef KILL_IP_OPTIONS
952aef6930SMark Murray     fix_options(&request);
962aef6930SMark Murray #endif
972aef6930SMark Murray 
982aef6930SMark Murray     /*
992aef6930SMark Murray      * Check whether this host can access the service in argv[0]. The
1002aef6930SMark Murray      * access-control code invokes optional shell commands as specified in
1012aef6930SMark Murray      * the access-control tables.
1022aef6930SMark Murray      */
1032aef6930SMark Murray 
1042aef6930SMark Murray #ifdef HOSTS_ACCESS
1052aef6930SMark Murray     if (!hosts_access(&request))
1062aef6930SMark Murray 	refuse(&request);
1072aef6930SMark Murray #endif
1082aef6930SMark Murray 
1092aef6930SMark Murray     /* Report request and invoke the real daemon program. */
1102aef6930SMark Murray 
1112aef6930SMark Murray     syslog(allow_severity, "connect from %s", eval_client(&request));
1122aef6930SMark Murray     sprintf(path, "%s/miscd", REAL_DAEMON_DIR);
1132aef6930SMark Murray     closelog();
1142aef6930SMark Murray     (void) execv(path, argv);
1152aef6930SMark Murray     syslog(LOG_ERR, "error: cannot execute %s: %m", path);
1162aef6930SMark Murray     clean_exit(&request);
1172aef6930SMark Murray     /* NOTREACHED */
1182aef6930SMark Murray }
119