2 * @(#) tcpd.h 1.5 96/03/19 16:22:24
4 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
9 /* Structure to describe one communications endpoint. */
11 #define STRING_LENGTH 128 /* hosts, users, processes */
14 char name[STRING_LENGTH]; /* access via eval_hostname(host) */
15 char addr[STRING_LENGTH]; /* access via eval_hostaddr(host) */
17 struct sockaddr *sin; /* socket address or 0 */
19 struct sockaddr_in *sin; /* socket address or 0 */
21 struct t_unitdata *unit; /* TLI transport address or 0 */
22 struct request_info *request; /* for shared information */
25 /* Structure to describe what we know about a service request. */
28 int fd; /* socket handle */
29 char user[STRING_LENGTH]; /* access via eval_user(request) */
30 char daemon[STRING_LENGTH]; /* access via eval_daemon(request) */
31 char pid[10]; /* access via eval_pid(request) */
32 struct host_info client[1]; /* client endpoint info */
33 struct host_info server[1]; /* server endpoint info */
34 void (*sink) (); /* datagram sink function or 0 */
35 void (*hostname) (); /* address to printable hostname */
36 void (*hostaddr) (); /* address to printable address */
37 void (*cleanup) (); /* cleanup function or 0 */
38 struct netconfig *config; /* netdir handle */
41 /* Common string operations. Less clutter should be more readable. */
43 #define STRN_CPY(d,s,l) { strncpy((d),(s),(l)); (d)[(l)-1] = 0; }
45 #define STRN_EQ(x,y,l) (strncasecmp((x),(y),(l)) == 0)
46 #define STRN_NE(x,y,l) (strncasecmp((x),(y),(l)) != 0)
47 #define STR_EQ(x,y) (strcasecmp((x),(y)) == 0)
48 #define STR_NE(x,y) (strcasecmp((x),(y)) != 0)
51 * Initially, all above strings have the empty value. Information that
52 * cannot be determined at runtime is set to "unknown", so that we can
53 * distinguish between `unavailable' and `not yet looked up'. A hostname
54 * that we do not believe in is set to "paranoid".
57 #define STRING_UNKNOWN "unknown" /* lookup failed */
58 #define STRING_PARANOID "paranoid" /* hostname conflict */
60 extern char unknown[];
61 extern char paranoid[];
63 #define HOSTNAME_KNOWN(s) (STR_NE((s),unknown) && STR_NE((s),paranoid))
65 #define NOT_INADDR(s) (s[strspn(s,"01234567890./")] != 0)
67 /* Global functions. */
69 #if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT)
70 extern void fromhost(); /* get/validate client host info */
72 #define fromhost sock_host /* no TLI support needed */
75 extern int hosts_access(); /* access control */
76 extern void shell_cmd(); /* execute shell command */
77 extern char *percent_x(); /* do %<char> expansion */
78 extern void rfc931(); /* client name from RFC 931 daemon */
79 extern void clean_exit(); /* clean up and exit */
80 extern void refuse(); /* clean up and exit */
81 extern char *xgets(); /* fgets() on steroids */
82 extern char *split_at(); /* strchr() and split */
83 extern unsigned long dot_quad_addr(); /* restricted inet_addr() */
85 /* Global variables. */
87 extern int allow_severity; /* for connection logging */
88 extern int deny_severity; /* for connection logging */
89 extern char *hosts_allow_table; /* for verification mode redirection */
90 extern char *hosts_deny_table; /* for verification mode redirection */
91 extern int hosts_access_verbose; /* for verbose matching mode */
92 extern int rfc931_timeout; /* user lookup timeout */
93 extern int resident; /* > 0 if resident process */
96 * Routines for controlled initialization and update of request structure
97 * attributes. Each attribute has its own key.
101 extern struct request_info *request_init(struct request_info *,...);
102 extern struct request_info *request_set(struct request_info *,...);
104 extern struct request_info *request_init(); /* initialize request */
105 extern struct request_info *request_set(); /* update request structure */
108 #define RQ_FILE 1 /* file descriptor */
109 #define RQ_DAEMON 2 /* server process (argv[0]) */
110 #define RQ_USER 3 /* client user name */
111 #define RQ_CLIENT_NAME 4 /* client host name */
112 #define RQ_CLIENT_ADDR 5 /* client host address */
113 #define RQ_CLIENT_SIN 6 /* client endpoint (internal) */
114 #define RQ_SERVER_NAME 7 /* server host name */
115 #define RQ_SERVER_ADDR 8 /* server host address */
116 #define RQ_SERVER_SIN 9 /* server endpoint (internal) */
119 * Routines for delayed evaluation of request attributes. Each attribute
120 * type has its own access method. The trivial ones are implemented by
121 * macros. The other ones are wrappers around the transport-specific host
122 * name, address, and client user lookup methods. The request_info and
123 * host_info structures serve as caches for the lookup results.
126 extern char *eval_user(); /* client user */
127 extern char *eval_hostname(); /* printable hostname */
128 extern char *eval_hostaddr(); /* printable host address */
129 extern char *eval_hostinfo(); /* host name or address */
130 extern char *eval_client(); /* whatever is available */
131 extern char *eval_server(); /* whatever is available */
132 #define eval_daemon(r) ((r)->daemon) /* daemon process name */
133 #define eval_pid(r) ((r)->pid) /* process id */
135 /* Socket-specific methods, including DNS hostname lookups. */
137 extern void sock_host(); /* look up endpoint addresses */
138 extern void sock_hostname(); /* translate address to hostname */
139 extern void sock_hostaddr(); /* address to printable address */
140 #define sock_methods(r) \
141 { (r)->hostname = sock_hostname; (r)->hostaddr = sock_hostaddr; }
143 /* The System V Transport-Level Interface (TLI) interface. */
145 #if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT)
146 extern void tli_host(); /* look up endpoint addresses etc. */
150 * Problem reporting interface. Additional file/line context is reported
151 * when available. The jump buffer (tcpd_buf) is not declared here, or
152 * everyone would have to include <setjmp.h>.
156 extern void tcpd_warn(char *, ...); /* report problem and proceed */
157 extern void tcpd_jump(char *, ...); /* report problem and jump */
159 extern void tcpd_warn();
160 extern void tcpd_jump();
163 struct tcpd_context {
164 char *file; /* current file */
165 int line; /* current line */
167 extern struct tcpd_context tcpd_context;
170 * While processing access control rules, error conditions are handled by
171 * jumping back into the hosts_access() routine. This is cleaner than
172 * checking the return value of each and every silly little function. The
173 * (-1) returns are here because zero is already taken by longjmp().
176 #define AC_PERMIT 1 /* permit access */
177 #define AC_DENY (-1) /* deny_access */
178 #define AC_ERROR AC_DENY /* XXX */
181 * In verification mode an option function should just say what it would do,
182 * instead of really doing it. An option function that would not return
183 * should clear the dry_run flag to inform the caller of this unusual
187 extern void process_options(); /* execute options */
188 extern int dry_run; /* verification flag */
190 /* Bug workarounds. */
192 #ifdef INET_ADDR_BUG /* inet_addr() returns struct */
193 #define inet_addr fix_inet_addr
194 extern long fix_inet_addr();
197 #ifdef BROKEN_FGETS /* partial reads from sockets */
198 #define fgets fix_fgets
199 extern char *fix_fgets();
202 #ifdef RECVFROM_BUG /* no address family info */
203 #define recvfrom fix_recvfrom
204 extern int fix_recvfrom();
207 #ifdef GETPEERNAME_BUG /* claims success with UDP */
208 #define getpeername fix_getpeername
209 extern int fix_getpeername();
212 #ifdef SOLARIS_24_GETHOSTBYNAME_BUG /* lists addresses as aliases */
213 #define gethostbyname fix_gethostbyname
214 extern struct hostent *fix_gethostbyname();
217 #ifdef USE_STRSEP /* libc calls strtok() */
218 #define strtok fix_strtok
219 extern char *fix_strtok();
222 #ifdef LIBC_CALLS_STRTOK /* libc calls strtok() */
223 #define strtok my_strtok
224 extern char *my_strtok();