Include valgrind.h if present on the system.
[samba.git] / source3 / include / includes.h
index 3d6147f587f1c7ecc5e7b8d9e2e214b4b38a1835..297f38ae9755ba9ec201809c0ac0652a86ead666 100644 (file)
@@ -1,10 +1,10 @@
 #ifndef _INCLUDES_H
 #define _INCLUDES_H
 /* 
-   Unix SMB/Netbios implementation.
-   Version 1.9.
+   Unix SMB/CIFS implementation.
    Machine customisation and include handling
    Copyright (C) Andrew Tridgell 1994-1998
+   Copyright (C) 2002 by Martin Pool <mbp@samba.org>
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #endif
 #endif
 
-/* use gcc attribute to check printf fns */
 #ifdef __GNUC__
+/** Use gcc attribute to check printf fns.  a1 is the 1-based index of
+ * the parameter containing the format, and a2 the index of the first
+ * argument.  **/
 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
 #else
 #define PRINTF_ATTRIBUTE(a1, a2)
 #endif
 
+#ifdef __GNUC__
+/** gcc attribute used on function parameters so that it does not emit
+ * warnings about them being unused. **/
+#  define UNUSED(param) param __attribute__ ((unused))
+#else
+#  define UNUSED(param) param
+/** Feel free to add definitions for other compilers here. */
+#endif
+
 #ifdef RELIANTUNIX
 /*
  * <unistd.h> has to be included before any other to get
 #include <sys/socket.h>
 #endif
 
-#ifdef HAVE_SYS_UN_H
+#ifdef HAVE_UNIXSOCKET
 #include <sys/un.h>
 #endif
 
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
+
+#ifdef HAVE_SYSLOG_H
 #include <syslog.h>
+#else
+#ifdef HAVE_SYS_SYSLOG_H
+#include <sys/syslog.h>
+#endif
+#endif
+
 #include <sys/file.h>
 
 #ifdef HAVE_NETINET_TCP_H
 #endif
 
 #ifdef HAVE_SYS_CAPABILITY_H
+
+#if defined(BROKEN_REDHAT_7_SYSTEM_HEADERS) && !defined(_I386_STATFS_H)
+#define _I386_STATFS_H
+#define BROKEN_REDHAT_7_STATFS_WORKAROUND
+#endif
+
 #include <sys/capability.h>
+
+#ifdef BROKEN_REDHAT_7_STATFS_WORKAROUND
+#undef _I386_STATFS_H
+#undef BROKEN_REDHAT_7_STATFS_WORKAROUND
+#endif
+
 #endif
 
 #if defined(HAVE_RPC_RPC_H)
 #endif /* HAVE_SYS_SHM_H */
 
 #ifdef HAVE_NATIVE_ICONV
+#ifdef HAVE_ICONV
 #include <iconv.h>
 #endif
+#ifdef HAVE_GICONV
+#include <giconv.h>
+#endif
+#endif
+
+#if HAVE_KRB5_H
+#include <krb5.h>
+#else
+#undef HAVE_KRB5
+#endif
+
+#if HAVE_LBER_H
+#include <lber.h>
+#endif
+
+#if HAVE_LDAP_H
+#include <ldap.h>
+#else
+#undef HAVE_LDAP
+#endif
+
+#if HAVE_GSSAPI_H
+#include <gssapi.h>
+#endif
+
+#if HAVE_GSSAPI_GSSAPI_H
+#include <gssapi/gssapi.h>
+#endif
+
+#if HAVE_GSSAPI_GSSAPI_GENERIC_H
+#include <gssapi/gssapi_generic.h>
+#endif
+
+#if HAVE_COM_ERR_H
+#include <com_err.h>
+#endif
+
+#if HAVE_VALGRIND_H
+/* Special macros that are no-ops except when run under Valgrind on x86.  */
+#include <valgrind.h>
+#endif
+
+/* we support ADS if we want it and have krb5 and ldap libs */
+#if defined(WITH_ADS) && defined(HAVE_KRB5) && defined(HAVE_LDAP)
+#define HAVE_ADS
+#endif
 
 /*
  * Define VOLATILE if needed.
 /*
  * Define additional missing types
  */
-#ifndef HAVE_SIG_ATOMIC_T_TYPE
-typedef int sig_atomic_t;
+#if defined(HAVE_SIG_ATOMIC_T_TYPE) && defined(AIX)
+typedef sig_atomic_t SIG_ATOMIC_T;
+#elif defined(HAVE_SIG_ATOMIC_T_TYPE) && !defined(AIX)
+typedef sig_atomic_t VOLATILE SIG_ATOMIC_T;
+#else
+typedef int VOLATILE SIG_ATOMIC_T;
 #endif
 
 #ifndef HAVE_SOCKLEN_T_TYPE
@@ -440,7 +522,7 @@ typedef int socklen_t;
 #define int32 short
 #else
 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
-#define uint32 int
+#define int32 int
 #endif
 #endif
 
@@ -467,7 +549,11 @@ typedef int socklen_t;
  */
 
 #ifndef SMB_DEV_T
-#define SMB_DEV_T dev_t
+#  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)
+#    define SMB_DEV_T dev64_t
+#  else
+#    define SMB_DEV_T dev_t
+#  endif
 #endif
 
 /*
@@ -521,9 +607,15 @@ typedef int socklen_t;
 #ifdef LARGE_SMB_OFF_T
 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
 #define SOFF_T_R(p, ofs, v) (SIVAL(p,(ofs)+4,(v)&0xFFFFFFFF), SIVAL(p,ofs,(v)>>32))
+#define IVAL_TO_SMB_OFF_T(buf,off) ((SMB_OFF_T)(( ((SMB_BIG_UINT)(IVAL((buf),(off)))) & ((SMB_BIG_UINT)0xFFFFFFFF) )))
+#define IVAL2_TO_SMB_BIG_UINT(buf,off) ( (((SMB_BIG_UINT)(IVAL((buf),(off)))) & ((SMB_BIG_UINT)0xFFFFFFFF)) | \
+               (( ((SMB_BIG_UINT)(IVAL((buf),(off+4)))) & ((SMB_BIG_UINT)0xFFFFFFFF) ) << 32 ) )
 #else 
 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
 #define SOFF_T_R(p, ofs, v) (SIVAL(p,(ofs)+4,v),SIVAL(p,ofs,0))
+#define IVAL_TO_SMB_OFF_T(buf,off) ((SMB_OFF_T)(( ((uint32)(IVAL((buf),(off)))) & 0xFFFFFFFF )))
+#define IVAL2_TO_SMB_BIG_UINT(buf,off) ( (((SMB_BIG_UINT)(IVAL((buf),(off)))) & ((SMB_BIG_UINT)0xFFFFFFFF)) | \
+                               (( ((SMB_BIG_UINT)(IVAL((buf),(off+4)))) & ((SMB_BIG_UINT)0xFFFFFFFF) ) << 32 ) )
 #endif
 
 /*
@@ -625,20 +717,30 @@ extern int errno;
 #define NGROUPS_MAX 32 /* Guess... */
 #endif
 
+/* Our own pstrings and fstrings */
+#include "pstring.h"
+
 /* Lists, trees, caching, database... */
+#include "xfile.h"
+#include "intl.h"
 #include "ubi_sLinkList.h"
 #include "ubi_dLinkList.h"
 #include "dlinklist.h"
 #include "../tdb/tdb.h"
 #include "../tdb/spinlock.h"
+#include "../tdb/tdbutil.h"
 #include "talloc.h"
+#include "nt_status.h"
+#include "ads.h"
 #include "interfaces.h"
 #include "hash.h"
 #include "trans2.h"
 #include "nterr.h"
-#include "secrets.h"
+#include "ntioctl.h"
 #include "messages.h"
-#include "util_list.h"
+#include "charset.h"
+#include "dynconfig.h"
+#include "adt_tree.h"
 
 #include "util_getent.h"
 
@@ -653,22 +755,44 @@ extern int errno;
 #include "smbw.h"
 #include "nameserv.h"
 
+#include "secrets.h"
+
 #include "byteorder.h"
 
 #include "ntdomain.h"
 
 #include "msdfs.h"
 
-#include "profile.h"
+#include "smbprofile.h"
 
 #include "mapping.h"
 
+#include "rap.h"
+
 #include "md5.h"
 #include "hmacmd5.h"
 
-#ifndef MAXCODEPAGELINES
-#define MAXCODEPAGELINES 256
-#endif
+#include "ntlmssp.h"
+
+#include "auth.h"
+
+#include "passdb.h"
+
+#include "sam.h"
+
+#include "gums.h"
+
+#include "session.h"
+
+#include "asn_1.h"
+
+#include "popt.h"
+
+#include "mangle.h"
+
+#include "nsswitch/winbind_client.h"
+
+#include "genparser.h"
 
 /*
  * Type for wide character dirent structure.
@@ -693,6 +817,13 @@ typedef struct smb_wpasswd {
        wpstring       pw_shell;
 } SMB_STRUCT_WPASSWD;
 
+/* used in net.c */
+struct functable {
+       const char *funcname;
+       int (*fn)(int argc, const char **argv);
+};
+
+
 /* Defines for wisXXX functions. */
 #define UNI_UPPER    0x1
 #define UNI_LOWER    0x2
@@ -700,40 +831,12 @@ typedef struct smb_wpasswd {
 #define UNI_XDIGIT   0x8
 #define UNI_SPACE    0x10
 
-#ifdef HAVE_NSS_COMMON_H
-
-/* Sun Solaris */
-
-#include <nss_common.h>
-#include <nss_dbdefs.h>
-#include <nsswitch.h>
-
-typedef nss_status_t NSS_STATUS;
-
-#define NSS_STATUS_SUCCESS     NSS_SUCCESS
-#define NSS_STATUS_NOTFOUND    NSS_NOTFOUND
-#define NSS_STATUS_UNAVAIL     NSS_UNAVAIL
-#define NSS_STATUS_TRYAGAIN    NSS_TRYAGAIN
-
-#elif HAVE_NSS_H
-
-/* GNU */
+#include "nsswitch/nss.h"
 
-#include <nss.h>
+/* forward declaration from printing.h to get around 
+   header file dependencies */
 
-typedef enum nss_status NSS_STATUS;
-
-#else /* Nothing's defined. Neither gnu nor sun */
-
-typedef enum
-{
-  NSS_STATUS_SUCCESS,
-  NSS_STATUS_NOTFOUND,
-  NSS_STATUS_UNAVAIL,
-  NSS_STATUS_TRYAGAIN
-} NSS_STATUS;
-
-#endif
+struct printjob;
 
 /***** automatically generated prototypes *****/
 #include "proto.h"
@@ -750,13 +853,8 @@ typedef enum
 #define QSORT_CAST (int (*)(const void *, const void *))
 #endif
 
-/* this guess needs to be improved (tridge) */
-#if (defined(STAT_STATVFS) || defined(STAT_STATVFS64)) && !defined(SYSV)
-#define SYSV 1
-#endif
-
 #ifndef DEFAULT_PRINTING
-#ifdef HAVE_LIBCUPS
+#ifdef HAVE_CUPS
 #define DEFAULT_PRINTING PRINT_CUPS
 #define PRINTCAP_NAME "cups"
 #elif defined(SYSV)
@@ -780,7 +878,7 @@ typedef enum
 #define MAP_FILE 0
 #endif
 
-#if (!defined(WITH_NISPLUS) && !defined(WITH_LDAP) && !defined(WITH_TDBPWD))
+#if (!defined(WITH_NISPLUS) && !defined(WITH_LDAP) && !defined(WITH_TDB_SAM))
 #define USE_SMBPASS_DB 1
 #endif
 
@@ -836,24 +934,6 @@ typedef enum
 #define ULTRIX_AUTH 1
 #endif
 
-#ifdef HAVE_LIBREADLINE
-#  ifdef HAVE_READLINE_READLINE_H
-#    include <readline/readline.h>
-#    ifdef HAVE_READLINE_HISTORY_H
-#      include <readline/history.h>
-#    endif
-#  else
-#    ifdef HAVE_READLINE_H
-#      include <readline.h>
-#      ifdef HAVE_HISTORY_H
-#        include <history.h>
-#      endif
-#    else
-#      undef HAVE_LIBREADLINE
-#    endif
-#  endif
-#endif
-
 #ifndef HAVE_STRDUP
 char *strdup(const char *s);
 #endif
@@ -874,14 +954,34 @@ int rename(const char *zfrom, const char *zto);
 time_t mktime(struct tm *t);
 #endif
 
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *d, const char *s, size_t bufsize);
+#endif
+
+#ifndef HAVE_STRLCAT
+size_t strlcat(char *d, const char *s, size_t bufsize);
+#endif
+
 #ifndef HAVE_FTRUNCATE
 int ftruncate(int f,long l);
 #endif
 
+#ifndef HAVE_STRNDUP
+char *strndup(const char *s, size_t n);
+#endif
+
+#ifndef HAVE_STRNLEN
+size_t strnlen(const char *s, size_t n);
+#endif
+
 #ifndef HAVE_STRTOUL
 unsigned long strtoul(const char *nptr, char **endptr, int base);
 #endif
 
+#ifndef HAVE_SETENV
+int setenv(const char *name, const char *value, int overwrite); 
+#endif
+
 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL))
 /* stupid glibc */
 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
@@ -929,12 +1029,19 @@ int vasprintf(char **ptr, const char *format, va_list ap);
 #define DEFAULT_SOCKET_OPTIONS ""
 #endif
 
-/* Load header file for libdl stuff */
+/* Load header file for dynamic linking stuff */
 
-#ifdef HAVE_LIBDL
+#ifdef HAVE_DLFCN_H
 #include <dlfcn.h>
 #endif
 
+/* dmalloc -- free heap debugger (dmalloc.org).  This should be near
+ * the *bottom* of include files so as not to conflict. */
+#ifdef ENABLE_DMALLOC
+#  include <dmalloc.h>
+#endif
+
+
 /* Some POSIX definitions for those without */
  
 #ifndef S_IFDIR
@@ -980,6 +1087,39 @@ int vasprintf(char **ptr, const char *format, va_list ap);
 #define S_IXOTH 00001           /* execute permission: other */
 #endif
 
+/* For sys_adminlog(). */
+#ifndef LOG_EMERG
+#define LOG_EMERG       0       /* system is unusable */
+#endif
+
+#ifndef LOG_ALERT
+#define LOG_ALERT       1       /* action must be taken immediately */
+#endif
+
+#ifndef LOG_CRIT
+#define LOG_CRIT        2       /* critical conditions */
+#endif
+
+#ifndef LOG_ERR
+#define LOG_ERR         3       /* error conditions */
+#endif
+
+#ifndef LOG_WARNING
+#define LOG_WARNING     4       /* warning conditions */
+#endif
+
+#ifndef LOG_NOTICE
+#define LOG_NOTICE      5       /* normal but significant condition */
+#endif
+
+#ifndef LOG_INFO
+#define LOG_INFO        6       /* informational */
+#endif
+
+#ifndef LOG_DEBUG
+#define LOG_DEBUG       7       /* debug-level messages */
+#endif
+
 /* NetBSD doesn't have these */
 #ifndef SHM_R
 #define SHM_R 0400
@@ -1029,8 +1169,16 @@ extern int DEBUGLEVEL;
 #define RTLD_NOW 0
 #endif
 
+/* needed for some systems without iconv. Doesn't really matter
+   what error code we use */
+#ifndef EILSEQ
+#define EILSEQ EIO
+#endif
+
 /* add varargs prototypes with printf checking */
-int fdprintf(int , char *, ...) PRINTF_ATTRIBUTE(2,3);
+int fdprintf(int , const char *, ...) PRINTF_ATTRIBUTE(2,3);
+int d_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2);
+int d_fprintf(FILE *f, const char *, ...) PRINTF_ATTRIBUTE(2,3);
 #ifndef HAVE_SNPRINTF_DECL
 int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
 #endif
@@ -1038,10 +1186,68 @@ int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
 int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
 #endif
 
+void sys_adminlog(int priority, const char *format_str, ...) PRINTF_ATTRIBUTE(2,3);
+
+int pstr_sprintf(pstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+int fstr_sprintf(fstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+
+int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
+
+int smb_xvasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
+
 /* we used to use these fns, but now we have good replacements
    for snprintf and vsnprintf */
 #define slprintf snprintf
 #define vslprintf vsnprintf
 
+
+/* we need to use __va_copy() on some platforms */
+#ifdef HAVE_VA_COPY
+#define VA_COPY(dest, src) __va_copy(dest, src)
+#else
+#define VA_COPY(dest, src) (dest) = (src)
+#endif
+
+#ifndef HAVE_TIMEGM
+time_t timegm(struct tm *tm);
+#endif
+
+#if defined(VALGRIND)
+#define strlen(x) valgrind_strlen(x)
+#endif
+
+/*
+ * Veritas File System.  Often in addition to native.
+ * Quotas different.
+ */
+#if defined(HAVE_SYS_FS_VX_QUOTA_H)
+#define VXFS_QUOTA
+#endif
+
+#if defined(HAVE_KRB5)
+
+#ifndef KRB5_SET_REAL_TIME
+krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds);
+#endif
+
+#ifndef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES
+krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
+#endif
+
+#if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
+krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
+#endif
+
+/* Samba wrapper function for krb5 functionality. */
+void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr);
+int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
+void get_auth_data_from_tkt(DATA_BLOB *auth_data, krb5_ticket *tkt);
+krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt);
+krb5_error_code krb5_locate_kdc(krb5_context ctx, const krb5_data *realm, struct sockaddr **addr_pp, int *naddrs, int get_masters);
+krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes);
+void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes);
+BOOL krb5_get_smb_session_key(krb5_context context, krb5_auth_context auth_context, uint8 session_key[16]);
+#endif /* HAVE_KRB5 */
+
 #endif /* _INCLUDES_H */