r3447: more include/system/XXX.h include files
[sfrench/samba-autobuild/.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 #ifdef HAVE_UNISTD_H
76 #include <unistd.h>
77 #endif
78
79 #include <sys/types.h>
80 #include <stdint.h>
81
82 #ifdef HAVE_SYS_RESOURCE_H
83 #include <sys/resource.h>
84 #endif
85
86 #include <unistd.h>
87
88 #include <stdio.h>
89 #include <stddef.h>
90
91 #ifdef HAVE_SYS_PARAM_H
92 #include <sys/param.h>
93 #endif
94
95 #ifdef HAVE_STDLIB_H
96 #include <stdlib.h>
97 #endif
98
99 #ifdef HAVE_STRING_H
100 #include <string.h>
101 #endif
102
103 #ifdef HAVE_STRINGS_H
104 #include <strings.h>
105 #endif
106
107 #ifdef HAVE_MEMORY_H
108 #include <memory.h>
109 #endif
110
111 #ifdef HAVE_MALLOC_H
112 #include <malloc.h>
113 #endif
114
115 #ifdef HAVE_FCNTL_H
116 #include <fcntl.h>
117 #else
118 #ifdef HAVE_SYS_FCNTL_H
119 #include <sys/fcntl.h>
120 #endif
121 #endif
122
123 #include <sys/stat.h>
124
125 #ifdef HAVE_LIMITS_H
126 #include <limits.h>
127 #endif
128
129 #ifdef HAVE_SYS_IOCTL_H
130 #include <sys/ioctl.h>
131 #endif
132
133 #ifdef HAVE_SYS_FILIO_H
134 #include <sys/filio.h>
135 #endif
136
137 #include <signal.h>
138
139 #ifdef HAVE_CTYPE_H
140 #include <ctype.h>
141 #endif
142
143 #include <errno.h>
144
145 #ifdef HAVE_SYS_MODE_H
146 /* apparently AIX needs this for S_ISLNK */
147 #ifndef S_ISLNK
148 #include <sys/mode.h>
149 #endif
150 #endif
151
152 #ifdef HAVE_STDARG_H
153 #include <stdarg.h>
154 #else
155 #include <varargs.h>
156 #endif
157
158 #include <sys/file.h>
159
160 #ifdef HAVE_STROPTS_H
161 #include <stropts.h>
162 #endif
163
164 /* we support ADS if we want it and have krb5 and ldap libs */
165 #if defined(WITH_ADS) && defined(HAVE_KRB5) && defined(HAVE_LDAP)
166 #define HAVE_ADS
167 #endif
168
169 /*
170  * Define VOLATILE if needed.
171  */
172
173 #if defined(HAVE_VOLATILE)
174 #define VOLATILE volatile
175 #else
176 #define VOLATILE
177 #endif
178
179 /*
180  * Define additional missing types
181  */
182 #ifndef HAVE_SIG_ATOMIC_T_TYPE
183 typedef int sig_atomic_t;
184 #endif
185
186 #ifndef HAVE_SOCKLEN_T_TYPE
187 typedef int socklen_t;
188 #endif
189
190
191 /*
192    Samba needs type definitions for 
193    int8_t,  int16_t,  int32_t, int64_t 
194    uint8_t, uint16_t, uint32_t and uint64_t.
195
196    Normally these are signed and unsigned 8, 16, 32 and 64 bit integers, but
197    they actually only need to be at least 8, 16, 32 and 64 bits
198    respectively. Thus if your word size is 8 bytes just defining them
199    as signed and unsigned int will work.
200 */
201
202 #if !defined(int8)
203 #define int8 int8_t
204 #endif
205
206 #if !defined(uint8)
207 #define uint8 uint8_t
208 #endif
209
210 #if !defined(int16)
211 #define int16 int16_t
212 #endif
213
214 #if !defined(uint16)
215 #define uint16 uint16_t
216 #endif
217
218 #if !defined(int32)
219 #define int32 int32_t
220 #endif
221
222 #if !defined(uint32)
223 #define uint32 uint32_t
224 #endif
225
226 #if !defined(int64)
227 #define int64 int64_t
228 #endif
229
230 #if !defined(uint64)
231 #define uint64 uint64_t
232 #endif
233
234 /*
235   we use struct ipv4_addr to avoid having to include all the
236   system networking headers everywhere
237 */
238 struct ipv4_addr {
239         uint32_t s_addr;
240 };
241
242 #ifndef UINT8_MAX
243 #define UINT8_MAX 255
244 #endif
245
246 #ifndef UINT16_MAX
247 #define UINT16_MAX 65535
248 #endif
249
250 /*
251  * Type for stat structure.
252  */
253
254 #ifndef MIN
255 #define MIN(a,b) ((a)<(b)?(a):(b))
256 #endif
257
258 #ifndef MAX
259 #define MAX(a,b) ((a)>(b)?(a):(b))
260 #endif
261
262 #ifndef HAVE_STRERROR
263 extern char *sys_errlist[];
264 #define strerror(i) sys_errlist[i]
265 #endif
266
267 #ifndef HAVE_ERRNO_DECL
268 extern int errno;
269 #endif
270
271 #ifdef HAVE_BROKEN_GETGROUPS
272 #define GID_T int
273 #else
274 #define GID_T gid_t
275 #endif
276
277 #ifndef NGROUPS_MAX
278 #define NGROUPS_MAX 32 /* Guess... */
279 #endif
280
281 /* Our own pstrings and fstrings */
282 #include "pstring.h"
283
284 /* Lists, trees, caching, database... */
285 #include "xfile.h"
286 #include "dlinklist.h"
287 #include "lib/ldb/include/ldb.h"
288 #include "lib/tdb/include/tdb.h"
289 #include "lib/tdb/include/spinlock.h"
290 #include "lib/tdb/include/tdbutil.h"
291 #include "talloc.h"
292 #include "db_wrap.h"
293 #include "nt_status.h"
294 #include "trans2.h"
295 #include "ioctl.h"
296 #include "nterr.h"
297 #include "messages.h"
298 #include "charset.h"
299 #include "dynconfig.h"
300
301 #include "version.h"
302 #include "rewrite.h"
303 #include "smb.h"
304 #include "ads.h"
305 #include "lib/socket/socket.h"
306 #include "libcli/ldap/ldap.h"
307 #include "nameserv.h"
308 #include "secrets.h"
309
310 #include "byteorder.h"
311
312 #include "md5.h"
313 #include "hmacmd5.h"
314
315
316 #include "module.h"
317
318 #include "asn_1.h"
319
320 #include "mutex.h"
321
322 #include "structs.h"
323 #include "librpc/ndr/libndr.h"
324 #include "librpc/ndr/ndr_sec.h"
325 #include "librpc/gen_ndr/ndr_misc.h"
326 #include "librpc/gen_ndr/ndr_dcerpc.h"
327 #include "librpc/rpc/dcerpc.h"
328 #include "librpc/gen_ndr/tables.h"
329
330 #include "libcli/auth/ntlmssp.h"
331 #include "libcli/auth/credentials.h"
332 #include "libcli/auth/gensec.h"
333 #include "libcli/auth/spnego.h"
334 #include "auth/auth.h"
335
336 #include "smb_interfaces.h"
337 #include "smbd/server.h"
338 #include "smbd/service.h"
339 #include "rpc_server/dcerpc_server.h"
340 #include "request.h"
341 #include "signing.h"
342 #include "smb_server/smb_server.h"
343 #include "ntvfs/ntvfs.h"
344 #include "cli_context.h"
345 #include "registry.h"
346 #include "rap.h"
347 #include "ldap_server/ldap_server.h"
348
349 #include "libnet/libnet.h"
350 #include "utils/net/net.h"
351
352 #include "nsswitch/winbind_client.h"
353
354 /* hmm, this really is getting ugly isn't it .... we probably need to
355    have some way to have subsystem includes without including it
356    globally */
357 #include "ntvfs/posix/vfs_posix.h"
358
359 #define malloc_p(type) (type *)malloc(sizeof(type))
360 #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count)
361 #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count)
362
363 #ifndef HAVE_COMPARISON_FN_T
364 typedef int (*comparison_fn_t)(const void *, const void *);
365 #endif
366
367 /***** automatically generated prototypes *****/
368 #define _PRINTF_ATTRIBUTE(a1, a2) PRINTF_ATTRIBUTE(a1, a2)
369 #include "proto.h"
370 #undef _PRINTF_ATTRIBUTE
371 #define _PRINTF_ATTRIBUTE(a1, a2)
372
373 /* String routines */
374
375 #include "safe_string.h"
376
377 #ifdef __COMPAR_FN_T
378 #define QSORT_CAST (__compar_fn_t)
379 #endif
380
381 #ifndef QSORT_CAST
382 #define QSORT_CAST (int (*)(const void *, const void *))
383 #endif
384
385 #ifndef SIGCLD
386 #define SIGCLD SIGCHLD
387 #endif
388
389 #ifndef MAP_FILE
390 #define MAP_FILE 0
391 #endif
392
393 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
394 #define OSF1_ENH_SEC 1
395 #endif
396
397 #ifndef ALLOW_CHANGE_PASSWORD
398 #if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
399 #define ALLOW_CHANGE_PASSWORD 1
400 #endif
401 #endif
402
403 /* what is the longest significant password available on your system? 
404  Knowing this speeds up password searches a lot */
405 #ifndef PASSWORD_LENGTH
406 #define PASSWORD_LENGTH 8
407 #endif
408
409 #ifdef REPLACE_INET_NTOA
410 #define inet_ntoa rep_inet_ntoa
411 #endif
412
413 #ifndef HAVE_PIPE
414 #define SYNC_DNS 1
415 #endif
416
417 #ifndef MAXPATHLEN
418 #define MAXPATHLEN 256
419 #endif
420
421 #ifndef SEEK_SET
422 #define SEEK_SET 0
423 #endif
424
425 #ifndef INADDR_LOOPBACK
426 #define INADDR_LOOPBACK 0x7f000001
427 #endif
428
429 #ifndef INADDR_NONE
430 #define INADDR_NONE 0xffffffff
431 #endif
432
433 #ifndef HAVE_CRYPT
434 #define crypt ufc_crypt
435 #endif
436
437 #ifndef O_ACCMODE
438 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
439 #endif
440
441 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
442 #define ULTRIX_AUTH 1
443 #endif
444
445 #ifndef HAVE_STRDUP
446 char *strdup(const char *s);
447 #endif
448
449 #ifndef HAVE_MEMMOVE
450 void *memmove(void *dest,const void *src,int size);
451 #endif
452
453 #ifndef HAVE_INITGROUPS
454 int initgroups(char *name,gid_t id);
455 #endif
456
457 #ifndef HAVE_RENAME
458 int rename(const char *zfrom, const char *zto);
459 #endif
460
461 #ifndef HAVE_MKTIME
462 time_t mktime(struct tm *t);
463 #endif
464
465 #ifndef HAVE_STRLCPY
466 size_t strlcpy(char *d, const char *s, size_t bufsize);
467 #endif
468
469 #ifndef HAVE_STRLCAT
470 size_t strlcat(char *d, const char *s, size_t bufsize);
471 #endif
472
473 #ifndef HAVE_FTRUNCATE
474 int ftruncate(int f,long l);
475 #endif
476
477 #ifndef HAVE_STRNDUP
478 char *strndup(const char *s, size_t n);
479 #endif
480
481 #ifndef HAVE_STRNLEN
482 size_t strnlen(const char *s, size_t n);
483 #endif
484
485 #ifndef HAVE_STRTOUL
486 unsigned long strtoul(const char *nptr, char **endptr, int base);
487 #endif
488
489 #ifndef HAVE_SETENV
490 int setenv(const char *name, const char *value, int overwrite); 
491 #endif
492
493 #ifndef HAVE_VASPRINTF_DECL
494 int vasprintf(char **ptr, const char *format, va_list ap);
495 #endif
496
497 #if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
498 #define bzero(a,b) memset((a),'\0',(b))
499 #endif
500
501 #ifdef REPLACE_GETPASS
502 #define getpass(prompt) getsmbpass((prompt))
503 #endif
504
505 /*
506  * Some older systems seem not to have MAXHOSTNAMELEN
507  * defined.
508  */
509 #ifndef MAXHOSTNAMELEN
510 #define MAXHOSTNAMELEN 254
511 #endif
512
513 /* yuck, I'd like a better way of doing this */
514 #define DIRP_SIZE (256 + 32)
515
516 /*
517  * glibc on linux doesn't seem to have MSG_WAITALL
518  * defined. I think the kernel has it though..
519  */
520
521 #ifndef MSG_WAITALL
522 #define MSG_WAITALL 0
523 #endif
524
525 /* default socket options. Dave Miller thinks we should default to TCP_NODELAY
526    given the socket IO pattern that Samba uses */
527 #ifdef TCP_NODELAY
528 #define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
529 #else
530 #define DEFAULT_SOCKET_OPTIONS ""
531 #endif
532
533 /* Load header file for dynamic linking stuff */
534
535 #ifdef HAVE_DLFCN_H
536 #include <dlfcn.h>
537 #endif
538
539 /* dmalloc -- free heap debugger (dmalloc.org).  This should be near
540  * the *bottom* of include files so as not to conflict. */
541 #ifdef ENABLE_DMALLOC
542 #  include <dmalloc.h>
543 #endif
544
545
546 /* Some POSIX definitions for those without */
547  
548 #ifndef S_IFDIR
549 #define S_IFDIR         0x4000
550 #endif
551 #ifndef S_ISDIR
552 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
553 #endif
554 #ifndef S_IRWXU
555 #define S_IRWXU 00700           /* read, write, execute: owner */
556 #endif
557 #ifndef S_IRUSR
558 #define S_IRUSR 00400           /* read permission: owner */
559 #endif
560 #ifndef S_IWUSR
561 #define S_IWUSR 00200           /* write permission: owner */
562 #endif
563 #ifndef S_IXUSR
564 #define S_IXUSR 00100           /* execute permission: owner */
565 #endif
566 #ifndef S_IRWXG
567 #define S_IRWXG 00070           /* read, write, execute: group */
568 #endif
569 #ifndef S_IRGRP
570 #define S_IRGRP 00040           /* read permission: group */
571 #endif
572 #ifndef S_IWGRP
573 #define S_IWGRP 00020           /* write permission: group */
574 #endif
575 #ifndef S_IXGRP
576 #define S_IXGRP 00010           /* execute permission: group */
577 #endif
578 #ifndef S_IRWXO
579 #define S_IRWXO 00007           /* read, write, execute: other */
580 #endif
581 #ifndef S_IROTH
582 #define S_IROTH 00004           /* read permission: other */
583 #endif
584 #ifndef S_IWOTH
585 #define S_IWOTH 00002           /* write permission: other */
586 #endif
587 #ifndef S_IXOTH
588 #define S_IXOTH 00001           /* execute permission: other */
589 #endif
590
591 /* For sys_adminlog(). */
592 #ifndef LOG_EMERG
593 #define LOG_EMERG       0       /* system is unusable */
594 #endif
595
596 #ifndef LOG_ALERT
597 #define LOG_ALERT       1       /* action must be taken immediately */
598 #endif
599
600 #ifndef LOG_CRIT
601 #define LOG_CRIT        2       /* critical conditions */
602 #endif
603
604 #ifndef LOG_ERR
605 #define LOG_ERR         3       /* error conditions */
606 #endif
607
608 #ifndef LOG_WARNING
609 #define LOG_WARNING     4       /* warning conditions */
610 #endif
611
612 #ifndef LOG_NOTICE
613 #define LOG_NOTICE      5       /* normal but significant condition */
614 #endif
615
616 #ifndef LOG_INFO
617 #define LOG_INFO        6       /* informational */
618 #endif
619
620 #ifndef LOG_DEBUG
621 #define LOG_DEBUG       7       /* debug-level messages */
622 #endif
623
624 extern int DEBUGLEVEL;
625
626 #ifndef RTLD_LAZY
627 #define RTLD_LAZY 0
628 #endif
629
630 /* needed for some systems without iconv. Doesn't really matter
631    what error code we use */
632 #ifndef EILSEQ
633 #define EILSEQ EIO
634 #endif
635
636 /* add varargs prototypes with printf checking */
637 #ifndef HAVE_SNPRINTF_DECL
638 int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
639 #endif
640 #ifndef HAVE_ASPRINTF_DECL
641 int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
642 #endif
643
644
645 /* we used to use these fns, but now we have good replacements
646    for snprintf and vsnprintf */
647 #define slprintf snprintf
648
649
650 /* we need to use __va_copy() on some platforms */
651 #ifdef HAVE_VA_COPY
652 #define VA_COPY(dest, src) __va_copy(dest, src)
653 #else
654 #define VA_COPY(dest, src) (dest) = (src)
655 #endif
656
657 #ifndef HAVE_TIMEGM
658 time_t timegm(struct tm *tm);
659 #endif
660
661 #if defined(VALGRIND)
662 #define strlen(x) valgrind_strlen(x)
663 #endif
664
665 /*
666  * Veritas File System.  Often in addition to native.
667  * Quotas different.
668  */
669 #if defined(HAVE_SYS_FS_VX_QUOTA_H)
670 #define VXFS_QUOTA
671 #endif
672
673 #if HAVE_SYS_ATTRIBUTES_H
674 #include <sys/attributes.h>
675 #endif
676
677 /* mutually exclusive (SuSE 8.2) */
678 #if HAVE_ATTR_XATTR_H
679 #include <attr/xattr.h>
680 #elif HAVE_SYS_XATTR_H
681 #include <sys/xattr.h>
682 #endif
683
684 #define TALLOC_ABORT(reason) smb_panic(reason)
685
686
687 /*
688   this is a warning hack. The idea is to use this everywhere that we
689   get the "discarding const" warning from gcc. That doesn't actually
690   fix the problem of course, but it means that when we do get to
691   cleaning them up we can do it by searching the code for
692   discard_const.
693
694   It also means that other error types aren't as swamped by the noise
695   of hundreds of const warnings, so we are more likely to notice when
696   we get new errors.
697
698   Please only add more uses of this macro when you find it
699   _really_ hard to fix const warnings. Our aim is to eventually use
700   this function in only a very few places.
701
702   Also, please call this via the discard_const_p() macro interface, as that
703   makes the return type safe.
704 */
705 #ifdef HAVE_INTPTR_T
706 #define discard_const(ptr) ((void *)((intptr_t)(ptr)))
707 #else
708 #define discard_const(ptr) ((void *)(ptr))
709 #endif
710 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
711
712 #endif /* _INCLUDES_H */
713