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