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