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