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