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