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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "../replace/replace.h"
25 #if _SAMBA_BUILD_ == 4
27 # define _SAMBA_BUILD_ 3
30 /* make sure we have included the correct config.h */
31 #ifndef NO_CONFIG_H /* for some tests */
32 #ifndef CONFIG_H_IS_FROM_SAMBA
33 #error "make sure you have removed all config.h files from standalone builds!"
34 #error "the included config.h isn't from samba!"
36 #endif /* NO_CONFIG_H */
38 /* only do the C++ reserved word check when we compile
39 to include --with-developer since too many systems
40 still have comflicts with their header files (e.g. IRIX 6.4) */
42 #if !defined(__cplusplus) && defined(DEVELOPER) && defined(__linux__)
43 #define class #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
44 #define private #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
45 #define public #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
46 #define protected #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
47 #define template #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
48 #define this #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
49 #define new #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
50 #define delete #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
51 #define friend #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
57 /* on SUNOS4 termios.h conflicts with sys/ioctl.h */
63 * <unistd.h> has to be included before any other to get
64 * large file support on Reliant UNIX. Yes, it's broken :-).
69 #endif /* RELIANTUNIX */
71 #include "system/dir.h"
72 #include "system/filesys.h"
73 #include "system/locale.h"
74 #include "system/network.h"
75 #include "system/passwd.h"
76 #include "system/select.h"
77 #include "system/shmem.h"
78 #include "system/terminal.h"
79 #include "system/time.h"
80 #include "system/wait.h"
82 #if defined(HAVE_RPC_RPC_H)
84 * Check for AUTH_ERROR define conflict with rpc/rpc.h in prot.h.
86 #if defined(HAVE_SYS_SECURITY_H) && defined(HAVE_RPC_AUTH_ERROR_CONFLICT)
90 * HP-UX 11.X has TCP_NODELAY and TCP_MAXSEG defined in <netinet/tcp.h> which
91 * was included above. However <rpc/rpc.h> includes <sys/xti.h> which defines
92 * them again without checking if they already exsist. This generates
93 * two "Redefinition of macro" warnings for every single .c file that is
96 #if defined(HPUX) && defined(TCP_NODELAY)
99 #if defined(HPUX) && defined(TCP_MAXSEG)
105 #if defined(HAVE_YP_GET_DEFAULT_DOMAIN) && defined(HAVE_SETNETGRENT) && defined(HAVE_ENDNETGRENT) && defined(HAVE_GETNETGRENT)
106 #define HAVE_NETGROUP 1
109 #if defined (HAVE_NETGROUP)
110 #if defined(HAVE_RPCSVC_YP_PROT_H)
112 * HP-UX 11.X has TCP_NODELAY and TCP_MAXSEG defined in <netinet/tcp.h> which
113 * was included above. However <rpc/rpc.h> includes <sys/xti.h> which defines
114 * them again without checking if they already exsist. This generates
115 * two "Redefinition of macro" warnings for every single .c file that is
118 #if defined(HPUX) && defined(TCP_NODELAY)
121 #if defined(HPUX) && defined(TCP_MAXSEG)
124 #include <rpcsvc/yp_prot.h>
126 #if defined(HAVE_RPCSVC_YPCLNT_H)
127 #include <rpcsvc/ypclnt.h>
129 #endif /* HAVE_NETGROUP */
139 #if HAVE_SYS_ATTRIBUTES_H
140 #include <sys/attributes.h>
145 #define ENOATTR ENODATA
147 #define ENOATTR ENOENT
151 /* mutually exclusive (SuSE 8.2) */
152 #if HAVE_ATTR_XATTR_H
153 #include <attr/xattr.h>
154 #elif HAVE_SYS_XATTR_H
155 #include <sys/xattr.h>
162 #ifdef HAVE_SYS_EXTATTR_H
163 #include <sys/extattr.h>
166 #ifdef HAVE_SYS_UIO_H
171 #include <langinfo.h>
175 #include <netgroup.h>
178 #if defined(HAVE_AIO_H) && defined(WITH_AIO)
182 #ifdef WITH_MADVISE_PROTECTED
183 #include <sys/mman.h>
186 /* Special macros that are no-ops except when run under Valgrind on
187 * x86. They've moved a little bit from valgrind 1.0.4 to 1.9.4 */
188 #if HAVE_VALGRIND_MEMCHECK_H
189 /* memcheck.h includes valgrind.h */
190 #include <valgrind/memcheck.h>
191 #elif HAVE_VALGRIND_H
192 #include <valgrind.h>
195 /* we support ADS if we want it and have krb5 and ldap libs */
196 #if defined(WITH_ADS) && defined(HAVE_KRB5) && defined(HAVE_LDAP)
201 * Define additional missing types
204 typedef sig_atomic_t SIG_ATOMIC_T;
206 typedef sig_atomic_t volatile SIG_ATOMIC_T;
210 #define uchar unsigned char
214 Samba needs type definitions for int16, int32, uint16 and uint32.
216 Normally these are signed and unsigned 16 and 32 bit integers, but
217 they actually only need to be at least 16 and 32 bits
218 respectively. Thus if your word size is 8 bytes just defining them
219 as signed and unsigned int will work.
223 #define uint8 uint8_t
226 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
227 # define int16 int16_t
228 /* needed to work around compile issue on HP-UX 11.x */
233 * Note we duplicate the size tests in the unsigned
234 * case as int16 may be a typedef from rpc/rpc.h
238 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
239 # define uint16 uint16_t
242 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
243 # define int32 int32_t
245 /* needed to work around compile issue on HP-UX 11.x */
251 * Note we duplicate the size tests in the unsigned
252 * case as int32 may be a typedef from rpc/rpc.h
255 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
256 # define uint32 uint32_t
260 * check for 8 byte long long
264 # define uint64 uint64_t
268 # define int64 int64_t
273 * Types for devices, inodes and offsets.
277 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)
278 # define SMB_DEV_T dev64_t
280 # define SMB_DEV_T dev_t
284 #ifndef LARGE_SMB_DEV_T
285 # if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)) || (defined(SIZEOF_DEV_T) && (SIZEOF_DEV_T == 8))
286 # define LARGE_SMB_DEV_T 1
290 #ifdef LARGE_SMB_DEV_T
291 #define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32))
292 #define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(((uint64_t)(IVAL((p),(ofs))))| (((uint64_t)(IVAL((p),(ofs)+4))) << 32)))
294 #define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),v),SIVAL((p),(ofs)+4,0))
295 #define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(IVAL((p),(ofs))))
299 * Setup the correctly sized inode type.
303 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)
304 # define SMB_INO_T ino64_t
306 # define SMB_INO_T ino_t
310 #ifndef LARGE_SMB_INO_T
311 # if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)) || (defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8))
312 # define LARGE_SMB_INO_T 1
316 #ifdef LARGE_SMB_INO_T
317 #define SINO_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32))
318 #define INO_T_VAL(p, ofs) ((SMB_INO_T)(((uint64_t)(IVAL(p,ofs)))| (((uint64_t)(IVAL(p,(ofs)+4))) << 32)))
320 #define SINO_T_VAL(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
321 #define INO_T_VAL(p, ofs) ((SMB_INO_T)(IVAL((p),(ofs))))
325 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)
326 # define SMB_OFF_T off64_t
328 # define SMB_OFF_T off_t
332 #define SBIG_UINT(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
333 #define BIG_UINT(p, ofs) ((((uint64_t) IVAL(p,(ofs)+4))<<32)|IVAL(p,ofs))
334 #define IVAL2_TO_SMB_BIG_UINT(buf,off) ( (((uint64_t)(IVAL((buf),(off)))) & ((uint64_t)0xFFFFFFFF)) | \
335 (( ((uint64_t)(IVAL((buf),(off+4)))) & ((uint64_t)0xFFFFFFFF) ) << 32 ) )
338 /* this should really be a 64 bit type if possible */
339 typedef uint64_t br_off;
341 #define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8)
344 * Set the define that tells us if we can do 64 bit
348 #ifndef LARGE_SMB_OFF_T
349 # if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8))
350 # define LARGE_SMB_OFF_T 1
354 #ifdef LARGE_SMB_OFF_T
355 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
356 #define SOFF_T_R(p, ofs, v) (SIVAL(p,(ofs)+4,(v)&0xFFFFFFFF), SIVAL(p,ofs,(v)>>32))
357 #define IVAL_TO_SMB_OFF_T(buf,off) ((SMB_OFF_T)(( ((uint64_t)(IVAL((buf),(off)))) & ((uint64_t)0xFFFFFFFF) )))
359 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
360 #define SOFF_T_R(p, ofs, v) (SIVAL(p,(ofs)+4,v),SIVAL(p,ofs,0))
361 #define IVAL_TO_SMB_OFF_T(buf,off) ((SMB_OFF_T)(( ((uint32)(IVAL((buf),(off)))) & 0xFFFFFFFF )))
364 #ifndef HAVE_BLKSIZE_T
365 /* This is mainly for HP/UX which defines st_blksize as long */
366 typedef long blksize_t;
369 #ifndef HAVE_BLKCNT_T
370 /* This is mainly for HP/UX which doesn't have blkcnt_t */
371 typedef long blkcnt_t;
375 * Type for stat structure.
387 struct timespec st_ex_atime;
388 struct timespec st_ex_mtime;
389 struct timespec st_ex_ctime;
390 struct timespec st_ex_btime; /* birthtime */
391 /* Is birthtime real, or was it calculated ? */
392 bool st_ex_calculated_birthtime;
393 blksize_t st_ex_blksize;
394 blkcnt_t st_ex_blocks;
396 uint32_t st_ex_flags;
400 * Add space for VFS internal extensions. The initial user of this
401 * would be the onefs modules, passing the snapid from the stat calls
402 * to the file_id_create call. Maybe we'll have to expand this later,
403 * but the core of Samba should never look at this field.
405 uint64_t vfs_private;
408 typedef struct stat_ex SMB_STRUCT_STAT;
411 * Type for dirent structure.
414 #ifndef SMB_STRUCT_DIRENT
415 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIRENT64)
416 # define SMB_STRUCT_DIRENT struct dirent64
418 # define SMB_STRUCT_DIRENT struct dirent
423 * Type for DIR structure.
426 #ifndef SMB_STRUCT_DIR
427 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIR64)
428 # define SMB_STRUCT_DIR DIR64
430 # define SMB_STRUCT_DIR DIR
435 * Defines for 64 bit fcntl locks.
438 #ifndef SMB_STRUCT_FLOCK
439 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
440 # define SMB_STRUCT_FLOCK struct flock64
442 # define SMB_STRUCT_FLOCK struct flock
447 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
448 # define SMB_F_SETLKW F_SETLKW64
450 # define SMB_F_SETLKW F_SETLKW
455 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
456 # define SMB_F_SETLK F_SETLK64
458 # define SMB_F_SETLK F_SETLK
463 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
464 # define SMB_F_GETLK F_GETLK64
466 # define SMB_F_GETLK F_GETLK
471 * Type for aiocb structure.
474 #ifndef SMB_STRUCT_AIOCB
475 # if defined(WITH_AIO)
476 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64)
477 # define SMB_STRUCT_AIOCB struct aiocb64
479 # define SMB_STRUCT_AIOCB struct aiocb
482 # define SMB_STRUCT_AIOCB int /* AIO not being used but we still need the define.... */
486 enum timestamp_set_resolution {
487 TIMESTAMP_SET_SECONDS = 0,
489 TIMESTAMP_SET_NT_OR_BETTER
492 /* Our own fstrings */
501 | The infamous pstring |
508 _________)/\\_//(\/(/\)/\//\/\///|_)_______
512 #define FSTRING_LEN 256
513 typedef char fstring[FSTRING_LEN];
516 /* Lists, trees, caching, database... */
517 #include "../lib/util/util.h"
518 #include "../lib/util/util_net.h"
519 #include "../lib/util/xfile.h"
520 #include "../lib/util/memory.h"
521 #include "../lib/util/attr.h"
522 #include "../lib/util/tsort.h"
523 #include "../lib/util/dlinklist.h"
525 #include "util_tdb.h"
530 #include "../lib/util/tevent_unix.h"
531 #include "../lib/util/tevent_ntstatus.h"
532 #include "../lib/tsocket/tsocket.h"
534 #include "../lib/util/data_blob.h"
535 #include "../lib/util/time.h"
537 #include "libads/ads_status.h"
538 #include "../libcli/util/error.h"
540 #include "../lib/util/charset/charset.h"
541 #include "dynconfig.h"
542 #include "debugparse.h"
543 #include "../libcli/security/privileges.h"
544 #include "messages.h"
546 #include "smb_perfcount.h"
548 #include "nameserv.h"
549 #include "../lib/util/byteorder.h"
554 #include "librpc/rpc/dcerpc.h"
555 #include "ntdomain.h"
559 #include "../lib/util/talloc_stack.h"
560 #include "../lib/util/smb_threads.h"
561 #include "../lib/util/smb_threads_internal.h"
564 * Reasons for cache flush.
567 enum flush_reason_enum {
572 OPLOCK_RELEASE_FLUSH,
576 /* NUM_FLUSH_REASONS must remain the last value in the enumeration. */
579 #include "modules/nfs4_acls.h"
581 /***** prototypes *****/
585 #include "libcli/security/secace.h"
586 #include "libcli/security/secacl.h"
587 #include "libcli/security/security_descriptor.h"
588 #include "libcli/security/sddl.h"
590 #if defined(HAVE_POSIX_ACLS)
591 #include "modules/vfs_posixacl.h"
594 #if defined(HAVE_TRU64_ACLS)
595 #include "modules/vfs_tru64acl.h"
598 #if defined(HAVE_SOLARIS_ACLS) || defined(HAVE_UNIXWARE_ACLS)
599 #include "modules/vfs_solarisacl.h"
602 #if defined(HAVE_HPUX_ACLS)
603 #include "modules/vfs_hpuxacl.h"
606 #if defined(HAVE_IRIX_ACLS)
607 #include "modules/vfs_irixacl.h"
610 /* We need this after proto.h to reference GetTimeOfDay(). */
611 #include "smbprofile.h"
613 /* String routines */
616 #include "safe_string.h"
618 /* prototypes from lib/util_transfer_file.c */
619 #include "transfer_file.h"
622 #define SIGCLD SIGCHLD
626 #define SIGRTMIN NSIG
633 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
634 #define OSF1_ENH_SEC 1
637 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
638 #define ULTRIX_AUTH 1
641 /* yuck, I'd like a better way of doing this */
642 #define DIRP_SIZE (256 + 32)
644 /* default socket options. Dave Miller thinks we should default to TCP_NODELAY
645 given the socket IO pattern that Samba uses */
647 #define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
649 #define DEFAULT_SOCKET_OPTIONS ""
652 /* dmalloc -- free heap debugger (dmalloc.org). This should be near
653 * the *bottom* of include files so as not to conflict. */
654 #ifdef ENABLE_DMALLOC
655 # include <dmalloc.h>
659 #if HAVE_KERNEL_SHARE_MODES
661 #define LOCK_MAND 32 /* This is a mandatory flock */
662 #define LOCK_READ 64 /* ... Which allows concurrent read operations */
663 #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */
664 #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */
668 #define MAX_SEC_CTX_DEPTH 8 /* Maximum number of security contexts */
671 #ifdef GLIBC_HACK_FCNTL64
672 /* this is a gross hack. 64 bit locking is completely screwed up on
673 i386 Linux in glibc 2.1.95 (which ships with RedHat 7.0). This hack
674 "fixes" the problem with the current 2.4.0test kernels
676 #define fcntl fcntl64
684 /* needed for some systems without iconv. Doesn't really matter
685 what error code we use */
690 /* add varargs prototypes with printf checking */
692 int fdprintf(int , const char *, ...) PRINTF_ATTRIBUTE(2,3);
694 int d_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2);
696 int d_fprintf(FILE *f, const char *, ...) PRINTF_ATTRIBUTE(2,3);
699 void sys_adminlog(int priority, const char *format_str, ...) PRINTF_ATTRIBUTE(2,3);
702 int fstr_sprintf(fstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
704 int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
706 int smb_xvasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
708 int asprintf_strupper_m(char **strp, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
709 char *talloc_asprintf_strupper_m(TALLOC_CTX *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
712 * Veritas File System. Often in addition to native.
715 #if defined(HAVE_SYS_FS_VX_QUOTA_H)
720 #define XATTR_CREATE 0x1 /* set value, fail if attr already exists */
723 #ifndef XATTR_REPLACE
724 #define XATTR_REPLACE 0x2 /* set value, fail if attr does not exist */
727 #if defined(HAVE_LINUX_READAHEAD) && ! defined(HAVE_READAHEAD_DECL)
728 ssize_t readahead(int fd, off64_t offset, size_t count);
734 #define TRUE __ERROR__XX__DONT_USE_TRUE
739 #define FALSE __ERROR__XX__DONT_USE_FALSE
741 /* If we have blacklisted mmap() try to avoid using it accidentally by
742 undefining the HAVE_MMAP symbol. */
744 #ifdef MMAP_BLACKLIST
748 #ifndef CONST_DISCARD
749 #define CONST_DISCARD(type, ptr) ((type) ((void *) (ptr)))
752 void dump_core(void) _NORETURN_;
753 void exit_server(const char *const reason) _NORETURN_;
754 void exit_server_cleanly(const char *const reason) _NORETURN_;
755 void exit_server_fault(void) _NORETURN_;
757 #if defined(HAVE_IPV6)
758 void in6_addr_to_sockaddr_storage(struct sockaddr_storage *ss,
762 /* samba3 doesn't use uwrap yet */
763 #define uwrap_enabled() 0
765 #define BASE_RID (0x000003E8L)
767 #endif /* _INCLUDES_H */