xref: /freebsd/contrib/tcp_wrappers/miscd.c (revision 2aef693010b252e8cff0ce46a6ebf15b74c82219)
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 
462aef6930SMark Murray main(argc, argv)
472aef6930SMark Murray int     argc;
482aef6930SMark Murray char  **argv;
492aef6930SMark Murray {
502aef6930SMark Murray     struct request_info request;
512aef6930SMark Murray     char    path[MAXPATHNAMELEN];
522aef6930SMark Murray 
532aef6930SMark Murray     /* Attempt to prevent the creation of world-writable files. */
542aef6930SMark Murray 
552aef6930SMark Murray #ifdef DAEMON_UMASK
562aef6930SMark Murray     umask(DAEMON_UMASK);
572aef6930SMark Murray #endif
582aef6930SMark Murray 
592aef6930SMark Murray     /*
602aef6930SMark Murray      * Open a channel to the syslog daemon. Older versions of openlog()
612aef6930SMark Murray      * require only two arguments.
622aef6930SMark Murray      */
632aef6930SMark Murray 
642aef6930SMark Murray #ifdef LOG_MAIL
652aef6930SMark Murray     (void) openlog(argv[0], LOG_PID, FACILITY);
662aef6930SMark Murray #else
672aef6930SMark Murray     (void) openlog(argv[0], LOG_PID);
682aef6930SMark Murray #endif
692aef6930SMark Murray 
702aef6930SMark Murray     /*
712aef6930SMark Murray      * Find out the endpoint addresses of this conversation. Host name
722aef6930SMark Murray      * lookups and double checks will be done on demand.
732aef6930SMark Murray      */
742aef6930SMark Murray 
752aef6930SMark Murray     request_init(&request, RQ_DAEMON, argv[0], RQ_FILE, STDIN_FILENO, 0);
762aef6930SMark Murray     fromhost(&request);
772aef6930SMark Murray 
782aef6930SMark Murray     /*
792aef6930SMark Murray      * Optionally look up and double check the remote host name. Sites
802aef6930SMark Murray      * concerned with security may choose to refuse connections from hosts
812aef6930SMark Murray      * that pretend to have someone elses host name.
822aef6930SMark Murray      */
832aef6930SMark Murray 
842aef6930SMark Murray #ifdef PARANOID
852aef6930SMark Murray     if (STR_EQ(eval_hostname(request.client), paranoid))
862aef6930SMark Murray 	refuse(&request);
872aef6930SMark Murray #endif
882aef6930SMark Murray 
892aef6930SMark Murray     /*
902aef6930SMark Murray      * The BSD rlogin and rsh daemons that came out after 4.3 BSD disallow
912aef6930SMark Murray      * socket options at the IP level. They do so for a good reason.
922aef6930SMark Murray      * Unfortunately, we cannot use this with SunOS 4.1.x because the
932aef6930SMark Murray      * getsockopt() system call can panic the system.
942aef6930SMark Murray      */
952aef6930SMark Murray 
962aef6930SMark Murray #ifdef KILL_IP_OPTIONS
972aef6930SMark Murray     fix_options(&request);
982aef6930SMark Murray #endif
992aef6930SMark Murray 
1002aef6930SMark Murray     /*
1012aef6930SMark Murray      * Check whether this host can access the service in argv[0]. The
1022aef6930SMark Murray      * access-control code invokes optional shell commands as specified in
1032aef6930SMark Murray      * the access-control tables.
1042aef6930SMark Murray      */
1052aef6930SMark Murray 
1062aef6930SMark Murray #ifdef HOSTS_ACCESS
1072aef6930SMark Murray     if (!hosts_access(&request))
1082aef6930SMark Murray 	refuse(&request);
1092aef6930SMark Murray #endif
1102aef6930SMark Murray 
1112aef6930SMark Murray     /* Report request and invoke the real daemon program. */
1122aef6930SMark Murray 
1132aef6930SMark Murray     syslog(allow_severity, "connect from %s", eval_client(&request));
1142aef6930SMark Murray     sprintf(path, "%s/miscd", REAL_DAEMON_DIR);
1152aef6930SMark Murray     closelog();
1162aef6930SMark Murray     (void) execv(path, argv);
1172aef6930SMark Murray     syslog(LOG_ERR, "error: cannot execute %s: %m", path);
1182aef6930SMark Murray     clean_exit(&request);
1192aef6930SMark Murray     /* NOTREACHED */
1202aef6930SMark Murray }
121