r18653: this stuff is in libreplace...
[sfrench/samba-autobuild/.git] / source3 / 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 /* work around broken krb5.h on sles9 */
25 #ifdef SIZEOF_LONG
26 #undef SIZEOF_LONG
27 #endif
28
29 #ifndef NO_CONFIG_H /* for some tests */
30 #include "lib/replace/replace.h"
31 #endif
32
33 /* only do the C++ reserved word check when we compile
34    to include --with-developer since too many systems
35    still have comflicts with their header files (e.g. IRIX 6.4) */
36
37 #if !defined(__cplusplus) && defined(DEVELOPER)
38 #define class #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
39 #define private #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
40 #define public #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
41 #define protected #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
42 #define template #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
43 #define this #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
44 #define new #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
45 #define delete #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
46 #define friend #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
47 #endif
48
49 #include "local.h"
50
51 #ifdef AIX
52 #define DEFAULT_PRINTING PRINT_AIX
53 #define PRINTCAP_NAME "/etc/qconfig"
54 #endif
55
56 #ifdef HPUX
57 #define DEFAULT_PRINTING PRINT_HPUX
58 #endif
59
60 #ifdef QNX
61 #define DEFAULT_PRINTING PRINT_QNX
62 #endif
63
64 #ifdef SUNOS4
65 /* on SUNOS4 termios.h conflicts with sys/ioctl.h */
66 #undef HAVE_TERMIOS_H
67 #endif
68
69 #ifndef _PUBLIC_
70 #ifdef HAVE_VISIBILITY_ATTR
71 #  define _PUBLIC_ __attribute__((visibility("default")))
72 #else
73 #  define _PUBLIC_
74 #endif
75 #endif
76
77 #ifndef NORETURN_ATTRIBUTE
78 #if (__GNUC__ >= 3)
79 #define NORETURN_ATTRIBUTE __attribute__ ((noreturn))
80 #else
81 #define NORETURN_ATTRIBUTE
82 #endif
83 #endif
84
85 #if defined(__GNUC__) && !defined(__cplusplus)
86 /** gcc attribute used on function parameters so that it does not emit
87  * warnings about them being unused. **/
88 #  define UNUSED(param) param __attribute__ ((unused))
89 #else
90 #  define UNUSED(param) param
91 /** Feel free to add definitions for other compilers here. */
92 #endif
93
94 #ifdef RELIANTUNIX
95 /*
96  * <unistd.h> has to be included before any other to get
97  * large file support on Reliant UNIX. Yes, it's broken :-).
98  */
99 #ifdef HAVE_UNISTD_H
100 #include <unistd.h>
101 #endif
102 #endif /* RELIANTUNIX */
103
104 #include "system/capability.h"
105 #include "system/dir.h"
106 #include "system/filesys.h"
107 #include "system/glob.h"
108 #include "system/iconv.h"
109 #include "system/locale.h"
110 #include "system/network.h"
111 #include "system/passwd.h"
112 #include "system/printing.h"
113 #include "system/readline.h"
114 #include "system/select.h"
115 #include "system/shmem.h"
116 #include "system/syslog.h"
117 #include "system/terminal.h"
118 #include "system/time.h"
119 #include "system/wait.h"
120
121 #include <sys/types.h>
122
123 #ifdef HAVE_STDINT_H
124 #include <stdint.h>
125 #endif
126
127 #if HAVE_INTTYPES_H
128 #include <inttypes.h>
129 #endif
130
131 #ifdef TIME_WITH_SYS_TIME
132 #include <sys/time.h>
133 #include <time.h>
134 #else
135 #ifdef HAVE_SYS_TIME_H
136 #include <sys/time.h>
137 #else
138 #include <time.h>
139 #endif
140 #endif
141
142 #ifdef HAVE_SYS_RESOURCE_H
143 #include <sys/resource.h>
144 #endif
145
146 #ifdef HAVE_UNISTD_H
147 #include <unistd.h>
148 #endif
149
150 #include <stdio.h>
151 #include <stddef.h>
152
153 #ifdef HAVE_SYS_PARAM_H
154 #include <sys/param.h>
155 #endif
156
157 #ifdef HAVE_STDLIB_H
158 #include <stdlib.h>
159 #endif
160
161 #ifdef HAVE_SYS_SOCKET_H
162 #include <sys/socket.h>
163 #endif
164
165 #ifdef HAVE_UNIXSOCKET
166 #include <sys/un.h>
167 #endif
168
169 #ifdef HAVE_SYS_SYSCALL_H
170 #include <sys/syscall.h>
171 #elif HAVE_SYSCALL_H
172 #include <syscall.h>
173 #endif
174
175 #ifdef HAVE_STRING_H
176 #include <string.h>
177 #endif
178
179 #ifdef HAVE_STRINGS_H
180 #include <strings.h>
181 #endif
182
183 #ifdef HAVE_MEMORY_H
184 #include <memory.h>
185 #endif
186
187 #ifdef HAVE_MALLOC_H
188 #include <malloc.h>
189 #endif
190
191 #ifdef HAVE_FCNTL_H
192 #include <fcntl.h>
193 #else
194 #ifdef HAVE_SYS_FCNTL_H
195 #include <sys/fcntl.h>
196 #endif
197 #endif
198
199 #include <sys/stat.h>
200
201 #ifdef HAVE_LIMITS_H
202 #include <limits.h>
203 #endif
204
205 #ifdef HAVE_SYS_IOCTL_H
206 #include <sys/ioctl.h>
207 #endif
208
209 #ifdef HAVE_SYS_FILIO_H
210 #include <sys/filio.h>
211 #endif
212
213 #include <signal.h>
214
215 #ifdef HAVE_SYS_WAIT_H
216 #include <sys/wait.h>
217 #endif
218 #ifdef HAVE_CTYPE_H
219 #include <ctype.h>
220 #endif
221 #ifdef HAVE_GRP_H
222 #include <grp.h>
223 #endif
224 #ifdef HAVE_SYS_PRIV_H
225 #include <sys/priv.h>
226 #endif
227 #ifdef HAVE_SYS_ID_H
228 #include <sys/id.h>
229 #endif
230
231 #include <errno.h>
232
233 #ifdef HAVE_UTIME_H
234 #include <utime.h>
235 #endif
236
237 #ifdef HAVE_SYS_SELECT_H
238 #include <sys/select.h>
239 #endif
240
241 #ifdef HAVE_SYS_MODE_H
242 /* apparently AIX needs this for S_ISLNK */
243 #ifndef S_ISLNK
244 #include <sys/mode.h>
245 #endif
246 #endif
247
248 #ifdef HAVE_GLOB_H
249 #include <glob.h>
250 #endif
251
252 #include <pwd.h>
253
254 #ifdef HAVE_STDARG_H
255 #include <stdarg.h>
256 #else
257 #include <varargs.h>
258 #endif
259
260 #include <netinet/in.h>
261 #include <arpa/inet.h>
262 #include <netdb.h>
263
264 #ifdef HAVE_SYSLOG_H
265 #include <syslog.h>
266 #else
267 #ifdef HAVE_SYS_SYSLOG_H
268 #include <sys/syslog.h>
269 #endif
270 #endif
271
272 #include <sys/file.h>
273
274 #ifdef HAVE_NETINET_TCP_H
275 #include <netinet/tcp.h>
276 #endif
277
278 /*
279  * The next three defines are needed to access the IPTOS_* options
280  * on some systems.
281  */
282
283 #ifdef HAVE_NETINET_IN_SYSTM_H
284 #include <netinet/in_systm.h>
285 #endif
286
287 #ifdef HAVE_NETINET_IN_IP_H
288 #include <netinet/in_ip.h>
289 #endif
290
291 #ifdef HAVE_NETINET_IP_H
292 #include <netinet/ip.h>
293 #endif
294
295 #if defined(HAVE_TERMIOS_H)
296 /* POSIX terminal handling. */
297 #include <termios.h>
298 #elif defined(HAVE_TERMIO_H)
299 /* Older SYSV terminal handling - don't use if we can avoid it. */
300 #include <termio.h>
301 #elif defined(HAVE_SYS_TERMIO_H)
302 /* Older SYSV terminal handling - don't use if we can avoid it. */
303 #include <sys/termio.h>
304 #endif
305
306 #if HAVE_DIRENT_H
307 # include <dirent.h>
308 # define NAMLEN(dirent) strlen((dirent)->d_name)
309 #else
310 # define dirent direct
311 # define NAMLEN(dirent) (dirent)->d_namlen
312 # if HAVE_SYS_NDIR_H
313 #  include <sys/ndir.h>
314 # endif
315 # if HAVE_SYS_DIR_H
316 #  include <sys/dir.h>
317 # endif
318 # if HAVE_NDIR_H
319 #  include <ndir.h>
320 # endif
321 #endif
322
323 #ifdef HAVE_SYS_MMAN_H
324 #include <sys/mman.h>
325 #endif
326
327 #ifdef HAVE_NET_IF_H
328 #include <net/if.h>
329 #endif
330
331
332 #ifdef HAVE_SYS_MOUNT_H
333 #include <sys/mount.h>
334 #endif
335
336 #ifdef HAVE_SYS_VFS_H
337 #include <sys/vfs.h>
338 #endif
339
340 #ifdef HAVE_SYS_ACL_H
341 #include <sys/acl.h>
342 #endif
343
344 #ifdef HAVE_SYS_FS_S5PARAM_H 
345 #include <sys/fs/s5param.h>
346 #endif
347
348 #if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
349 #include <sys/filsys.h> 
350 #endif
351
352 #ifdef HAVE_SYS_STATFS_H
353 # include <sys/statfs.h>
354 #endif
355
356 #ifdef HAVE_DUSTAT_H              
357 #include <sys/dustat.h>
358 #endif
359
360 #ifdef HAVE_SYS_STATVFS_H          
361 #include <sys/statvfs.h>
362 #endif
363
364 #ifdef HAVE_SHADOW_H
365 /*
366  * HP-UX 11.X has TCP_NODELAY and TCP_MAXSEG defined in <netinet/tcp.h> which
367  * was included above.  However <rpc/rpc.h> includes <sys/xti.h> which defines
368  * them again without checking if they already exsist.  This generates
369  * two "Redefinition of macro" warnings for every single .c file that is
370  * compiled.
371  */
372 #if defined(HPUX) && defined(TCP_NODELAY)
373 #undef TCP_NODELAY
374 #endif
375 #if defined(HPUX) && defined(TCP_MAXSEG)
376 #undef TCP_MAXSEG
377 #endif
378 #include <shadow.h>
379 #endif
380
381 #ifdef HAVE_GETPWANAM
382 #include <sys/label.h>
383 #include <sys/audit.h>
384 #include <pwdadj.h>
385 #endif
386
387 #ifdef HAVE_SYS_SECURITY_H
388 #include <sys/security.h>
389 #include <prot.h>
390 #define PASSWORD_LENGTH 16
391 #endif  /* HAVE_SYS_SECURITY_H */
392
393 #ifdef HAVE_STROPTS_H
394 #include <stropts.h>
395 #endif
396
397 #ifdef HAVE_POLL_H
398 #include <poll.h>
399 #endif
400
401 #if defined(HAVE_RPC_RPC_H)
402 /*
403  * Check for AUTH_ERROR define conflict with rpc/rpc.h in prot.h.
404  */
405 #if defined(HAVE_SYS_SECURITY_H) && defined(HAVE_RPC_AUTH_ERROR_CONFLICT)
406 #undef AUTH_ERROR
407 #endif
408 /*
409  * HP-UX 11.X has TCP_NODELAY and TCP_MAXSEG defined in <netinet/tcp.h> which
410  * was included above.  However <rpc/rpc.h> includes <sys/xti.h> which defines
411  * them again without checking if they already exsist.  This generates
412  * two "Redefinition of macro" warnings for every single .c file that is
413  * compiled.
414  */
415 #if defined(HPUX) && defined(TCP_NODELAY)
416 #undef TCP_NODELAY
417 #endif
418 #if defined(HPUX) && defined(TCP_MAXSEG)
419 #undef TCP_MAXSEG
420 #endif
421 #include <rpc/rpc.h>
422 #endif
423
424 #if defined(HAVE_YP_GET_DEFAULT_DOMAIN) && defined(HAVE_SETNETGRENT) && defined(HAVE_ENDNETGRENT) && defined(HAVE_GETNETGRENT)
425 #define HAVE_NETGROUP 1
426 #endif
427
428 #if defined (HAVE_NETGROUP)
429 #if defined(HAVE_RPCSVC_YP_PROT_H)
430 /*
431  * HP-UX 11.X has TCP_NODELAY and TCP_MAXSEG defined in <netinet/tcp.h> which
432  * was included above.  However <rpc/rpc.h> includes <sys/xti.h> which defines
433  * them again without checking if they already exsist.  This generates
434  * two "Redefinition of macro" warnings for every single .c file that is
435  * compiled.
436  */
437 #if defined(HPUX) && defined(TCP_NODELAY)
438 #undef TCP_NODELAY
439 #endif
440 #if defined(HPUX) && defined(TCP_MAXSEG)
441 #undef TCP_MAXSEG
442 #endif
443 #include <rpcsvc/yp_prot.h>
444 #endif
445 #if defined(HAVE_RPCSVC_YPCLNT_H)
446 #include <rpcsvc/ypclnt.h>
447 #endif
448 #endif /* HAVE_NETGROUP */
449
450 #if defined(HAVE_SYS_IPC_H)
451 #include <sys/ipc.h>
452 #endif /* HAVE_SYS_IPC_H */
453
454 #if defined(HAVE_SYS_SHM_H)
455 #include <sys/shm.h>
456 #endif /* HAVE_SYS_SHM_H */
457
458 #ifdef HAVE_NATIVE_ICONV
459 #ifdef HAVE_ICONV
460 #include <iconv.h>
461 #endif
462 #ifdef HAVE_GICONV
463 #include <giconv.h>
464 #endif
465 #ifdef HAVE_BICONV
466 #include <biconv.h>
467 #endif
468 #endif
469
470 #if HAVE_KRB5_H
471 #include <krb5.h>
472 #else
473 #undef HAVE_KRB5
474 #endif
475
476 #if HAVE_LBER_H
477 #include <lber.h>
478 #ifndef LBER_USE_DER
479 #define LBER_USE_DER 0x01
480 #endif
481 #endif
482
483 #if HAVE_LDAP_H
484 #include <ldap.h>
485 #ifndef LDAP_CONST
486 #define LDAP_CONST const
487 #endif
488 #ifndef LDAP_OPT_SUCCESS
489 #define LDAP_OPT_SUCCESS 0
490 #endif
491 /* Solaris 8 and maybe other LDAP implementations spell this "..._INPROGRESS": */
492 #if defined(LDAP_SASL_BIND_INPROGRESS) && !defined(LDAP_SASL_BIND_IN_PROGRESS)
493 #define LDAP_SASL_BIND_IN_PROGRESS LDAP_SASL_BIND_INPROGRESS
494 #endif
495 /* Solaris 8 defines SSL_LDAP_PORT, not LDAPS_PORT and it only does so if
496    LDAP_SSL is defined - but SSL is not working. We just want the
497    port number! Let's just define LDAPS_PORT correct. */
498 #if !defined(LDAPS_PORT)
499 #define LDAPS_PORT 636
500 #endif
501 #else
502 #undef HAVE_LDAP
503 #endif
504
505 #if HAVE_GSSAPI_H
506 #include <gssapi.h>
507 #elif HAVE_GSSAPI_GSSAPI_H
508 #include <gssapi/gssapi.h>
509 #elif HAVE_GSSAPI_GSSAPI_GENERIC_H
510 #include <gssapi/gssapi_generic.h>
511 #endif
512
513 #if HAVE_COM_ERR_H
514 #include <com_err.h>
515 #endif
516
517 #if HAVE_SYS_ATTRIBUTES_H
518 #include <sys/attributes.h>
519 #endif
520
521 /* mutually exclusive (SuSE 8.2) */
522 #if HAVE_ATTR_XATTR_H
523 #include <attr/xattr.h>
524 #elif HAVE_SYS_XATTR_H
525 #include <sys/xattr.h>
526 #endif
527
528 #ifdef HAVE_SYS_EA_H
529 #include <sys/ea.h>
530 #endif
531
532 #ifdef HAVE_SYS_EXTATTR_H
533 #include <sys/extattr.h>
534 #endif
535
536 #ifdef HAVE_SYS_UIO_H
537 #include <sys/uio.h>
538 #endif
539
540 #if HAVE_LOCALE_H
541 #include <locale.h>
542 #endif
543
544 #if HAVE_LANGINFO_H
545 #include <langinfo.h>
546 #endif
547
548 #if defined(HAVE_AIO_H) && defined(WITH_AIO)
549 #include <aio.h>
550 #endif
551
552 /* skip valgrind headers on 64bit AMD boxes */
553 #ifndef HAVE_64BIT_LINUX
554 /* Special macros that are no-ops except when run under Valgrind on
555  * x86.  They've moved a little bit from valgrind 1.0.4 to 1.9.4 */
556 #if HAVE_VALGRIND_MEMCHECK_H
557         /* memcheck.h includes valgrind.h */
558 #include <valgrind/memcheck.h>
559 #elif HAVE_VALGRIND_H
560 #include <valgrind.h>
561 #endif
562 #endif
563
564 /* If we have --enable-developer and the valgrind header is present,
565  * then we're OK to use it.  Set a macro so this logic can be done only
566  * once. */
567 #if defined(DEVELOPER) && !defined(HAVE_64BIT_LINUX)
568 #if (HAVE_VALGRIND_H || HAVE_VALGRIND_VALGRIND_H)
569 #define VALGRIND
570 #endif
571 #endif
572
573
574 /* we support ADS if we want it and have krb5 and ldap libs */
575 #if defined(WITH_ADS) && defined(HAVE_KRB5) && defined(HAVE_LDAP)
576 #define HAVE_ADS
577 #endif
578
579 /*
580  * Define VOLATILE if needed.
581  */
582
583 #if defined(HAVE_VOLATILE)
584 #define VOLATILE volatile
585 #else
586 #define VOLATILE
587 #endif
588
589 /*
590  * Define additional missing types
591  */
592 #if defined(HAVE_SIG_ATOMIC_T_TYPE) && defined(AIX)
593 typedef sig_atomic_t SIG_ATOMIC_T;
594 #elif defined(HAVE_SIG_ATOMIC_T_TYPE) && !defined(AIX)
595 typedef sig_atomic_t VOLATILE SIG_ATOMIC_T;
596 #else
597 typedef int VOLATILE SIG_ATOMIC_T;
598 #endif
599
600 #ifndef HAVE_SOCKLEN_T_TYPE
601 #define HAVE_SOCKLEN_T_TYPE
602 typedef int socklen_t;
603 #endif
604
605
606 #ifndef uchar
607 #define uchar unsigned char
608 #endif
609
610 #ifdef HAVE_UNSIGNED_CHAR
611 #define schar signed char
612 #else
613 #define schar char
614 #endif
615
616 /*
617    Samba needs type definitions for int16, int32, uint16 and uint32.
618
619    Normally these are signed and unsigned 16 and 32 bit integers, but
620    they actually only need to be at least 16 and 32 bits
621    respectively. Thus if your word size is 8 bytes just defining them
622    as signed and unsigned int will work.
623 */
624
625 #ifndef uint8
626 #define uint8 unsigned char
627 #endif
628
629 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
630 #  if (SIZEOF_SHORT == 4)
631 #    define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
632 #  else /* SIZEOF_SHORT != 4 */
633 #    define int16 short
634 #  endif /* SIZEOF_SHORT != 4 */
635    /* needed to work around compile issue on HP-UX 11.x */
636 #  define _INT16        1
637 #endif
638
639 /*
640  * Note we duplicate the size tests in the unsigned 
641  * case as int16 may be a typedef from rpc/rpc.h
642  */
643
644 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
645 #if (SIZEOF_SHORT == 4)
646 #define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
647 #else /* SIZEOF_SHORT != 4 */
648 #define uint16 unsigned short
649 #endif /* SIZEOF_SHORT != 4 */
650 #endif
651
652 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
653 #  if (SIZEOF_INT == 4)
654 #    define int32 int
655 #  elif (SIZEOF_LONG == 4)
656 #    define int32 long
657 #  elif (SIZEOF_SHORT == 4)
658 #    define int32 short
659 #  else
660      /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
661 #    define int32 int
662 #  endif
663    /* needed to work around compile issue on HP-UX 11.x */
664 #  define _INT32        1
665 #endif
666
667 /*
668  * Note we duplicate the size tests in the unsigned 
669  * case as int32 may be a typedef from rpc/rpc.h
670  */
671
672 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
673 #if (SIZEOF_INT == 4)
674 #define uint32 unsigned int
675 #elif (SIZEOF_LONG == 4)
676 #define uint32 unsigned long
677 #elif (SIZEOF_SHORT == 4)
678 #define uint32 unsigned short
679 #else
680 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
681 #define uint32 unsigned
682 #endif
683 #endif
684
685 /*
686  * check for 8 byte long long
687  */
688
689 #if !defined(uint64)
690 #if (SIZEOF_LONG == 8)
691 #define uint64 unsigned long
692 #elif (SIZEOF_LONG_LONG == 8)
693 #define uint64 unsigned long long
694 #endif  /* don't lie.  If we don't have it, then don't use it */
695 #endif
696
697 #if !defined(int64)
698 #if (SIZEOF_LONG == 8)
699 #define int64 long
700 #elif (SIZEOF_LONG_LONG == 8)
701 #define int64 long long
702 #endif  /* don't lie.  If we don't have it, then don't use it */
703 #endif
704
705
706 /*
707  * Types for devices, inodes and offsets.
708  */
709
710 #ifndef SMB_DEV_T
711 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)
712 #    define SMB_DEV_T dev64_t
713 #  else
714 #    define SMB_DEV_T dev_t
715 #  endif
716 #endif
717
718 #ifndef LARGE_SMB_DEV_T
719 #  if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)) || (defined(SIZEOF_DEV_T) && (SIZEOF_DEV_T == 8))
720 #    define LARGE_SMB_DEV_T 1
721 #  endif
722 #endif
723
724 #ifdef LARGE_SMB_DEV_T
725 #define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32))
726 #define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(((SMB_BIG_UINT)(IVAL((p),(ofs))))| (((SMB_BIG_UINT)(IVAL((p),(ofs)+4))) << 32)))
727 #else 
728 #define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),v),SIVAL((p),(ofs)+4,0))
729 #define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(IVAL((p),(ofs))))
730 #endif
731
732 /*
733  * Setup the correctly sized inode type.
734  */
735
736 #ifndef SMB_INO_T
737 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)
738 #    define SMB_INO_T ino64_t
739 #  else
740 #    define SMB_INO_T ino_t
741 #  endif
742 #endif
743
744 #ifndef LARGE_SMB_INO_T
745 #  if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)) || (defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8))
746 #    define LARGE_SMB_INO_T 1
747 #  endif
748 #endif
749
750 #ifdef LARGE_SMB_INO_T
751 #define SINO_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32))
752 #define INO_T_VAL(p, ofs) ((SMB_INO_T)(((SMB_BIG_UINT)(IVAL(p,ofs)))| (((SMB_BIG_UINT)(IVAL(p,(ofs)+4))) << 32)))
753 #else 
754 #define SINO_T_VAL(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
755 #define INO_T_VAL(p, ofs) ((SMB_INO_T)(IVAL((p),(ofs))))
756 #endif
757
758 #ifndef SMB_OFF_T
759 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)
760 #    define SMB_OFF_T off64_t
761 #  else
762 #    define SMB_OFF_T off_t
763 #  endif
764 #endif
765
766 #if defined(HAVE_LONGLONG)
767 #define SMB_BIG_UINT unsigned long long
768 #define SMB_BIG_INT long long
769 #define SBIG_UINT(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
770 #else
771 #define SMB_BIG_UINT unsigned long
772 #define SMB_BIG_INT long
773 #define SBIG_UINT(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
774 #endif
775
776 #define SMB_BIG_UINT_BITS (sizeof(SMB_BIG_UINT)*8)
777
778 /* this should really be a 64 bit type if possible */
779 #define br_off SMB_BIG_UINT
780
781 #define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8)
782
783 /*
784  * Set the define that tells us if we can do 64 bit
785  * NT SMB calls.
786  */
787
788 #ifndef LARGE_SMB_OFF_T
789 #  if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8))
790 #    define LARGE_SMB_OFF_T 1
791 #  endif
792 #endif
793
794 #ifdef LARGE_SMB_OFF_T
795 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
796 #define SOFF_T_R(p, ofs, v) (SIVAL(p,(ofs)+4,(v)&0xFFFFFFFF), SIVAL(p,ofs,(v)>>32))
797 #define IVAL_TO_SMB_OFF_T(buf,off) ((SMB_OFF_T)(( ((SMB_BIG_UINT)(IVAL((buf),(off)))) & ((SMB_BIG_UINT)0xFFFFFFFF) )))
798 #define IVAL2_TO_SMB_BIG_UINT(buf,off) ( (((SMB_BIG_UINT)(IVAL((buf),(off)))) & ((SMB_BIG_UINT)0xFFFFFFFF)) | \
799                 (( ((SMB_BIG_UINT)(IVAL((buf),(off+4)))) & ((SMB_BIG_UINT)0xFFFFFFFF) ) << 32 ) )
800 #else 
801 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
802 #define SOFF_T_R(p, ofs, v) (SIVAL(p,(ofs)+4,v),SIVAL(p,ofs,0))
803 #define IVAL_TO_SMB_OFF_T(buf,off) ((SMB_OFF_T)(( ((uint32)(IVAL((buf),(off)))) & 0xFFFFFFFF )))
804 #define IVAL2_TO_SMB_BIG_UINT(buf,off) ( (((SMB_BIG_UINT)(IVAL((buf),(off)))) & ((SMB_BIG_UINT)0xFFFFFFFF)) | \
805                                 (( ((SMB_BIG_UINT)(IVAL((buf),(off+4)))) & ((SMB_BIG_UINT)0xFFFFFFFF) ) << 32 ) )
806 #endif
807
808 /*
809  * Type for stat structure.
810  */
811
812 #ifndef SMB_STRUCT_STAT
813 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STAT64) && defined(HAVE_OFF64_T)
814 #    define SMB_STRUCT_STAT struct stat64
815 #  else
816 #    define SMB_STRUCT_STAT struct stat
817 #  endif
818 #endif
819
820 /*
821  * Type for dirent structure.
822  */
823
824 #ifndef SMB_STRUCT_DIRENT
825 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIRENT64)
826 #    define SMB_STRUCT_DIRENT struct dirent64
827 #  else
828 #    define SMB_STRUCT_DIRENT struct dirent
829 #  endif
830 #endif
831
832 /*
833  * Type for DIR structure.
834  */
835
836 #ifndef SMB_STRUCT_DIR
837 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIR64)
838 #    define SMB_STRUCT_DIR DIR64
839 #  else
840 #    define SMB_STRUCT_DIR DIR
841 #  endif
842 #endif
843
844 /*
845  * Defines for 64 bit fcntl locks.
846  */
847
848 #ifndef SMB_STRUCT_FLOCK
849 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
850 #    define SMB_STRUCT_FLOCK struct flock64
851 #  else
852 #    define SMB_STRUCT_FLOCK struct flock
853 #  endif
854 #endif
855
856 #ifndef SMB_F_SETLKW
857 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
858 #    define SMB_F_SETLKW F_SETLKW64
859 #  else
860 #    define SMB_F_SETLKW F_SETLKW
861 #  endif
862 #endif
863
864 #ifndef SMB_F_SETLK
865 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
866 #    define SMB_F_SETLK F_SETLK64
867 #  else
868 #    define SMB_F_SETLK F_SETLK
869 #  endif
870 #endif
871
872 #ifndef SMB_F_GETLK
873 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
874 #    define SMB_F_GETLK F_GETLK64
875 #  else
876 #    define SMB_F_GETLK F_GETLK
877 #  endif
878 #endif
879
880 /*
881  * Type for aiocb structure.
882  */
883
884 #ifndef SMB_STRUCT_AIOCB
885 #  if defined(WITH_AIO)
886 #    if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64)
887 #      define SMB_STRUCT_AIOCB struct aiocb64
888 #    else
889 #      define SMB_STRUCT_AIOCB struct aiocb
890 #    endif
891 #  else
892 #    define SMB_STRUCT_AIOCB int /* AIO not being used but we still need the define.... */
893 #  endif
894 #endif
895
896 #ifndef HAVE_STRUCT_TIMESPEC
897 struct timespec {
898         time_t tv_sec;            /* Seconds.  */
899         long tv_nsec;           /* Nanoseconds.  */
900 };
901 #endif
902
903 #ifndef MIN
904 #define MIN(a,b) ((a)<(b)?(a):(b))
905 #endif
906
907 #ifndef MAX
908 #define MAX(a,b) ((a)>(b)?(a):(b))
909 #endif
910
911 #ifdef HAVE_BROKEN_GETGROUPS
912 #define GID_T int
913 #else
914 #define GID_T gid_t
915 #endif
916
917 #ifndef NGROUPS_MAX
918 #define NGROUPS_MAX 32 /* Guess... */
919 #endif
920
921 /* Our own pstrings and fstrings */
922 #include "pstring.h"
923
924 /* Lists, trees, caching, database... */
925 #include "xfile.h"
926 #include "intl.h"
927 #include "dlinklist.h"
928 #include "tdb.h"
929 #include "tdbutil.h"
930 #include "tdbback.h"
931
932 #include "talloc.h"
933 /* And a little extension. Abort on type mismatch */
934 #define talloc_get_type_abort(ptr, type) \
935         (type *)talloc_check_name_abort(ptr, #type)
936
937 #include "nt_status.h"
938 #include "ads.h"
939 #include "ads_dns.h"
940 #include "interfaces.h"
941 #include "trans2.h"
942 #include "nterr.h"
943 #include "ntioctl.h"
944 #include "messages.h"
945 #include "charset.h"
946 #include "dynconfig.h"
947 #include "util_getent.h"
948 #include "debugparse.h"
949 #include "version.h"
950 #include "privileges.h"
951 #include "locking.h"
952 #include "smb.h"
953 #include "ads_cldap.h"
954 #include "nameserv.h"
955 #include "secrets.h"
956 #include "byteorder.h"
957 #include "privileges.h"
958 #include "rpc_misc.h"
959 #include "rpc_dce.h"
960 #include "mapping.h"
961 #include "passdb.h"
962 #include "rpc_secdes.h"
963 #include "authdata.h"
964 #include "msdfs.h"
965 #include "rap.h"
966 #include "md5.h"
967 #include "hmacmd5.h"
968 #include "ntlmssp.h"
969 #include "auth.h"
970 #include "ntdomain.h"
971 #include "rpc_svcctl.h"
972 #include "rpc_ntsvcs.h"
973 #include "rpc_lsa.h"
974 #include "rpc_netlogon.h"
975 #include "reg_objects.h"
976 #include "rpc_reg.h"
977 #include "rpc_samr.h"
978 #include "rpc_srvsvc.h"
979 #include "rpc_wkssvc.h"
980 #include "rpc_spoolss.h"
981 #include "rpc_eventlog.h"
982 #include "rpc_ds.h"
983 #include "rpc_shutdown.h"
984 #include "rpc_perfcount.h"
985 #include "rpc_perfcount_defs.h"
986 #include "librpc/gen_ndr/echo.h"
987 #include "nt_printing.h"
988 #include "idmap.h"
989 #include "client.h"
990
991 #ifdef WITH_SMBWRAPPER
992 #include "smbw.h"
993 #endif
994
995 #include "session.h"
996 #include "asn_1.h"
997 #include "popt.h"
998 #include "mangle.h"
999 #include "module.h"
1000 #include "nsswitch/winbind_client.h"
1001 #include "spnego.h"
1002 #include "rpc_client.h"
1003 #include "event.h"
1004
1005 /*
1006  * Type for wide character dirent structure.
1007  * Only d_name is defined by POSIX.
1008  */
1009
1010 typedef struct smb_wdirent {
1011         wpstring        d_name;
1012 } SMB_STRUCT_WDIRENT;
1013
1014 /*
1015  * Type for wide character passwd structure.
1016  */
1017
1018 typedef struct smb_wpasswd {
1019         wfstring       pw_name;
1020         char           *pw_passwd;
1021         uid_t          pw_uid;
1022         gid_t          pw_gid;
1023         wpstring       pw_gecos;
1024         wpstring       pw_dir;
1025         wpstring       pw_shell;
1026 } SMB_STRUCT_WPASSWD;
1027
1028 /* used in net.c */
1029 struct functable {
1030         const char *funcname;
1031         int (*fn)(int argc, const char **argv);
1032 };
1033
1034 struct functable2 {
1035         const char *funcname;
1036         int (*fn)(int argc, const char **argv);
1037         const char *helptext;
1038 };
1039
1040 /* Defines for wisXXX functions. */
1041 #define UNI_UPPER    0x1
1042 #define UNI_LOWER    0x2
1043 #define UNI_DIGIT    0x4
1044 #define UNI_XDIGIT   0x8
1045 #define UNI_SPACE    0x10
1046
1047 #include "nsswitch/winbind_nss.h"
1048
1049 /* forward declaration from printing.h to get around 
1050    header file dependencies */
1051
1052 struct printjob;
1053
1054 struct smb_ldap_privates;
1055
1056 /* forward declarations from smbldap.c */
1057
1058 #include "smbldap.h"
1059
1060 #include "smb_ldap.h"
1061
1062 /*
1063  * Reasons for cache flush.
1064  */
1065
1066 enum flush_reason_enum {
1067     SEEK_FLUSH,
1068     READ_FLUSH,
1069     WRITE_FLUSH,
1070     READRAW_FLUSH,
1071     OPLOCK_RELEASE_FLUSH,
1072     CLOSE_FLUSH,
1073     SYNC_FLUSH,
1074     SIZECHANGE_FLUSH,
1075     /* NUM_FLUSH_REASONS must remain the last value in the enumeration. */
1076     NUM_FLUSH_REASONS};
1077
1078 /***** automatically generated prototypes *****/
1079 #ifndef NO_PROTO_H
1080 #include "proto.h"
1081 #endif
1082
1083 #ifdef HAVE_LDAP
1084 #include "ads_protos.h"
1085 #endif
1086
1087 /* We need this after proto.h to reference GetTimeOfDay(). */
1088 #include "smbprofile.h"
1089
1090 /* String routines */
1091
1092 #include "srvstr.h"
1093 #include "safe_string.h"
1094
1095 #ifdef __COMPAR_FN_T
1096 #define QSORT_CAST (__compar_fn_t)
1097 #endif
1098
1099 #ifndef QSORT_CAST
1100 #define QSORT_CAST (int (*)(const void *, const void *))
1101 #endif
1102
1103 #ifndef DEFAULT_PRINTING
1104 #ifdef HAVE_CUPS
1105 #define DEFAULT_PRINTING PRINT_CUPS
1106 #define PRINTCAP_NAME "cups"
1107 #elif defined(SYSV)
1108 #define DEFAULT_PRINTING PRINT_SYSV
1109 #define PRINTCAP_NAME "lpstat"
1110 #else
1111 #define DEFAULT_PRINTING PRINT_BSD
1112 #define PRINTCAP_NAME "/etc/printcap"
1113 #endif
1114 #endif
1115
1116 #ifndef PRINTCAP_NAME
1117 #define PRINTCAP_NAME "/etc/printcap"
1118 #endif
1119
1120 #ifndef SIGCLD
1121 #define SIGCLD SIGCHLD
1122 #endif
1123
1124 #ifndef SIGRTMIN
1125 #define SIGRTMIN 32
1126 #endif
1127
1128 #ifndef MAP_FILE
1129 #define MAP_FILE 0
1130 #endif
1131
1132 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
1133 #define OSF1_ENH_SEC 1
1134 #endif
1135
1136 #ifndef ALLOW_CHANGE_PASSWORD
1137 #if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
1138 #define ALLOW_CHANGE_PASSWORD 1
1139 #endif
1140 #endif
1141
1142 /* what is the longest significant password available on your system? 
1143  Knowing this speeds up password searches a lot */
1144 #ifndef PASSWORD_LENGTH
1145 #define PASSWORD_LENGTH 8
1146 #endif
1147
1148 #ifndef HAVE_PIPE
1149 #define SYNC_DNS 1
1150 #endif
1151
1152 #ifndef SEEK_SET
1153 #define SEEK_SET 0
1154 #endif
1155
1156 #ifndef INADDR_LOOPBACK
1157 #define INADDR_LOOPBACK 0x7f000001
1158 #endif
1159
1160 #ifndef INADDR_NONE
1161 #define INADDR_NONE 0xffffffff
1162 #endif
1163
1164 #ifndef HAVE_CRYPT
1165 #define crypt ufc_crypt
1166 #endif
1167
1168 #ifndef O_ACCMODE
1169 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
1170 #endif
1171
1172 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
1173 #define ULTRIX_AUTH 1
1174 #endif
1175
1176 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL))
1177 /* stupid glibc */
1178 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
1179 #endif
1180 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESGID_DECL))
1181 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
1182 #endif
1183
1184 /*
1185  * Some older systems seem not to have MAXHOSTNAMELEN
1186  * defined.
1187  */
1188 #ifndef MAXHOSTNAMELEN
1189 #define MAXHOSTNAMELEN 254
1190 #endif
1191
1192 /* yuck, I'd like a better way of doing this */
1193 #define DIRP_SIZE (256 + 32)
1194
1195 /*
1196  * glibc on linux doesn't seem to have MSG_WAITALL
1197  * defined. I think the kernel has it though..
1198  */
1199
1200 #ifndef MSG_WAITALL
1201 #define MSG_WAITALL 0
1202 #endif
1203
1204 /* default socket options. Dave Miller thinks we should default to TCP_NODELAY
1205    given the socket IO pattern that Samba uses */
1206 #ifdef TCP_NODELAY
1207 #define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
1208 #else
1209 #define DEFAULT_SOCKET_OPTIONS ""
1210 #endif
1211
1212 /* Load header file for dynamic linking stuff */
1213
1214 #ifdef HAVE_DLFCN_H
1215 #include <dlfcn.h>
1216 #endif
1217
1218 /* dmalloc -- free heap debugger (dmalloc.org).  This should be near
1219  * the *bottom* of include files so as not to conflict. */
1220 #ifdef ENABLE_DMALLOC
1221 #  include <dmalloc.h>
1222 #endif
1223
1224
1225 /* Some POSIX definitions for those without */
1226  
1227 #ifndef S_IFDIR
1228 #define S_IFDIR         0x4000
1229 #endif
1230 #ifndef S_ISDIR
1231 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
1232 #endif
1233 #ifndef S_IRWXU
1234 #define S_IRWXU 00700           /* read, write, execute: owner */
1235 #endif
1236 #ifndef S_IRUSR
1237 #define S_IRUSR 00400           /* read permission: owner */
1238 #endif
1239 #ifndef S_IWUSR
1240 #define S_IWUSR 00200           /* write permission: owner */
1241 #endif
1242 #ifndef S_IXUSR
1243 #define S_IXUSR 00100           /* execute permission: owner */
1244 #endif
1245 #ifndef S_IRWXG
1246 #define S_IRWXG 00070           /* read, write, execute: group */
1247 #endif
1248 #ifndef S_IRGRP
1249 #define S_IRGRP 00040           /* read permission: group */
1250 #endif
1251 #ifndef S_IWGRP
1252 #define S_IWGRP 00020           /* write permission: group */
1253 #endif
1254 #ifndef S_IXGRP
1255 #define S_IXGRP 00010           /* execute permission: group */
1256 #endif
1257 #ifndef S_IRWXO
1258 #define S_IRWXO 00007           /* read, write, execute: other */
1259 #endif
1260 #ifndef S_IROTH
1261 #define S_IROTH 00004           /* read permission: other */
1262 #endif
1263 #ifndef S_IWOTH
1264 #define S_IWOTH 00002           /* write permission: other */
1265 #endif
1266 #ifndef S_IXOTH
1267 #define S_IXOTH 00001           /* execute permission: other */
1268 #endif
1269
1270 /* For sys_adminlog(). */
1271 #ifndef LOG_EMERG
1272 #define LOG_EMERG       0       /* system is unusable */
1273 #endif
1274
1275 #ifndef LOG_ALERT
1276 #define LOG_ALERT       1       /* action must be taken immediately */
1277 #endif
1278
1279 #ifndef LOG_CRIT
1280 #define LOG_CRIT        2       /* critical conditions */
1281 #endif
1282
1283 #ifndef LOG_ERR
1284 #define LOG_ERR         3       /* error conditions */
1285 #endif
1286
1287 #ifndef LOG_WARNING
1288 #define LOG_WARNING     4       /* warning conditions */
1289 #endif
1290
1291 #ifndef LOG_NOTICE
1292 #define LOG_NOTICE      5       /* normal but significant condition */
1293 #endif
1294
1295 #ifndef LOG_INFO
1296 #define LOG_INFO        6       /* informational */
1297 #endif
1298
1299 #ifndef LOG_DEBUG
1300 #define LOG_DEBUG       7       /* debug-level messages */
1301 #endif
1302
1303 #if HAVE_KERNEL_SHARE_MODES
1304 #ifndef LOCK_MAND 
1305 #define LOCK_MAND       32      /* This is a mandatory flock */
1306 #define LOCK_READ       64      /* ... Which allows concurrent read operations */
1307 #define LOCK_WRITE      128     /* ... Which allows concurrent write operations */
1308 #define LOCK_RW         192     /* ... Which allows concurrent read & write ops */
1309 #endif
1310 #endif
1311
1312 extern int DEBUGLEVEL;
1313
1314 #define MAX_SEC_CTX_DEPTH 8    /* Maximum number of security contexts */
1315
1316
1317 #ifdef GLIBC_HACK_FCNTL64
1318 /* this is a gross hack. 64 bit locking is completely screwed up on
1319    i386 Linux in glibc 2.1.95 (which ships with RedHat 7.0). This hack
1320    "fixes" the problem with the current 2.4.0test kernels 
1321 */
1322 #define fcntl fcntl64
1323 #undef F_SETLKW 
1324 #undef F_SETLK 
1325 #define F_SETLK 13
1326 #define F_SETLKW 14
1327 #endif
1328
1329
1330 /* Needed for sys_dlopen/sys_dlsym/sys_dlclose */
1331 #ifndef RTLD_GLOBAL
1332 #define RTLD_GLOBAL 0
1333 #endif
1334
1335 #ifndef RTLD_LAZY
1336 #define RTLD_LAZY 0
1337 #endif
1338
1339 #ifndef RTLD_NOW
1340 #define RTLD_NOW 0
1341 #endif
1342
1343 /* needed for some systems without iconv. Doesn't really matter
1344    what error code we use */
1345 #ifndef EILSEQ
1346 #define EILSEQ EIO
1347 #endif
1348
1349 /* add varargs prototypes with printf checking */
1350 /*PRINTFLIKE2 */
1351 int fdprintf(int , const char *, ...) PRINTF_ATTRIBUTE(2,3);
1352 /*PRINTFLIKE1 */
1353 int d_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2);
1354 /*PRINTFLIKE2 */
1355 int d_fprintf(FILE *f, const char *, ...) PRINTF_ATTRIBUTE(2,3);
1356
1357 /* PRINTFLIKE2 */
1358 void sys_adminlog(int priority, const char *format_str, ...) PRINTF_ATTRIBUTE(2,3);
1359
1360 /* PRINTFLIKE2 */
1361 int pstr_sprintf(pstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1362 /* PRINTFLIKE2 */
1363 int fstr_sprintf(fstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1364
1365 int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1366
1367 int smb_xvasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1368
1369 /* we used to use these fns, but now we have good replacements
1370    for snprintf and vsnprintf */
1371 #define slprintf snprintf
1372 #define vslprintf vsnprintf
1373
1374 /* we need to use __va_copy() on some platforms */
1375 #ifdef HAVE_VA_COPY
1376 #define VA_COPY(dest, src) va_copy(dest, src)
1377 #else
1378 #ifdef HAVE___VA_COPY
1379 #define VA_COPY(dest, src) __va_copy(dest, src)
1380 #else
1381 #define VA_COPY(dest, src) (dest) = (src)
1382 #endif
1383 #endif
1384
1385 /*
1386  * Veritas File System.  Often in addition to native.
1387  * Quotas different.
1388  */
1389 #if defined(HAVE_SYS_FS_VX_QUOTA_H)
1390 #define VXFS_QUOTA
1391 #endif
1392
1393 #if defined(HAVE_KRB5)
1394
1395 krb5_error_code smb_krb5_parse_name(krb5_context context,
1396                                 const char *name, /* in unix charset */
1397                                 krb5_principal *principal);
1398
1399 krb5_error_code smb_krb5_unparse_name(krb5_context context,
1400                                 krb5_const_principal principal,
1401                                 char **unix_name);
1402
1403 #ifndef HAVE_KRB5_SET_REAL_TIME
1404 krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds);
1405 #endif
1406
1407 #ifndef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES
1408 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
1409 #endif
1410
1411 #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
1412 krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
1413 #endif
1414
1415 #ifndef HAVE_KRB5_FREE_UNPARSED_NAME
1416 void krb5_free_unparsed_name(krb5_context ctx, char *val);
1417 #endif
1418
1419 /* Samba wrapper function for krb5 functionality. */
1420 void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr);
1421 int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
1422 int create_kerberos_key_from_string_direct(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
1423 BOOL get_auth_data_from_tkt(TALLOC_CTX *mem_ctx, DATA_BLOB *auth_data, krb5_ticket *tkt);
1424 krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt);
1425 krb5_error_code krb5_locate_kdc(krb5_context ctx, const krb5_data *realm, struct sockaddr **addr_pp, int *naddrs, int get_masters);
1426 krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes);
1427 void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes);
1428 BOOL get_krb5_smb_session_key(krb5_context context, krb5_auth_context auth_context, DATA_BLOB *session_key, BOOL remote);
1429 krb5_error_code smb_krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *kt_entry);
1430 krb5_principal kerberos_fetch_salt_princ_for_host_princ(krb5_context context, krb5_principal host_princ, int enctype);
1431 void kerberos_set_creds_enctype(krb5_creds *pcreds, int enctype);
1432 BOOL kerberos_compatible_enctypes(krb5_context context, krb5_enctype enctype1, krb5_enctype enctype2);
1433 void kerberos_free_data_contents(krb5_context context, krb5_data *pdata);
1434 NTSTATUS decode_pac_data(TALLOC_CTX *mem_ctx,
1435                          DATA_BLOB *pac_data_blob,
1436                          krb5_context context, 
1437                          krb5_keyblock *service_keyblock,
1438                          krb5_const_principal client_principal,
1439                          time_t tgs_authtime,
1440                          PAC_DATA **pac_data);
1441 void smb_krb5_checksum_from_pac_sig(krb5_checksum *cksum, 
1442                                     PAC_SIGNATURE_DATA *sig);
1443 krb5_error_code smb_krb5_verify_checksum(krb5_context context,
1444                                          krb5_keyblock *keyblock,
1445                                          krb5_keyusage usage,
1446                                          krb5_checksum *cksum,
1447                                          uint8 *data,
1448                                          size_t length);
1449 time_t get_authtime_from_tkt(krb5_ticket *tkt);
1450 void smb_krb5_free_ap_req(krb5_context context, 
1451                           krb5_ap_req *ap_req);
1452 krb5_error_code smb_krb5_get_keyinfo_from_ap_req(krb5_context context, 
1453                                                  const krb5_data *inbuf, 
1454                                                  krb5_kvno *kvno, 
1455                                                  krb5_enctype *enctype);
1456 krb5_error_code krb5_rd_req_return_keyblock_from_keytab(krb5_context context,
1457                                                         krb5_auth_context *auth_context,
1458                                                         const krb5_data *inbuf,
1459                                                         krb5_const_principal server,
1460                                                         krb5_keytab keytab,
1461                                                         krb5_flags *ap_req_options,
1462                                                         krb5_ticket **ticket, 
1463                                                         krb5_keyblock **keyblock);
1464 krb5_error_code smb_krb5_parse_name_norealm(krb5_context context, 
1465                                             const char *name, 
1466                                             krb5_principal *principal);
1467 BOOL smb_krb5_principal_compare_any_realm(krb5_context context, 
1468                                           krb5_const_principal princ1, 
1469                                           krb5_const_principal princ2);
1470 int cli_krb5_get_ticket(const char *principal, time_t time_offset, 
1471                         DATA_BLOB *ticket, DATA_BLOB *session_key_krb5, uint32 extra_ap_opts, const char *ccname);
1472 PAC_LOGON_INFO *get_logon_info_from_pac(PAC_DATA *pac_data);
1473 krb5_error_code smb_krb5_renew_ticket(const char *ccache_string, const char *client_string, const char *service_string, time_t *new_start_time);
1474 krb5_error_code kpasswd_err_to_krb5_err(krb5_error_code res_code);
1475 krb5_error_code smb_krb5_gen_netbios_krb5_address(smb_krb5_addresses **kerb_addr);
1476 krb5_error_code smb_krb5_free_addresses(krb5_context context, smb_krb5_addresses *addr);
1477 NTSTATUS krb5_to_nt_status(krb5_error_code kerberos_error);
1478 krb5_error_code nt_status_to_krb5(NTSTATUS nt_status);
1479 void smb_krb5_free_error(krb5_context context, krb5_error *krberror);
1480 krb5_error_code handle_krberror_packet(krb5_context context,
1481                                          krb5_data *packet);
1482 #endif /* HAVE_KRB5 */
1483
1484
1485 #ifdef HAVE_LDAP
1486
1487 /* function declarations not included in proto.h */
1488 LDAP *ldap_open_with_timeout(const char *server, int port, unsigned int to);
1489
1490 #endif  /* HAVE_LDAP */
1491
1492
1493 /* TRUE and FALSE are part of the C99 standard and gcc, but
1494    unfortunately many vendor compilers don't support them.  Use True
1495    and False instead. */
1496
1497 #ifdef TRUE
1498 #undef TRUE
1499 #endif
1500 #define TRUE __ERROR__XX__DONT_USE_TRUE
1501
1502 #ifdef FALSE
1503 #undef FALSE
1504 #endif
1505 #define FALSE __ERROR__XX__DONT_USE_FALSE
1506
1507 /* If we have blacklisted mmap() try to avoid using it accidentally by
1508    undefining the HAVE_MMAP symbol. */
1509
1510 #ifdef MMAP_BLACKLIST
1511 #undef HAVE_MMAP
1512 #endif
1513
1514 #define CONST_DISCARD(type, ptr)      ((type) ((void *) (ptr)))
1515 #define CONST_ADD(type, ptr)          ((type) ((const void *) (ptr)))
1516
1517 #ifndef NORETURN_ATTRIBUTE
1518 #if (__GNUC__ >= 3)
1519 #define NORETURN_ATTRIBUTE __attribute__ ((noreturn))
1520 #else
1521 #define NORETURN_ATTRIBUTE
1522 #endif
1523 #endif
1524
1525 void smb_panic( const char *why ) NORETURN_ATTRIBUTE ;
1526 void dump_core(void) NORETURN_ATTRIBUTE ;
1527 void exit_server(const char *const reason) NORETURN_ATTRIBUTE ;
1528 void exit_server_cleanly(const char *const reason) NORETURN_ATTRIBUTE ;
1529 void exit_server_fault(void) NORETURN_ATTRIBUTE ;
1530
1531 #endif /* _INCLUDES_H */