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