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 #define DEFAULT_PRINTING PRINT_BSD
50 #define PRINTCAP_NAME "/etc/printcap"
55 * <unistd.h> has to be included before any other to get
56 * large file support on Reliant UNIX
61 #endif /* RELIANTUNIX */
67 #ifdef HAVE_SHARED_MMAP
68 #define USE_SHARED_MMAP
72 /* if we have both SYSV IPC and shared mmap then we need to choose */
73 #if (defined(USE_SYSV_IPC) && defined(USE_SHARED_MMAP))
74 # undef USE_SHARED_MMAP
77 #include <sys/types.h>
79 #ifdef TIME_WITH_SYS_TIME
83 #ifdef HAVE_SYS_TIME_H
90 #ifdef HAVE_SYS_RESOURCE_H
91 #include <sys/resource.h>
101 #ifdef HAVE_SYS_PARAM_H
102 #include <sys/param.h>
109 #ifdef HAVE_SYS_SOCKET_H
110 #include <sys/socket.h>
117 #ifdef HAVE_SYS_SYSCALL_H
118 #include <sys/syscall.h>
127 #ifdef HAVE_STRINGS_H
142 #ifdef HAVE_SYS_FCNTL_H
143 #include <sys/fcntl.h>
147 #include <sys/stat.h>
153 #ifdef HAVE_SYS_IOCTL_H
154 #include <sys/ioctl.h>
157 #ifdef HAVE_SYS_FILIO_H
158 #include <sys/filio.h>
163 #ifdef HAVE_SYS_WAIT_H
164 #include <sys/wait.h>
172 #ifdef HAVE_SYS_PRIV_H
173 #include <sys/priv.h>
185 #ifdef HAVE_SYS_SELECT_H
186 #include <sys/select.h>
189 #ifdef HAVE_SYS_MODE_H
190 /* apparently AIX needs this for S_ISLNK */
192 #include <sys/mode.h>
208 #include <netinet/in.h>
209 #include <arpa/inet.h>
212 #include <sys/file.h>
214 #ifdef HAVE_NETINET_TCP_H
215 #include <netinet/tcp.h>
219 * The next three defines are needed to access the IPTOS_* options
223 #ifdef HAVE_NETINET_IN_SYSTM_H
224 #include <netinet/in_systm.h>
227 #ifdef HAVE_NETINET_IN_IP_H
228 #include <netinet/in_ip.h>
231 #ifdef HAVE_NETINET_IP_H
232 #include <netinet/ip.h>
235 #if defined(HAVE_TERMIOS_H)
236 /* POSIX terminal handling. */
238 #elif defined(HAVE_TERMIO_H)
239 /* Older SYSV terminal handling - don't use if we can avoid it. */
241 #elif defined(HAVE_SYS_TERMIO_H)
242 /* Older SYSV terminal handling - don't use if we can avoid it. */
243 #include <sys/termio.h>
248 # define NAMLEN(dirent) strlen((dirent)->d_name)
250 # define dirent direct
251 # define NAMLEN(dirent) (dirent)->d_namlen
253 # include <sys/ndir.h>
256 # include <sys/dir.h>
263 #ifdef HAVE_SYS_MMAN_H
264 #include <sys/mman.h>
278 #ifdef HAVE_SYS_MOUNT_H
279 #include <sys/mount.h>
282 #ifdef HAVE_SYS_VFS_H
286 #ifdef HAVE_SYS_ACL_H
290 #ifdef HAVE_SYS_FS_S5PARAM_H
291 #include <sys/fs/s5param.h>
294 #if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
295 #include <sys/filsys.h>
298 #ifdef HAVE_SYS_STATFS_H
299 # include <sys/statfs.h>
303 #include <sys/dustat.h>
306 #ifdef HAVE_SYS_STATVFS_H
307 #include <sys/statvfs.h>
314 #ifdef HAVE_GETPWANAM
315 #include <sys/label.h>
316 #include <sys/audit.h>
320 #ifdef HAVE_SYS_SECURITY_H
321 #include <sys/security.h>
323 #define PASSWORD_LENGTH 16
324 #endif /* HAVE_SYS_SECURITY_H */
330 #ifdef HAVE_STROPTS_H
338 #ifdef HAVE_SYS_CAPABILITY_H
339 #include <sys/capability.h>
342 #if defined(HAVE_RPC_RPC_H)
344 * Check for AUTH_ERROR define conflict with rpc/rpc.h in prot.h.
346 #if defined(HAVE_SYS_SECURITY_H) && defined(HAVE_RPC_AUTH_ERROR_CONFLICT)
352 #if defined(HAVE_YP_GET_DEFAULT_DOMAIN) && defined(HAVE_SETNETGRENT) && defined(HAVE_ENDNETGRENT) && defined(HAVE_GETNETGRENT)
353 #define HAVE_NETGROUP 1
356 #if defined (HAVE_NETGROUP)
357 #if defined(HAVE_RPCSVC_YP_PROT_H)
358 #include <rpcsvc/yp_prot.h>
360 #if defined(HAVE_RPCSVC_YPCLNT_H)
361 #include <rpcsvc/ypclnt.h>
363 #endif /* HAVE_NETGROUP */
366 * Define VOLATILE if needed.
369 #if defined(HAVE_VOLATILE)
370 #define VOLATILE volatile
376 * Define SIG_ATOMIC_T if needed.
379 #if defined(HAVE_SIG_ATOMIC_T_TYPE)
380 #define SIG_ATOMIC_T sig_atomic_t
382 #define SIG_ATOMIC_T int
386 #define uchar unsigned char
389 #ifdef HAVE_UNSIGNED_CHAR
390 #define schar signed char
396 Samba needs type definitions for int16, int32, uint16 and uint32.
398 Normally these are signed and unsigned 16 and 32 bit integers, but
399 they actually only need to be at least 16 and 32 bits
400 respectively. Thus if your word size is 8 bytes just defining them
401 as signed and unsigned int will work.
405 #define uint8 unsigned char
408 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
409 #if (SIZEOF_SHORT == 4)
410 #define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
411 #else /* SIZEOF_SHORT != 4 */
413 #endif /* SIZEOF_SHORT != 4 */
417 * Note we duplicate the size tests in the unsigned
418 * case as int16 may be a typedef from rpc/rpc.h
421 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
422 #if (SIZEOF_SHORT == 4)
423 #define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
424 #else /* SIZEOF_SHORT != 4 */
425 #define uint16 unsigned short
426 #endif /* SIZEOF_SHORT != 4 */
429 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
430 #if (SIZEOF_INT == 4)
432 #elif (SIZEOF_LONG == 4)
434 #elif (SIZEOF_SHORT == 4)
440 * Note we duplicate the size tests in the unsigned
441 * case as int32 may be a typedef from rpc/rpc.h
444 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
445 #if (SIZEOF_INT == 4)
446 #define uint32 unsigned int
447 #elif (SIZEOF_LONG == 4)
448 #define uint32 unsigned long
449 #elif (SIZEOF_SHORT == 4)
450 #define uint32 unsigned short
455 * Types for devices, inodes and offsets.
459 #define SMB_DEV_T dev_t
463 * Setup the correctly sized inode type.
467 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)
468 # define SMB_INO_T ino64_t
470 # define SMB_INO_T ino_t
474 #ifndef LARGE_SMB_INO_T
475 # if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)) || (defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8))
476 # define LARGE_SMB_INO_T 1
480 #ifdef LARGE_SMB_INO_T
481 #define SINO_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
483 #define SINO_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
487 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)
488 # define SMB_OFF_T off64_t
490 # define SMB_OFF_T off_t
494 /* this should really be a 64 bit type if possible */
495 #define br_off SMB_BIG_UINT
497 #define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8)
500 * Set the define that tells us if we can do 64 bit
504 #ifndef LARGE_SMB_OFF_T
505 # if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8))
506 # define LARGE_SMB_OFF_T 1
510 #ifdef LARGE_SMB_OFF_T
511 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
513 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
517 * Type for stat structure.
520 #ifndef SMB_STRUCT_STAT
521 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STAT64) && defined(HAVE_OFF64_T)
522 # define SMB_STRUCT_STAT struct stat64
524 # define SMB_STRUCT_STAT struct stat
529 * Type for dirent structure.
532 #ifndef SMB_STRUCT_DIRENT
533 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIRENT64)
534 # define SMB_STRUCT_DIRENT struct dirent64
536 # define SMB_STRUCT_DIRENT struct dirent
541 * Defines for 64 bit fcntl locks.
544 #ifndef SMB_STRUCT_FLOCK
545 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
546 # define SMB_STRUCT_FLOCK struct flock64
548 # define SMB_STRUCT_FLOCK struct flock
553 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
554 # define SMB_F_SETLKW F_SETLKW64
556 # define SMB_F_SETLKW F_SETLKW
561 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
562 # define SMB_F_SETLK F_SETLK64
564 # define SMB_F_SETLK F_SETLK
569 # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
570 # define SMB_F_GETLK F_GETLK64
572 # define SMB_F_GETLK F_GETLK
576 #if defined(HAVE_LONGLONG)
577 #define SMB_BIG_UINT unsigned long long
578 #define SMB_BIG_INT long long
579 #define SBIG_UINT(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
581 #define SMB_BIG_UINT unsigned long
582 #define SMB_BIG_INT long
583 #define SBIG_UINT(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
587 #define MIN(a,b) ((a)<(b)?(a):(b))
591 #define MAX(a,b) ((a)>(b)?(a):(b))
594 #ifndef HAVE_STRERROR
595 extern char *sys_errlist[];
596 #define strerror(i) sys_errlist[i]
600 # define strchr index
601 # define strrchr rindex
604 #ifndef HAVE_ERRNO_DECL
608 #ifdef HAVE_BROKEN_GETGROUPS
615 /* Lists, trees, caching, datbase... */
616 #include "ubi_sLinkList.h"
617 #include "ubi_dLinkList.h"
618 #include "dlinklist.h"
619 #include "../tdb/tdb.h"
621 #include "interfaces.h"
630 #ifndef UBI_BINTREE_H
631 #include "ubi_Cache.h"
632 #endif /* UBI_BINTREE_H */
634 #include "debugparse.h"
639 #include "nameserv.h"
641 #include "byteorder.h"
652 #ifndef MAXCODEPAGELINES
653 #define MAXCODEPAGELINES 256
657 * Type for wide character dirent structure.
658 * Only d_name is defined by POSIX.
661 typedef struct smb_wdirent {
663 } SMB_STRUCT_WDIRENT;
666 * Type for wide character passwd structure.
669 typedef struct smb_wpasswd {
677 } SMB_STRUCT_WPASSWD;
679 /* Defines for wisXXX functions. */
680 #define UNI_UPPER 0x1
681 #define UNI_LOWER 0x2
682 #define UNI_DIGIT 0x4
683 #define UNI_XDIGIT 0x8
684 #define UNI_SPACE 0x10
686 /***** automatically generated prototypes *****/
692 #define strcpy(dest,src) __ERROR__XX__NEVER_USE_STRCPY___;
697 #define strcat(dest,src) __ERROR__XX__NEVER_USE_STRCAT___;
702 #define sprintf __ERROR__XX__NEVER_USE_SPRINTF__;
704 #define pstrcpy(d,s) safe_strcpy((d),(s),sizeof(pstring)-1)
705 #define pstrcat(d,s) safe_strcat((d),(s),sizeof(pstring)-1)
706 #define fstrcpy(d,s) safe_strcpy((d),(s),sizeof(fstring)-1)
707 #define fstrcat(d,s) safe_strcat((d),(s),sizeof(fstring)-1)
709 /* smb_ucs2_t versions of the above. */
710 #define wpstrcpy(d,s) safe_strcpy_w((d),(s),sizeof(wpstring))
711 #define wpstrcat(d,s) safe_strcat_w((d),(s),sizeof(wpstring))
712 #define wfstrcpy(d,s) safe_strcpy_w((d),(s),sizeof(wfstring))
713 #define wfstrcat(d,s) safe_strcat_w((d),(s),sizeof(wfstring))
716 #define QSORT_CAST (__compar_fn_t)
720 #define QSORT_CAST (int (*)(const void *, const void *))
723 /* this guess needs to be improved (tridge) */
724 #if (defined(STAT_STATVFS) || defined(STAT_STATVFS64)) && !defined(SYSV)
728 #ifndef DEFAULT_PRINTING
730 #define DEFAULT_PRINTING PRINT_CUPS
731 #define PRINTCAP_NAME "cups"
733 #define DEFAULT_PRINTING PRINT_SYSV
734 #define PRINTCAP_NAME "lpstat"
736 #define DEFAULT_PRINTING PRINT_BSD
737 #define PRINTCAP_NAME "/etc/printcap"
741 #ifndef PRINTCAP_NAME
742 #define PRINTCAP_NAME "/etc/printcap"
746 #define SIGCLD SIGCHLD
749 #if (defined(HAVE_SYSV_IPC) || defined(HAVE_SHARED_MMAP))
750 #define FAST_SHARE_MODES 1
758 #ifndef HAVE_UNION_SEMUN
761 struct semid_ds *buf;
762 unsigned short *array;
767 #if (!defined(WITH_NISPLUS) && !defined(WITH_LDAP))
768 #define USE_SMBPASS_DB 1
771 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
772 #define OSF1_ENH_SEC 1
775 #ifndef ALLOW_CHANGE_PASSWORD
776 #if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
777 #define ALLOW_CHANGE_PASSWORD 1
781 /* what is the longest significant password available on your system?
782 Knowing this speeds up password searches a lot */
783 #ifndef PASSWORD_LENGTH
784 #define PASSWORD_LENGTH 8
787 #ifdef REPLACE_INET_NTOA
788 #define inet_ntoa rep_inet_ntoa
796 #define MAXPATHLEN 256
803 #ifndef INADDR_LOOPBACK
804 #define INADDR_LOOPBACK 0x7f000001
808 #define INADDR_NONE 0xffffffff
812 #define crypt ufc_crypt
816 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
819 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
820 #define ULTRIX_AUTH 1
823 #ifdef HAVE_LIBREADLINE
824 # ifdef HAVE_READLINE_READLINE_H
825 # include <readline/readline.h>
826 # ifdef HAVE_READLINE_HISTORY_H
827 # include <readline/history.h>
830 # ifdef HAVE_READLINE_H
831 # include <readline.h>
832 # ifdef HAVE_HISTORY_H
833 # include <history.h>
836 # undef HAVE_LIBREADLINE
842 char *strdup(const char *s);
846 void *memmove(void *dest,const void *src,int size);
849 #ifndef HAVE_INITGROUPS
850 int initgroups(char *name,gid_t id);
854 int rename(const char *zfrom, const char *zto);
858 time_t mktime(struct tm *t);
861 #ifndef HAVE_FTRUNCATE
862 int ftruncate(int f,long l);
866 unsigned long strtoul(const char *nptr, char **endptr, int base);
869 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL))
871 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
873 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESGID_DECL))
874 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
877 #if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
878 #define bzero(a,b) memset((a),'\0',(b))
881 #ifdef REPLACE_GETPASS
882 #define getpass(prompt) getsmbpass((prompt))
886 * Some older systems seem not to have MAXHOSTNAMELEN
889 #ifndef MAXHOSTNAMELEN
890 #define MAXHOSTNAMELEN 254
893 /* yuck, I'd like a better way of doing this */
894 #define DIRP_SIZE (256 + 32)
897 * glibc on linux doesn't seem to have MSG_WAITALL
898 * defined. I think the kernel has it though..
902 #define MSG_WAITALL 0
905 /* default socket options. Dave Miller thinks we should default to TCP_NODELAY
906 given the socket IO pattern that Samba uses */
908 #define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
910 #define DEFAULT_SOCKET_OPTIONS ""
913 #endif /* _INCLUDES_H */