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 #ifndef NO_CONFIG_H /* for some tests */
26 #include "smb_build.h"
32 #define DEFAULT_PRINTING PRINT_AIX
33 #define PRINTCAP_NAME "/etc/qconfig"
37 #define DEFAULT_PRINTING PRINT_HPUX
41 #define DEFAULT_PRINTING PRINT_QNX
45 /* on SUNOS4 termios.h conflicts with sys/ioctl.h */
49 #ifndef DEFAULT_PRINTING
50 #define DEFAULT_PRINTING PRINT_BSD
53 #define PRINTCAP_NAME "/etc/printcap"
57 /** Use gcc attribute to check printf fns. a1 is the 1-based index of
58 * the parameter containing the format, and a2 the index of the first
59 * argument. Note that some gcc 2.x versions don't handle this
61 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
63 #define PRINTF_ATTRIBUTE(a1, a2)
67 /** gcc attribute used on function parameters so that it does not emit
68 * warnings about them being unused. **/
69 # define UNUSED(param) param __attribute__ ((unused))
71 # define UNUSED(param) param
72 /** Feel free to add definitions for other compilers here. */
77 * <unistd.h> has to be included before any other to get
78 * large file support on Reliant UNIX. Yes, it's broken :-).
83 #endif /* RELIANTUNIX */
85 #include <sys/types.h>
87 #ifdef TIME_WITH_SYS_TIME
91 #ifdef HAVE_SYS_TIME_H
98 #ifdef HAVE_SYS_RESOURCE_H
99 #include <sys/resource.h>
109 #ifdef HAVE_SYS_PARAM_H
110 #include <sys/param.h>
117 #ifdef HAVE_SYS_SOCKET_H
118 #include <sys/socket.h>
121 #ifdef HAVE_UNIXSOCKET
125 #ifdef HAVE_SYS_SYSCALL_H
126 #include <sys/syscall.h>
135 #ifdef HAVE_STRINGS_H
150 #ifdef HAVE_SYS_FCNTL_H
151 #include <sys/fcntl.h>
155 #include <sys/stat.h>
161 #ifdef HAVE_SYS_IOCTL_H
162 #include <sys/ioctl.h>
165 #ifdef HAVE_SYS_FILIO_H
166 #include <sys/filio.h>
171 #ifdef HAVE_SYS_WAIT_H
172 #include <sys/wait.h>
180 #ifdef HAVE_SYS_PRIV_H
181 #include <sys/priv.h>
193 #ifdef HAVE_SYS_SELECT_H
194 #include <sys/select.h>
197 #ifdef HAVE_SYS_MODE_H
198 /* apparently AIX needs this for S_ISLNK */
200 #include <sys/mode.h>
216 #include <netinet/in.h>
217 #include <arpa/inet.h>
223 #ifdef HAVE_SYS_SYSLOG_H
224 #include <sys/syslog.h>
228 #include <sys/file.h>
230 #ifdef HAVE_NETINET_TCP_H
231 #include <netinet/tcp.h>
235 * The next three defines are needed to access the IPTOS_* options
239 #ifdef HAVE_NETINET_IN_SYSTM_H
240 #include <netinet/in_systm.h>
243 #ifdef HAVE_NETINET_IN_IP_H
244 #include <netinet/in_ip.h>
247 #ifdef HAVE_NETINET_IP_H
248 #include <netinet/ip.h>
251 #if defined(HAVE_TERMIOS_H)
252 /* POSIX terminal handling. */
254 #elif defined(HAVE_TERMIO_H)
255 /* Older SYSV terminal handling - don't use if we can avoid it. */
257 #elif defined(HAVE_SYS_TERMIO_H)
258 /* Older SYSV terminal handling - don't use if we can avoid it. */
259 #include <sys/termio.h>
264 # define NAMLEN(dirent) strlen((dirent)->d_name)
266 # define dirent direct
267 # define NAMLEN(dirent) (dirent)->d_namlen
269 # include <sys/ndir.h>
272 # include <sys/dir.h>
279 #ifdef HAVE_SYS_MMAN_H
280 #include <sys/mman.h>
288 #ifdef HAVE_SYS_MOUNT_H
289 #include <sys/mount.h>
292 #ifdef HAVE_SYS_VFS_H
296 #ifdef HAVE_SYS_ACL_H
300 #ifdef HAVE_SYS_FS_S5PARAM_H
301 #include <sys/fs/s5param.h>
304 #if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
305 #include <sys/filsys.h>
308 #ifdef HAVE_SYS_STATFS_H
309 # include <sys/statfs.h>
313 #include <sys/dustat.h>
316 #ifdef HAVE_SYS_STATVFS_H
317 #include <sys/statvfs.h>
324 #ifdef HAVE_GETPWANAM
325 #include <sys/label.h>
326 #include <sys/audit.h>
330 #ifdef HAVE_SYS_SECURITY_H
331 #include <sys/security.h>
333 #define PASSWORD_LENGTH 16
334 #endif /* HAVE_SYS_SECURITY_H */
340 #ifdef HAVE_STROPTS_H
344 #ifdef HAVE_SYS_CAPABILITY_H
346 #if defined(BROKEN_REDHAT_7_SYSTEM_HEADERS) && !defined(_I386_STATFS_H)
347 #define _I386_STATFS_H
348 #define BROKEN_REDHAT_7_STATFS_WORKAROUND
351 #include <sys/capability.h>
353 #ifdef BROKEN_REDHAT_7_STATFS_WORKAROUND
354 #undef _I386_STATFS_H
355 #undef BROKEN_REDHAT_7_STATFS_WORKAROUND
360 #if defined(HAVE_SYS_IPC_H)
362 #endif /* HAVE_SYS_IPC_H */
364 #if defined(HAVE_SYS_SHM_H)
366 #endif /* HAVE_SYS_SHM_H */
368 #ifdef HAVE_NATIVE_ICONV
387 #ifdef HAVE_GSSAPI_GSSAPI_H
388 #include <gssapi/gssapi.h>
391 #ifdef HAVE_GSSAPI_GSSAPI_GENERIC_H
392 #include <gssapi/gssapi_generic.h>
395 #ifdef HAVE_COM_ERR_H
399 /* we support ADS if we want it and have krb5 and ldap libs */
400 #if defined(WITH_ADS) && defined(HAVE_KRB5) && defined(HAVE_LDAP)
405 * Define VOLATILE if needed.
408 #if defined(HAVE_VOLATILE)
409 #define VOLATILE volatile
415 * Define additional missing types
417 #ifndef HAVE_SIG_ATOMIC_T_TYPE
418 typedef int sig_atomic_t;
421 #ifndef HAVE_SOCKLEN_T_TYPE
422 typedef int socklen_t;
427 Samba needs type definitions for
428 int8_t, int16_t, int32_t, int64_t
429 uint8_t, uint16_t, uint32_t and uint64_t.
431 Normally these are signed and unsigned 8, 16, 32 and 64 bit integers, but
432 they actually only need to be at least 8, 16, 32 and 64 bits
433 respectively. Thus if your word size is 8 bytes just defining them
434 as signed and unsigned int will work.
442 #define uint8 uint8_t
446 #define int16 int16_t
450 #define uint16 uint16_t
454 #define int32 int32_t
458 #define uint32 uint32_t
462 #define int64 int64_t
466 #define uint64 uint64_t
470 #define UINT8_MAX 255
474 #define UINT16_MAX 65535
478 * Types for devices, inodes and offsets.
482 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)
483 # define SMB_DEV_T dev64_t
485 # define SMB_DEV_T dev_t
490 * Setup the correctly sized inode type.
494 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)
495 # define SMB_INO_T ino64_t
497 # define SMB_INO_T ino_t
501 #ifndef LARGE_SMB_INO_T
502 # if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)) || (defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8))
503 # define LARGE_SMB_INO_T 1
507 #ifdef LARGE_SMB_INO_T
508 #define SINO_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
510 #define SINO_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
514 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)
515 # define SMB_OFF_T off64_t
517 # define SMB_OFF_T off_t
522 * Set the define that tells us if we can do 64 bit
526 #ifndef LARGE_SMB_OFF_T
527 # if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8))
528 # define LARGE_SMB_OFF_T 1
533 * Type for stat structure.
536 #ifndef SMB_STRUCT_STAT
537 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STAT64) && defined(HAVE_OFF64_T)
538 # define SMB_STRUCT_STAT struct stat64
540 # define SMB_STRUCT_STAT struct stat
545 * Type for dirent structure.
548 #ifndef SMB_STRUCT_DIRENT
549 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIRENT64)
550 # define smb_dirent dirent64
552 # define smb_dirent dirent
557 * Defines for 64 bit fcntl locks.
560 #ifndef SMB_STRUCT_FLOCK
561 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
562 # define SMB_STRUCT_FLOCK struct flock64
564 # define SMB_STRUCT_FLOCK struct flock
569 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
570 # define SMB_F_SETLKW F_SETLKW64
572 # define SMB_F_SETLKW F_SETLKW
577 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
578 # define SMB_F_SETLK F_SETLK64
580 # define SMB_F_SETLK F_SETLK
585 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
586 # define SMB_F_GETLK F_GETLK64
588 # define SMB_F_GETLK F_GETLK
593 #define MIN(a,b) ((a)<(b)?(a):(b))
597 #define MAX(a,b) ((a)>(b)?(a):(b))
600 #ifndef HAVE_STRERROR
601 extern char *sys_errlist[];
602 #define strerror(i) sys_errlist[i]
605 #ifndef HAVE_ERRNO_DECL
609 #ifdef HAVE_BROKEN_GETGROUPS
616 #define NGROUPS_MAX 32 /* Guess... */
619 /* Our own pstrings and fstrings */
622 /* Lists, trees, caching, database... */
624 #include "dlinklist.h"
625 #include "lib/ldb/include/ldb.h"
626 #include "lib/tdb/include/tdb.h"
627 #include "lib/tdb/include/spinlock.h"
628 #include "lib/tdb/include/tdbutil.h"
631 #include "nt_status.h"
632 #include "interfaces.h"
636 #include "messages.h"
638 #include "dynconfig.h"
644 #include "lib/socket/socket.h"
645 #include "libcli/ldap/ldap.h"
646 #include "nameserv.h"
649 #include "byteorder.h"
662 #include "librpc/ndr/libndr.h"
663 #include "librpc/ndr/ndr_sec.h"
664 #include "librpc/gen_ndr/ndr_misc.h"
665 #include "librpc/gen_ndr/ndr_dcerpc.h"
666 #include "librpc/rpc/dcerpc.h"
667 #include "librpc/gen_ndr/tables.h"
669 #include "libcli/auth/ntlmssp.h"
670 #include "libcli/auth/credentials.h"
671 #include "libcli/auth/kerberos.h"
672 #include "libcli/auth/gensec.h"
673 #include "libcli/auth/spnego.h"
674 #include "auth/auth.h"
676 #include "smb_interfaces.h"
677 #include "smbd/server.h"
678 #include "smbd/service.h"
679 #include "rpc_server/dcerpc_server.h"
682 #include "smb_server/smb_server.h"
683 #include "ntvfs/ntvfs.h"
684 #include "cli_context.h"
685 #include "registry.h"
687 #include "ldap_server/ldap_server.h"
688 #include "gtk/common/gtk-smb.h"
689 #include "gtk/common/select.h"
691 #include "libnet/libnet.h"
692 #include "utils/net/net.h"
694 #include "nsswitch/winbind_client.h"
696 /* hmm, this really is getting ugly isn't it .... we probably need to
697 have some way to have subsystem includes without including it
699 #include "ntvfs/posix/vfs_posix.h"
701 #define malloc_p(type) (type *)malloc(sizeof(type))
702 #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count)
703 #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count)
705 #ifndef HAVE_COMPARISON_FN_T
706 typedef int (*comparison_fn_t)(const void *, const void *);
709 /***** automatically generated prototypes *****/
710 #define _PRINTF_ATTRIBUTE(a1, a2) PRINTF_ATTRIBUTE(a1, a2)
712 #undef _PRINTF_ATTRIBUTE
713 #define _PRINTF_ATTRIBUTE(a1, a2)
715 /* String routines */
717 #include "safe_string.h"
720 #define QSORT_CAST (__compar_fn_t)
724 #define QSORT_CAST (int (*)(const void *, const void *))
728 #define SIGCLD SIGCHLD
735 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
736 #define OSF1_ENH_SEC 1
739 #ifndef ALLOW_CHANGE_PASSWORD
740 #if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
741 #define ALLOW_CHANGE_PASSWORD 1
745 /* what is the longest significant password available on your system?
746 Knowing this speeds up password searches a lot */
747 #ifndef PASSWORD_LENGTH
748 #define PASSWORD_LENGTH 8
751 #ifdef REPLACE_INET_NTOA
752 #define inet_ntoa rep_inet_ntoa
760 #define MAXPATHLEN 256
767 #ifndef INADDR_LOOPBACK
768 #define INADDR_LOOPBACK 0x7f000001
772 #define INADDR_NONE 0xffffffff
776 #define crypt ufc_crypt
780 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
783 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
784 #define ULTRIX_AUTH 1
788 char *strdup(const char *s);
792 void *memmove(void *dest,const void *src,int size);
795 #ifndef HAVE_INITGROUPS
796 int initgroups(char *name,gid_t id);
800 int rename(const char *zfrom, const char *zto);
804 time_t mktime(struct tm *t);
808 size_t strlcpy(char *d, const char *s, size_t bufsize);
812 size_t strlcat(char *d, const char *s, size_t bufsize);
815 #ifndef HAVE_FTRUNCATE
816 int ftruncate(int f,long l);
820 char *strndup(const char *s, size_t n);
824 size_t strnlen(const char *s, size_t n);
828 unsigned long strtoul(const char *nptr, char **endptr, int base);
832 int setenv(const char *name, const char *value, int overwrite);
835 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL))
837 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
839 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESGID_DECL))
840 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
842 #ifndef HAVE_VASPRINTF_DECL
843 int vasprintf(char **ptr, const char *format, va_list ap);
846 #if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
847 #define bzero(a,b) memset((a),'\0',(b))
850 #ifdef REPLACE_GETPASS
851 #define getpass(prompt) getsmbpass((prompt))
855 * Some older systems seem not to have MAXHOSTNAMELEN
858 #ifndef MAXHOSTNAMELEN
859 #define MAXHOSTNAMELEN 254
862 /* yuck, I'd like a better way of doing this */
863 #define DIRP_SIZE (256 + 32)
866 * glibc on linux doesn't seem to have MSG_WAITALL
867 * defined. I think the kernel has it though..
871 #define MSG_WAITALL 0
874 /* default socket options. Dave Miller thinks we should default to TCP_NODELAY
875 given the socket IO pattern that Samba uses */
877 #define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
879 #define DEFAULT_SOCKET_OPTIONS ""
882 /* Load header file for dynamic linking stuff */
888 /* dmalloc -- free heap debugger (dmalloc.org). This should be near
889 * the *bottom* of include files so as not to conflict. */
890 #ifdef ENABLE_DMALLOC
891 # include <dmalloc.h>
895 /* Some POSIX definitions for those without */
898 #define S_IFDIR 0x4000
901 #define S_ISDIR(mode) ((mode & 0xF000) == S_IFDIR)
904 #define S_IRWXU 00700 /* read, write, execute: owner */
907 #define S_IRUSR 00400 /* read permission: owner */
910 #define S_IWUSR 00200 /* write permission: owner */
913 #define S_IXUSR 00100 /* execute permission: owner */
916 #define S_IRWXG 00070 /* read, write, execute: group */
919 #define S_IRGRP 00040 /* read permission: group */
922 #define S_IWGRP 00020 /* write permission: group */
925 #define S_IXGRP 00010 /* execute permission: group */
928 #define S_IRWXO 00007 /* read, write, execute: other */
931 #define S_IROTH 00004 /* read permission: other */
934 #define S_IWOTH 00002 /* write permission: other */
937 #define S_IXOTH 00001 /* execute permission: other */
940 /* For sys_adminlog(). */
942 #define LOG_EMERG 0 /* system is unusable */
946 #define LOG_ALERT 1 /* action must be taken immediately */
950 #define LOG_CRIT 2 /* critical conditions */
954 #define LOG_ERR 3 /* error conditions */
958 #define LOG_WARNING 4 /* warning conditions */
962 #define LOG_NOTICE 5 /* normal but significant condition */
966 #define LOG_INFO 6 /* informational */
970 #define LOG_DEBUG 7 /* debug-level messages */
973 /* NetBSD doesn't have these */
982 #if HAVE_KERNEL_SHARE_MODES
984 #define LOCK_MAND 32 /* This is a mandatory flock */
985 #define LOCK_READ 64 /* ... Which allows concurrent read operations */
986 #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */
987 #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */
991 extern int DEBUGLEVEL;
993 #define MAX_SEC_CTX_DEPTH 8 /* Maximum number of security contexts */
996 #ifdef GLIBC_HACK_FCNTL64
997 /* this is a gross hack. 64 bit locking is completely screwed up on
998 i386 Linux in glibc 2.1.95 (which ships with RedHat 7.0). This hack
999 "fixes" the problem with the current 2.4.0test kernels
1001 #define fcntl fcntl64
1009 /* Needed for sys_dlopen/sys_dlsym/sys_dlclose */
1011 #define RTLD_GLOBAL 0
1022 /* needed for some systems without iconv. Doesn't really matter
1023 what error code we use */
1028 /* add varargs prototypes with printf checking */
1029 int fdprintf(int , const char *, ...) PRINTF_ATTRIBUTE(2,3);
1030 int d_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2);
1031 int d_fprintf(FILE *f, const char *, ...) PRINTF_ATTRIBUTE(2,3);
1032 #ifndef HAVE_SNPRINTF_DECL
1033 int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
1035 #ifndef HAVE_ASPRINTF_DECL
1036 int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
1039 void sys_adminlog(int priority, const char *format_str, ...) PRINTF_ATTRIBUTE(2,3);
1041 int pstr_sprintf(pstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1042 int fstr_sprintf(fstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1044 int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1046 int smb_xvasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1048 /* we used to use these fns, but now we have good replacements
1049 for snprintf and vsnprintf */
1050 #define slprintf snprintf
1051 #define vslprintf vsnprintf
1054 /* we need to use __va_copy() on some platforms */
1056 #define VA_COPY(dest, src) __va_copy(dest, src)
1058 #define VA_COPY(dest, src) (dest) = (src)
1062 time_t timegm(struct tm *tm);
1065 #if defined(VALGRIND)
1066 #define strlen(x) valgrind_strlen(x)
1070 * Veritas File System. Often in addition to native.
1073 #if defined(HAVE_SYS_FS_VX_QUOTA_H)
1077 #if HAVE_SYS_ATTRIBUTES_H
1078 #include <sys/attributes.h>
1081 /* mutually exclusive (SuSE 8.2) */
1082 #if HAVE_ATTR_XATTR_H
1083 #include <attr/xattr.h>
1084 #elif HAVE_SYS_XATTR_H
1085 #include <sys/xattr.h>
1088 #define TALLOC_ABORT(reason) smb_panic(reason)
1092 this is a warning hack. The idea is to use this everywhere that we
1093 get the "discarding const" warning from gcc. That doesn't actually
1094 fix the problem of course, but it means that when we do get to
1095 cleaning them up we can do it by searching the code for
1098 It also means that other error types aren't as swamped by the noise
1099 of hundreds of const warnings, so we are more likely to notice when
1102 Please only add more uses of this macro when you find it
1103 _really_ hard to fix const warnings. Our aim is to eventually use
1104 this function in only a very few places.
1106 Also, please call this via the discard_const_p() macro interface, as that
1107 makes the return type safe.
1109 #ifdef HAVE_INTPTR_T
1110 #define discard_const(ptr) ((void *)((intptr_t)(ptr)))
1112 #define discard_const(ptr) ((void *)(ptr))
1114 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
1116 #endif /* _INCLUDES_H */