r3428: switched to using minimal includes for the auto-generated RPC code.
[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 RELIANTUNIX
76 /*
77  * <unistd.h> has to be included before any other to get
78  * large file support on Reliant UNIX. Yes, it's broken :-).
79  */
80 #ifdef HAVE_UNISTD_H
81 #include <unistd.h>
82 #endif
83 #endif /* RELIANTUNIX */
84
85 #include <sys/types.h>
86
87 #ifdef TIME_WITH_SYS_TIME
88 #include <sys/time.h>
89 #include <time.h>
90 #else
91 #ifdef HAVE_SYS_TIME_H
92 #include <sys/time.h>
93 #else
94 #include <time.h>
95 #endif
96 #endif
97
98 #ifdef HAVE_SYS_RESOURCE_H
99 #include <sys/resource.h>
100 #endif
101
102 #ifdef HAVE_UNISTD_H
103 #include <unistd.h>
104 #endif
105
106 #include <stdio.h>
107 #include <stddef.h>
108
109 #ifdef HAVE_SYS_PARAM_H
110 #include <sys/param.h>
111 #endif
112
113 #ifdef HAVE_STDLIB_H
114 #include <stdlib.h>
115 #endif
116
117 #ifdef HAVE_SYS_SOCKET_H
118 #include <sys/socket.h>
119 #endif
120
121 #ifdef HAVE_UNIXSOCKET
122 #include <sys/un.h>
123 #endif
124
125 #ifdef HAVE_SYS_SYSCALL_H
126 #include <sys/syscall.h>
127 #elif HAVE_SYSCALL_H
128 #include <syscall.h>
129 #endif
130
131 #ifdef HAVE_STRING_H
132 #include <string.h>
133 #endif
134
135 #ifdef HAVE_STRINGS_H
136 #include <strings.h>
137 #endif
138
139 #ifdef HAVE_MEMORY_H
140 #include <memory.h>
141 #endif
142
143 #ifdef HAVE_MALLOC_H
144 #include <malloc.h>
145 #endif
146
147 #ifdef HAVE_FCNTL_H
148 #include <fcntl.h>
149 #else
150 #ifdef HAVE_SYS_FCNTL_H
151 #include <sys/fcntl.h>
152 #endif
153 #endif
154
155 #include <sys/stat.h>
156
157 #ifdef HAVE_LIMITS_H
158 #include <limits.h>
159 #endif
160
161 #ifdef HAVE_SYS_IOCTL_H
162 #include <sys/ioctl.h>
163 #endif
164
165 #ifdef HAVE_SYS_FILIO_H
166 #include <sys/filio.h>
167 #endif
168
169 #include <signal.h>
170
171 #ifdef HAVE_SYS_WAIT_H
172 #include <sys/wait.h>
173 #endif
174 #ifdef HAVE_CTYPE_H
175 #include <ctype.h>
176 #endif
177 #ifdef HAVE_GRP_H
178 #include <grp.h>
179 #endif
180 #ifdef HAVE_SYS_PRIV_H
181 #include <sys/priv.h>
182 #endif
183 #ifdef HAVE_SYS_ID_H
184 #include <sys/id.h>
185 #endif
186
187 #include <errno.h>
188
189 #ifdef HAVE_UTIME_H
190 #include <utime.h>
191 #endif
192
193 #ifdef HAVE_SYS_SELECT_H
194 #include <sys/select.h>
195 #endif
196
197 #ifdef HAVE_SYS_MODE_H
198 /* apparently AIX needs this for S_ISLNK */
199 #ifndef S_ISLNK
200 #include <sys/mode.h>
201 #endif
202 #endif
203
204 #ifdef HAVE_GLOB_H
205 #include <glob.h>
206 #endif
207
208 #include <pwd.h>
209
210 #ifdef HAVE_STDARG_H
211 #include <stdarg.h>
212 #else
213 #include <varargs.h>
214 #endif
215
216 #include <netinet/in.h>
217 #include <arpa/inet.h>
218 #include <netdb.h>
219
220 #ifdef HAVE_SYSLOG_H
221 #include <syslog.h>
222 #else
223 #ifdef HAVE_SYS_SYSLOG_H
224 #include <sys/syslog.h>
225 #endif
226 #endif
227
228 #include <sys/file.h>
229
230 #ifdef HAVE_NETINET_TCP_H
231 #include <netinet/tcp.h>
232 #endif
233
234 /*
235  * The next three defines are needed to access the IPTOS_* options
236  * on some systems.
237  */
238
239 #ifdef HAVE_NETINET_IN_SYSTM_H
240 #include <netinet/in_systm.h>
241 #endif
242
243 #ifdef HAVE_NETINET_IN_IP_H
244 #include <netinet/in_ip.h>
245 #endif
246
247 #ifdef HAVE_NETINET_IP_H
248 #include <netinet/ip.h>
249 #endif
250
251 #if defined(HAVE_TERMIOS_H)
252 /* POSIX terminal handling. */
253 #include <termios.h>
254 #elif defined(HAVE_TERMIO_H)
255 /* Older SYSV terminal handling - don't use if we can avoid it. */
256 #include <termio.h>
257 #elif defined(HAVE_SYS_TERMIO_H)
258 /* Older SYSV terminal handling - don't use if we can avoid it. */
259 #include <sys/termio.h>
260 #endif
261
262 #if HAVE_DIRENT_H
263 # include <dirent.h>
264 # define NAMLEN(dirent) strlen((dirent)->d_name)
265 #else
266 # define dirent direct
267 # define NAMLEN(dirent) (dirent)->d_namlen
268 # if HAVE_SYS_NDIR_H
269 #  include <sys/ndir.h>
270 # endif
271 # if HAVE_SYS_DIR_H
272 #  include <sys/dir.h>
273 # endif
274 # if HAVE_NDIR_H
275 #  include <ndir.h>
276 # endif
277 #endif
278
279 #ifdef HAVE_SYS_MMAN_H
280 #include <sys/mman.h>
281 #endif
282
283 #ifdef HAVE_NET_IF_H
284 #include <net/if.h>
285 #endif
286
287
288 #ifdef HAVE_SYS_MOUNT_H
289 #include <sys/mount.h>
290 #endif
291
292 #ifdef HAVE_SYS_VFS_H
293 #include <sys/vfs.h>
294 #endif
295
296 #ifdef HAVE_SYS_ACL_H
297 #include <sys/acl.h>
298 #endif
299
300 #ifdef HAVE_SYS_FS_S5PARAM_H 
301 #include <sys/fs/s5param.h>
302 #endif
303
304 #if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
305 #include <sys/filsys.h> 
306 #endif
307
308 #ifdef HAVE_SYS_STATFS_H
309 # include <sys/statfs.h>
310 #endif
311
312 #ifdef HAVE_DUSTAT_H              
313 #include <sys/dustat.h>
314 #endif
315
316 #ifdef HAVE_SYS_STATVFS_H          
317 #include <sys/statvfs.h>
318 #endif
319
320 #ifdef HAVE_SHADOW_H
321 #include <shadow.h>
322 #endif
323
324 #ifdef HAVE_GETPWANAM
325 #include <sys/label.h>
326 #include <sys/audit.h>
327 #include <pwdadj.h>
328 #endif
329
330 #ifdef HAVE_SYS_SECURITY_H
331 #include <sys/security.h>
332 #include <prot.h>
333 #define PASSWORD_LENGTH 16
334 #endif  /* HAVE_SYS_SECURITY_H */
335
336 #ifdef HAVE_COMPAT_H
337 #include <compat.h>
338 #endif
339
340 #ifdef HAVE_STROPTS_H
341 #include <stropts.h>
342 #endif
343
344 #ifdef HAVE_SYS_CAPABILITY_H
345
346 #if defined(BROKEN_REDHAT_7_SYSTEM_HEADERS) && !defined(_I386_STATFS_H)
347 #define _I386_STATFS_H
348 #define BROKEN_REDHAT_7_STATFS_WORKAROUND
349 #endif
350
351 #include <sys/capability.h>
352
353 #ifdef BROKEN_REDHAT_7_STATFS_WORKAROUND
354 #undef _I386_STATFS_H
355 #undef BROKEN_REDHAT_7_STATFS_WORKAROUND
356 #endif
357
358 #endif
359
360 #if defined(HAVE_SYS_IPC_H)
361 #include <sys/ipc.h>
362 #endif /* HAVE_SYS_IPC_H */
363
364 #if defined(HAVE_SYS_SHM_H)
365 #include <sys/shm.h>
366 #endif /* HAVE_SYS_SHM_H */
367
368 #ifdef HAVE_NATIVE_ICONV
369 #ifdef HAVE_ICONV
370 #include <iconv.h>
371 #endif
372 #ifdef HAVE_GICONV
373 #include <giconv.h>
374 #endif
375 #endif
376
377 #ifdef HAVE_KRB5_H
378 #include <krb5.h>
379 #else
380 #undef HAVE_KRB5
381 #endif
382
383 #ifdef HAVE_GSSAPI_H
384 #include <gssapi.h>
385 #endif
386
387 #ifdef HAVE_GSSAPI_GSSAPI_H
388 #include <gssapi/gssapi.h>
389 #endif
390
391 #ifdef HAVE_GSSAPI_GSSAPI_GENERIC_H
392 #include <gssapi/gssapi_generic.h>
393 #endif
394
395 #ifdef HAVE_COM_ERR_H
396 #include <com_err.h>
397 #endif
398
399 /* we support ADS if we want it and have krb5 and ldap libs */
400 #if defined(WITH_ADS) && defined(HAVE_KRB5) && defined(HAVE_LDAP)
401 #define HAVE_ADS
402 #endif
403
404 /*
405  * Define VOLATILE if needed.
406  */
407
408 #if defined(HAVE_VOLATILE)
409 #define VOLATILE volatile
410 #else
411 #define VOLATILE
412 #endif
413
414 /*
415  * Define additional missing types
416  */
417 #ifndef HAVE_SIG_ATOMIC_T_TYPE
418 typedef int sig_atomic_t;
419 #endif
420
421 #ifndef HAVE_SOCKLEN_T_TYPE
422 typedef int socklen_t;
423 #endif
424
425
426 /*
427    Samba needs type definitions for 
428    int8_t,  int16_t,  int32_t, int64_t 
429    uint8_t, uint16_t, uint32_t and uint64_t.
430
431    Normally these are signed and unsigned 8, 16, 32 and 64 bit integers, but
432    they actually only need to be at least 8, 16, 32 and 64 bits
433    respectively. Thus if your word size is 8 bytes just defining them
434    as signed and unsigned int will work.
435 */
436
437 #if !defined(int8)
438 #define int8 int8_t
439 #endif
440
441 #if !defined(uint8)
442 #define uint8 uint8_t
443 #endif
444
445 #if !defined(int16)
446 #define int16 int16_t
447 #endif
448
449 #if !defined(uint16)
450 #define uint16 uint16_t
451 #endif
452
453 #if !defined(int32)
454 #define int32 int32_t
455 #endif
456
457 #if !defined(uint32)
458 #define uint32 uint32_t
459 #endif
460
461 #if !defined(int64)
462 #define int64 int64_t
463 #endif
464
465 #if !defined(uint64)
466 #define uint64 uint64_t
467 #endif
468
469 #ifndef UINT8_MAX
470 #define UINT8_MAX 255
471 #endif
472
473 #ifndef UINT16_MAX
474 #define UINT16_MAX 65535
475 #endif
476
477 /*
478  * Types for devices, inodes and offsets.
479  */
480
481 #ifndef SMB_DEV_T
482 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)
483 #    define SMB_DEV_T dev64_t
484 #  else
485 #    define SMB_DEV_T dev_t
486 #  endif
487 #endif
488
489 /*
490  * Setup the correctly sized inode type.
491  */
492
493 #ifndef SMB_INO_T
494 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)
495 #    define SMB_INO_T ino64_t
496 #  else
497 #    define SMB_INO_T ino_t
498 #  endif
499 #endif
500
501 #ifndef LARGE_SMB_INO_T
502 #  if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)) || (defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8))
503 #    define LARGE_SMB_INO_T 1
504 #  endif
505 #endif
506
507 #ifdef LARGE_SMB_INO_T
508 #define SINO_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
509 #else 
510 #define SINO_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
511 #endif
512
513 #ifndef SMB_OFF_T
514 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)
515 #    define SMB_OFF_T off64_t
516 #  else
517 #    define SMB_OFF_T off_t
518 #  endif
519 #endif
520
521 /*
522  * Set the define that tells us if we can do 64 bit
523  * NT SMB calls.
524  */
525
526 #ifndef LARGE_SMB_OFF_T
527 #  if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8))
528 #    define LARGE_SMB_OFF_T 1
529 #  endif
530 #endif
531
532 /*
533  * Type for stat structure.
534  */
535
536 #ifndef SMB_STRUCT_STAT
537 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STAT64) && defined(HAVE_OFF64_T)
538 #    define SMB_STRUCT_STAT struct stat64
539 #  else
540 #    define SMB_STRUCT_STAT struct stat
541 #  endif
542 #endif
543
544 /*
545  * Type for dirent structure.
546  */
547
548 #ifndef SMB_STRUCT_DIRENT
549 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIRENT64)
550 #    define smb_dirent dirent64
551 #  else
552 #    define smb_dirent dirent
553 #  endif
554 #endif
555
556 /*
557  * Defines for 64 bit fcntl locks.
558  */
559
560 #ifndef SMB_STRUCT_FLOCK
561 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
562 #    define SMB_STRUCT_FLOCK struct flock64
563 #  else
564 #    define SMB_STRUCT_FLOCK struct flock
565 #  endif
566 #endif
567
568 #ifndef SMB_F_SETLKW
569 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
570 #    define SMB_F_SETLKW F_SETLKW64
571 #  else
572 #    define SMB_F_SETLKW F_SETLKW
573 #  endif
574 #endif
575
576 #ifndef SMB_F_SETLK
577 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
578 #    define SMB_F_SETLK F_SETLK64
579 #  else
580 #    define SMB_F_SETLK F_SETLK
581 #  endif
582 #endif
583
584 #ifndef SMB_F_GETLK
585 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
586 #    define SMB_F_GETLK F_GETLK64
587 #  else
588 #    define SMB_F_GETLK F_GETLK
589 #  endif
590 #endif
591
592 #ifndef MIN
593 #define MIN(a,b) ((a)<(b)?(a):(b))
594 #endif
595
596 #ifndef MAX
597 #define MAX(a,b) ((a)>(b)?(a):(b))
598 #endif
599
600 #ifndef HAVE_STRERROR
601 extern char *sys_errlist[];
602 #define strerror(i) sys_errlist[i]
603 #endif
604
605 #ifndef HAVE_ERRNO_DECL
606 extern int errno;
607 #endif
608
609 #ifdef HAVE_BROKEN_GETGROUPS
610 #define GID_T int
611 #else
612 #define GID_T gid_t
613 #endif
614
615 #ifndef NGROUPS_MAX
616 #define NGROUPS_MAX 32 /* Guess... */
617 #endif
618
619 /* Our own pstrings and fstrings */
620 #include "pstring.h"
621
622 /* Lists, trees, caching, database... */
623 #include "xfile.h"
624 #include "dlinklist.h"
625 #include "lib/ldb/include/ldb.h"
626 #include "lib/tdb/include/tdb.h"
627 #include "lib/tdb/include/spinlock.h"
628 #include "lib/tdb/include/tdbutil.h"
629 #include "talloc.h"
630 #include "db_wrap.h"
631 #include "nt_status.h"
632 #include "interfaces.h"
633 #include "trans2.h"
634 #include "ioctl.h"
635 #include "nterr.h"
636 #include "messages.h"
637 #include "charset.h"
638 #include "dynconfig.h"
639
640 #include "version.h"
641 #include "rewrite.h"
642 #include "smb.h"
643 #include "ads.h"
644 #include "lib/socket/socket.h"
645 #include "libcli/ldap/ldap.h"
646 #include "nameserv.h"
647 #include "secrets.h"
648
649 #include "byteorder.h"
650
651 #include "md5.h"
652 #include "hmacmd5.h"
653
654
655 #include "module.h"
656
657 #include "asn_1.h"
658
659 #include "mutex.h"
660
661 #include "structs.h"
662 #include "librpc/ndr/libndr.h"
663 #include "librpc/ndr/ndr_sec.h"
664 #include "librpc/gen_ndr/ndr_misc.h"
665 #include "librpc/gen_ndr/ndr_dcerpc.h"
666 #include "librpc/rpc/dcerpc.h"
667 #include "librpc/gen_ndr/tables.h"
668
669 #include "libcli/auth/ntlmssp.h"
670 #include "libcli/auth/credentials.h"
671 #include "libcli/auth/kerberos.h"
672 #include "libcli/auth/gensec.h"
673 #include "libcli/auth/spnego.h"
674 #include "auth/auth.h"
675
676 #include "smb_interfaces.h"
677 #include "smbd/server.h"
678 #include "smbd/service.h"
679 #include "rpc_server/dcerpc_server.h"
680 #include "request.h"
681 #include "signing.h"
682 #include "smb_server/smb_server.h"
683 #include "ntvfs/ntvfs.h"
684 #include "cli_context.h"
685 #include "registry.h"
686 #include "rap.h"
687 #include "ldap_server/ldap_server.h"
688 #include "gtk/common/gtk-smb.h"
689 #include "gtk/common/select.h"
690
691 #include "libnet/libnet.h"
692 #include "utils/net/net.h"
693
694 #include "nsswitch/winbind_client.h"
695
696 /* hmm, this really is getting ugly isn't it .... we probably need to
697    have some way to have subsystem includes without including it
698    globally */
699 #include "ntvfs/posix/vfs_posix.h"
700
701 #define malloc_p(type) (type *)malloc(sizeof(type))
702 #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count)
703 #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count)
704
705 #ifndef HAVE_COMPARISON_FN_T
706 typedef int (*comparison_fn_t)(const void *, const void *);
707 #endif
708
709 /***** automatically generated prototypes *****/
710 #define _PRINTF_ATTRIBUTE(a1, a2) PRINTF_ATTRIBUTE(a1, a2)
711 #include "proto.h"
712 #undef _PRINTF_ATTRIBUTE
713 #define _PRINTF_ATTRIBUTE(a1, a2)
714
715 /* String routines */
716
717 #include "safe_string.h"
718
719 #ifdef __COMPAR_FN_T
720 #define QSORT_CAST (__compar_fn_t)
721 #endif
722
723 #ifndef QSORT_CAST
724 #define QSORT_CAST (int (*)(const void *, const void *))
725 #endif
726
727 #ifndef SIGCLD
728 #define SIGCLD SIGCHLD
729 #endif
730
731 #ifndef MAP_FILE
732 #define MAP_FILE 0
733 #endif
734
735 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
736 #define OSF1_ENH_SEC 1
737 #endif
738
739 #ifndef ALLOW_CHANGE_PASSWORD
740 #if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
741 #define ALLOW_CHANGE_PASSWORD 1
742 #endif
743 #endif
744
745 /* what is the longest significant password available on your system? 
746  Knowing this speeds up password searches a lot */
747 #ifndef PASSWORD_LENGTH
748 #define PASSWORD_LENGTH 8
749 #endif
750
751 #ifdef REPLACE_INET_NTOA
752 #define inet_ntoa rep_inet_ntoa
753 #endif
754
755 #ifndef HAVE_PIPE
756 #define SYNC_DNS 1
757 #endif
758
759 #ifndef MAXPATHLEN
760 #define MAXPATHLEN 256
761 #endif
762
763 #ifndef SEEK_SET
764 #define SEEK_SET 0
765 #endif
766
767 #ifndef INADDR_LOOPBACK
768 #define INADDR_LOOPBACK 0x7f000001
769 #endif
770
771 #ifndef INADDR_NONE
772 #define INADDR_NONE 0xffffffff
773 #endif
774
775 #ifndef HAVE_CRYPT
776 #define crypt ufc_crypt
777 #endif
778
779 #ifndef O_ACCMODE
780 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
781 #endif
782
783 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
784 #define ULTRIX_AUTH 1
785 #endif
786
787 #ifndef HAVE_STRDUP
788 char *strdup(const char *s);
789 #endif
790
791 #ifndef HAVE_MEMMOVE
792 void *memmove(void *dest,const void *src,int size);
793 #endif
794
795 #ifndef HAVE_INITGROUPS
796 int initgroups(char *name,gid_t id);
797 #endif
798
799 #ifndef HAVE_RENAME
800 int rename(const char *zfrom, const char *zto);
801 #endif
802
803 #ifndef HAVE_MKTIME
804 time_t mktime(struct tm *t);
805 #endif
806
807 #ifndef HAVE_STRLCPY
808 size_t strlcpy(char *d, const char *s, size_t bufsize);
809 #endif
810
811 #ifndef HAVE_STRLCAT
812 size_t strlcat(char *d, const char *s, size_t bufsize);
813 #endif
814
815 #ifndef HAVE_FTRUNCATE
816 int ftruncate(int f,long l);
817 #endif
818
819 #ifndef HAVE_STRNDUP
820 char *strndup(const char *s, size_t n);
821 #endif
822
823 #ifndef HAVE_STRNLEN
824 size_t strnlen(const char *s, size_t n);
825 #endif
826
827 #ifndef HAVE_STRTOUL
828 unsigned long strtoul(const char *nptr, char **endptr, int base);
829 #endif
830
831 #ifndef HAVE_SETENV
832 int setenv(const char *name, const char *value, int overwrite); 
833 #endif
834
835 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL))
836 /* stupid glibc */
837 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
838 #endif
839 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESGID_DECL))
840 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
841 #endif
842 #ifndef HAVE_VASPRINTF_DECL
843 int vasprintf(char **ptr, const char *format, va_list ap);
844 #endif
845
846 #if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
847 #define bzero(a,b) memset((a),'\0',(b))
848 #endif
849
850 #ifdef REPLACE_GETPASS
851 #define getpass(prompt) getsmbpass((prompt))
852 #endif
853
854 /*
855  * Some older systems seem not to have MAXHOSTNAMELEN
856  * defined.
857  */
858 #ifndef MAXHOSTNAMELEN
859 #define MAXHOSTNAMELEN 254
860 #endif
861
862 /* yuck, I'd like a better way of doing this */
863 #define DIRP_SIZE (256 + 32)
864
865 /*
866  * glibc on linux doesn't seem to have MSG_WAITALL
867  * defined. I think the kernel has it though..
868  */
869
870 #ifndef MSG_WAITALL
871 #define MSG_WAITALL 0
872 #endif
873
874 /* default socket options. Dave Miller thinks we should default to TCP_NODELAY
875    given the socket IO pattern that Samba uses */
876 #ifdef TCP_NODELAY
877 #define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
878 #else
879 #define DEFAULT_SOCKET_OPTIONS ""
880 #endif
881
882 /* Load header file for dynamic linking stuff */
883
884 #ifdef HAVE_DLFCN_H
885 #include <dlfcn.h>
886 #endif
887
888 /* dmalloc -- free heap debugger (dmalloc.org).  This should be near
889  * the *bottom* of include files so as not to conflict. */
890 #ifdef ENABLE_DMALLOC
891 #  include <dmalloc.h>
892 #endif
893
894
895 /* Some POSIX definitions for those without */
896  
897 #ifndef S_IFDIR
898 #define S_IFDIR         0x4000
899 #endif
900 #ifndef S_ISDIR
901 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
902 #endif
903 #ifndef S_IRWXU
904 #define S_IRWXU 00700           /* read, write, execute: owner */
905 #endif
906 #ifndef S_IRUSR
907 #define S_IRUSR 00400           /* read permission: owner */
908 #endif
909 #ifndef S_IWUSR
910 #define S_IWUSR 00200           /* write permission: owner */
911 #endif
912 #ifndef S_IXUSR
913 #define S_IXUSR 00100           /* execute permission: owner */
914 #endif
915 #ifndef S_IRWXG
916 #define S_IRWXG 00070           /* read, write, execute: group */
917 #endif
918 #ifndef S_IRGRP
919 #define S_IRGRP 00040           /* read permission: group */
920 #endif
921 #ifndef S_IWGRP
922 #define S_IWGRP 00020           /* write permission: group */
923 #endif
924 #ifndef S_IXGRP
925 #define S_IXGRP 00010           /* execute permission: group */
926 #endif
927 #ifndef S_IRWXO
928 #define S_IRWXO 00007           /* read, write, execute: other */
929 #endif
930 #ifndef S_IROTH
931 #define S_IROTH 00004           /* read permission: other */
932 #endif
933 #ifndef S_IWOTH
934 #define S_IWOTH 00002           /* write permission: other */
935 #endif
936 #ifndef S_IXOTH
937 #define S_IXOTH 00001           /* execute permission: other */
938 #endif
939
940 /* For sys_adminlog(). */
941 #ifndef LOG_EMERG
942 #define LOG_EMERG       0       /* system is unusable */
943 #endif
944
945 #ifndef LOG_ALERT
946 #define LOG_ALERT       1       /* action must be taken immediately */
947 #endif
948
949 #ifndef LOG_CRIT
950 #define LOG_CRIT        2       /* critical conditions */
951 #endif
952
953 #ifndef LOG_ERR
954 #define LOG_ERR         3       /* error conditions */
955 #endif
956
957 #ifndef LOG_WARNING
958 #define LOG_WARNING     4       /* warning conditions */
959 #endif
960
961 #ifndef LOG_NOTICE
962 #define LOG_NOTICE      5       /* normal but significant condition */
963 #endif
964
965 #ifndef LOG_INFO
966 #define LOG_INFO        6       /* informational */
967 #endif
968
969 #ifndef LOG_DEBUG
970 #define LOG_DEBUG       7       /* debug-level messages */
971 #endif
972
973 /* NetBSD doesn't have these */
974 #ifndef SHM_R
975 #define SHM_R 0400
976 #endif
977
978 #ifndef SHM_W
979 #define SHM_W 0200
980 #endif
981
982 #if HAVE_KERNEL_SHARE_MODES
983 #ifndef LOCK_MAND 
984 #define LOCK_MAND       32      /* This is a mandatory flock */
985 #define LOCK_READ       64      /* ... Which allows concurrent read operations */
986 #define LOCK_WRITE      128     /* ... Which allows concurrent write operations */
987 #define LOCK_RW         192     /* ... Which allows concurrent read & write ops */
988 #endif
989 #endif
990
991 extern int DEBUGLEVEL;
992
993 #define MAX_SEC_CTX_DEPTH 8    /* Maximum number of security contexts */
994
995
996 #ifdef GLIBC_HACK_FCNTL64
997 /* this is a gross hack. 64 bit locking is completely screwed up on
998    i386 Linux in glibc 2.1.95 (which ships with RedHat 7.0). This hack
999    "fixes" the problem with the current 2.4.0test kernels 
1000 */
1001 #define fcntl fcntl64
1002 #undef F_SETLKW 
1003 #undef F_SETLK 
1004 #define F_SETLK 13
1005 #define F_SETLKW 14
1006 #endif
1007
1008
1009 /* Needed for sys_dlopen/sys_dlsym/sys_dlclose */
1010 #ifndef RTLD_GLOBAL
1011 #define RTLD_GLOBAL 0
1012 #endif
1013
1014 #ifndef RTLD_LAZY
1015 #define RTLD_LAZY 0
1016 #endif
1017
1018 #ifndef RTLD_NOW
1019 #define RTLD_NOW 0
1020 #endif
1021
1022 /* needed for some systems without iconv. Doesn't really matter
1023    what error code we use */
1024 #ifndef EILSEQ
1025 #define EILSEQ EIO
1026 #endif
1027
1028 /* add varargs prototypes with printf checking */
1029 int fdprintf(int , const char *, ...) PRINTF_ATTRIBUTE(2,3);
1030 int d_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2);
1031 int d_fprintf(FILE *f, const char *, ...) PRINTF_ATTRIBUTE(2,3);
1032 #ifndef HAVE_SNPRINTF_DECL
1033 int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
1034 #endif
1035 #ifndef HAVE_ASPRINTF_DECL
1036 int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
1037 #endif
1038
1039 void sys_adminlog(int priority, const char *format_str, ...) PRINTF_ATTRIBUTE(2,3);
1040
1041 int pstr_sprintf(pstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1042 int fstr_sprintf(fstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1043
1044 int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1045
1046 int smb_xvasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1047
1048 /* we used to use these fns, but now we have good replacements
1049    for snprintf and vsnprintf */
1050 #define slprintf snprintf
1051 #define vslprintf vsnprintf
1052
1053
1054 /* we need to use __va_copy() on some platforms */
1055 #ifdef HAVE_VA_COPY
1056 #define VA_COPY(dest, src) __va_copy(dest, src)
1057 #else
1058 #define VA_COPY(dest, src) (dest) = (src)
1059 #endif
1060
1061 #ifndef HAVE_TIMEGM
1062 time_t timegm(struct tm *tm);
1063 #endif
1064
1065 #if defined(VALGRIND)
1066 #define strlen(x) valgrind_strlen(x)
1067 #endif
1068
1069 /*
1070  * Veritas File System.  Often in addition to native.
1071  * Quotas different.
1072  */
1073 #if defined(HAVE_SYS_FS_VX_QUOTA_H)
1074 #define VXFS_QUOTA
1075 #endif
1076
1077 #if HAVE_SYS_ATTRIBUTES_H
1078 #include <sys/attributes.h>
1079 #endif
1080
1081 /* mutually exclusive (SuSE 8.2) */
1082 #if HAVE_ATTR_XATTR_H
1083 #include <attr/xattr.h>
1084 #elif HAVE_SYS_XATTR_H
1085 #include <sys/xattr.h>
1086 #endif
1087
1088 #define TALLOC_ABORT(reason) smb_panic(reason)
1089
1090
1091 /*
1092   this is a warning hack. The idea is to use this everywhere that we
1093   get the "discarding const" warning from gcc. That doesn't actually
1094   fix the problem of course, but it means that when we do get to
1095   cleaning them up we can do it by searching the code for
1096   discard_const.
1097
1098   It also means that other error types aren't as swamped by the noise
1099   of hundreds of const warnings, so we are more likely to notice when
1100   we get new errors.
1101
1102   Please only add more uses of this macro when you find it
1103   _really_ hard to fix const warnings. Our aim is to eventually use
1104   this function in only a very few places.
1105
1106   Also, please call this via the discard_const_p() macro interface, as that
1107   makes the return type safe.
1108 */
1109 #ifdef HAVE_INTPTR_T
1110 #define discard_const(ptr) ((void *)((intptr_t)(ptr)))
1111 #else
1112 #define discard_const(ptr) ((void *)(ptr))
1113 #endif
1114 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
1115
1116 #endif /* _INCLUDES_H */
1117