r3462: separate out the crypto includes
[samba.git] / source4 / include / includes.h
1 #ifndef _INCLUDES_H
2 #define _INCLUDES_H
3 /* 
4    Unix SMB/CIFS implementation.
5    Machine customisation and include handling
6    Copyright (C) Andrew Tridgell 1994-1998
7    Copyright (C) 2002 by Martin Pool <mbp@samba.org>
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #ifndef NO_CONFIG_H /* for some tests */
25 #include "config.h"
26 #include "smb_build.h"
27 #endif
28
29 #include "local.h"
30
31 #ifdef AIX
32 #define DEFAULT_PRINTING PRINT_AIX
33 #define PRINTCAP_NAME "/etc/qconfig"
34 #endif
35
36 #ifdef HPUX
37 #define DEFAULT_PRINTING PRINT_HPUX
38 #endif
39
40 #ifdef QNX
41 #define DEFAULT_PRINTING PRINT_QNX
42 #endif
43
44 #ifdef SUNOS4
45 /* on SUNOS4 termios.h conflicts with sys/ioctl.h */
46 #undef HAVE_TERMIOS_H
47 #endif
48
49 #ifndef DEFAULT_PRINTING
50 #define DEFAULT_PRINTING PRINT_BSD
51 #endif
52 #ifndef PRINTCAP_NAME
53 #define PRINTCAP_NAME "/etc/printcap"
54 #endif
55
56 #if (__GNUC__ >= 3)
57 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
58  * the parameter containing the format, and a2 the index of the first
59  * argument. Note that some gcc 2.x versions don't handle this
60  * properly **/
61 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
62 #else
63 #define PRINTF_ATTRIBUTE(a1, a2)
64 #endif
65
66 #ifdef __GNUC__
67 /** gcc attribute used on function parameters so that it does not emit
68  * warnings about them being unused. **/
69 #  define UNUSED(param) param __attribute__ ((unused))
70 #else
71 #  define UNUSED(param) param
72 /** Feel free to add definitions for other compilers here. */
73 #endif
74
75 #include <sys/types.h>
76 #include <stdio.h>
77 #include <stdlib.h>
78 #include <stddef.h>
79
80 #ifdef HAVE_STDINT_H
81 #include <stdint.h>
82 #endif
83
84 #ifdef HAVE_STRING_H
85 #include <string.h>
86 #endif
87
88 #include <signal.h>
89 #include <errno.h>
90
91 #ifdef HAVE_STDARG_H
92 #include <stdarg.h>
93 #else
94 #include <varargs.h>
95 #endif
96
97 /* we support ADS if we want it and have krb5 and ldap libs */
98 #if defined(WITH_ADS) && defined(HAVE_KRB5) && defined(HAVE_LDAP)
99 #define HAVE_ADS
100 #endif
101
102 /*
103  * Define VOLATILE if needed.
104  */
105
106 #if defined(HAVE_VOLATILE)
107 #define VOLATILE volatile
108 #else
109 #define VOLATILE
110 #endif
111
112 /*
113  * Define additional missing types
114  */
115 #ifndef HAVE_SIG_ATOMIC_T_TYPE
116 typedef int sig_atomic_t;
117 #endif
118
119 #ifndef HAVE_SOCKLEN_T_TYPE
120 typedef int socklen_t;
121 #endif
122
123
124 /*
125    Samba needs type definitions for 
126    int8_t,  int16_t,  int32_t, int64_t 
127    uint8_t, uint16_t, uint32_t and uint64_t.
128
129    Normally these are signed and unsigned 8, 16, 32 and 64 bit integers, but
130    they actually only need to be at least 8, 16, 32 and 64 bits
131    respectively. Thus if your word size is 8 bytes just defining them
132    as signed and unsigned int will work.
133 */
134
135 #if !defined(int8)
136 #define int8 int8_t
137 #endif
138
139 #if !defined(uint8)
140 #define uint8 uint8_t
141 #endif
142
143 #if !defined(int16)
144 #define int16 int16_t
145 #endif
146
147 #if !defined(uint16)
148 #define uint16 uint16_t
149 #endif
150
151 #if !defined(int32)
152 #define int32 int32_t
153 #endif
154
155 #if !defined(uint32)
156 #define uint32 uint32_t
157 #endif
158
159 #if !defined(int64)
160 #define int64 int64_t
161 #endif
162
163 #if !defined(uint64)
164 #define uint64 uint64_t
165 #endif
166
167 /*
168   we use struct ipv4_addr to avoid having to include all the
169   system networking headers everywhere
170 */
171 struct ipv4_addr {
172         uint32_t addr;
173 };
174
175 #ifndef MIN
176 #define MIN(a,b) ((a)<(b)?(a):(b))
177 #endif
178
179 #ifndef MAX
180 #define MAX(a,b) ((a)>(b)?(a):(b))
181 #endif
182
183 #ifndef HAVE_STRERROR
184 extern char *sys_errlist[];
185 #define strerror(i) sys_errlist[i]
186 #endif
187
188 #ifndef HAVE_ERRNO_DECL
189 extern int errno;
190 #endif
191
192 /* Our own pstrings and fstrings */
193 #include "pstring.h"
194
195 /* Lists, trees, caching, database... */
196 #include "xfile.h"
197 #include "dlinklist.h"
198 #include "talloc.h"
199 #include "lib/ldb/include/ldb.h"
200 #include "lib/tdb/include/tdb.h"
201 #include "lib/tdb/include/spinlock.h"
202 #include "lib/tdb/include/tdbutil.h"
203 #include "db_wrap.h"
204 #include "nt_status.h"
205 #include "trans2.h"
206 #include "ioctl.h"
207 #include "nterr.h"
208 #include "messages.h"
209 #include "charset.h"
210 #include "dynconfig.h"
211
212 #include "version.h"
213 #include "rewrite.h"
214 #include "smb.h"
215 #include "ads.h"
216 #include "lib/socket/socket.h"
217 #include "libcli/ldap/ldap.h"
218 #include "nameserv.h"
219
220 #include "byteorder.h"
221
222 #include "module.h"
223
224 #include "asn_1.h"
225
226 #include "mutex.h"
227
228 #include "structs.h"
229 #include "librpc/ndr/libndr.h"
230 #include "librpc/ndr/ndr_sec.h"
231 #include "librpc/gen_ndr/ndr_misc.h"
232 #include "librpc/gen_ndr/ndr_dcerpc.h"
233 #include "librpc/rpc/dcerpc.h"
234 #include "librpc/gen_ndr/tables.h"
235
236 #include "smb_interfaces.h"
237 #include "smbd/server.h"
238 #include "smbd/service.h"
239 #include "rpc_server/dcerpc_server.h"
240 #include "request.h"
241 #include "signing.h"
242 #include "smb_server/smb_server.h"
243 #include "ntvfs/ntvfs.h"
244 #include "cli_context.h"
245 #include "registry.h"
246 #include "rap.h"
247 #include "ldap_server/ldap_server.h"
248
249 #include "libnet/libnet.h"
250 #include "utils/net/net.h"
251
252 #include "nsswitch/winbind_client.h"
253
254 /* hmm, this really is getting ugly isn't it .... we probably need to
255    have some way to have subsystem includes without including it
256    globally */
257 #include "ntvfs/posix/vfs_posix.h"
258
259 #define malloc_p(type) (type *)malloc(sizeof(type))
260 #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count)
261 #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count)
262
263 #ifndef HAVE_COMPARISON_FN_T
264 typedef int (*comparison_fn_t)(const void *, const void *);
265 #endif
266
267 /***** automatically generated prototypes *****/
268 #define _PRINTF_ATTRIBUTE(a1, a2) PRINTF_ATTRIBUTE(a1, a2)
269 #include "proto.h"
270 #undef _PRINTF_ATTRIBUTE
271 #define _PRINTF_ATTRIBUTE(a1, a2)
272
273 /* String routines */
274
275 #include "safe_string.h"
276
277 #ifdef __COMPAR_FN_T
278 #define QSORT_CAST (__compar_fn_t)
279 #endif
280
281 #ifndef QSORT_CAST
282 #define QSORT_CAST (int (*)(const void *, const void *))
283 #endif
284
285 #ifndef SIGCLD
286 #define SIGCLD SIGCHLD
287 #endif
288
289 #ifndef MAP_FILE
290 #define MAP_FILE 0
291 #endif
292
293 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
294 #define OSF1_ENH_SEC 1
295 #endif
296
297 #ifndef ALLOW_CHANGE_PASSWORD
298 #if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
299 #define ALLOW_CHANGE_PASSWORD 1
300 #endif
301 #endif
302
303 /* what is the longest significant password available on your system? 
304  Knowing this speeds up password searches a lot */
305 #ifndef PASSWORD_LENGTH
306 #define PASSWORD_LENGTH 8
307 #endif
308
309 #ifndef HAVE_PIPE
310 #define SYNC_DNS 1
311 #endif
312
313 #ifndef MAXPATHLEN
314 #define MAXPATHLEN 256
315 #endif
316
317 #ifndef SEEK_SET
318 #define SEEK_SET 0
319 #endif
320
321 #ifndef INADDR_LOOPBACK
322 #define INADDR_LOOPBACK 0x7f000001
323 #endif
324
325 #ifndef INADDR_NONE
326 #define INADDR_NONE 0xffffffff
327 #endif
328
329 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
330 #define ULTRIX_AUTH 1
331 #endif
332
333 #ifndef HAVE_STRDUP
334 char *strdup(const char *s);
335 #endif
336
337 #ifndef HAVE_MEMMOVE
338 void *memmove(void *dest,const void *src,int size);
339 #endif
340
341 #ifndef HAVE_MKTIME
342 time_t mktime(struct tm *t);
343 #endif
344
345 #ifndef HAVE_STRLCPY
346 size_t strlcpy(char *d, const char *s, size_t bufsize);
347 #endif
348
349 #ifndef HAVE_STRLCAT
350 size_t strlcat(char *d, const char *s, size_t bufsize);
351 #endif
352
353 #ifndef HAVE_FTRUNCATE
354 int ftruncate(int f,long l);
355 #endif
356
357 #ifndef HAVE_STRNDUP
358 char *strndup(const char *s, size_t n);
359 #endif
360
361 #ifndef HAVE_STRNLEN
362 size_t strnlen(const char *s, size_t n);
363 #endif
364
365 #ifndef HAVE_STRTOUL
366 unsigned long strtoul(const char *nptr, char **endptr, int base);
367 #endif
368
369 #ifndef HAVE_SETENV
370 int setenv(const char *name, const char *value, int overwrite); 
371 #endif
372
373 #ifndef HAVE_VASPRINTF_DECL
374 int vasprintf(char **ptr, const char *format, va_list ap);
375 #endif
376
377 #if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
378 #define bzero(a,b) memset((a),'\0',(b))
379 #endif
380
381 extern int DEBUGLEVEL;
382
383 /* add varargs prototypes with printf checking */
384 #ifndef HAVE_SNPRINTF_DECL
385 int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
386 #endif
387 #ifndef HAVE_ASPRINTF_DECL
388 int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
389 #endif
390
391
392 /* we used to use these fns, but now we have good replacements
393    for snprintf and vsnprintf */
394 #define slprintf snprintf
395
396
397 /* we need to use __va_copy() on some platforms */
398 #ifdef HAVE_VA_COPY
399 #define VA_COPY(dest, src) __va_copy(dest, src)
400 #else
401 #define VA_COPY(dest, src) (dest) = (src)
402 #endif
403
404 #ifndef HAVE_TIMEGM
405 time_t timegm(struct tm *tm);
406 #endif
407
408 #if defined(VALGRIND)
409 #define strlen(x) valgrind_strlen(x)
410 #endif
411
412 #define TALLOC_ABORT(reason) smb_panic(reason)
413
414
415 /*
416   this is a warning hack. The idea is to use this everywhere that we
417   get the "discarding const" warning from gcc. That doesn't actually
418   fix the problem of course, but it means that when we do get to
419   cleaning them up we can do it by searching the code for
420   discard_const.
421
422   It also means that other error types aren't as swamped by the noise
423   of hundreds of const warnings, so we are more likely to notice when
424   we get new errors.
425
426   Please only add more uses of this macro when you find it
427   _really_ hard to fix const warnings. Our aim is to eventually use
428   this function in only a very few places.
429
430   Also, please call this via the discard_const_p() macro interface, as that
431   makes the return type safe.
432 */
433 #ifdef HAVE_INTPTR_T
434 #define discard_const(ptr) ((void *)((intptr_t)(ptr)))
435 #else
436 #define discard_const(ptr) ((void *)(ptr))
437 #endif
438 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
439
440 #endif /* _INCLUDES_H */
441