4 Unix SMB/Netbios implementation.
6 Machine customisation and include handling
7 Copyright (C) Andrew Tridgell 1994-1998
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 */
31 #define DEFAULT_PRINTING PRINT_AIX
32 #define PRINTCAP_NAME "/etc/qconfig"
36 #define DEFAULT_PRINTING PRINT_HPUX
40 #define DEFAULT_PRINTING PRINT_QNX
44 /* 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"
59 * <unistd.h> has to be included before any other to get
60 * large file support on Reliant UNIX
65 #endif /* RELIANTUNIX */
67 #include <sys/types.h>
69 #ifdef TIME_WITH_SYS_TIME
73 #ifdef HAVE_SYS_TIME_H
80 #ifdef HAVE_SYS_RESOURCE_H
81 #include <sys/resource.h>
91 #ifdef HAVE_SYS_PARAM_H
92 #include <sys/param.h>
99 #ifdef HAVE_SYS_SOCKET_H
100 #include <sys/socket.h>
107 #ifdef HAVE_SYS_SYSCALL_H
108 #include <sys/syscall.h>
117 #ifdef HAVE_STRINGS_H
132 #ifdef HAVE_SYS_FCNTL_H
133 #include <sys/fcntl.h>
137 #include <sys/stat.h>
143 #ifdef HAVE_SYS_IOCTL_H
144 #include <sys/ioctl.h>
147 #ifdef HAVE_SYS_FILIO_H
148 #include <sys/filio.h>
153 #ifdef HAVE_SYS_WAIT_H
154 #include <sys/wait.h>
162 #ifdef HAVE_SYS_PRIV_H
163 #include <sys/priv.h>
175 #ifdef HAVE_SYS_SELECT_H
176 #include <sys/select.h>
179 #ifdef HAVE_SYS_MODE_H
180 /* apparently AIX needs this for S_ISLNK */
182 #include <sys/mode.h>
198 #include <netinet/in.h>
199 #include <arpa/inet.h>
202 #include <sys/file.h>
204 #ifdef HAVE_NETINET_TCP_H
205 #include <netinet/tcp.h>
209 * The next three defines are needed to access the IPTOS_* options
213 #ifdef HAVE_NETINET_IN_SYSTM_H
214 #include <netinet/in_systm.h>
217 #ifdef HAVE_NETINET_IN_IP_H
218 #include <netinet/in_ip.h>
221 #ifdef HAVE_NETINET_IP_H
222 #include <netinet/ip.h>
225 #if defined(HAVE_TERMIOS_H)
226 /* POSIX terminal handling. */
228 #elif defined(HAVE_TERMIO_H)
229 /* Older SYSV terminal handling - don't use if we can avoid it. */
231 #elif defined(HAVE_SYS_TERMIO_H)
232 /* Older SYSV terminal handling - don't use if we can avoid it. */
233 #include <sys/termio.h>
238 # define NAMLEN(dirent) strlen((dirent)->d_name)
240 # define dirent direct
241 # define NAMLEN(dirent) (dirent)->d_namlen
243 # include <sys/ndir.h>
246 # include <sys/dir.h>
253 #ifdef HAVE_SYS_MMAN_H
254 #include <sys/mman.h>
262 #ifdef HAVE_SYS_MOUNT_H
263 #include <sys/mount.h>
266 #ifdef HAVE_SYS_VFS_H
270 #ifdef HAVE_SYS_ACL_H
274 #ifdef HAVE_SYS_FS_S5PARAM_H
275 #include <sys/fs/s5param.h>
278 #if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
279 #include <sys/filsys.h>
282 #ifdef HAVE_SYS_STATFS_H
283 # include <sys/statfs.h>
287 #include <sys/dustat.h>
290 #ifdef HAVE_SYS_STATVFS_H
291 #include <sys/statvfs.h>
298 #ifdef HAVE_GETPWANAM
299 #include <sys/label.h>
300 #include <sys/audit.h>
304 #ifdef HAVE_SYS_SECURITY_H
305 #include <sys/security.h>
307 #define PASSWORD_LENGTH 16
308 #endif /* HAVE_SYS_SECURITY_H */
314 #ifdef HAVE_STROPTS_H
322 #ifdef HAVE_SYS_CAPABILITY_H
323 #include <sys/capability.h>
326 #if defined(HAVE_RPC_RPC_H)
328 * Check for AUTH_ERROR define conflict with rpc/rpc.h in prot.h.
330 #if defined(HAVE_SYS_SECURITY_H) && defined(HAVE_RPC_AUTH_ERROR_CONFLICT)
336 #if defined(HAVE_YP_GET_DEFAULT_DOMAIN) && defined(HAVE_SETNETGRENT) && defined(HAVE_ENDNETGRENT) && defined(HAVE_GETNETGRENT)
337 #define HAVE_NETGROUP 1
340 #if defined (HAVE_NETGROUP)
341 #if defined(HAVE_RPCSVC_YP_PROT_H)
342 #include <rpcsvc/yp_prot.h>
344 #if defined(HAVE_RPCSVC_YPCLNT_H)
345 #include <rpcsvc/ypclnt.h>
347 #endif /* HAVE_NETGROUP */
350 * Define VOLATILE if needed.
353 #if defined(HAVE_VOLATILE)
354 #define VOLATILE volatile
360 * Define SIG_ATOMIC_T if needed.
363 #if defined(HAVE_SIG_ATOMIC_T_TYPE)
364 #define SIG_ATOMIC_T sig_atomic_t
366 #define SIG_ATOMIC_T int
370 #define uchar unsigned char
373 #ifdef HAVE_UNSIGNED_CHAR
374 #define schar signed char
380 Samba needs type definitions for int16, int32, uint16 and uint32.
382 Normally these are signed and unsigned 16 and 32 bit integers, but
383 they actually only need to be at least 16 and 32 bits
384 respectively. Thus if your word size is 8 bytes just defining them
385 as signed and unsigned int will work.
389 #define uint8 unsigned char
392 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
393 #if (SIZEOF_SHORT == 4)
394 #define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
395 #else /* SIZEOF_SHORT != 4 */
397 #endif /* SIZEOF_SHORT != 4 */
401 * Note we duplicate the size tests in the unsigned
402 * case as int16 may be a typedef from rpc/rpc.h
405 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
406 #if (SIZEOF_SHORT == 4)
407 #define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
408 #else /* SIZEOF_SHORT != 4 */
409 #define uint16 unsigned short
410 #endif /* SIZEOF_SHORT != 4 */
413 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
414 #if (SIZEOF_INT == 4)
416 #elif (SIZEOF_LONG == 4)
418 #elif (SIZEOF_SHORT == 4)
424 * Note we duplicate the size tests in the unsigned
425 * case as int32 may be a typedef from rpc/rpc.h
428 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
429 #if (SIZEOF_INT == 4)
430 #define uint32 unsigned int
431 #elif (SIZEOF_LONG == 4)
432 #define uint32 unsigned long
433 #elif (SIZEOF_SHORT == 4)
434 #define uint32 unsigned short
439 * Types for devices, inodes and offsets.
443 #define SMB_DEV_T dev_t
447 * Setup the correctly sized inode type.
451 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)
452 # define SMB_INO_T ino64_t
454 # define SMB_INO_T ino_t
458 #ifndef LARGE_SMB_INO_T
459 # if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)) || (defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8))
460 # define LARGE_SMB_INO_T 1
464 #ifdef LARGE_SMB_INO_T
465 #define SINO_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
467 #define SINO_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
471 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)
472 # define SMB_OFF_T off64_t
474 # define SMB_OFF_T off_t
478 /* this should really be a 64 bit type if possible */
479 #define br_off SMB_BIG_UINT
481 #define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8)
484 * Set the define that tells us if we can do 64 bit
488 #ifndef LARGE_SMB_OFF_T
489 # if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8))
490 # define LARGE_SMB_OFF_T 1
494 #ifdef LARGE_SMB_OFF_T
495 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
497 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
501 * Type for stat structure.
504 #ifndef SMB_STRUCT_STAT
505 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STAT64) && defined(HAVE_OFF64_T)
506 # define SMB_STRUCT_STAT struct stat64
508 # define SMB_STRUCT_STAT struct stat
513 * Type for dirent structure.
516 #ifndef SMB_STRUCT_DIRENT
517 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIRENT64)
518 # define SMB_STRUCT_DIRENT struct dirent64
520 # define SMB_STRUCT_DIRENT struct dirent
525 * Defines for 64 bit fcntl locks.
528 #ifndef SMB_STRUCT_FLOCK
529 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
530 # define SMB_STRUCT_FLOCK struct flock64
532 # define SMB_STRUCT_FLOCK struct flock
537 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
538 # define SMB_F_SETLKW F_SETLKW64
540 # define SMB_F_SETLKW F_SETLKW
545 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
546 # define SMB_F_SETLK F_SETLK64
548 # define SMB_F_SETLK F_SETLK
553 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
554 # define SMB_F_GETLK F_GETLK64
556 # define SMB_F_GETLK F_GETLK
560 #if defined(HAVE_LONGLONG)
561 #define SMB_BIG_UINT unsigned long long
562 #define SMB_BIG_INT long long
563 #define SBIG_UINT(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
565 #define SMB_BIG_UINT unsigned long
566 #define SMB_BIG_INT long
567 #define SBIG_UINT(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
570 #define SMB_BIG_UINT_BITS (sizeof(SMB_BIG_UINT)*8)
573 #define MIN(a,b) ((a)<(b)?(a):(b))
577 #define MAX(a,b) ((a)>(b)?(a):(b))
580 #ifndef HAVE_STRERROR
581 extern char *sys_errlist
[];
582 #define strerror(i) sys_errlist[i]
586 # define strchr index
587 # define strrchr rindex
590 #ifndef HAVE_ERRNO_DECL
594 #ifdef HAVE_BROKEN_GETGROUPS
601 #define NGROUPS_MAX 32 /* Guess... */
604 /* Lists, trees, caching, database... */
605 #include "ubi_sLinkList.h"
606 #include "ubi_dLinkList.h"
607 #include "dlinklist.h"
608 #include "../tdb/tdb.h"
610 #include "interfaces.h"
615 #include "messages.h"
616 #include "util_list.h"
618 #ifndef UBI_BINTREE_H
619 #include "ubi_Cache.h"
620 #endif /* UBI_BINTREE_H */
622 #include "debugparse.h"
627 #include "nameserv.h"
629 #include "byteorder.h"
634 #include "ntdomain.h"
640 #ifndef MAXCODEPAGELINES
641 #define MAXCODEPAGELINES 256
645 * Type for wide character dirent structure.
646 * Only d_name is defined by POSIX.
649 typedef struct smb_wdirent
{
651 } SMB_STRUCT_WDIRENT
;
654 * Type for wide character passwd structure.
657 typedef struct smb_wpasswd
{
665 } SMB_STRUCT_WPASSWD
;
667 /* Defines for wisXXX functions. */
668 #define UNI_UPPER 0x1
669 #define UNI_LOWER 0x2
670 #define UNI_DIGIT 0x4
671 #define UNI_XDIGIT 0x8
672 #define UNI_SPACE 0x10
678 /* Minimal needed to compile.. */
688 /***** automatically generated prototypes *****/
691 /* String routines */
693 #include "safe_string.h"
696 #define QSORT_CAST (__compar_fn_t)
700 #define QSORT_CAST (int (*)(const void *, const void *))
703 /* this guess needs to be improved (tridge) */
704 #if (defined(STAT_STATVFS) || defined(STAT_STATVFS64)) && !defined(SYSV)
708 #ifndef DEFAULT_PRINTING
710 #define DEFAULT_PRINTING PRINT_CUPS
711 #define PRINTCAP_NAME "cups"
713 #define DEFAULT_PRINTING PRINT_SYSV
714 #define PRINTCAP_NAME "lpstat"
716 #define DEFAULT_PRINTING PRINT_BSD
717 #define PRINTCAP_NAME "/etc/printcap"
721 #ifndef PRINTCAP_NAME
722 #define PRINTCAP_NAME "/etc/printcap"
726 #define SIGCLD SIGCHLD
733 #if (!defined(WITH_NISPLUS) && !defined(WITH_LDAP) && !defined(WITH_TDBPWD))
734 #define USE_SMBPASS_DB 1
737 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
738 #define OSF1_ENH_SEC 1
741 #ifndef ALLOW_CHANGE_PASSWORD
742 #if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
743 #define ALLOW_CHANGE_PASSWORD 1
747 /* what is the longest significant password available on your system?
748 Knowing this speeds up password searches a lot */
749 #ifndef PASSWORD_LENGTH
750 #define PASSWORD_LENGTH 8
753 #ifdef REPLACE_INET_NTOA
754 #define inet_ntoa rep_inet_ntoa
762 #define MAXPATHLEN 256
769 #ifndef INADDR_LOOPBACK
770 #define INADDR_LOOPBACK 0x7f000001
774 #define INADDR_NONE 0xffffffff
778 #define crypt ufc_crypt
782 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
785 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
786 #define ULTRIX_AUTH 1
789 #ifdef HAVE_LIBREADLINE
790 # ifdef HAVE_READLINE_READLINE_H
791 # include <readline/readline.h>
792 # ifdef HAVE_READLINE_HISTORY_H
793 # include <readline/history.h>
796 # ifdef HAVE_READLINE_H
797 # include <readline.h>
798 # ifdef HAVE_HISTORY_H
799 # include <history.h>
802 # undef HAVE_LIBREADLINE
808 char *strdup(const char *s
);
812 void *memmove(void *dest
,const void *src
,int size
);
815 #ifndef HAVE_INITGROUPS
816 int initgroups(char *name
,gid_t id
);
820 int rename(const char *zfrom
, const char *zto
);
824 time_t mktime(struct tm
*t
);
827 #ifndef HAVE_FTRUNCATE
828 int ftruncate(int f
,long l
);
832 unsigned long strtoul(const char *nptr
, char **endptr
, int base
);
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
);
843 #if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
844 #define bzero(a,b) memset((a),'\0',(b))
847 #ifdef REPLACE_GETPASS
848 #define getpass(prompt) getsmbpass((prompt))
852 * Some older systems seem not to have MAXHOSTNAMELEN
855 #ifndef MAXHOSTNAMELEN
856 #define MAXHOSTNAMELEN 254
859 /* yuck, I'd like a better way of doing this */
860 #define DIRP_SIZE (256 + 32)
863 * glibc on linux doesn't seem to have MSG_WAITALL
864 * defined. I think the kernel has it though..
868 #define MSG_WAITALL 0
871 /* default socket options. Dave Miller thinks we should default to TCP_NODELAY
872 given the socket IO pattern that Samba uses */
874 #define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
876 #define DEFAULT_SOCKET_OPTIONS ""
879 /* Load header file for libdl stuff */
885 /* Some POSIX definitions for those without */
888 #define S_IFDIR 0x4000
891 #define S_ISDIR(mode) ((mode & 0xF000) == S_IFDIR)
894 #define S_IRWXU 00700 /* read, write, execute: owner */
897 #define S_IRUSR 00400 /* read permission: owner */
900 #define S_IWUSR 00200 /* write permission: owner */
903 #define S_IXUSR 00100 /* execute permission: owner */
906 #define S_IRWXG 00070 /* read, write, execute: group */
909 #define S_IRGRP 00040 /* read permission: group */
912 #define S_IWGRP 00020 /* write permission: group */
915 #define S_IXGRP 00010 /* execute permission: group */
918 #define S_IRWXO 00007 /* read, write, execute: other */
921 #define S_IROTH 00004 /* read permission: other */
924 #define S_IWOTH 00002 /* write permission: other */
927 #define S_IXOTH 00001 /* execute permission: other */
930 /* Some systems (SCO) treat UNIX domain sockets as FIFOs */
933 #define S_IFSOCK S_IFIFO
936 #define S_ISSOCK(mode) ((mode & S_IFSOCK) == S_IFSOCK)
939 #if HAVE_KERNEL_SHARE_MODES
941 #define LOCK_MAND 32 /* This is a mandatory flock */
942 #define LOCK_READ 64 /* ... Which allows concurrent read operations */
943 #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */
944 #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */
948 extern int DEBUGLEVEL
;
950 #define MAX_SEC_CTX_DEPTH 8 /* Maximum number of security contexts */
953 #ifdef GLIBC_HACK_FCNTL64
954 /* this is a gross hack. 64 bit locking is completely screwed up on
955 i386 Linux in glibc 2.1.95 (which ships with RedHat 7.0). This hack
956 "fixes" the problem with the current 2.4.0test kernels
958 #define fcntl fcntl64
965 #endif /* _INCLUDES_H */