r10438: Move portability functions to lib/replace/; replace now simply ensures
authorJelmer Vernooij <jelmer@samba.org>
Fri, 23 Sep 2005 00:38:22 +0000 (00:38 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:38:45 +0000 (13:38 -0500)
that a given set of (working) POSIX functions are available (without
prefixes to their names, etc). See lib/replace/README for a list.

Functions that behave different from their POSIX specification
(such as sys_select, sys_read, etc) have kept the sys_ prefix.
(This used to be commit 29919a71059b29fa27a49b1f5b84bb8881de65fc)

22 files changed:
source4/SConstruct
source4/build/m4/rewrite.m4
source4/client/client.c
source4/dynconfig.c
source4/heimdal_build/glue.c
source4/include/includes.h
source4/lib/com/tables.c
source4/lib/replace/README [new file with mode: 0644]
source4/lib/replace/SConscript
source4/lib/replace/config.m4
source4/lib/replace/config.mk
source4/lib/replace/dlfcn.c [new file with mode: 0644]
source4/lib/replace/replace.c
source4/lib/replace/replace.h
source4/lib/signal.c
source4/lib/system.c
source4/lib/time.c
source4/lib/util.c
source4/libcli/resolve/host.c
source4/librpc/ndr/ndr_basic.c
source4/torture/torture.c
source4/winbind/wb_samba3_protocol.c

index e791f97d7c1e518521df9b7bc54001f5684e9518..8376479fe110820c6e8f44eff3daff85293946f4 100644 (file)
@@ -9,8 +9,6 @@
 
 import cPickle, string, os
 
-# We don't care about NFS builds...
-
 opts = Options(None, ARGUMENTS)
 opts.AddOptions(
                BoolOption('developer','enable developer flags', False),
@@ -26,6 +24,7 @@ hostenv = Environment(
                 CPPDEFINES={'_SAMBA_BUILD_': None},
                )
 
+# We don't care about NFS builds...
 hostenv.SetOption('max_drift', 1)
 
 if hostenv['developer']:
index d8ba0104ab174bb94b081491f9e94832d83fb5d8..8d72d852f43d5e92eba4490c2c0878bfc854a949 100644 (file)
@@ -53,19 +53,14 @@ AC_HEADER_DIRENT
 AC_HEADER_TIME
 AC_HEADER_SYS_WAIT
 AC_CHECK_HEADERS(sys/select.h fcntl.h sys/fcntl.h sys/time.h)
-AC_CHECK_HEADERS(utime.h grp.h sys/id.h limits.h memory.h)
-AC_CHECK_HEADERS(compat.h math.h)
+AC_CHECK_HEADERS(utime.h grp.h sys/id.h limits.h memory.h compat.h math.h)
 AC_CHECK_HEADERS(sys/param.h ctype.h sys/wait.h sys/resource.h sys/ioctl.h sys/ipc.h sys/mode.h)
 AC_CHECK_HEADERS(sys/mman.h sys/filio.h sys/priv.h sys/shm.h string.h strings.h stdlib.h)
 AC_CHECK_HEADERS(sys/vfs.h sys/fs/s5param.h sys/filsys.h termios.h termio.h)
 AC_CHECK_HEADERS(fnmatch.h pwd.h sys/termio.h sys/time.h sys/statfs.h sys/statvfs.h stdarg.h)
-AC_CHECK_HEADERS(security/pam_modules.h security/_pam_macros.h dlfcn.h)
-AC_CHECK_HEADERS(sys/syslog.h syslog.h)
-AC_CHECK_HEADERS(stdint.h inttypes.h locale.h)
-AC_CHECK_HEADERS(shadow.h)
+AC_CHECK_HEADERS(stdint.h inttypes.h locale.h shadow.h)
 AC_CHECK_HEADERS(nss.h nss_common.h ns_api.h sys/security.h security/pam_appl.h)
-AC_CHECK_HEADERS(sys/capability.h syscall.h sys/syscall.h)
-AC_CHECK_HEADERS(sys/acl.h)
+AC_CHECK_HEADERS(sys/capability.h sys/acl.h)
 
 AC_CHECK_HEADERS(sys/mount.h, , , [AC_INCLUDES_DEFAULT
 #ifdef HAVE_SYS_PARAM_H
@@ -89,12 +84,6 @@ AC_CHECK_TYPES(intptr_t)
 AC_CHECK_TYPES(long long)
 
 
-############################################
-# we need dlopen/dlclose/dlsym/dlerror for PAM, the password database plugins and the plugin loading code
-AC_SEARCH_LIBS_EXT(dlopen, [dl], DL_LIBS)
-SMB_EXT_LIB(DL,[${DL_LIBS}],[${DL_CFLAGS}],[${DL_CPPFLAGS}],[${DL_LDFLAGS}])
-# dlopen/dlclose/dlsym/dlerror will be checked again later and defines will be set then
-
 AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
     AC_TRY_COMPILE([
 #include <sys/types.h>
@@ -108,29 +97,12 @@ if test x"$samba_cv_sig_atomic_t" = x"yes"; then
    AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
 fi
 
-# stupid headers have the functions but no declaration. grrrr.
-AC_HAVE_DECL(errno, [#include <errno.h>])
-AC_HAVE_DECL(setresuid, [#include <unistd.h>])
-AC_HAVE_DECL(setresgid, [#include <unistd.h>])
-AC_HAVE_DECL(asprintf, [#include <stdio.h>])
-AC_HAVE_DECL(vasprintf, [#include <stdio.h>])
-AC_HAVE_DECL(vsnprintf, [#include <stdio.h>])
-AC_HAVE_DECL(snprintf, [#include <stdio.h>])
-
 AC_FUNC_MEMCMP
 
-AC_CHECK_FUNCS(dlopen dlsym dlerror waitpid getcwd strdup strndup strnlen strerror chroot)
-AC_CHECK_FUNCS(bzero memset strlcpy strlcat)
-AC_CHECK_FUNCS(memmove vsnprintf snprintf asprintf vasprintf setsid pipe crypt16 getauthuid)
-AC_CHECK_FUNCS(strftime sigprocmask sigblock sigaction innetgr setnetgrent getnetgrent endnetgrent)
-AC_CHECK_FUNCS(initgroups)
-AC_CHECK_FUNCS(setgroups sysconf mktime rename ftruncate chsize)
-AC_CHECK_FUNCS(getpwanam setlinebuf)
-AC_CHECK_FUNCS(srandom random srand rand setenv usleep)
-AC_CHECK_FUNCS(syslog vsyslog timegm backtrace)
-AC_CHECK_FUNCS(setbuffer)
-
-AC_CHECK_FUNCS(pread pwrite)
+AC_CHECK_FUNCS(setsid pipe crypt16 getauthuid)
+AC_CHECK_FUNCS(strftime sigprocmask sigblock sigaction)
+AC_CHECK_FUNCS(setgroups sysconf getpwanam srandom random srand rand usleep)
+AC_CHECK_FUNCS(backtrace setbuffer pread pwrite)
 
 # Assume non-shared by default and override below
 BLDSHARED="false"
@@ -358,39 +330,6 @@ if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then
 fi
 fi
 
-AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
-AC_TRY_RUN([
-#include <sys/types.h>
-#include <stdarg.h>
-void foo(const char *format, ...) { 
-       va_list ap;
-       int len;
-       char buf[20];
-       long long l = 1234567890;
-       l *= 100;
-
-       va_start(ap, format);
-       len = vsnprintf(buf, 0, format, ap);
-       va_end(ap);
-       if (len != 5) exit(1);
-
-       va_start(ap, format);
-       len = vsnprintf(0, 0, format, ap);
-       va_end(ap);
-       if (len != 5) exit(1);
-
-       if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);
-
-       if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(1);
-
-       exit(0);
-}
-main() { foo("hello"); }
-],
-samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
-if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
-    AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
-fi
 
 AC_CACHE_CHECK([for utimbuf],samba_cv_HAVE_UTIMBUF,[
 AC_TRY_COMPILE([#include <sys/types.h>
@@ -499,28 +438,6 @@ if test x"$samba_cv_HAVE_BROKEN_GETGROUPS" = x"yes"; then
     AC_DEFINE(HAVE_BROKEN_GETGROUPS,1,[Whether getgroups is broken])
 fi
 
-AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
-AC_TRY_RUN([#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-main() { 
-  struct stat st;
-  char tpl[20]="/tmp/test.XXXXXX"; 
-  int fd = mkstemp(tpl); 
-  if (fd == -1) exit(1);
-  unlink(tpl);
-  if (fstat(fd, &st) != 0) exit(1);
-  if ((st.st_mode & 0777) != 0600) exit(1);
-  exit(0);
-}],
-samba_cv_HAVE_SECURE_MKSTEMP=yes,
-samba_cv_HAVE_SECURE_MKSTEMP=no,
-samba_cv_HAVE_SECURE_MKSTEMP=cross)])
-if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
-    AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
-fi
-
 AC_CACHE_CHECK([for sysconf(_SC_NGROUPS_MAX)],samba_cv_SYSCONF_SC_NGROUPS_MAX,[
 AC_TRY_RUN([#include <unistd.h>
 main() { exit(sysconf(_SC_NGROUPS_MAX) == -1 ? 1 : 0); }],
@@ -581,9 +498,6 @@ fi
 ;;
 esac
 
-AC_SUBST(SMBD_EXTRA_OBJS)
-AC_SUBST(SMBD_EXTRA_LIBS)
-
 ###############################################
 # test for where we get crypt() from
 AC_CHECK_LIB_EXT(crypt, CRYPT_LIBS, crypt)
index b6b95a4ebd883d0e261aca2309a7dc55eeb6c4c5..1e41924321b8678e8fa55bc9f15328b7967aa7c8 100644 (file)
@@ -960,7 +960,7 @@ static int cmd_more(const char **cmd_ptr)
        fstrcat(rname,"\\");
        
        slprintf(lname,sizeof(lname)-1, "%s/smbmore.XXXXXX",tmpdir());
-       fd = smb_mkstemp(lname);
+       fd = mkstemp(lname);
        if (fd == -1) {
                d_printf("failed to create temporary file for more\n");
                return 1;
@@ -2601,11 +2601,11 @@ static int cmd_printmode(const char **cmd_ptr)
 static int cmd_lcd(const char **cmd_ptr)
 {
        fstring buf;
-       pstring d;
+       char d[PATH_MAX];
        
        if (next_token(cmd_ptr,buf,NULL,sizeof(buf)))
                chdir(buf);
-       DEBUG(2,("the local directory is now %s\n",sys_getwd(d)));
+       DEBUG(2,("the local directory is now %s\n",getcwd(d, PATH_MAX)));
 
        return 0;
 }
index 20567dcafcc2adc65dbdba2780fa5fe72b183655..caf75762d558148203469eb868255036591b270f 100644 (file)
@@ -18,9 +18,6 @@
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include "includes.h"
-#include "pstring.h"
-
 /**
  * @file dynconfig.c
  *
  * table?  There's kind of a chicken-and-egg situation there...
  **/
 
-const char *dyn_SBINDIR = SBINDIR,
-       *dyn_BINDIR = BINDIR;
+/** Directory with super-user binaries */
+const char *dyn_SBINDIR = SBINDIR;
+
+/** Directory with generic binaries */
+const char *dyn_BINDIR = BINDIR;
 
-const char *dyn_CONFIGFILE = CONFIGFILE; /**< Location of smb.conf file. **/
+/**< Location of smb.conf file. **/
+const char *dyn_CONFIGFILE = CONFIGFILE; 
 
 /** Log file directory. **/
-const char *dyn_LOGFILEBASE = LOGFILEBASE;
+const char *dyn_LOGFILEBASE = LOGFILEBASE; 
 
+/** Directory for local RPC (ncalrpc: transport) */
 const char *dyn_NCALRPCDIR = NCALRPCDIR;
 
 /** Statically configured LanMan hosts. **/
-const char *dyn_LMHOSTSFILE = LMHOSTSFILE;
+const char *dyn_LMHOSTSFILE = LMHOSTSFILE; 
 
-/**
- * @brief Samba library directory.
- *
- * @sa lib_path() to get the path to a file inside the LIBDIR.
- **/
+/** Samba library directory. */
 const char *dyn_LIBDIR = LIBDIR;
+
+/** Shared library extension */
 const char *dyn_SHLIBEXT = SHLIBEXT;
 
 /**
@@ -68,7 +68,12 @@ const char *dyn_SHLIBEXT = SHLIBEXT;
  * Not writable, but used to set a default in the parameter table.
  **/
 const char *dyn_LOCKDIR = LOCKDIR;
+
+/** pid file directory */
 const char *dyn_PIDDIR  = PIDDIR;
 
+/** Private data directory; holds ldb files and the like */
 const char *dyn_PRIVATE_DIR = PRIVATE_DIR;
+
+/** SWAT data file (images, etc) directory */
 const char *dyn_SWATDIR = SWATDIR;
index 07c58b77899b6eff7e010c42dc487f7a25614b82..819a395ca8118cbc40654da961e09edd6d4532b5 100644 (file)
@@ -43,7 +43,7 @@ krb5_error_code KRB5_LIB_FUNCTION krb5_get_all_client_addrs(krb5_context context
                if (res->val[i].address.data == NULL) {
                        return ENOMEM;
                }
-               ((struct in_addr *)res->val[i].address.data)->s_addr = sys_inet_addr(ip);
+               ((struct in_addr *)res->val[i].address.data)->s_addr = inet_addr(ip);
        }
 
        return 0;
index 94b88d37b2162774257674aac827ad484800ae1d..3636dec58d956fcd16ed53ede66ab92bce4b3258 100644 (file)
 #include <windows.h>
 #endif
 
-#if defined(_MSC_VER) || defined(__MINGW32__)
-#include "lib/replace/win32/replace.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
@@ -106,15 +102,6 @@ struct ipv4_addr {
        uint32_t addr;
 };
 
-#ifndef HAVE_STRERROR
-extern char *sys_errlist[];
-#define strerror(i) sys_errlist[i]
-#endif
-
-#ifndef HAVE_ERRNO_DECL
-extern int errno;
-#endif
-
 
 #include "lib/replace/replace.h"
 
index cf63e7e9a2549ffe69d40a97023d5ba046caac99..39bd6a6bd76f45fc42452a90e11b0993e6296fdb 100644 (file)
@@ -58,13 +58,13 @@ static struct IUnknown *get_com_class_so(TALLOC_CTX *mem_ctx, const struct GUID
        mod_name = talloc_asprintf(mem_ctx, "%s.so", clsid_str);
        talloc_free(clsid_str);
 
-       mod = sys_dlopen(mod_name, 0);
+       mod = dlopen(mod_name, 0);
 
        if (!mod) {
                return NULL;
        }
        
-       f = sys_dlsym(mod, "get_class_object");
+       f = dlsym(mod, "get_class_object");
 
        if (!f) {
                return NULL;
diff --git a/source4/lib/replace/README b/source4/lib/replace/README
new file mode 100644 (file)
index 0000000..74b5397
--- /dev/null
@@ -0,0 +1,54 @@
+This subsystem ensures that we can always use a certain core set of 
+functions and types, that are either provided by the OS or by replacement 
+functions / definitions in this subsystem. The aim is to try to stick 
+to POSIX functions in here as much as possible. Convenience functions 
+that are available on no platform at all belong in different subsystems
+(such as LIBUTIL).
+
+The following functions are guarenteed:
+
+ftruncate
+strlcpy
+strlcat
+mktime
+rename
+innetgr
+initgroups
+memmove
+strdup
+inet_ntoa
+setlinebuf
+vsyslog
+timegm
+setenv
+strtoull
+strtoll
+strndup
+strnlen
+waitpid
+seteuid
+setegid
+asprintf
+snprintf
+vasprintf
+vsnprintf
+opendir
+readdir
+telldir
+seekdir
+closedir
+dlopen
+dlclose
+dlsym
+dlerror
+chroot
+bzero
+strerror
+errno
+mkstemp (a secure one!)
+
+Prerequisites:
+memset (for bzero)
+syslog (for vsyslog)
+setnetgrent, getnetgrent, endnetgrent (for innetgr)
+mktemp (for mkstemp)
index 84088db162cf9be0b00d9bac20b89f47c8d9d2ca..982120e1bf33cb22fd2a4874f57f11b11e2e31a5 100644 (file)
@@ -9,4 +9,4 @@ if hostenv['configure']:
        conf.Finish()
 
 hostenv.StaticLibrary('repdir', ['repdir/repdir.c'])
-hostenv.StaticLibrary('replace', ['replace.c', 'snprintf.c'])
+hostenv.StaticLibrary('replace', ['replace.c', 'snprintf.c','dlfcn.c'])
index 4dfeb5647a096ecc4bc8533f0cb779d043919888..88e3be5e94d81ee25604d4d548d1e4d73fc301e7 100644 (file)
@@ -15,5 +15,87 @@ if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
     AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
 fi
 
+dnl Provided by replace.c:
+AC_CHECK_HEADERS(sys/syslog.h syslog.h)
 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
-AC_CHECK_FUNCS(seteuid setresuid setegid setresgid)
+AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
+AC_CHECK_FUNCS(timegm setenv vsyslog setlinebuf mktime ftruncate chsize rename)
+AC_CHECK_FUNCS(waitpid strnlen strlcpy strlcat innetgr initgroups memmove strdup)
+AC_HAVE_DECL(setresuid, [#include <unistd.h>])
+AC_HAVE_DECL(setresgid, [#include <unistd.h>])
+AC_HAVE_DECL(errno, [#include <errno.h>])
+
+AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
+AC_TRY_RUN([#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+main() { 
+  struct stat st;
+  char tpl[20]="/tmp/test.XXXXXX"; 
+  int fd = mkstemp(tpl); 
+  if (fd == -1) exit(1);
+  unlink(tpl);
+  if (fstat(fd, &st) != 0) exit(1);
+  if ((st.st_mode & 0777) != 0600) exit(1);
+  exit(0);
+}],
+samba_cv_HAVE_SECURE_MKSTEMP=yes,
+samba_cv_HAVE_SECURE_MKSTEMP=no,
+samba_cv_HAVE_SECURE_MKSTEMP=cross)])
+if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
+    AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
+fi
+
+dnl Provided by snprintf.c:
+AC_HAVE_DECL(asprintf, [#include <stdio.h>])
+AC_HAVE_DECL(vasprintf, [#include <stdio.h>])
+AC_HAVE_DECL(vsnprintf, [#include <stdio.h>])
+AC_HAVE_DECL(snprintf, [#include <stdio.h>])
+AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
+
+AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
+AC_TRY_RUN([
+#include <sys/types.h>
+#include <stdarg.h>
+void foo(const char *format, ...) { 
+       va_list ap;
+       int len;
+       char buf[20];
+       long long l = 1234567890;
+       l *= 100;
+
+       va_start(ap, format);
+       len = vsnprintf(buf, 0, format, ap);
+       va_end(ap);
+       if (len != 5) exit(1);
+
+       va_start(ap, format);
+       len = vsnprintf(0, 0, format, ap);
+       va_end(ap);
+       if (len != 5) exit(1);
+
+       if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);
+
+       if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(1);
+
+       exit(0);
+}
+main() { foo("hello"); }
+],
+samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
+if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
+    AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
+fi
+
+dnl Provided by dlfcn.c:
+AC_SEARCH_LIBS_EXT(dlopen, [dl], DL_LIBS)
+SMB_EXT_LIB(DL,[${DL_LIBS}],[${DL_CFLAGS}],[${DL_CPPFLAGS}],[${DL_LDFLAGS}])
+SAVE_LIBS="$LIBS"
+LIBS="$LIBS $DL_LIBS"
+AC_CHECK_HEADERS(dlfcn.h)
+AC_CHECK_FUNCS(dlopen dlsym dlerror dlclose)
+LIBS="$SAVE_LIBS"
+
+AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent],,
+                          [AC_MSG_ERROR([Need syslog and memset])])
index 16952ea32d594587612f1e6b6a6a9ff1decbdcae..2658f0e96a95fa63996f85d72fd9daf1f2f6e42f 100644 (file)
@@ -13,7 +13,9 @@ NOPROTO = YES
 [SUBSYSTEM::LIBREPLACE]
 INIT_OBJ_FILES = lib/replace/replace.o
 ADD_OBJ_FILES = \
-               lib/replace/snprintf.o
+               lib/replace/snprintf.o \
+               lib/replace/dlfcn.o
+NOPROTO = YES
 REQUIRED_SUBSYSTEMS = REPLACE_READDIR
 # End SUBSYSTEM LIBREPLACE
 ##############################
diff --git a/source4/lib/replace/dlfcn.c b/source4/lib/replace/dlfcn.c
new file mode 100644 (file)
index 0000000..7a9e723
--- /dev/null
@@ -0,0 +1,71 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Samba system utilities
+   Copyright (C) Andrew Tridgell 1992-1998
+   Copyright (C) Jeremy Allison 1998-2002
+   
+   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
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/* 
+   Unix SMB/CIFS implementation.
+   Samba system utilities
+   Copyright (C) Andrew Tridgell 1992-1998
+   Copyright (C) Jeremy Allison 1998-2002
+   
+   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
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+
+#ifndef HAVE_DLOPEN
+void *dlopen(const char *name, int flags)
+{
+       return NULL;
+}
+#endif
+
+#ifndef HAVE_DLSYM
+void *dlsym(void *handle, const char *symbol)
+{
+    return NULL;
+}
+#endif
+
+#ifndef HAVE_DLERROR
+const char *dlerror(void)
+{
+       return "dynamic loading of objects not supported on this platform";
+}
+#endif
+
+#ifndef HAVE_DLCLOSE
+int dlclose(void *handle)
+{
+       return 0;
+}
+#endif
index ef8e05325793b2dc8c76287b8fe0d068f48e97c7..aa79f23fd0abf7b5751c12d15f2a8de387b63701 100644 (file)
@@ -361,39 +361,6 @@ duplicate a string
 #endif /* HAVE_SYSLOG */
 #endif /* HAVE_VSYSLOG */
 
-/*******************************************************************
-yield the difference between *A and *B, in seconds, ignoring leap seconds
-********************************************************************/
-static int tm_diff(struct tm *a, struct tm *b)
-{
-       int ay = a->tm_year + (1900 - 1);
-       int by = b->tm_year + (1900 - 1);
-       int intervening_leap_days =
-               (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400);
-       int years = ay - by;
-       int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday);
-       int hours = 24*days + (a->tm_hour - b->tm_hour);
-       int minutes = 60*hours + (a->tm_min - b->tm_min);
-       int seconds = 60*minutes + (a->tm_sec - b->tm_sec);
-
-       return seconds;
-}
-
-/*******************************************************************
-  return the UTC offset in seconds west of UTC, or 0 if it cannot be determined
-  ******************************************************************/
-int get_time_zone(time_t t)
-{
-       struct tm *tm = gmtime(&t);
-       struct tm tm_utc;
-       if (!tm)
-               return 0;
-       tm_utc = *tm;
-       tm = localtime(&t);
-       if (!tm)
-               return 0;
-       return tm_diff(&tm_utc,tm);
-}
 
 #ifndef HAVE_TIMEGM
 /*
@@ -496,14 +463,12 @@ int get_time_zone(time_t t)
 }
 #endif
 
-int sys_waitpid(pid_t pid,int *status,int options)
+#ifndef HAVE_WAITPID
+int waitpid(pid_t pid,int *status,int options)
 {
-#ifdef HAVE_WAITPID
-  return waitpid(pid,status,options);
-#else /* USE_WAITPID */
   return wait4(pid, status, options, NULL);
-#endif /* USE_WAITPID */
 }
+#endif
 
 #ifndef HAVE_SETEUID
  int seteuid(uid_t euid)
@@ -526,3 +491,35 @@ int sys_waitpid(pid_t pid,int *status,int options)
 #endif
 }
 #endif
+
+/*******************************************************************
+os/2 also doesn't have chroot
+********************************************************************/
+#ifndef HAVE_CHROOT
+int chroot(const char *dname)
+{
+       static int done;
+       if (!done) {
+               DEBUG(1,("WARNING: no chroot!\n"));
+               done=1;
+       }
+       errno = ENOSYS;
+       return -1;
+}
+#endif
+
+/*****************************************************************
+ Possibly replace mkstemp if it is broken.
+*****************************************************************/  
+
+#ifndef HAVE_SECURE_MKSTEMP
+int rep_mkstemp(char *template)
+{
+       /* have a reasonable go at emulating it. Hope that
+          the system mktemp() isn't completly hopeless */
+       char *p = mktemp(template);
+       if (!p)
+               return -1;
+       return open(p, O_CREAT|O_EXCL|O_RDWR, 0600);
+}
+#endif
index f85c8de634f077d298b43bee749783d43e4156d6..f906e7a2f50dc25675bebd07866e1038e7f77017 100644 (file)
 #ifndef _replace_h
 #define _replace_h
 
+#if defined(_MSC_VER) || defined(__MINGW32__)
+#include "lib/replace/win32/replace.h"
+#endif
+
 #ifdef __COMPAR_FN_T
 #define QSORT_CAST (__compar_fn_t)
 #endif
 #define QSORT_CAST (int (*)(const void *, const void *))
 #endif
 
+#ifndef HAVE_STRERROR
+extern char *sys_errlist[];
+#define strerror(i) sys_errlist[i]
+#endif
+
+#ifndef HAVE_ERRNO_DECL
+extern int errno;
+#endif
+
 #ifndef HAVE_STRDUP
 char *strdup(const char *s);
 #endif
@@ -136,4 +149,13 @@ typedef unsigned char u_int8_t;
 #define HAVE_SOCKLEN_T 1
 #endif
 
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#ifndef HAVE_SECURE_MKSTEMP
+#define mkstemp(path) rep_mkstemp(path)
+int rep_mkstemp(char *temp);
+#endif
+
 #endif
index 66d3e1f76ed65de0e26c0e79e8d4f87541968a2c..6c0bb4007a1c80cf4df8cf54b44637df497f01a0 100644 (file)
@@ -28,7 +28,7 @@
 
 static void sig_cld(int signum)
 {
-       while (sys_waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0)
+       while (waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0)
                ;
 
        /*
index eb3799c7cad8cd95df57a64beb423f79c4263647..629b2b07ffb61fe5f473d8dc626d32c9b4e92b88 100644 (file)
@@ -23,7 +23,6 @@
 #include "system/network.h"
 #include "system/wait.h"
 #include "system/filesys.h"
-#include "pstring.h"
 
 /*
    The idea is that this file will eventually have wrappers around all
@@ -77,20 +76,6 @@ int sys_usleep(long usecs)
 }
 
 
-/*******************************************************************
- System wrapper for getwd
-********************************************************************/
-char *sys_getwd(char *s)
-{
-       char *wd;
-#ifdef HAVE_GETCWD
-       wd = (char *)getcwd(s, sizeof (pstring));
-#else
-       wd = (char *)getwd(s);
-#endif
-       return wd;
-}
-
 /*******************************************************************
 A read wrapper that will deal with EINTR.
 ********************************************************************/
@@ -121,24 +106,6 @@ ssize_t sys_write(int fd, const void *buf, size_t count)
 
 
 
-/*******************************************************************
-os/2 also doesn't have chroot
-********************************************************************/
-int sys_chroot(const char *dname)
-{
-#ifndef HAVE_CHROOT
-       static int done;
-       if (!done) {
-               DEBUG(1,("WARNING: no chroot!\n"));
-               done=1;
-       }
-       errno = ENOSYS;
-       return -1;
-#else
-       return(chroot(dname));
-#endif
-}
-
 /**************************************************************************
 A wrapper for gethostbyname() that tries avoids looking up hostnames 
 in the root domain, which can cause dial-on-demand links to come up for no
@@ -181,39 +148,6 @@ struct hostent *sys_gethostbyname(const char *name)
 #endif /* REDUCE_ROOT_DNS_LOOKUPS */
 }
 
-
-
-/**************************************************************************
- Wrappers for dlopen, dlsym, dlclose.
-****************************************************************************/
-
-void *sys_dlopen(const char *name, int flags)
-{
-#if defined(HAVE_DLOPEN)
-       return dlopen(name, flags);
-#else
-       return NULL;
-#endif
-}
-
-void *sys_dlsym(void *handle, const char *symbol)
-{
-#if defined(HAVE_DLSYM)
-    return dlsym(handle, symbol);
-#else
-    return NULL;
-#endif
-}
-
-const char *sys_dlerror(void)
-{
-#if defined(HAVE_DLERROR)
-       return dlerror();
-#else
-       return NULL;
-#endif
-}
-
 const char *sys_inet_ntoa(struct ipv4_addr in)
 {
        struct in_addr in2;
@@ -221,11 +155,6 @@ const char *sys_inet_ntoa(struct ipv4_addr in)
        return inet_ntoa(in2);
 }
 
-uint32_t sys_inet_addr(const char *s)
-{
-       return inet_addr(s);
-}
-
 struct ipv4_addr sys_inet_makeaddr(int net, int host)
 {
        struct in_addr in;
index 61e92b8c0037d9fadf6e913435085f8e74fe5a78..5de9046c8dcd452f5fa98f6700f36d262b3431f2 100644 (file)
@@ -594,3 +594,37 @@ NTTIME timeval_to_nttime(const struct timeval *tv)
        return 10*(tv->tv_usec + 
                  ((TIME_FIXUP_CONSTANT + (uint64_t)tv->tv_sec) * 1000000));
 }
+
+/*******************************************************************
+yield the difference between *A and *B, in seconds, ignoring leap seconds
+********************************************************************/
+static int tm_diff(struct tm *a, struct tm *b)
+{
+       int ay = a->tm_year + (1900 - 1);
+       int by = b->tm_year + (1900 - 1);
+       int intervening_leap_days =
+               (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400);
+       int years = ay - by;
+       int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday);
+       int hours = 24*days + (a->tm_hour - b->tm_hour);
+       int minutes = 60*hours + (a->tm_min - b->tm_min);
+       int seconds = 60*minutes + (a->tm_sec - b->tm_sec);
+
+       return seconds;
+}
+
+/*******************************************************************
+  return the UTC offset in seconds west of UTC, or 0 if it cannot be determined
+  ******************************************************************/
+int get_time_zone(time_t t)
+{
+       struct tm *tm = gmtime(&t);
+       struct tm tm_utc;
+       if (!tm)
+               return 0;
+       tm_utc = *tm;
+       tm = localtime(&t);
+       if (!tm)
+               return 0;
+       return tm_diff(&tm_utc,tm);
+}
index a1d6f85eb93664308584b97e78d62028fc7f2173..0733103e930d2c9dbc961a87bd4ef051f6b7d0e8 100644 (file)
@@ -347,7 +347,7 @@ uint32_t interpret_addr(const char *str)
 
        /* if it's in the form of an IP address then get the lib to interpret it */
        if (is_ipaddress(str)) {
-               res = sys_inet_addr(str);
+               res = inet_addr(str);
        } else {
                /* otherwise assume it's a network name of some sort and use 
                        sys_gethostbyname */
@@ -518,24 +518,6 @@ void dump_data(int level, const uint8_t *buf,int len)
        }       
 }
 
-/*****************************************************************
- Possibly replace mkstemp if it is broken.
-*****************************************************************/  
-
-int smb_mkstemp(char *template)
-{
-#if HAVE_SECURE_MKSTEMP
-       return mkstemp(template);
-#else
-       /* have a reasonable go at emulating it. Hope that
-          the system mktemp() isn't completly hopeless */
-       char *p = mktemp(template);
-       if (!p)
-               return -1;
-       return open(p, O_CREAT|O_EXCL|O_RDWR, 0600);
-#endif
-}
-
 /*****************************************************************
  malloc that aborts with smb_panic on fail or zero size.
  *****************************************************************/  
index 9f48f83ba421274f9033626f0a20acc6fc0ee88d..a5edfcbc8a9d4a1ff4e9681e775db534af9311e0 100644 (file)
@@ -105,7 +105,7 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde,
        /* enusre the address looks good */
        address[ret] = 0;
        if (strcmp(address, "0.0.0.0") == 0 ||
-           sys_inet_addr(address) == INADDR_NONE) {
+           inet_addr(address) == INADDR_NONE) {
                goto failed;
        }
 
index e559ea8ff63db75c305e22d22e7841cb4fe8620c..b3740c5e01c967753253a2f2dfa7f8c7e07919ba 100644 (file)
@@ -571,7 +571,7 @@ NTSTATUS ndr_push_ipv4address(struct ndr_push *ndr, int ndr_flags, const char *a
 {
        uint32_t addr;
        if (!is_ipaddress(address)) return NT_STATUS_INVALID_PARAMETER_MIX;
-       addr = sys_inet_addr(address);
+       addr = inet_addr(address);
        NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, htonl(addr)));
        return NT_STATUS_OK;
 }
index e60f1caf78ddcee8714a857d28d38079812c166e..b4aefb87805b1b7d155595cafbd6cac7a33fad02 100644 (file)
@@ -2168,7 +2168,7 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
 
        for (i=0;i<torture_nprocs;i++) {
                int ret;
-               while ((ret=sys_waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
+               while ((ret=waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
                if (ret == -1 || WEXITSTATUS(status) != 0) {
                        *result = False;
                }
index bff39ab4823c49fb1e47779af2e5f81728de9354..a5ad66ae16883db2f39c75a0831b39ec1e1f8327 100644 (file)
@@ -50,7 +50,7 @@ NTSTATUS wbsrv_samba3_pull_request(DATA_BLOB blob, TALLOC_CTX *mem_ctx, struct w
 
        s3_call = talloc_zero(call, struct wbsrv_samba3_call);
        NT_STATUS_HAVE_NO_MEMORY(s3_call);
-       s3call->call = call;
+       s3_call->call = call;
 
        /* the packet layout is the same as the in memory layout of the request, so just copy it */
        memcpy(&s3_call->request, blob.data, sizeof(s3_call->request));