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 */
30 #include "lib/replace/replace.h"
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
98 #if defined(__GNUC__) && !defined(__cplusplus)
99 /** gcc attribute used on function parameters so that it does not emit
100 * warnings about them being unused. **/
101 # define UNUSED(param) param __attribute__ ((unused))
103 # define UNUSED(param) param
104 /** Feel free to add definitions for other compilers here. */
109 * <unistd.h> has to be included before any other to get
110 * large file support on Reliant UNIX. Yes, it's broken :-).
115 #endif /* RELIANTUNIX */
117 #include "system/capability.h"
118 #include "system/dir.h"
119 #include "system/filesys.h"
120 #include "system/glob.h"
121 #include "system/iconv.h"
122 #include "system/locale.h"
123 #include "system/network.h"
124 #include "system/passwd.h"
125 #include "system/printing.h"
126 #include "system/readline.h"
127 #include "system/select.h"
128 #include "system/shmem.h"
129 #include "system/syslog.h"
130 #include "system/terminal.h"
131 #include "system/time.h"
132 #include "system/wait.h"
134 #include <sys/types.h>
141 #include <inttypes.h>
144 #ifdef TIME_WITH_SYS_TIME
145 #include <sys/time.h>
148 #ifdef HAVE_SYS_TIME_H
149 #include <sys/time.h>
155 #ifdef HAVE_SYS_RESOURCE_H
156 #include <sys/resource.h>
166 #ifdef HAVE_SYS_PARAM_H
167 #include <sys/param.h>
174 #ifdef HAVE_SYS_SOCKET_H
175 #include <sys/socket.h>
178 #ifdef HAVE_UNIXSOCKET
182 #ifdef HAVE_SYS_SYSCALL_H
183 #include <sys/syscall.h>
192 #ifdef HAVE_STRINGS_H
207 #ifdef HAVE_SYS_FCNTL_H
208 #include <sys/fcntl.h>
212 #include <sys/stat.h>
218 #ifdef HAVE_SYS_IOCTL_H
219 #include <sys/ioctl.h>
222 #ifdef HAVE_SYS_FILIO_H
223 #include <sys/filio.h>
228 #ifdef HAVE_SYS_WAIT_H
229 #include <sys/wait.h>
237 #ifdef HAVE_SYS_PRIV_H
238 #include <sys/priv.h>
250 #ifdef HAVE_SYS_SELECT_H
251 #include <sys/select.h>
254 #ifdef HAVE_SYS_MODE_H
255 /* apparently AIX needs this for S_ISLNK */
257 #include <sys/mode.h>
273 #include <netinet/in.h>
274 #include <arpa/inet.h>
280 #ifdef HAVE_SYS_SYSLOG_H
281 #include <sys/syslog.h>
285 #include <sys/file.h>
287 #ifdef HAVE_NETINET_TCP_H
288 #include <netinet/tcp.h>
292 * The next three defines are needed to access the IPTOS_* options
296 #ifdef HAVE_NETINET_IN_SYSTM_H
297 #include <netinet/in_systm.h>
300 #ifdef HAVE_NETINET_IN_IP_H
301 #include <netinet/in_ip.h>
304 #ifdef HAVE_NETINET_IP_H
305 #include <netinet/ip.h>
308 #if defined(HAVE_TERMIOS_H)
309 /* POSIX terminal handling. */
311 #elif defined(HAVE_TERMIO_H)
312 /* Older SYSV terminal handling - don't use if we can avoid it. */
314 #elif defined(HAVE_SYS_TERMIO_H)
315 /* Older SYSV terminal handling - don't use if we can avoid it. */
316 #include <sys/termio.h>
321 # define NAMLEN(dirent) strlen((dirent)->d_name)
323 # define dirent direct
324 # define NAMLEN(dirent) (dirent)->d_namlen
326 # include <sys/ndir.h>
329 # include <sys/dir.h>
336 #ifdef HAVE_SYS_MMAN_H
337 #include <sys/mman.h>
345 #ifdef HAVE_SYS_MOUNT_H
346 #include <sys/mount.h>
349 #ifdef HAVE_SYS_VFS_H
353 #ifdef HAVE_SYS_ACL_H
357 #ifdef HAVE_SYS_FS_S5PARAM_H
358 #include <sys/fs/s5param.h>
361 #if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
362 #include <sys/filsys.h>
365 #ifdef HAVE_SYS_STATFS_H
366 # include <sys/statfs.h>
370 #include <sys/dustat.h>
373 #ifdef HAVE_SYS_STATVFS_H
374 #include <sys/statvfs.h>
379 * HP-UX 11.X has TCP_NODELAY and TCP_MAXSEG defined in <netinet/tcp.h> which
380 * was included above. However <rpc/rpc.h> includes <sys/xti.h> which defines
381 * them again without checking if they already exsist. This generates
382 * two "Redefinition of macro" warnings for every single .c file that is
385 #if defined(HPUX) && defined(TCP_NODELAY)
388 #if defined(HPUX) && defined(TCP_MAXSEG)
394 #ifdef HAVE_GETPWANAM
395 #include <sys/label.h>
396 #include <sys/audit.h>
400 #ifdef HAVE_SYS_SECURITY_H
401 #include <sys/security.h>
403 #define PASSWORD_LENGTH 16
404 #endif /* HAVE_SYS_SECURITY_H */
406 #ifdef HAVE_STROPTS_H
414 #if defined(HAVE_RPC_RPC_H)
416 * Check for AUTH_ERROR define conflict with rpc/rpc.h in prot.h.
418 #if defined(HAVE_SYS_SECURITY_H) && defined(HAVE_RPC_AUTH_ERROR_CONFLICT)
422 * HP-UX 11.X has TCP_NODELAY and TCP_MAXSEG defined in <netinet/tcp.h> which
423 * was included above. However <rpc/rpc.h> includes <sys/xti.h> which defines
424 * them again without checking if they already exsist. This generates
425 * two "Redefinition of macro" warnings for every single .c file that is
428 #if defined(HPUX) && defined(TCP_NODELAY)
431 #if defined(HPUX) && defined(TCP_MAXSEG)
437 #if defined(HAVE_YP_GET_DEFAULT_DOMAIN) && defined(HAVE_SETNETGRENT) && defined(HAVE_ENDNETGRENT) && defined(HAVE_GETNETGRENT)
438 #define HAVE_NETGROUP 1
441 #if defined (HAVE_NETGROUP)
442 #if defined(HAVE_RPCSVC_YP_PROT_H)
444 * HP-UX 11.X has TCP_NODELAY and TCP_MAXSEG defined in <netinet/tcp.h> which
445 * was included above. However <rpc/rpc.h> includes <sys/xti.h> which defines
446 * them again without checking if they already exsist. This generates
447 * two "Redefinition of macro" warnings for every single .c file that is
450 #if defined(HPUX) && defined(TCP_NODELAY)
453 #if defined(HPUX) && defined(TCP_MAXSEG)
456 #include <rpcsvc/yp_prot.h>
458 #if defined(HAVE_RPCSVC_YPCLNT_H)
459 #include <rpcsvc/ypclnt.h>
461 #endif /* HAVE_NETGROUP */
463 #if defined(HAVE_SYS_IPC_H)
465 #endif /* HAVE_SYS_IPC_H */
467 #if defined(HAVE_SYS_SHM_H)
469 #endif /* HAVE_SYS_SHM_H */
471 #ifdef HAVE_NATIVE_ICONV
492 #define LBER_USE_DER 0x01
499 #define LDAP_CONST const
501 #ifndef LDAP_OPT_SUCCESS
502 #define LDAP_OPT_SUCCESS 0
504 /* Solaris 8 and maybe other LDAP implementations spell this "..._INPROGRESS": */
505 #if defined(LDAP_SASL_BIND_INPROGRESS) && !defined(LDAP_SASL_BIND_IN_PROGRESS)
506 #define LDAP_SASL_BIND_IN_PROGRESS LDAP_SASL_BIND_INPROGRESS
508 /* Solaris 8 defines SSL_LDAP_PORT, not LDAPS_PORT and it only does so if
509 LDAP_SSL is defined - but SSL is not working. We just want the
510 port number! Let's just define LDAPS_PORT correct. */
511 #if !defined(LDAPS_PORT)
512 #define LDAPS_PORT 636
520 #elif HAVE_GSSAPI_GSSAPI_H
521 #include <gssapi/gssapi.h>
522 #elif HAVE_GSSAPI_GSSAPI_GENERIC_H
523 #include <gssapi/gssapi_generic.h>
530 #if HAVE_SYS_ATTRIBUTES_H
531 #include <sys/attributes.h>
534 /* mutually exclusive (SuSE 8.2) */
535 #if HAVE_ATTR_XATTR_H
536 #include <attr/xattr.h>
537 #elif HAVE_SYS_XATTR_H
538 #include <sys/xattr.h>
545 #ifdef HAVE_SYS_EXTATTR_H
546 #include <sys/extattr.h>
549 #ifdef HAVE_SYS_UIO_H
558 #include <langinfo.h>
561 #if defined(HAVE_AIO_H) && defined(WITH_AIO)
565 /* skip valgrind headers on 64bit AMD boxes */
566 #ifndef HAVE_64BIT_LINUX
567 /* Special macros that are no-ops except when run under Valgrind on
568 * x86. They've moved a little bit from valgrind 1.0.4 to 1.9.4 */
569 #if HAVE_VALGRIND_MEMCHECK_H
570 /* memcheck.h includes valgrind.h */
571 #include <valgrind/memcheck.h>
572 #elif HAVE_VALGRIND_H
573 #include <valgrind.h>
577 /* If we have --enable-developer and the valgrind header is present,
578 * then we're OK to use it. Set a macro so this logic can be done only
580 #if defined(DEVELOPER) && !defined(HAVE_64BIT_LINUX)
581 #if (HAVE_VALGRIND_H || HAVE_VALGRIND_VALGRIND_H)
587 /* we support ADS if we want it and have krb5 and ldap libs */
588 #if defined(WITH_ADS) && defined(HAVE_KRB5) && defined(HAVE_LDAP)
593 * Define VOLATILE if needed.
596 #if defined(HAVE_VOLATILE)
597 #define VOLATILE volatile
603 * Define additional missing types
605 #if defined(HAVE_SIG_ATOMIC_T_TYPE) && defined(AIX)
606 typedef sig_atomic_t SIG_ATOMIC_T;
607 #elif defined(HAVE_SIG_ATOMIC_T_TYPE) && !defined(AIX)
608 typedef sig_atomic_t VOLATILE SIG_ATOMIC_T;
610 typedef int VOLATILE SIG_ATOMIC_T;
613 #ifndef HAVE_SOCKLEN_T_TYPE
614 #define HAVE_SOCKLEN_T_TYPE
615 typedef int socklen_t;
620 #define uchar unsigned char
623 #ifdef HAVE_UNSIGNED_CHAR
624 #define schar signed char
630 Samba needs type definitions for int16, int32, uint16 and uint32.
632 Normally these are signed and unsigned 16 and 32 bit integers, but
633 they actually only need to be at least 16 and 32 bits
634 respectively. Thus if your word size is 8 bytes just defining them
635 as signed and unsigned int will work.
639 #define uint8 unsigned char
642 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
643 # if (SIZEOF_SHORT == 4)
644 # define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
645 # else /* SIZEOF_SHORT != 4 */
647 # endif /* SIZEOF_SHORT != 4 */
648 /* needed to work around compile issue on HP-UX 11.x */
653 * Note we duplicate the size tests in the unsigned
654 * case as int16 may be a typedef from rpc/rpc.h
657 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
658 #if (SIZEOF_SHORT == 4)
659 #define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
660 #else /* SIZEOF_SHORT != 4 */
661 #define uint16 unsigned short
662 #endif /* SIZEOF_SHORT != 4 */
665 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
666 # if (SIZEOF_INT == 4)
668 # elif (SIZEOF_LONG == 4)
670 # elif (SIZEOF_SHORT == 4)
673 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
676 /* needed to work around compile issue on HP-UX 11.x */
681 * Note we duplicate the size tests in the unsigned
682 * case as int32 may be a typedef from rpc/rpc.h
685 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
686 #if (SIZEOF_INT == 4)
687 #define uint32 unsigned int
688 #elif (SIZEOF_LONG == 4)
689 #define uint32 unsigned long
690 #elif (SIZEOF_SHORT == 4)
691 #define uint32 unsigned short
693 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
694 #define uint32 unsigned
699 * check for 8 byte long long
703 #if (SIZEOF_LONG == 8)
704 #define uint64 unsigned long
705 #elif (SIZEOF_LONG_LONG == 8)
706 #define uint64 unsigned long long
707 #endif /* don't lie. If we don't have it, then don't use it */
711 #if (SIZEOF_LONG == 8)
713 #elif (SIZEOF_LONG_LONG == 8)
714 #define int64 long long
715 #endif /* don't lie. If we don't have it, then don't use it */
720 * Types for devices, inodes and offsets.
724 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)
725 # define SMB_DEV_T dev64_t
727 # define SMB_DEV_T dev_t
731 #ifndef LARGE_SMB_DEV_T
732 # if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)) || (defined(SIZEOF_DEV_T) && (SIZEOF_DEV_T == 8))
733 # define LARGE_SMB_DEV_T 1
737 #ifdef LARGE_SMB_DEV_T
738 #define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32))
739 #define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(((SMB_BIG_UINT)(IVAL((p),(ofs))))| (((SMB_BIG_UINT)(IVAL((p),(ofs)+4))) << 32)))
741 #define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),v),SIVAL((p),(ofs)+4,0))
742 #define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(IVAL((p),(ofs))))
746 * Setup the correctly sized inode type.
750 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)
751 # define SMB_INO_T ino64_t
753 # define SMB_INO_T ino_t
757 #ifndef LARGE_SMB_INO_T
758 # if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)) || (defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8))
759 # define LARGE_SMB_INO_T 1
763 #ifdef LARGE_SMB_INO_T
764 #define SINO_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32))
765 #define INO_T_VAL(p, ofs) ((SMB_INO_T)(((SMB_BIG_UINT)(IVAL(p,ofs)))| (((SMB_BIG_UINT)(IVAL(p,(ofs)+4))) << 32)))
767 #define SINO_T_VAL(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
768 #define INO_T_VAL(p, ofs) ((SMB_INO_T)(IVAL((p),(ofs))))
772 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)
773 # define SMB_OFF_T off64_t
775 # define SMB_OFF_T off_t
779 #if defined(HAVE_LONGLONG)
780 #define SMB_BIG_UINT unsigned long long
781 #define SMB_BIG_INT long long
782 #define SBIG_UINT(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
784 #define SMB_BIG_UINT unsigned long
785 #define SMB_BIG_INT long
786 #define SBIG_UINT(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
789 #define SMB_BIG_UINT_BITS (sizeof(SMB_BIG_UINT)*8)
791 /* this should really be a 64 bit type if possible */
792 #define br_off SMB_BIG_UINT
794 #define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8)
797 * Set the define that tells us if we can do 64 bit
801 #ifndef LARGE_SMB_OFF_T
802 # if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8))
803 # define LARGE_SMB_OFF_T 1
807 #ifdef LARGE_SMB_OFF_T
808 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
809 #define SOFF_T_R(p, ofs, v) (SIVAL(p,(ofs)+4,(v)&0xFFFFFFFF), SIVAL(p,ofs,(v)>>32))
810 #define IVAL_TO_SMB_OFF_T(buf,off) ((SMB_OFF_T)(( ((SMB_BIG_UINT)(IVAL((buf),(off)))) & ((SMB_BIG_UINT)0xFFFFFFFF) )))
811 #define IVAL2_TO_SMB_BIG_UINT(buf,off) ( (((SMB_BIG_UINT)(IVAL((buf),(off)))) & ((SMB_BIG_UINT)0xFFFFFFFF)) | \
812 (( ((SMB_BIG_UINT)(IVAL((buf),(off+4)))) & ((SMB_BIG_UINT)0xFFFFFFFF) ) << 32 ) )
814 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
815 #define SOFF_T_R(p, ofs, v) (SIVAL(p,(ofs)+4,v),SIVAL(p,ofs,0))
816 #define IVAL_TO_SMB_OFF_T(buf,off) ((SMB_OFF_T)(( ((uint32)(IVAL((buf),(off)))) & 0xFFFFFFFF )))
817 #define IVAL2_TO_SMB_BIG_UINT(buf,off) ( (((SMB_BIG_UINT)(IVAL((buf),(off)))) & ((SMB_BIG_UINT)0xFFFFFFFF)) | \
818 (( ((SMB_BIG_UINT)(IVAL((buf),(off+4)))) & ((SMB_BIG_UINT)0xFFFFFFFF) ) << 32 ) )
822 * Type for stat structure.
825 #ifndef SMB_STRUCT_STAT
826 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STAT64) && defined(HAVE_OFF64_T)
827 # define SMB_STRUCT_STAT struct stat64
829 # define SMB_STRUCT_STAT struct stat
834 * Type for dirent structure.
837 #ifndef SMB_STRUCT_DIRENT
838 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIRENT64)
839 # define SMB_STRUCT_DIRENT struct dirent64
841 # define SMB_STRUCT_DIRENT struct dirent
846 * Type for DIR structure.
849 #ifndef SMB_STRUCT_DIR
850 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIR64)
851 # define SMB_STRUCT_DIR DIR64
853 # define SMB_STRUCT_DIR DIR
858 * Defines for 64 bit fcntl locks.
861 #ifndef SMB_STRUCT_FLOCK
862 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
863 # define SMB_STRUCT_FLOCK struct flock64
865 # define SMB_STRUCT_FLOCK struct flock
870 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
871 # define SMB_F_SETLKW F_SETLKW64
873 # define SMB_F_SETLKW F_SETLKW
878 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
879 # define SMB_F_SETLK F_SETLK64
881 # define SMB_F_SETLK F_SETLK
886 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
887 # define SMB_F_GETLK F_GETLK64
889 # define SMB_F_GETLK F_GETLK
894 * Type for aiocb structure.
897 #ifndef SMB_STRUCT_AIOCB
898 # if defined(WITH_AIO)
899 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64)
900 # define SMB_STRUCT_AIOCB struct aiocb64
902 # define SMB_STRUCT_AIOCB struct aiocb
905 # define SMB_STRUCT_AIOCB int /* AIO not being used but we still need the define.... */
909 #ifndef HAVE_STRUCT_TIMESPEC
911 time_t tv_sec; /* Seconds. */
912 long tv_nsec; /* Nanoseconds. */
917 #define MIN(a,b) ((a)<(b)?(a):(b))
921 #define MAX(a,b) ((a)>(b)?(a):(b))
926 #define _BOOL /* So we don't typedef BOOL again in vfs.h */
929 #ifndef HAVE_STRERROR
930 extern char *sys_errlist[];
931 #define strerror(i) sys_errlist[i]
934 #ifndef HAVE_ERRNO_DECL
938 #ifdef HAVE_BROKEN_GETGROUPS
945 #define NGROUPS_MAX 32 /* Guess... */
948 /* Our own pstrings and fstrings */
951 /* Lists, trees, caching, database... */
954 #include "dlinklist.h"
960 /* And a little extension. Abort on type mismatch */
961 #define talloc_get_type_abort(ptr, type) \
962 (type *)talloc_check_name_abort(ptr, #type)
964 #include "nt_status.h"
967 #include "interfaces.h"
971 #include "messages.h"
973 #include "dynconfig.h"
974 #include "util_getent.h"
975 #include "debugparse.h"
977 #include "privileges.h"
980 #include "ads_cldap.h"
981 #include "nameserv.h"
983 #include "byteorder.h"
984 #include "privileges.h"
985 #include "rpc_misc.h"
989 #include "rpc_secdes.h"
990 #include "authdata.h"
997 #include "ntdomain.h"
998 #include "rpc_svcctl.h"
999 #include "rpc_ntsvcs.h"
1000 #include "rpc_lsa.h"
1001 #include "rpc_netlogon.h"
1002 #include "reg_objects.h"
1003 #include "rpc_reg.h"
1004 #include "rpc_samr.h"
1005 #include "rpc_srvsvc.h"
1006 #include "rpc_wkssvc.h"
1007 #include "rpc_spoolss.h"
1008 #include "rpc_eventlog.h"
1010 #include "rpc_shutdown.h"
1011 #include "rpc_perfcount.h"
1012 #include "rpc_perfcount_defs.h"
1013 #include "librpc/gen_ndr/echo.h"
1014 #include "nt_printing.h"
1018 #ifdef WITH_SMBWRAPPER
1022 #include "session.h"
1027 #include "nsswitch/winbind_client.h"
1029 #include "rpc_client.h"
1033 * Type for wide character dirent structure.
1034 * Only d_name is defined by POSIX.
1037 typedef struct smb_wdirent {
1039 } SMB_STRUCT_WDIRENT;
1042 * Type for wide character passwd structure.
1045 typedef struct smb_wpasswd {
1053 } SMB_STRUCT_WPASSWD;
1057 const char *funcname;
1058 int (*fn)(int argc, const char **argv);
1062 const char *funcname;
1063 int (*fn)(int argc, const char **argv);
1064 const char *helptext;
1067 /* Defines for wisXXX functions. */
1068 #define UNI_UPPER 0x1
1069 #define UNI_LOWER 0x2
1070 #define UNI_DIGIT 0x4
1071 #define UNI_XDIGIT 0x8
1072 #define UNI_SPACE 0x10
1074 #include "nsswitch/winbind_nss.h"
1076 /* forward declaration from printing.h to get around
1077 header file dependencies */
1081 struct smb_ldap_privates;
1083 /* forward declarations from smbldap.c */
1085 #include "smbldap.h"
1087 #include "smb_ldap.h"
1090 * Reasons for cache flush.
1093 enum flush_reason_enum {
1098 OPLOCK_RELEASE_FLUSH,
1102 /* NUM_FLUSH_REASONS must remain the last value in the enumeration. */
1105 /***** automatically generated prototypes *****/
1111 #include "ads_protos.h"
1114 /* We need this after proto.h to reference GetTimeOfDay(). */
1115 #include "smbprofile.h"
1117 /* String routines */
1120 #include "safe_string.h"
1122 #ifdef __COMPAR_FN_T
1123 #define QSORT_CAST (__compar_fn_t)
1127 #define QSORT_CAST (int (*)(const void *, const void *))
1130 #ifndef DEFAULT_PRINTING
1132 #define DEFAULT_PRINTING PRINT_CUPS
1133 #define PRINTCAP_NAME "cups"
1135 #define DEFAULT_PRINTING PRINT_SYSV
1136 #define PRINTCAP_NAME "lpstat"
1138 #define DEFAULT_PRINTING PRINT_BSD
1139 #define PRINTCAP_NAME "/etc/printcap"
1143 #ifndef PRINTCAP_NAME
1144 #define PRINTCAP_NAME "/etc/printcap"
1148 #define SIGCLD SIGCHLD
1159 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
1160 #define OSF1_ENH_SEC 1
1163 #ifndef ALLOW_CHANGE_PASSWORD
1164 #if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
1165 #define ALLOW_CHANGE_PASSWORD 1
1169 /* what is the longest significant password available on your system?
1170 Knowing this speeds up password searches a lot */
1171 #ifndef PASSWORD_LENGTH
1172 #define PASSWORD_LENGTH 8
1175 #ifdef REPLACE_INET_NTOA
1176 #define inet_ntoa rep_inet_ntoa
1187 #ifndef INADDR_LOOPBACK
1188 #define INADDR_LOOPBACK 0x7f000001
1192 #define INADDR_NONE 0xffffffff
1196 #define crypt ufc_crypt
1200 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
1203 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
1204 #define ULTRIX_AUTH 1
1208 char *strdup(const char *s);
1211 #ifndef HAVE_STRNDUP
1212 char *strndup(const char *s, size_t size);
1215 #ifndef HAVE_MEMMOVE
1216 void *memmove(void *dest,const void *src,int size);
1219 #ifndef HAVE_INITGROUPS
1220 int initgroups(char *name,gid_t id);
1224 int rename(const char *zfrom, const char *zto);
1228 time_t mktime(struct tm *t);
1231 #ifndef HAVE_STRLCPY
1232 size_t strlcpy(char *d, const char *s, size_t bufsize);
1235 #ifndef HAVE_STRLCAT
1236 size_t strlcat(char *d, const char *s, size_t bufsize);
1239 #ifndef HAVE_FTRUNCATE
1240 int ftruncate(int f,long l);
1243 #ifndef HAVE_STRNDUP
1244 char *strndup(const char *s, size_t n);
1247 #ifndef HAVE_STRNLEN
1248 size_t strnlen(const char *s, size_t n);
1251 #ifndef HAVE_STRTOUL
1252 unsigned long strtoul(const char *nptr, char **endptr, int base);
1256 int setenv(const char *name, const char *value, int overwrite);
1259 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL))
1261 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
1263 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESGID_DECL))
1264 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
1266 #ifndef HAVE_VASPRINTF_DECL
1267 int vasprintf(char **ptr, const char *format, va_list ap);
1270 #ifdef REPLACE_GETPASS
1271 #define getpass(prompt) getsmbpass((prompt))
1275 * Some older systems seem not to have MAXHOSTNAMELEN
1278 #ifndef MAXHOSTNAMELEN
1279 #define MAXHOSTNAMELEN 254
1282 /* yuck, I'd like a better way of doing this */
1283 #define DIRP_SIZE (256 + 32)
1286 * glibc on linux doesn't seem to have MSG_WAITALL
1287 * defined. I think the kernel has it though..
1291 #define MSG_WAITALL 0
1294 /* default socket options. Dave Miller thinks we should default to TCP_NODELAY
1295 given the socket IO pattern that Samba uses */
1297 #define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
1299 #define DEFAULT_SOCKET_OPTIONS ""
1302 /* Load header file for dynamic linking stuff */
1308 /* dmalloc -- free heap debugger (dmalloc.org). This should be near
1309 * the *bottom* of include files so as not to conflict. */
1310 #ifdef ENABLE_DMALLOC
1311 # include <dmalloc.h>
1315 /* Some POSIX definitions for those without */
1318 #define S_IFDIR 0x4000
1321 #define S_ISDIR(mode) ((mode & 0xF000) == S_IFDIR)
1324 #define S_IRWXU 00700 /* read, write, execute: owner */
1327 #define S_IRUSR 00400 /* read permission: owner */
1330 #define S_IWUSR 00200 /* write permission: owner */
1333 #define S_IXUSR 00100 /* execute permission: owner */
1336 #define S_IRWXG 00070 /* read, write, execute: group */
1339 #define S_IRGRP 00040 /* read permission: group */
1342 #define S_IWGRP 00020 /* write permission: group */
1345 #define S_IXGRP 00010 /* execute permission: group */
1348 #define S_IRWXO 00007 /* read, write, execute: other */
1351 #define S_IROTH 00004 /* read permission: other */
1354 #define S_IWOTH 00002 /* write permission: other */
1357 #define S_IXOTH 00001 /* execute permission: other */
1360 /* For sys_adminlog(). */
1362 #define LOG_EMERG 0 /* system is unusable */
1366 #define LOG_ALERT 1 /* action must be taken immediately */
1370 #define LOG_CRIT 2 /* critical conditions */
1374 #define LOG_ERR 3 /* error conditions */
1378 #define LOG_WARNING 4 /* warning conditions */
1382 #define LOG_NOTICE 5 /* normal but significant condition */
1386 #define LOG_INFO 6 /* informational */
1390 #define LOG_DEBUG 7 /* debug-level messages */
1393 #if HAVE_KERNEL_SHARE_MODES
1395 #define LOCK_MAND 32 /* This is a mandatory flock */
1396 #define LOCK_READ 64 /* ... Which allows concurrent read operations */
1397 #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */
1398 #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */
1402 extern int DEBUGLEVEL;
1404 #define MAX_SEC_CTX_DEPTH 8 /* Maximum number of security contexts */
1407 #ifdef GLIBC_HACK_FCNTL64
1408 /* this is a gross hack. 64 bit locking is completely screwed up on
1409 i386 Linux in glibc 2.1.95 (which ships with RedHat 7.0). This hack
1410 "fixes" the problem with the current 2.4.0test kernels
1412 #define fcntl fcntl64
1420 /* Needed for sys_dlopen/sys_dlsym/sys_dlclose */
1422 #define RTLD_GLOBAL 0
1433 /* needed for some systems without iconv. Doesn't really matter
1434 what error code we use */
1439 /* add varargs prototypes with printf checking */
1441 int fdprintf(int , const char *, ...) PRINTF_ATTRIBUTE(2,3);
1443 int d_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2);
1445 int d_fprintf(FILE *f, const char *, ...) PRINTF_ATTRIBUTE(2,3);
1446 #ifndef HAVE_SNPRINTF_DECL
1448 int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
1450 #ifndef HAVE_ASPRINTF_DECL
1452 int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
1455 /* Fix prototype problem with non-C99 compliant snprintf implementations, esp
1456 HPUX 11. Don't change the sense of this #if statement. Read the comments
1457 in lib/snprint.c if you think you need to. See also bugzilla bug 174. */
1459 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
1460 #define snprintf smb_snprintf
1461 #define vsnprintf smb_vsnprintf
1464 int smb_snprintf(char *str,size_t count,const char *fmt,...);
1465 int smb_vsnprintf (char *str, size_t count, const char *fmt, va_list args);
1470 void sys_adminlog(int priority, const char *format_str, ...) PRINTF_ATTRIBUTE(2,3);
1473 int pstr_sprintf(pstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1475 int fstr_sprintf(fstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1477 int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1479 int smb_xvasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1481 /* we used to use these fns, but now we have good replacements
1482 for snprintf and vsnprintf */
1483 #define slprintf snprintf
1484 #define vslprintf vsnprintf
1486 /* we need to use __va_copy() on some platforms */
1488 #define VA_COPY(dest, src) va_copy(dest, src)
1490 #ifdef HAVE___VA_COPY
1491 #define VA_COPY(dest, src) __va_copy(dest, src)
1493 #define VA_COPY(dest, src) (dest) = (src)
1498 time_t timegm(struct tm *tm);
1502 * Veritas File System. Often in addition to native.
1505 #if defined(HAVE_SYS_FS_VX_QUOTA_H)
1509 #if defined(HAVE_KRB5)
1511 krb5_error_code smb_krb5_parse_name(krb5_context context,
1512 const char *name, /* in unix charset */
1513 krb5_principal *principal);
1515 krb5_error_code smb_krb5_unparse_name(krb5_context context,
1516 krb5_const_principal principal,
1519 #ifndef HAVE_KRB5_SET_REAL_TIME
1520 krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds);
1523 #ifndef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES
1524 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
1527 #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
1528 krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
1531 #ifndef HAVE_KRB5_FREE_UNPARSED_NAME
1532 void krb5_free_unparsed_name(krb5_context ctx, char *val);
1535 /* Samba wrapper function for krb5 functionality. */
1536 void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr);
1537 int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
1538 int create_kerberos_key_from_string_direct(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
1539 BOOL get_auth_data_from_tkt(TALLOC_CTX *mem_ctx, DATA_BLOB *auth_data, krb5_ticket *tkt);
1540 krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt);
1541 krb5_error_code krb5_locate_kdc(krb5_context ctx, const krb5_data *realm, struct sockaddr **addr_pp, int *naddrs, int get_masters);
1542 krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes);
1543 void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes);
1544 BOOL get_krb5_smb_session_key(krb5_context context, krb5_auth_context auth_context, DATA_BLOB *session_key, BOOL remote);
1545 krb5_error_code smb_krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *kt_entry);
1546 krb5_principal kerberos_fetch_salt_princ_for_host_princ(krb5_context context, krb5_principal host_princ, int enctype);
1547 void kerberos_set_creds_enctype(krb5_creds *pcreds, int enctype);
1548 BOOL kerberos_compatible_enctypes(krb5_context context, krb5_enctype enctype1, krb5_enctype enctype2);
1549 void kerberos_free_data_contents(krb5_context context, krb5_data *pdata);
1550 NTSTATUS decode_pac_data(TALLOC_CTX *mem_ctx,
1551 DATA_BLOB *pac_data_blob,
1552 krb5_context context,
1553 krb5_keyblock *service_keyblock,
1554 krb5_const_principal client_principal,
1555 time_t tgs_authtime,
1556 PAC_DATA **pac_data);
1557 void smb_krb5_checksum_from_pac_sig(krb5_checksum *cksum,
1558 PAC_SIGNATURE_DATA *sig);
1559 krb5_error_code smb_krb5_verify_checksum(krb5_context context,
1560 krb5_keyblock *keyblock,
1561 krb5_keyusage usage,
1562 krb5_checksum *cksum,
1565 time_t get_authtime_from_tkt(krb5_ticket *tkt);
1566 void smb_krb5_free_ap_req(krb5_context context,
1567 krb5_ap_req *ap_req);
1568 krb5_error_code smb_krb5_get_keyinfo_from_ap_req(krb5_context context,
1569 const krb5_data *inbuf,
1571 krb5_enctype *enctype);
1572 krb5_error_code krb5_rd_req_return_keyblock_from_keytab(krb5_context context,
1573 krb5_auth_context *auth_context,
1574 const krb5_data *inbuf,
1575 krb5_const_principal server,
1577 krb5_flags *ap_req_options,
1578 krb5_ticket **ticket,
1579 krb5_keyblock **keyblock);
1580 krb5_error_code smb_krb5_parse_name_norealm(krb5_context context,
1582 krb5_principal *principal);
1583 BOOL smb_krb5_principal_compare_any_realm(krb5_context context,
1584 krb5_const_principal princ1,
1585 krb5_const_principal princ2);
1586 int cli_krb5_get_ticket(const char *principal, time_t time_offset,
1587 DATA_BLOB *ticket, DATA_BLOB *session_key_krb5, uint32 extra_ap_opts, const char *ccname);
1588 PAC_LOGON_INFO *get_logon_info_from_pac(PAC_DATA *pac_data);
1589 krb5_error_code smb_krb5_renew_ticket(const char *ccache_string, const char *client_string, const char *service_string, time_t *new_start_time);
1590 krb5_error_code kpasswd_err_to_krb5_err(krb5_error_code res_code);
1591 krb5_error_code smb_krb5_gen_netbios_krb5_address(smb_krb5_addresses **kerb_addr);
1592 krb5_error_code smb_krb5_free_addresses(krb5_context context, smb_krb5_addresses *addr);
1593 NTSTATUS krb5_to_nt_status(krb5_error_code kerberos_error);
1594 krb5_error_code nt_status_to_krb5(NTSTATUS nt_status);
1595 void smb_krb5_free_error(krb5_context context, krb5_error *krberror);
1596 krb5_error_code handle_krberror_packet(krb5_context context,
1598 #endif /* HAVE_KRB5 */
1603 /* function declarations not included in proto.h */
1604 LDAP *ldap_open_with_timeout(const char *server, int port, unsigned int to);
1606 #endif /* HAVE_LDAP */
1609 /* TRUE and FALSE are part of the C99 standard and gcc, but
1610 unfortunately many vendor compilers don't support them. Use True
1611 and False instead. */
1616 #define TRUE __ERROR__XX__DONT_USE_TRUE
1621 #define FALSE __ERROR__XX__DONT_USE_FALSE
1623 /* If we have blacklisted mmap() try to avoid using it accidentally by
1624 undefining the HAVE_MMAP symbol. */
1626 #ifdef MMAP_BLACKLIST
1630 #define CONST_DISCARD(type, ptr) ((type) ((void *) (ptr)))
1631 #define CONST_ADD(type, ptr) ((type) ((const void *) (ptr)))
1633 #ifndef NORETURN_ATTRIBUTE
1635 #define NORETURN_ATTRIBUTE __attribute__ ((noreturn))
1637 #define NORETURN_ATTRIBUTE
1641 void smb_panic( const char *why ) NORETURN_ATTRIBUTE ;
1642 void dump_core(void) NORETURN_ATTRIBUTE ;
1643 void exit_server(const char *const reason) NORETURN_ATTRIBUTE ;
1644 void exit_server_cleanly(const char *const reason) NORETURN_ATTRIBUTE ;
1645 void exit_server_fault(void) NORETURN_ATTRIBUTE ;
1647 #endif /* _INCLUDES_H */