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