tftpd: handle rule filter flags more cleanly
[tftp-hpa.git] / config.h
bloba6a402b47045d2bcb15a82a2864aa0ccfc9e8dfb
1 /* -*- c -*- ------------------------------------------------------------- *
3 * Copyright 2001-2024 H. Peter Anvin - All Rights Reserved
5 * This program is free software available under the same license
6 * as the "OpenBSD" operating system, distributed at
7 * http://www.openbsd.org/.
9 * ----------------------------------------------------------------------- */
12 * config.h
14 * Sets up a common baseline environment, based on "autoconf" findings...
17 #ifndef CONFIG_H
18 #define CONFIG_H 1
20 /* Feature enables for specific environments */
21 #ifdef __APPLE__
22 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1070
23 #define __APPLE_USE_RFC_3542 1
24 #endif
25 #endif
27 /* Must be included before we include any system headers! */
28 #include "aconfig.h" /* autogenerated configuration header */
30 /* Standard includes */
32 #include <stdio.h>
33 #include <time.h>
34 #include <stdlib.h>
35 #include <errno.h>
36 #include <signal.h>
38 #ifdef HAVE_SYS_TYPES_H
39 #include <sys/types.h>
40 #endif
42 #ifdef HAVE_SYS_STAT_H
43 #include <sys/stat.h>
44 #endif
46 #ifdef HAVE_STRING_H
47 #include <string.h>
48 #endif
50 #ifdef HAVE_STRINGS_H
51 #include <strings.h>
52 #endif
54 #ifdef HAVE_INTTYPES_H
55 #ifdef INTTYPES_H_IS_SANE
56 #include <inttypes.h>
57 #endif
58 #else
59 #ifdef HAVE_STDINT_H
60 #include <stdint.h>
61 #endif
62 #endif
64 #ifdef HAVE_UNISTD_H
65 #include <unistd.h>
66 #endif
68 #ifdef HAVE_SETJMP_H
69 #include <setjmp.h>
70 #endif
72 #ifdef HAVE_SYS_TIME_H
73 #include <sys/time.h>
74 #endif
76 #ifdef HAVE_GRP_H
77 #include <grp.h>
78 #endif
80 #ifdef HAVE_FCNTL_H
81 #include <fcntl.h>
82 #endif
84 #ifdef HAVE_SYS_SOCKET_H
85 #include <sys/socket.h>
86 #else
87 #ifdef HAVE_WINSOCK2_H
88 #include <winsock2.h>
89 #else
90 #ifdef HAVE_WINSOCK_H
91 #include <winsock.h>
92 #endif
93 #endif
94 #endif
95 #ifdef HAVE_NETDB_H
96 #include <netdb.h>
97 #endif
99 #ifdef HAVE_GETOPT_LONG
100 #include <getopt.h>
101 #else
102 #include "lib/getopt.h"
103 #endif
105 /* Test for EAGAIN/EWOULDBLOCK */
106 #ifdef EAGAIN
107 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
108 #define E_WOULD_BLOCK(x) ((x) == EAGAIN || (x) == EWOULDBLOCK)
109 #else
110 #define E_WOULD_BLOCK(x) ((x) == EAGAIN)
111 #endif
112 #else
113 #define E_WOULD_BLOCK(x) ((x) == EWOULDBLOCK)
114 #endif
116 /* Some broken systems care about text versus binary, but
117 real Unix systems don't... */
118 #ifndef HAVE_O_TEXT_DEFINITION
119 #define O_TEXT 0
120 #endif
121 #ifndef HAVE_O_BINARY_DEFINITION
122 #define O_BINARY 0
123 #endif
125 /* If we don't have intmax_t, try creating it */
127 #ifndef HAVE_INTMAX_T
128 #ifdef HAVE_LONG_LONG
129 typedef long long intmax_t;
130 typedef unsigned long long uintmax_t;
131 #define PRIdMAX "lld"
132 #define PRIuMAX "llu"
133 #define PRIxMAX "llx"
134 #define INTMAX_C(x) (x##LL)
135 #define UINTMAX_C(x) (x##ULL)
136 #else
137 typedef long intmax_t;
138 typedef unsigned long uintmax_t;
139 #define PRIdMAX "ld"
140 #define PRIuMAX "lu"
141 #define PRIxMAX "lx"
142 #define INTMAX_C(x) (x##L)
143 #define UINTMAX_C(x) (x##UL)
144 #endif
145 #endif
147 /* On some version of AIX, <inttypes.h> is buggy to the point of
148 unusability. We have to use macros here, not typedefs, to override. */
149 #ifdef HAVE_INTTYPES_H
150 #ifndef INTTYPES_H_IS_SANE
151 #undef PRIdMAX
152 #undef PRIuMAX
153 #undef PRIxMAX
154 #undef INTMAX_C
155 #undef UINTMAX_C
156 #undef HAVE_STRTOUMAX
158 #ifdef HAVE_LONG_LONG
159 #define intmax_t long long
160 #define uintmax_t unsigned long long
161 #define PRIdMAX "Ld"
162 #define PRIuMAX "Lu"
163 #define PRIxMAX "Lx"
164 #define INTMAX_C(x) (x##LL)
165 #define UINTMAX_C(x) (x##ULL)
166 #else
167 #define intmax_t long
168 #define uintmax_t unsigned long
169 #define PRIdMAX "ld"
170 #define PRIuMAX "lu"
171 #define PRIxMAX "lx"
172 #define INTMAX_C(x) (x##L)
173 #define UINTMAX_C(x) (x##UL)
174 #endif
175 #endif
176 #endif
178 /* Even if intmax_t is defined, we may need this (Solaris 8 braindamage) */
179 #ifndef HAVE_STRTOUMAX
180 #if defined(HAVE_LONG_LONG) && defined(HAVE_STRTOULL)
181 #define strtoumax(p,e,b) ((uintmax_t)strtoull(p,e,b))
182 #else
183 #define strtoumax(p,e,b) ((uintmax_t)strtoul(p,e,b))
184 #endif
185 #endif
187 /* A lot of this is old BSD code. Some newer systems don't approve. */
189 /* The type used by htons(), ntohs() */
190 #ifndef HAVE_U_SHORT
191 #ifdef HAVE_UINT16_T
192 typedef uint16_t u_short;
193 #else
194 typedef unsigned short u_short;
195 #endif
196 #endif
198 /* The type used to htonl(), ntohl() */
199 #ifndef HAVE_U_LONG
200 #ifdef HAVE_UINT32_T
201 typedef uint32_t u_long;
202 #else
203 typedef unsigned long u_long;
204 #endif
205 #endif
207 /* socklen_t */
208 #ifndef HAVE_SOCKLEN_T
209 typedef int socklen_t;
210 #endif
212 /* sysexits.h */
214 #ifdef HAVE_SYSEXITS_H
215 #include <sysexits.h>
216 #else
217 #define EX_USAGE 64 /* command line usage error */
218 #define EX_DATAERR 65 /* data format error */
219 #define EX_NOINPUT 66 /* cannot open input */
220 #define EX_NOUSER 67 /* addressee unknown */
221 #define EX_NOHOST 68 /* host name unknown */
222 #define EX_UNAVAILABLE 69 /* service unavailable */
223 #define EX_SOFTWARE 70 /* internal software error */
224 #define EX_OSERR 71 /* system error (e.g., can't fork) */
225 #define EX_OSFILE 72 /* critical OS file missing */
226 #define EX_CANTCREAT 73 /* can't create (user) output file */
227 #define EX_IOERR 74 /* input/output error */
228 #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
229 #define EX_PROTOCOL 76 /* remote error in protocol */
230 #define EX_NOPERM 77 /* permission denied */
231 #define EX_CONFIG 78 /* configuration error */
232 #endif
234 /* If we don't have sigsetjmp() et all, setjmp() will have to do */
236 #ifndef HAVE_SIGSETJMP
237 #define sigsetjmp(x,y) setjmp(x)
238 #define siglongjmp(x,y) longjmp(x,y)
239 #define sigjmp_buf jmp_buf
240 #endif
242 /* How do we annotate unused data items? */
244 #ifndef UNUSED
245 #ifdef __GNUC__
246 #define UNUSED __attribute__((unused))
247 #else
248 #define UNUSED
249 #endif
250 #endif
252 /* netinet/in.h, and possible missing pieces */
254 #include <netinet/in.h>
256 #ifndef HAVE_IPPORT_TFTP_DEFINITION
257 #ifndef IPPORT_TFTP
258 #define IPPORT_TFTP 69
259 #endif
260 #endif
262 /* arpa/{inet,tftp}.h, and possible missing pieces */
264 #ifdef HAVE_ARPA_INET_H
265 #include <arpa/inet.h>
266 #endif
267 /* If we don't have arpa/tftp.h we have problems... */
268 #include <arpa/tftp.h>
270 #ifndef OACK
271 #define OACK 6
272 #endif
273 #ifndef EOPTNEG
274 #define EOPTNEG 8
275 #endif
277 /* Prototypes for libxtra functions */
279 void *xmalloc(size_t);
280 char *xstrdup(const char *);
282 #ifndef HAVE_SIGHANDLER_T
283 typedef void (*sighandler_t)(int);
284 #endif
285 #ifndef SIG_ERR
286 #define SIG_ERR NULL
287 #endif
288 sighandler_t tftp_signal(int, sighandler_t);
290 #ifndef HAVE_DUP2
291 int dup2(int, int);
292 #endif
293 #ifndef HAVE_DAEMON
294 int daemon(int, int);
295 #endif
297 #ifndef HAVE_GETADDRINFO
298 #ifndef HAVE_STRUCT_ADDRINFO
299 struct addrinfo {
300 int ai_flags;
301 int ai_family;
302 int ai_socktype;
303 int ai_protocol;
304 size_t ai_addrlen;
305 struct sockaddr *ai_addr;
306 char *ai_canonname;
307 struct addrinfo *ai_next;
309 #endif
310 int getaddrinfo(const char *, const char *, const struct addrinfo *,
311 struct addrinfo **);
312 void freeaddrinfo(struct addrinfo *);
313 const char *gai_strerror(int);
316 #ifndef EAI_NONAME
317 #define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
318 #endif
319 #ifndef EAI_ADDRFAMILY
320 #define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
321 #endif
322 #ifndef EAI_MEMORY
323 #define EAI_MEMORY -10 /* Memory allocation failure. */
324 #endif
325 #ifndef EAI_SYSTEM
326 #define EAI_SYSTEM -11 /* System error returned in `errno'. */
327 #endif
328 #endif
330 #ifndef AI_CANONNAME
331 #define AI_CANONNAME 0
332 #endif
334 #ifndef AI_ADDRCONFIG
335 #define AI_ADDRCONFIG 0
336 #endif
338 #ifndef INET6_ADDRSTRLEN
339 #define INET6_ADDRSTRLEN 46
340 #endif
342 #ifndef HAVE_INET_NTOP
343 const char *inet_ntop(int, const void *, char *, socklen_t);
344 #endif
346 /* tftp-hpa version and configuration strings */
348 #include "version.h"
350 #ifdef WITH_READLINE
351 #define WITH_READLINE_STR ", with readline"
352 #else
353 #define WITH_READLINE_STR ", without readline"
354 #endif
356 #ifdef WITH_REGEX
357 #define WITH_REGEX_STR ", with remap"
358 #else
359 #define WITH_REGEX_STR ", without remap"
360 #endif
362 #ifdef HAVE_LIBWRAP
363 #define HAVE_LIBWRAP_STR ", with tcpwrappers"
364 #else
365 #define HAVE_LIBWRAP_STR ", without tcpwrappers"
366 #endif
368 #define TFTP_CONFIG_STR VERSION WITH_READLINE_STR
369 #define TFTPD_CONFIG_STR VERSION WITH_REGEX_STR HAVE_LIBWRAP_STR
371 #endif