xref: /freebsd/contrib/tcp_wrappers/tcpd.h (revision 39beb93c)
1  /*
2   * @(#) tcpd.h 1.5 96/03/19 16:22:24
3   *
4   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
5   *
6   * $FreeBSD$
7   */
8 
9 /* Structure to describe one communications endpoint. */
10 
11 #define STRING_LENGTH	128		/* hosts, users, processes */
12 
13 struct host_info {
14     char    name[STRING_LENGTH];	/* access via eval_hostname(host) */
15     char    addr[STRING_LENGTH];	/* access via eval_hostaddr(host) */
16 #ifdef INET6
17     struct sockaddr *sin;		/* socket address or 0 */
18 #else
19     struct sockaddr_in *sin;		/* socket address or 0 */
20 #endif
21     struct t_unitdata *unit;		/* TLI transport address or 0 */
22     struct request_info *request;	/* for shared information */
23 };
24 
25 /* Structure to describe what we know about a service request. */
26 
27 struct request_info {
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 */
39 };
40 
41 /* Common string operations. Less clutter should be more readable. */
42 
43 #define STRN_CPY(d,s,l)	{ strncpy((d),(s),(l)); (d)[(l)-1] = 0; }
44 
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)
49 
50  /*
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".
55   */
56 
57 #define STRING_UNKNOWN	"unknown"	/* lookup failed */
58 #define STRING_PARANOID	"paranoid"	/* hostname conflict */
59 
60 extern char unknown[];
61 extern char paranoid[];
62 
63 #define HOSTNAME_KNOWN(s) (STR_NE((s),unknown) && STR_NE((s),paranoid))
64 
65 #define NOT_INADDR(s) (s[strspn(s,"01234567890./")] != 0)
66 
67 /* Global functions. */
68 
69 #if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT)
70 extern void fromhost();			/* get/validate client host info */
71 #else
72 #define fromhost sock_host		/* no TLI support needed */
73 #endif
74 
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() */
84 
85 /* Global variables. */
86 
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 */
94 
95  /*
96   * Routines for controlled initialization and update of request structure
97   * attributes. Each attribute has its own key.
98   */
99 
100 #ifdef __STDC__
101 extern struct request_info *request_init(struct request_info *,...);
102 extern struct request_info *request_set(struct request_info *,...);
103 #else
104 extern struct request_info *request_init();	/* initialize request */
105 extern struct request_info *request_set();	/* update request structure */
106 #endif
107 
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) */
117 
118  /*
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.
124   */
125 
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 */
134 
135 /* Socket-specific methods, including DNS hostname lookups. */
136 
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; }
142 
143 /* The System V Transport-Level Interface (TLI) interface. */
144 
145 #if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT)
146 extern void tli_host();			/* look up endpoint addresses etc. */
147 #endif
148 
149  /*
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>.
153   */
154 
155 #ifdef __STDC__
156 extern void tcpd_warn(char *, ...);	/* report problem and proceed */
157 extern void tcpd_jump(char *, ...);	/* report problem and jump */
158 #else
159 extern void tcpd_warn();
160 extern void tcpd_jump();
161 #endif
162 
163 struct tcpd_context {
164     char   *file;			/* current file */
165     int     line;			/* current line */
166 };
167 extern struct tcpd_context tcpd_context;
168 
169  /*
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().
174   */
175 
176 #define AC_PERMIT	1		/* permit access */
177 #define AC_DENY		(-1)		/* deny_access */
178 #define AC_ERROR	AC_DENY		/* XXX */
179 
180  /*
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
184   * behavior.
185   */
186 
187 extern void process_options();		/* execute options */
188 extern int dry_run;			/* verification flag */
189 
190 /* Bug workarounds. */
191 
192 #ifdef INET_ADDR_BUG			/* inet_addr() returns struct */
193 #define inet_addr fix_inet_addr
194 extern long fix_inet_addr();
195 #endif
196 
197 #ifdef BROKEN_FGETS			/* partial reads from sockets */
198 #define fgets fix_fgets
199 extern char *fix_fgets();
200 #endif
201 
202 #ifdef RECVFROM_BUG			/* no address family info */
203 #define recvfrom fix_recvfrom
204 extern int fix_recvfrom();
205 #endif
206 
207 #ifdef GETPEERNAME_BUG			/* claims success with UDP */
208 #define getpeername fix_getpeername
209 extern int fix_getpeername();
210 #endif
211 
212 #ifdef SOLARIS_24_GETHOSTBYNAME_BUG	/* lists addresses as aliases */
213 #define gethostbyname fix_gethostbyname
214 extern struct hostent *fix_gethostbyname();
215 #endif
216 
217 #ifdef USE_STRSEP			/* libc calls strtok() */
218 #define strtok	fix_strtok
219 extern char *fix_strtok();
220 #endif
221 
222 #ifdef LIBC_CALLS_STRTOK		/* libc calls strtok() */
223 #define strtok	my_strtok
224 extern char *my_strtok();
225 #endif
226