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).
10 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
14 static char sccsid
[] = "@(#) tcpd.c 1.10 96/02/11 17:01:32";
17 /* System libraries. */
19 #include <sys/types.h>
20 #include <sys/param.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
28 #ifndef MAXPATHNAMELEN
29 #define MAXPATHNAMELEN BUFSIZ
33 #define STDIN_FILENO 0
38 #include "patchlevel.h"
41 int allow_severity
= SEVERITY
; /* run-time adjustable */
42 int deny_severity
= LOG_WARNING
; /* ditto */
49 struct request_info request
;
50 char path
[MAXPATHNAMELEN
];
52 /* Attempt to prevent the creation of world-writable files. */
59 * If argv[0] is an absolute path name, ignore REAL_DAEMON_DIR, and strip
60 * argv[0] to its basename.
63 if (argv
[0][0] == '/') {
64 strcpy(path
, argv
[0]);
65 argv
[0] = strrchr(argv
[0], '/') + 1;
67 sprintf(path
, "%s/%s", REAL_DAEMON_DIR
, argv
[0]);
71 * Open a channel to the syslog daemon. Older versions of openlog()
72 * require only two arguments.
76 (void) openlog(argv
[0], LOG_PID
, FACILITY
);
78 (void) openlog(argv
[0], LOG_PID
);
82 * Find out the endpoint addresses of this conversation. Host name
83 * lookups and double checks will be done on demand.
86 request_init(&request
, RQ_DAEMON
, argv
[0], RQ_FILE
, STDIN_FILENO
, 0);
90 * Optionally look up and double check the remote host name. Sites
91 * concerned with security may choose to refuse connections from hosts
92 * that pretend to have someone elses host name.
96 if (STR_EQ(eval_hostname(request
.client
), paranoid
))
101 * The BSD rlogin and rsh daemons that came out after 4.3 BSD disallow
102 * socket options at the IP level. They do so for a good reason.
103 * Unfortunately, we cannot use this with SunOS 4.1.x because the
104 * getsockopt() system call can panic the system.
107 #ifdef KILL_IP_OPTIONS
108 fix_options(&request
);
112 * Check whether this host can access the service in argv[0]. The
113 * access-control code invokes optional shell commands as specified in
114 * the access-control tables.
118 if (!hosts_access(&request
))
122 /* Report request and invoke the real daemon program. */
124 syslog(allow_severity
, "connect from %s", eval_client(&request
));
126 (void) execv(path
, argv
);
127 syslog(LOG_ERR
, "error: cannot execute %s: %m", path
);
128 clean_exit(&request
);