r18640: move to socket_wrapper to lib/socket_wrapper/
[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 "lib/socket_wrapper/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_shutdown.h"
1010 #include "rpc_perfcount.h"
1011 #include "rpc_perfcount_defs.h"
1012 #include "librpc/gen_ndr/echo.h"
1013 #include "nt_printing.h"
1014 #include "idmap.h"
1015 #include "client.h"
1016
1017 #ifdef WITH_SMBWRAPPER
1018 #include "smbw.h"
1019 #endif
1020
1021 #include "session.h"
1022 #include "asn_1.h"
1023 #include "popt.h"
1024 #include "mangle.h"
1025 #include "module.h"
1026 #include "nsswitch/winbind_client.h"
1027 #include "spnego.h"
1028 #include "rpc_client.h"
1029 #include "event.h"
1030
1031 /*
1032  * Type for wide character dirent structure.
1033  * Only d_name is defined by POSIX.
1034  */
1035
1036 typedef struct smb_wdirent {
1037         wpstring        d_name;
1038 } SMB_STRUCT_WDIRENT;
1039
1040 /*
1041  * Type for wide character passwd structure.
1042  */
1043
1044 typedef struct smb_wpasswd {
1045         wfstring       pw_name;
1046         char           *pw_passwd;
1047         uid_t          pw_uid;
1048         gid_t          pw_gid;
1049         wpstring       pw_gecos;
1050         wpstring       pw_dir;
1051         wpstring       pw_shell;
1052 } SMB_STRUCT_WPASSWD;
1053
1054 /* used in net.c */
1055 struct functable {
1056         const char *funcname;
1057         int (*fn)(int argc, const char **argv);
1058 };
1059
1060 struct functable2 {
1061         const char *funcname;
1062         int (*fn)(int argc, const char **argv);
1063         const char *helptext;
1064 };
1065
1066 /* Defines for wisXXX functions. */
1067 #define UNI_UPPER    0x1
1068 #define UNI_LOWER    0x2
1069 #define UNI_DIGIT    0x4
1070 #define UNI_XDIGIT   0x8
1071 #define UNI_SPACE    0x10
1072
1073 #include "nsswitch/winbind_nss.h"
1074
1075 /* forward declaration from printing.h to get around 
1076    header file dependencies */
1077
1078 struct printjob;
1079
1080 struct smb_ldap_privates;
1081
1082 /* forward declarations from smbldap.c */
1083
1084 #include "smbldap.h"
1085
1086 #include "smb_ldap.h"
1087
1088 /*
1089  * Reasons for cache flush.
1090  */
1091
1092 enum flush_reason_enum {
1093     SEEK_FLUSH,
1094     READ_FLUSH,
1095     WRITE_FLUSH,
1096     READRAW_FLUSH,
1097     OPLOCK_RELEASE_FLUSH,
1098     CLOSE_FLUSH,
1099     SYNC_FLUSH,
1100     SIZECHANGE_FLUSH,
1101     /* NUM_FLUSH_REASONS must remain the last value in the enumeration. */
1102     NUM_FLUSH_REASONS};
1103
1104 #ifndef HAVE_COMPARISON_FN_T
1105 typedef int (*comparison_fn_t)(const void *, const void *);
1106 #endif
1107
1108 /***** automatically generated prototypes *****/
1109 #ifndef NO_PROTO_H
1110 #include "proto.h"
1111 #endif
1112
1113 #ifdef HAVE_LDAP
1114 #include "ads_protos.h"
1115 #endif
1116
1117 /* We need this after proto.h to reference GetTimeOfDay(). */
1118 #include "smbprofile.h"
1119
1120 /* String routines */
1121
1122 #include "srvstr.h"
1123 #include "safe_string.h"
1124
1125 #ifdef __COMPAR_FN_T
1126 #define QSORT_CAST (__compar_fn_t)
1127 #endif
1128
1129 #ifndef QSORT_CAST
1130 #define QSORT_CAST (int (*)(const void *, const void *))
1131 #endif
1132
1133 #ifndef DEFAULT_PRINTING
1134 #ifdef HAVE_CUPS
1135 #define DEFAULT_PRINTING PRINT_CUPS
1136 #define PRINTCAP_NAME "cups"
1137 #elif defined(SYSV)
1138 #define DEFAULT_PRINTING PRINT_SYSV
1139 #define PRINTCAP_NAME "lpstat"
1140 #else
1141 #define DEFAULT_PRINTING PRINT_BSD
1142 #define PRINTCAP_NAME "/etc/printcap"
1143 #endif
1144 #endif
1145
1146 #ifndef PRINTCAP_NAME
1147 #define PRINTCAP_NAME "/etc/printcap"
1148 #endif
1149
1150 #ifndef SIGCLD
1151 #define SIGCLD SIGCHLD
1152 #endif
1153
1154 #ifndef SIGRTMIN
1155 #define SIGRTMIN 32
1156 #endif
1157
1158 #ifndef MAP_FILE
1159 #define MAP_FILE 0
1160 #endif
1161
1162 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
1163 #define OSF1_ENH_SEC 1
1164 #endif
1165
1166 #ifndef ALLOW_CHANGE_PASSWORD
1167 #if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
1168 #define ALLOW_CHANGE_PASSWORD 1
1169 #endif
1170 #endif
1171
1172 /* what is the longest significant password available on your system? 
1173  Knowing this speeds up password searches a lot */
1174 #ifndef PASSWORD_LENGTH
1175 #define PASSWORD_LENGTH 8
1176 #endif
1177
1178 #ifdef REPLACE_INET_NTOA
1179 #define inet_ntoa rep_inet_ntoa
1180 #endif
1181
1182 #ifndef HAVE_PIPE
1183 #define SYNC_DNS 1
1184 #endif
1185
1186 #ifndef SEEK_SET
1187 #define SEEK_SET 0
1188 #endif
1189
1190 #ifndef INADDR_LOOPBACK
1191 #define INADDR_LOOPBACK 0x7f000001
1192 #endif
1193
1194 #ifndef INADDR_NONE
1195 #define INADDR_NONE 0xffffffff
1196 #endif
1197
1198 #ifndef HAVE_CRYPT
1199 #define crypt ufc_crypt
1200 #endif
1201
1202 #ifndef O_ACCMODE
1203 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
1204 #endif
1205
1206 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
1207 #define ULTRIX_AUTH 1
1208 #endif
1209
1210 #ifndef HAVE_STRDUP
1211 char *strdup(const char *s);
1212 #endif
1213
1214 #ifndef HAVE_STRNDUP
1215 char *strndup(const char *s, size_t size);
1216 #endif
1217
1218 #ifndef HAVE_MEMMOVE
1219 void *memmove(void *dest,const void *src,int size);
1220 #endif
1221
1222 #ifndef HAVE_INITGROUPS
1223 int initgroups(char *name,gid_t id);
1224 #endif
1225
1226 #ifndef HAVE_RENAME
1227 int rename(const char *zfrom, const char *zto);
1228 #endif
1229
1230 #ifndef HAVE_MKTIME
1231 time_t mktime(struct tm *t);
1232 #endif
1233
1234 #ifndef HAVE_STRLCPY
1235 size_t strlcpy(char *d, const char *s, size_t bufsize);
1236 #endif
1237
1238 #ifndef HAVE_STRLCAT
1239 size_t strlcat(char *d, const char *s, size_t bufsize);
1240 #endif
1241
1242 #ifndef HAVE_FTRUNCATE
1243 int ftruncate(int f,long l);
1244 #endif
1245
1246 #ifndef HAVE_STRNDUP
1247 char *strndup(const char *s, size_t n);
1248 #endif
1249
1250 #ifndef HAVE_STRNLEN
1251 size_t strnlen(const char *s, size_t n);
1252 #endif
1253
1254 #ifndef HAVE_STRTOUL
1255 unsigned long strtoul(const char *nptr, char **endptr, int base);
1256 #endif
1257
1258 #ifndef HAVE_SETENV
1259 int setenv(const char *name, const char *value, int overwrite); 
1260 #endif
1261
1262 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL))
1263 /* stupid glibc */
1264 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
1265 #endif
1266 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESGID_DECL))
1267 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
1268 #endif
1269 #ifndef HAVE_VASPRINTF_DECL
1270 int vasprintf(char **ptr, const char *format, va_list ap);
1271 #endif
1272
1273 #ifdef REPLACE_GETPASS
1274 #define getpass(prompt) getsmbpass((prompt))
1275 #endif
1276
1277 /*
1278  * Some older systems seem not to have MAXHOSTNAMELEN
1279  * defined.
1280  */
1281 #ifndef MAXHOSTNAMELEN
1282 #define MAXHOSTNAMELEN 254
1283 #endif
1284
1285 /* yuck, I'd like a better way of doing this */
1286 #define DIRP_SIZE (256 + 32)
1287
1288 /*
1289  * glibc on linux doesn't seem to have MSG_WAITALL
1290  * defined. I think the kernel has it though..
1291  */
1292
1293 #ifndef MSG_WAITALL
1294 #define MSG_WAITALL 0
1295 #endif
1296
1297 /* default socket options. Dave Miller thinks we should default to TCP_NODELAY
1298    given the socket IO pattern that Samba uses */
1299 #ifdef TCP_NODELAY
1300 #define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
1301 #else
1302 #define DEFAULT_SOCKET_OPTIONS ""
1303 #endif
1304
1305 /* Load header file for dynamic linking stuff */
1306
1307 #ifdef HAVE_DLFCN_H
1308 #include <dlfcn.h>
1309 #endif
1310
1311 /* dmalloc -- free heap debugger (dmalloc.org).  This should be near
1312  * the *bottom* of include files so as not to conflict. */
1313 #ifdef ENABLE_DMALLOC
1314 #  include <dmalloc.h>
1315 #endif
1316
1317
1318 /* Some POSIX definitions for those without */
1319  
1320 #ifndef S_IFDIR
1321 #define S_IFDIR         0x4000
1322 #endif
1323 #ifndef S_ISDIR
1324 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
1325 #endif
1326 #ifndef S_IRWXU
1327 #define S_IRWXU 00700           /* read, write, execute: owner */
1328 #endif
1329 #ifndef S_IRUSR
1330 #define S_IRUSR 00400           /* read permission: owner */
1331 #endif
1332 #ifndef S_IWUSR
1333 #define S_IWUSR 00200           /* write permission: owner */
1334 #endif
1335 #ifndef S_IXUSR
1336 #define S_IXUSR 00100           /* execute permission: owner */
1337 #endif
1338 #ifndef S_IRWXG
1339 #define S_IRWXG 00070           /* read, write, execute: group */
1340 #endif
1341 #ifndef S_IRGRP
1342 #define S_IRGRP 00040           /* read permission: group */
1343 #endif
1344 #ifndef S_IWGRP
1345 #define S_IWGRP 00020           /* write permission: group */
1346 #endif
1347 #ifndef S_IXGRP
1348 #define S_IXGRP 00010           /* execute permission: group */
1349 #endif
1350 #ifndef S_IRWXO
1351 #define S_IRWXO 00007           /* read, write, execute: other */
1352 #endif
1353 #ifndef S_IROTH
1354 #define S_IROTH 00004           /* read permission: other */
1355 #endif
1356 #ifndef S_IWOTH
1357 #define S_IWOTH 00002           /* write permission: other */
1358 #endif
1359 #ifndef S_IXOTH
1360 #define S_IXOTH 00001           /* execute permission: other */
1361 #endif
1362
1363 /* For sys_adminlog(). */
1364 #ifndef LOG_EMERG
1365 #define LOG_EMERG       0       /* system is unusable */
1366 #endif
1367
1368 #ifndef LOG_ALERT
1369 #define LOG_ALERT       1       /* action must be taken immediately */
1370 #endif
1371
1372 #ifndef LOG_CRIT
1373 #define LOG_CRIT        2       /* critical conditions */
1374 #endif
1375
1376 #ifndef LOG_ERR
1377 #define LOG_ERR         3       /* error conditions */
1378 #endif
1379
1380 #ifndef LOG_WARNING
1381 #define LOG_WARNING     4       /* warning conditions */
1382 #endif
1383
1384 #ifndef LOG_NOTICE
1385 #define LOG_NOTICE      5       /* normal but significant condition */
1386 #endif
1387
1388 #ifndef LOG_INFO
1389 #define LOG_INFO        6       /* informational */
1390 #endif
1391
1392 #ifndef LOG_DEBUG
1393 #define LOG_DEBUG       7       /* debug-level messages */
1394 #endif
1395
1396 #if HAVE_KERNEL_SHARE_MODES
1397 #ifndef LOCK_MAND 
1398 #define LOCK_MAND       32      /* This is a mandatory flock */
1399 #define LOCK_READ       64      /* ... Which allows concurrent read operations */
1400 #define LOCK_WRITE      128     /* ... Which allows concurrent write operations */
1401 #define LOCK_RW         192     /* ... Which allows concurrent read & write ops */
1402 #endif
1403 #endif
1404
1405 extern int DEBUGLEVEL;
1406
1407 #define MAX_SEC_CTX_DEPTH 8    /* Maximum number of security contexts */
1408
1409
1410 #ifdef GLIBC_HACK_FCNTL64
1411 /* this is a gross hack. 64 bit locking is completely screwed up on
1412    i386 Linux in glibc 2.1.95 (which ships with RedHat 7.0). This hack
1413    "fixes" the problem with the current 2.4.0test kernels 
1414 */
1415 #define fcntl fcntl64
1416 #undef F_SETLKW 
1417 #undef F_SETLK 
1418 #define F_SETLK 13
1419 #define F_SETLKW 14
1420 #endif
1421
1422
1423 /* Needed for sys_dlopen/sys_dlsym/sys_dlclose */
1424 #ifndef RTLD_GLOBAL
1425 #define RTLD_GLOBAL 0
1426 #endif
1427
1428 #ifndef RTLD_LAZY
1429 #define RTLD_LAZY 0
1430 #endif
1431
1432 #ifndef RTLD_NOW
1433 #define RTLD_NOW 0
1434 #endif
1435
1436 /* needed for some systems without iconv. Doesn't really matter
1437    what error code we use */
1438 #ifndef EILSEQ
1439 #define EILSEQ EIO
1440 #endif
1441
1442 /* add varargs prototypes with printf checking */
1443 /*PRINTFLIKE2 */
1444 int fdprintf(int , const char *, ...) PRINTF_ATTRIBUTE(2,3);
1445 /*PRINTFLIKE1 */
1446 int d_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2);
1447 /*PRINTFLIKE2 */
1448 int d_fprintf(FILE *f, const char *, ...) PRINTF_ATTRIBUTE(2,3);
1449 #ifndef HAVE_SNPRINTF_DECL
1450 /*PRINTFLIKE3 */
1451 int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
1452 #endif
1453 #ifndef HAVE_ASPRINTF_DECL
1454 /*PRINTFLIKE2 */
1455 int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
1456 #endif
1457
1458 /* Fix prototype problem with non-C99 compliant snprintf implementations, esp
1459    HPUX 11.  Don't change the sense of this #if statement.  Read the comments
1460    in lib/snprint.c if you think you need to.  See also bugzilla bug 174. */
1461
1462 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
1463 #define snprintf smb_snprintf
1464 #define vsnprintf smb_vsnprintf
1465
1466 /* PRINTFLIKE3 */
1467 int smb_snprintf(char *str,size_t count,const char *fmt,...);
1468 int smb_vsnprintf (char *str, size_t count, const char *fmt, va_list args);
1469
1470 #endif
1471
1472 /* PRINTFLIKE2 */
1473 void sys_adminlog(int priority, const char *format_str, ...) PRINTF_ATTRIBUTE(2,3);
1474
1475 /* PRINTFLIKE2 */
1476 int pstr_sprintf(pstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1477 /* PRINTFLIKE2 */
1478 int fstr_sprintf(fstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1479
1480 int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1481
1482 int smb_xvasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1483
1484 /* we used to use these fns, but now we have good replacements
1485    for snprintf and vsnprintf */
1486 #define slprintf snprintf
1487 #define vslprintf vsnprintf
1488
1489 /* we need to use __va_copy() on some platforms */
1490 #ifdef HAVE_VA_COPY
1491 #define VA_COPY(dest, src) va_copy(dest, src)
1492 #else
1493 #ifdef HAVE___VA_COPY
1494 #define VA_COPY(dest, src) __va_copy(dest, src)
1495 #else
1496 #define VA_COPY(dest, src) (dest) = (src)
1497 #endif
1498 #endif
1499
1500 #ifndef HAVE_TIMEGM
1501 time_t timegm(struct tm *tm);
1502 #endif
1503
1504 /*
1505  * Veritas File System.  Often in addition to native.
1506  * Quotas different.
1507  */
1508 #if defined(HAVE_SYS_FS_VX_QUOTA_H)
1509 #define VXFS_QUOTA
1510 #endif
1511
1512 #if defined(HAVE_KRB5)
1513
1514 krb5_error_code smb_krb5_parse_name(krb5_context context,
1515                                 const char *name, /* in unix charset */
1516                                 krb5_principal *principal);
1517
1518 krb5_error_code smb_krb5_unparse_name(krb5_context context,
1519                                 krb5_const_principal principal,
1520                                 char **unix_name);
1521
1522 #ifndef HAVE_KRB5_SET_REAL_TIME
1523 krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds);
1524 #endif
1525
1526 #ifndef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES
1527 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
1528 #endif
1529
1530 #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
1531 krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
1532 #endif
1533
1534 #ifndef HAVE_KRB5_FREE_UNPARSED_NAME
1535 void krb5_free_unparsed_name(krb5_context ctx, char *val);
1536 #endif
1537
1538 /* Samba wrapper function for krb5 functionality. */
1539 void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr);
1540 int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
1541 int create_kerberos_key_from_string_direct(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
1542 BOOL get_auth_data_from_tkt(TALLOC_CTX *mem_ctx, DATA_BLOB *auth_data, krb5_ticket *tkt);
1543 krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt);
1544 krb5_error_code krb5_locate_kdc(krb5_context ctx, const krb5_data *realm, struct sockaddr **addr_pp, int *naddrs, int get_masters);
1545 krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes);
1546 void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes);
1547 BOOL get_krb5_smb_session_key(krb5_context context, krb5_auth_context auth_context, DATA_BLOB *session_key, BOOL remote);
1548 krb5_error_code smb_krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *kt_entry);
1549 krb5_principal kerberos_fetch_salt_princ_for_host_princ(krb5_context context, krb5_principal host_princ, int enctype);
1550 void kerberos_set_creds_enctype(krb5_creds *pcreds, int enctype);
1551 BOOL kerberos_compatible_enctypes(krb5_context context, krb5_enctype enctype1, krb5_enctype enctype2);
1552 void kerberos_free_data_contents(krb5_context context, krb5_data *pdata);
1553 NTSTATUS decode_pac_data(TALLOC_CTX *mem_ctx,
1554                          DATA_BLOB *pac_data_blob,
1555                          krb5_context context, 
1556                          krb5_keyblock *service_keyblock,
1557                          krb5_const_principal client_principal,
1558                          time_t tgs_authtime,
1559                          PAC_DATA **pac_data);
1560 void smb_krb5_checksum_from_pac_sig(krb5_checksum *cksum, 
1561                                     PAC_SIGNATURE_DATA *sig);
1562 krb5_error_code smb_krb5_verify_checksum(krb5_context context,
1563                                          krb5_keyblock *keyblock,
1564                                          krb5_keyusage usage,
1565                                          krb5_checksum *cksum,
1566                                          uint8 *data,
1567                                          size_t length);
1568 time_t get_authtime_from_tkt(krb5_ticket *tkt);
1569 void smb_krb5_free_ap_req(krb5_context context, 
1570                           krb5_ap_req *ap_req);
1571 krb5_error_code smb_krb5_get_keyinfo_from_ap_req(krb5_context context, 
1572                                                  const krb5_data *inbuf, 
1573                                                  krb5_kvno *kvno, 
1574                                                  krb5_enctype *enctype);
1575 krb5_error_code krb5_rd_req_return_keyblock_from_keytab(krb5_context context,
1576                                                         krb5_auth_context *auth_context,
1577                                                         const krb5_data *inbuf,
1578                                                         krb5_const_principal server,
1579                                                         krb5_keytab keytab,
1580                                                         krb5_flags *ap_req_options,
1581                                                         krb5_ticket **ticket, 
1582                                                         krb5_keyblock **keyblock);
1583 krb5_error_code smb_krb5_parse_name_norealm(krb5_context context, 
1584                                             const char *name, 
1585                                             krb5_principal *principal);
1586 BOOL smb_krb5_principal_compare_any_realm(krb5_context context, 
1587                                           krb5_const_principal princ1, 
1588                                           krb5_const_principal princ2);
1589 int cli_krb5_get_ticket(const char *principal, time_t time_offset, 
1590                         DATA_BLOB *ticket, DATA_BLOB *session_key_krb5, uint32 extra_ap_opts, const char *ccname);
1591 PAC_LOGON_INFO *get_logon_info_from_pac(PAC_DATA *pac_data);
1592 krb5_error_code smb_krb5_renew_ticket(const char *ccache_string, const char *client_string, const char *service_string, time_t *new_start_time);
1593 krb5_error_code kpasswd_err_to_krb5_err(krb5_error_code res_code);
1594 krb5_error_code smb_krb5_gen_netbios_krb5_address(smb_krb5_addresses **kerb_addr);
1595 krb5_error_code smb_krb5_free_addresses(krb5_context context, smb_krb5_addresses *addr);
1596 NTSTATUS krb5_to_nt_status(krb5_error_code kerberos_error);
1597 krb5_error_code nt_status_to_krb5(NTSTATUS nt_status);
1598 void smb_krb5_free_error(krb5_context context, krb5_error *krberror);
1599 krb5_error_code handle_krberror_packet(krb5_context context,
1600                                          krb5_data *packet);
1601 #endif /* HAVE_KRB5 */
1602
1603
1604 #ifdef HAVE_LDAP
1605
1606 /* function declarations not included in proto.h */
1607 LDAP *ldap_open_with_timeout(const char *server, int port, unsigned int to);
1608
1609 #endif  /* HAVE_LDAP */
1610
1611
1612 /* TRUE and FALSE are part of the C99 standard and gcc, but
1613    unfortunately many vendor compilers don't support them.  Use True
1614    and False instead. */
1615
1616 #ifdef TRUE
1617 #undef TRUE
1618 #endif
1619 #define TRUE __ERROR__XX__DONT_USE_TRUE
1620
1621 #ifdef FALSE
1622 #undef FALSE
1623 #endif
1624 #define FALSE __ERROR__XX__DONT_USE_FALSE
1625
1626 /* If we have blacklisted mmap() try to avoid using it accidentally by
1627    undefining the HAVE_MMAP symbol. */
1628
1629 #ifdef MMAP_BLACKLIST
1630 #undef HAVE_MMAP
1631 #endif
1632
1633 #define CONST_DISCARD(type, ptr)      ((type) ((void *) (ptr)))
1634 #define CONST_ADD(type, ptr)          ((type) ((const void *) (ptr)))
1635
1636 #ifndef NORETURN_ATTRIBUTE
1637 #if (__GNUC__ >= 3)
1638 #define NORETURN_ATTRIBUTE __attribute__ ((noreturn))
1639 #else
1640 #define NORETURN_ATTRIBUTE
1641 #endif
1642 #endif
1643
1644 void smb_panic( const char *why ) NORETURN_ATTRIBUTE ;
1645 void dump_core(void) NORETURN_ATTRIBUTE ;
1646 void exit_server(const char *const reason) NORETURN_ATTRIBUTE ;
1647 void exit_server_cleanly(const char *const reason) NORETURN_ATTRIBUTE ;
1648 void exit_server_fault(void) NORETURN_ATTRIBUTE ;
1649
1650 #endif /* _INCLUDES_H */