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>
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.
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.
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.
24 /* work around broken krb5.h on sles9 */
29 #ifndef NO_CONFIG_H /* for some tests */
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) */
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
52 #define DEFAULT_PRINTING PRINT_AIX
53 #define PRINTCAP_NAME "/etc/qconfig"
57 #define DEFAULT_PRINTING PRINT_HPUX
61 #define DEFAULT_PRINTING PRINT_QNX
65 /* on SUNOS4 termios.h conflicts with sys/ioctl.h */
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))
74 # define UNUSED(param) param
75 /** Feel free to add definitions for other compilers here. */
79 #ifdef HAVE_VISIBILITY_ATTR
80 # define _PUBLIC_ __attribute__((visibility("default")))
86 #ifndef NORETURN_ATTRIBUTE
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
92 #define NORETURN_ATTRIBUTE __attribute__ ((noreturn))
94 #define NORETURN_ATTRIBUTE
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
104 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
106 #define PRINTF_ATTRIBUTE(a1, a2)
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))
114 # define UNUSED(param) param
115 /** Feel free to add definitions for other compilers here. */
120 * <unistd.h> has to be included before any other to get
121 * large file support on Reliant UNIX. Yes, it's broken :-).
126 #endif /* RELIANTUNIX */
128 #include <sys/types.h>
135 #include <inttypes.h>
138 #ifdef TIME_WITH_SYS_TIME
139 #include <sys/time.h>
142 #ifdef HAVE_SYS_TIME_H
143 #include <sys/time.h>
149 #ifdef HAVE_SYS_RESOURCE_H
150 #include <sys/resource.h>
160 #ifdef HAVE_SYS_PARAM_H
161 #include <sys/param.h>
168 #ifdef HAVE_SYS_SOCKET_H
169 #include <sys/socket.h>
172 #ifdef HAVE_UNIXSOCKET
176 #ifdef HAVE_SYS_SYSCALL_H
177 #include <sys/syscall.h>
186 #ifdef HAVE_STRINGS_H
201 #ifdef HAVE_SYS_FCNTL_H
202 #include <sys/fcntl.h>
206 #include <sys/stat.h>
212 #ifdef HAVE_SYS_IOCTL_H
213 #include <sys/ioctl.h>
216 #ifdef HAVE_SYS_FILIO_H
217 #include <sys/filio.h>
222 #ifdef HAVE_SYS_WAIT_H
223 #include <sys/wait.h>
231 #ifdef HAVE_SYS_PRIV_H
232 #include <sys/priv.h>
244 #ifdef HAVE_SYS_SELECT_H
245 #include <sys/select.h>
248 #ifdef HAVE_SYS_MODE_H
249 /* apparently AIX needs this for S_ISLNK */
251 #include <sys/mode.h>
267 #include <netinet/in.h>
268 #include <arpa/inet.h>
274 #ifdef HAVE_SYS_SYSLOG_H
275 #include <sys/syslog.h>
279 #include <sys/file.h>
281 #ifdef HAVE_NETINET_TCP_H
282 #include <netinet/tcp.h>
286 * The next three defines are needed to access the IPTOS_* options
290 #ifdef HAVE_NETINET_IN_SYSTM_H
291 #include <netinet/in_systm.h>
294 #ifdef HAVE_NETINET_IN_IP_H
295 #include <netinet/in_ip.h>
298 #ifdef HAVE_NETINET_IP_H
299 #include <netinet/ip.h>
302 #if defined(HAVE_TERMIOS_H)
303 /* POSIX terminal handling. */
305 #elif defined(HAVE_TERMIO_H)
306 /* Older SYSV terminal handling - don't use if we can avoid it. */
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>
315 # define NAMLEN(dirent) strlen((dirent)->d_name)
317 # define dirent direct
318 # define NAMLEN(dirent) (dirent)->d_namlen
320 # include <sys/ndir.h>
323 # include <sys/dir.h>
330 #ifdef HAVE_SYS_MMAN_H
331 #include <sys/mman.h>
339 #ifdef HAVE_SYS_MOUNT_H
340 #include <sys/mount.h>
343 #ifdef HAVE_SYS_VFS_H
347 #ifdef HAVE_SYS_ACL_H
351 #ifdef HAVE_SYS_FS_S5PARAM_H
352 #include <sys/fs/s5param.h>
355 #if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
356 #include <sys/filsys.h>
359 #ifdef HAVE_SYS_STATFS_H
360 # include <sys/statfs.h>
364 #include <sys/dustat.h>
367 #ifdef HAVE_SYS_STATVFS_H
368 #include <sys/statvfs.h>
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
379 #if defined(HPUX) && defined(TCP_NODELAY)
382 #if defined(HPUX) && defined(TCP_MAXSEG)
388 #ifdef HAVE_GETPWANAM
389 #include <sys/label.h>
390 #include <sys/audit.h>
394 #ifdef HAVE_SYS_SECURITY_H
395 #include <sys/security.h>
397 #define PASSWORD_LENGTH 16
398 #endif /* HAVE_SYS_SECURITY_H */
400 #ifdef HAVE_STROPTS_H
408 #if defined(HAVE_RPC_RPC_H)
410 * Check for AUTH_ERROR define conflict with rpc/rpc.h in prot.h.
412 #if defined(HAVE_SYS_SECURITY_H) && defined(HAVE_RPC_AUTH_ERROR_CONFLICT)
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
422 #if defined(HPUX) && defined(TCP_NODELAY)
425 #if defined(HPUX) && defined(TCP_MAXSEG)
431 #if defined(HAVE_YP_GET_DEFAULT_DOMAIN) && defined(HAVE_SETNETGRENT) && defined(HAVE_ENDNETGRENT) && defined(HAVE_GETNETGRENT)
432 #define HAVE_NETGROUP 1
435 #if defined (HAVE_NETGROUP)
436 #if defined(HAVE_RPCSVC_YP_PROT_H)
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
444 #if defined(HPUX) && defined(TCP_NODELAY)
447 #if defined(HPUX) && defined(TCP_MAXSEG)
450 #include <rpcsvc/yp_prot.h>
452 #if defined(HAVE_RPCSVC_YPCLNT_H)
453 #include <rpcsvc/ypclnt.h>
455 #endif /* HAVE_NETGROUP */
457 #if defined(HAVE_SYS_IPC_H)
459 #endif /* HAVE_SYS_IPC_H */
461 #if defined(HAVE_SYS_SHM_H)
463 #endif /* HAVE_SYS_SHM_H */
465 #ifdef HAVE_NATIVE_ICONV
486 #define LBER_USE_DER 0x01
493 #define LDAP_CONST const
495 #ifndef LDAP_OPT_SUCCESS
496 #define LDAP_OPT_SUCCESS 0
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
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
514 #elif HAVE_GSSAPI_GSSAPI_H
515 #include <gssapi/gssapi.h>
516 #elif HAVE_GSSAPI_GSSAPI_GENERIC_H
517 #include <gssapi/gssapi_generic.h>
524 #if HAVE_SYS_ATTRIBUTES_H
525 #include <sys/attributes.h>
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>
539 #ifdef HAVE_SYS_EXTATTR_H
540 #include <sys/extattr.h>
543 #ifdef HAVE_SYS_UIO_H
552 #include <langinfo.h>
555 #if defined(HAVE_AIO_H) && defined(WITH_AIO)
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>
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
574 #if defined(DEVELOPER) && !defined(HAVE_64BIT_LINUX)
575 #if (HAVE_VALGRIND_H || HAVE_VALGRIND_VALGRIND_H)
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)
587 * Define VOLATILE if needed.
590 #if defined(HAVE_VOLATILE)
591 #define VOLATILE volatile
597 * Define additional missing types
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;
604 typedef int VOLATILE SIG_ATOMIC_T;
607 #ifndef HAVE_SOCKLEN_T_TYPE
608 #define HAVE_SOCKLEN_T_TYPE
609 typedef int socklen_t;
614 #define uchar unsigned char
617 #ifdef HAVE_UNSIGNED_CHAR
618 #define schar signed char
624 Samba needs type definitions for int16, int32, uint16 and uint32.
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.
633 #define uint8 unsigned char
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 */
641 # endif /* SIZEOF_SHORT != 4 */
642 /* needed to work around compile issue on HP-UX 11.x */
647 * Note we duplicate the size tests in the unsigned
648 * case as int16 may be a typedef from rpc/rpc.h
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 */
659 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
660 # if (SIZEOF_INT == 4)
662 # elif (SIZEOF_LONG == 4)
664 # elif (SIZEOF_SHORT == 4)
667 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
670 /* needed to work around compile issue on HP-UX 11.x */
675 * Note we duplicate the size tests in the unsigned
676 * case as int32 may be a typedef from rpc/rpc.h
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
687 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
688 #define uint32 unsigned
693 * check for 8 byte long long
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 */
705 #if (SIZEOF_LONG == 8)
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 */
714 * Types for devices, inodes and offsets.
718 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)
719 # define SMB_DEV_T dev64_t
721 # define SMB_DEV_T dev_t
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
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)))
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))))
740 * Setup the correctly sized inode type.
744 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)
745 # define SMB_INO_T ino64_t
747 # define SMB_INO_T ino_t
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
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)))
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))))
766 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)
767 # define SMB_OFF_T off64_t
769 # define SMB_OFF_T off_t
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))
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))
783 #define SMB_BIG_UINT_BITS (sizeof(SMB_BIG_UINT)*8)
785 /* this should really be a 64 bit type if possible */
786 #define br_off SMB_BIG_UINT
788 #define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8)
791 * Set the define that tells us if we can do 64 bit
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
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 ) )
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 ) )
816 * Type for stat structure.
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
823 # define SMB_STRUCT_STAT struct stat
828 * Type for dirent structure.
831 #ifndef SMB_STRUCT_DIRENT
832 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIRENT64)
833 # define SMB_STRUCT_DIRENT struct dirent64
835 # define SMB_STRUCT_DIRENT struct dirent
840 * Type for DIR structure.
843 #ifndef SMB_STRUCT_DIR
844 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIR64)
845 # define SMB_STRUCT_DIR DIR64
847 # define SMB_STRUCT_DIR DIR
852 * Defines for 64 bit fcntl locks.
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
859 # define SMB_STRUCT_FLOCK struct flock
864 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
865 # define SMB_F_SETLKW F_SETLKW64
867 # define SMB_F_SETLKW F_SETLKW
872 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
873 # define SMB_F_SETLK F_SETLK64
875 # define SMB_F_SETLK F_SETLK
880 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
881 # define SMB_F_GETLK F_GETLK64
883 # define SMB_F_GETLK F_GETLK
888 * Type for aiocb structure.
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
896 # define SMB_STRUCT_AIOCB struct aiocb
899 # define SMB_STRUCT_AIOCB int /* AIO not being used but we still need the define.... */
903 #ifndef HAVE_STRUCT_TIMESPEC
905 time_t tv_sec; /* Seconds. */
906 long tv_nsec; /* Nanoseconds. */
911 #define MIN(a,b) ((a)<(b)?(a):(b))
915 #define MAX(a,b) ((a)>(b)?(a):(b))
920 #define _BOOL /* So we don't typedef BOOL again in vfs.h */
923 #ifndef HAVE_STRERROR
924 extern char *sys_errlist[];
925 #define strerror(i) sys_errlist[i]
928 #ifndef HAVE_ERRNO_DECL
932 #ifdef HAVE_BROKEN_GETGROUPS
939 #define NGROUPS_MAX 32 /* Guess... */
942 #ifdef SOCKET_WRAPPER
943 #define SOCKET_WRAPPER_REPLACE
944 #include "lib/socket_wrapper/socket_wrapper.h"
947 /* Our own pstrings and fstrings */
950 /* Lists, trees, caching, database... */
953 #include "dlinklist.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)
963 #include "nt_status.h"
966 #include "interfaces.h"
970 #include "messages.h"
972 #include "dynconfig.h"
973 #include "util_getent.h"
974 #include "debugparse.h"
976 #include "privileges.h"
979 #include "ads_cldap.h"
980 #include "nameserv.h"
982 #include "byteorder.h"
983 #include "privileges.h"
984 #include "rpc_misc.h"
988 #include "rpc_secdes.h"
989 #include "authdata.h"
996 #include "ntdomain.h"
997 #include "rpc_svcctl.h"
998 #include "rpc_ntsvcs.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"
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"
1017 #ifdef WITH_SMBWRAPPER
1021 #include "session.h"
1026 #include "nsswitch/winbind_client.h"
1028 #include "rpc_client.h"
1032 * Type for wide character dirent structure.
1033 * Only d_name is defined by POSIX.
1036 typedef struct smb_wdirent {
1038 } SMB_STRUCT_WDIRENT;
1041 * Type for wide character passwd structure.
1044 typedef struct smb_wpasswd {
1052 } SMB_STRUCT_WPASSWD;
1056 const char *funcname;
1057 int (*fn)(int argc, const char **argv);
1061 const char *funcname;
1062 int (*fn)(int argc, const char **argv);
1063 const char *helptext;
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
1073 #include "nsswitch/winbind_nss.h"
1075 /* forward declaration from printing.h to get around
1076 header file dependencies */
1080 struct smb_ldap_privates;
1082 /* forward declarations from smbldap.c */
1084 #include "smbldap.h"
1086 #include "smb_ldap.h"
1089 * Reasons for cache flush.
1092 enum flush_reason_enum {
1097 OPLOCK_RELEASE_FLUSH,
1101 /* NUM_FLUSH_REASONS must remain the last value in the enumeration. */
1104 #ifndef HAVE_COMPARISON_FN_T
1105 typedef int (*comparison_fn_t)(const void *, const void *);
1108 /***** automatically generated prototypes *****/
1114 #include "ads_protos.h"
1117 /* We need this after proto.h to reference GetTimeOfDay(). */
1118 #include "smbprofile.h"
1120 /* String routines */
1123 #include "safe_string.h"
1125 #ifdef __COMPAR_FN_T
1126 #define QSORT_CAST (__compar_fn_t)
1130 #define QSORT_CAST (int (*)(const void *, const void *))
1133 #ifndef DEFAULT_PRINTING
1135 #define DEFAULT_PRINTING PRINT_CUPS
1136 #define PRINTCAP_NAME "cups"
1138 #define DEFAULT_PRINTING PRINT_SYSV
1139 #define PRINTCAP_NAME "lpstat"
1141 #define DEFAULT_PRINTING PRINT_BSD
1142 #define PRINTCAP_NAME "/etc/printcap"
1146 #ifndef PRINTCAP_NAME
1147 #define PRINTCAP_NAME "/etc/printcap"
1151 #define SIGCLD SIGCHLD
1162 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
1163 #define OSF1_ENH_SEC 1
1166 #ifndef ALLOW_CHANGE_PASSWORD
1167 #if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
1168 #define ALLOW_CHANGE_PASSWORD 1
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
1178 #ifdef REPLACE_INET_NTOA
1179 #define inet_ntoa rep_inet_ntoa
1190 #ifndef INADDR_LOOPBACK
1191 #define INADDR_LOOPBACK 0x7f000001
1195 #define INADDR_NONE 0xffffffff
1199 #define crypt ufc_crypt
1203 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
1206 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
1207 #define ULTRIX_AUTH 1
1211 char *strdup(const char *s);
1214 #ifndef HAVE_STRNDUP
1215 char *strndup(const char *s, size_t size);
1218 #ifndef HAVE_MEMMOVE
1219 void *memmove(void *dest,const void *src,int size);
1222 #ifndef HAVE_INITGROUPS
1223 int initgroups(char *name,gid_t id);
1227 int rename(const char *zfrom, const char *zto);
1231 time_t mktime(struct tm *t);
1234 #ifndef HAVE_STRLCPY
1235 size_t strlcpy(char *d, const char *s, size_t bufsize);
1238 #ifndef HAVE_STRLCAT
1239 size_t strlcat(char *d, const char *s, size_t bufsize);
1242 #ifndef HAVE_FTRUNCATE
1243 int ftruncate(int f,long l);
1246 #ifndef HAVE_STRNDUP
1247 char *strndup(const char *s, size_t n);
1250 #ifndef HAVE_STRNLEN
1251 size_t strnlen(const char *s, size_t n);
1254 #ifndef HAVE_STRTOUL
1255 unsigned long strtoul(const char *nptr, char **endptr, int base);
1259 int setenv(const char *name, const char *value, int overwrite);
1262 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL))
1264 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
1266 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESGID_DECL))
1267 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
1269 #ifndef HAVE_VASPRINTF_DECL
1270 int vasprintf(char **ptr, const char *format, va_list ap);
1273 #ifdef REPLACE_GETPASS
1274 #define getpass(prompt) getsmbpass((prompt))
1278 * Some older systems seem not to have MAXHOSTNAMELEN
1281 #ifndef MAXHOSTNAMELEN
1282 #define MAXHOSTNAMELEN 254
1285 /* yuck, I'd like a better way of doing this */
1286 #define DIRP_SIZE (256 + 32)
1289 * glibc on linux doesn't seem to have MSG_WAITALL
1290 * defined. I think the kernel has it though..
1294 #define MSG_WAITALL 0
1297 /* default socket options. Dave Miller thinks we should default to TCP_NODELAY
1298 given the socket IO pattern that Samba uses */
1300 #define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
1302 #define DEFAULT_SOCKET_OPTIONS ""
1305 /* Load header file for dynamic linking stuff */
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>
1318 /* Some POSIX definitions for those without */
1321 #define S_IFDIR 0x4000
1324 #define S_ISDIR(mode) ((mode & 0xF000) == S_IFDIR)
1327 #define S_IRWXU 00700 /* read, write, execute: owner */
1330 #define S_IRUSR 00400 /* read permission: owner */
1333 #define S_IWUSR 00200 /* write permission: owner */
1336 #define S_IXUSR 00100 /* execute permission: owner */
1339 #define S_IRWXG 00070 /* read, write, execute: group */
1342 #define S_IRGRP 00040 /* read permission: group */
1345 #define S_IWGRP 00020 /* write permission: group */
1348 #define S_IXGRP 00010 /* execute permission: group */
1351 #define S_IRWXO 00007 /* read, write, execute: other */
1354 #define S_IROTH 00004 /* read permission: other */
1357 #define S_IWOTH 00002 /* write permission: other */
1360 #define S_IXOTH 00001 /* execute permission: other */
1363 /* For sys_adminlog(). */
1365 #define LOG_EMERG 0 /* system is unusable */
1369 #define LOG_ALERT 1 /* action must be taken immediately */
1373 #define LOG_CRIT 2 /* critical conditions */
1377 #define LOG_ERR 3 /* error conditions */
1381 #define LOG_WARNING 4 /* warning conditions */
1385 #define LOG_NOTICE 5 /* normal but significant condition */
1389 #define LOG_INFO 6 /* informational */
1393 #define LOG_DEBUG 7 /* debug-level messages */
1396 #if HAVE_KERNEL_SHARE_MODES
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 */
1405 extern int DEBUGLEVEL;
1407 #define MAX_SEC_CTX_DEPTH 8 /* Maximum number of security contexts */
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
1415 #define fcntl fcntl64
1423 /* Needed for sys_dlopen/sys_dlsym/sys_dlclose */
1425 #define RTLD_GLOBAL 0
1436 /* needed for some systems without iconv. Doesn't really matter
1437 what error code we use */
1442 /* add varargs prototypes with printf checking */
1444 int fdprintf(int , const char *, ...) PRINTF_ATTRIBUTE(2,3);
1446 int d_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2);
1448 int d_fprintf(FILE *f, const char *, ...) PRINTF_ATTRIBUTE(2,3);
1449 #ifndef HAVE_SNPRINTF_DECL
1451 int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
1453 #ifndef HAVE_ASPRINTF_DECL
1455 int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
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. */
1462 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
1463 #define snprintf smb_snprintf
1464 #define vsnprintf smb_vsnprintf
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);
1473 void sys_adminlog(int priority, const char *format_str, ...) PRINTF_ATTRIBUTE(2,3);
1476 int pstr_sprintf(pstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1478 int fstr_sprintf(fstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1480 int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1482 int smb_xvasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
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
1489 /* we need to use __va_copy() on some platforms */
1491 #define VA_COPY(dest, src) va_copy(dest, src)
1493 #ifdef HAVE___VA_COPY
1494 #define VA_COPY(dest, src) __va_copy(dest, src)
1496 #define VA_COPY(dest, src) (dest) = (src)
1501 time_t timegm(struct tm *tm);
1505 * Veritas File System. Often in addition to native.
1508 #if defined(HAVE_SYS_FS_VX_QUOTA_H)
1512 #if defined(HAVE_KRB5)
1514 krb5_error_code smb_krb5_parse_name(krb5_context context,
1515 const char *name, /* in unix charset */
1516 krb5_principal *principal);
1518 krb5_error_code smb_krb5_unparse_name(krb5_context context,
1519 krb5_const_principal principal,
1522 #ifndef HAVE_KRB5_SET_REAL_TIME
1523 krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds);
1526 #ifndef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES
1527 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
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);
1534 #ifndef HAVE_KRB5_FREE_UNPARSED_NAME
1535 void krb5_free_unparsed_name(krb5_context ctx, char *val);
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,
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,
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,
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,
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,
1601 #endif /* HAVE_KRB5 */
1606 /* function declarations not included in proto.h */
1607 LDAP *ldap_open_with_timeout(const char *server, int port, unsigned int to);
1609 #endif /* HAVE_LDAP */
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. */
1619 #define TRUE __ERROR__XX__DONT_USE_TRUE
1624 #define FALSE __ERROR__XX__DONT_USE_FALSE
1626 /* If we have blacklisted mmap() try to avoid using it accidentally by
1627 undefining the HAVE_MMAP symbol. */
1629 #ifdef MMAP_BLACKLIST
1633 #define CONST_DISCARD(type, ptr) ((type) ((void *) (ptr)))
1634 #define CONST_ADD(type, ptr) ((type) ((const void *) (ptr)))
1636 #ifndef NORETURN_ATTRIBUTE
1638 #define NORETURN_ATTRIBUTE __attribute__ ((noreturn))
1640 #define NORETURN_ATTRIBUTE
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 ;
1650 #endif /* _INCLUDES_H */