1 /* 2 * General front end for stream and datagram IP services. This program logs 3 * the remote host name and then invokes the real daemon. For example, 4 * install as /usr/etc/{tftpd,fingerd,telnetd,ftpd,rlogind,rshd,rexecd}, 5 * after saving the real daemons in the directory specified with the 6 * REAL_DAEMON_DIR macro. This arrangement requires that the network daemons 7 * are started by inetd or something similar. Connections and diagnostics 8 * are logged through syslog(3). 9 * 10 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
| 1 /* 2 * General front end for stream and datagram IP services. This program logs 3 * the remote host name and then invokes the real daemon. For example, 4 * install as /usr/etc/{tftpd,fingerd,telnetd,ftpd,rlogind,rshd,rexecd}, 5 * after saving the real daemons in the directory specified with the 6 * REAL_DAEMON_DIR macro. This arrangement requires that the network daemons 7 * are started by inetd or something similar. Connections and diagnostics 8 * are logged through syslog(3). 9 * 10 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
|
| 11 * 12 * $FreeBSD: head/contrib/tcp_wrappers/tcpd.c 56977 2000-02-03 10:27:03Z shin $
|
11 */ 12 13#ifndef lint 14static char sccsid[] = "@(#) tcpd.c 1.10 96/02/11 17:01:32"; 15#endif 16 17/* System libraries. */ 18 19#include <sys/types.h> 20#include <sys/param.h> 21#include <sys/stat.h> 22#include <sys/socket.h> 23#include <netinet/in.h> 24#include <stdio.h> 25#include <syslog.h> 26#include <string.h> 27 28#ifndef MAXPATHNAMELEN 29#define MAXPATHNAMELEN BUFSIZ 30#endif 31 32#ifndef STDIN_FILENO 33#define STDIN_FILENO 0 34#endif 35 36/* Local stuff. */ 37 38#include "patchlevel.h" 39#include "tcpd.h" 40 41int allow_severity = SEVERITY; /* run-time adjustable */ 42int deny_severity = LOG_WARNING; /* ditto */ 43 44main(argc, argv) 45int argc; 46char **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 * If argv[0] is an absolute path name, ignore REAL_DAEMON_DIR, and strip 59 * argv[0] to its basename. 60 */ 61 62 if (argv[0][0] == '/') { 63 strcpy(path, argv[0]); 64 argv[0] = strrchr(argv[0], '/') + 1; 65 } else { 66 sprintf(path, "%s/%s", REAL_DAEMON_DIR, argv[0]); 67 } 68 69 /* 70 * Open a channel to the syslog daemon. Older versions of openlog() 71 * require only two arguments. 72 */ 73 74#ifdef LOG_MAIL 75 (void) openlog(argv[0], LOG_PID, FACILITY); 76#else 77 (void) openlog(argv[0], LOG_PID); 78#endif 79 80 /* 81 * Find out the endpoint addresses of this conversation. Host name 82 * lookups and double checks will be done on demand. 83 */ 84 85 request_init(&request, RQ_DAEMON, argv[0], RQ_FILE, STDIN_FILENO, 0); 86 fromhost(&request); 87 88 /* 89 * Optionally look up and double check the remote host name. Sites 90 * concerned with security may choose to refuse connections from hosts 91 * that pretend to have someone elses host name. 92 */ 93 94#ifdef PARANOID 95 if (STR_EQ(eval_hostname(request.client), paranoid)) 96 refuse(&request); 97#endif 98 99 /* 100 * The BSD rlogin and rsh daemons that came out after 4.3 BSD disallow 101 * socket options at the IP level. They do so for a good reason. 102 * Unfortunately, we cannot use this with SunOS 4.1.x because the 103 * getsockopt() system call can panic the system. 104 */ 105 106#ifdef KILL_IP_OPTIONS 107 fix_options(&request); 108#endif 109 110 /* 111 * Check whether this host can access the service in argv[0]. The 112 * access-control code invokes optional shell commands as specified in 113 * the access-control tables. 114 */ 115 116#ifdef HOSTS_ACCESS 117 if (!hosts_access(&request)) 118 refuse(&request); 119#endif 120 121 /* Report request and invoke the real daemon program. */ 122
| 13 */ 14 15#ifndef lint 16static char sccsid[] = "@(#) tcpd.c 1.10 96/02/11 17:01:32"; 17#endif 18 19/* System libraries. */ 20 21#include <sys/types.h> 22#include <sys/param.h> 23#include <sys/stat.h> 24#include <sys/socket.h> 25#include <netinet/in.h> 26#include <stdio.h> 27#include <syslog.h> 28#include <string.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 43int allow_severity = SEVERITY; /* run-time adjustable */ 44int deny_severity = LOG_WARNING; /* ditto */ 45 46main(argc, argv) 47int argc; 48char **argv; 49{ 50 struct request_info request; 51 char path[MAXPATHNAMELEN]; 52 53 /* Attempt to prevent the creation of world-writable files. */ 54 55#ifdef DAEMON_UMASK 56 umask(DAEMON_UMASK); 57#endif 58 59 /* 60 * If argv[0] is an absolute path name, ignore REAL_DAEMON_DIR, and strip 61 * argv[0] to its basename. 62 */ 63 64 if (argv[0][0] == '/') { 65 strcpy(path, argv[0]); 66 argv[0] = strrchr(argv[0], '/') + 1; 67 } else { 68 sprintf(path, "%s/%s", REAL_DAEMON_DIR, argv[0]); 69 } 70 71 /* 72 * Open a channel to the syslog daemon. Older versions of openlog() 73 * require only two arguments. 74 */ 75 76#ifdef LOG_MAIL 77 (void) openlog(argv[0], LOG_PID, FACILITY); 78#else 79 (void) openlog(argv[0], LOG_PID); 80#endif 81 82 /* 83 * Find out the endpoint addresses of this conversation. Host name 84 * lookups and double checks will be done on demand. 85 */ 86 87 request_init(&request, RQ_DAEMON, argv[0], RQ_FILE, STDIN_FILENO, 0); 88 fromhost(&request); 89 90 /* 91 * Optionally look up and double check the remote host name. Sites 92 * concerned with security may choose to refuse connections from hosts 93 * that pretend to have someone elses host name. 94 */ 95 96#ifdef PARANOID 97 if (STR_EQ(eval_hostname(request.client), paranoid)) 98 refuse(&request); 99#endif 100 101 /* 102 * The BSD rlogin and rsh daemons that came out after 4.3 BSD disallow 103 * socket options at the IP level. They do so for a good reason. 104 * Unfortunately, we cannot use this with SunOS 4.1.x because the 105 * getsockopt() system call can panic the system. 106 */ 107 108#ifdef KILL_IP_OPTIONS 109 fix_options(&request); 110#endif 111 112 /* 113 * Check whether this host can access the service in argv[0]. The 114 * access-control code invokes optional shell commands as specified in 115 * the access-control tables. 116 */ 117 118#ifdef HOSTS_ACCESS 119 if (!hosts_access(&request)) 120 refuse(&request); 121#endif 122 123 /* Report request and invoke the real daemon program. */ 124
|
| 125#ifdef INET6 126 syslog(allow_severity, "connect from %s (%s)", 127 eval_client(&request), eval_hostaddr(request.client)); 128#else
|
123 syslog(allow_severity, "connect from %s", eval_client(&request));
| 129 syslog(allow_severity, "connect from %s", eval_client(&request));
|
| 130#endif
|
124 closelog(); 125 (void) execv(path, argv); 126 syslog(LOG_ERR, "error: cannot execute %s: %m", path); 127 clean_exit(&request); 128 /* NOTREACHED */ 129}
| 131 closelog(); 132 (void) execv(path, argv); 133 syslog(LOG_ERR, "error: cannot execute %s: %m", path); 134 clean_exit(&request); 135 /* NOTREACHED */ 136}
|