summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2013-07-19 22:12:58 +1000
committerAndrew Bartlett <abartlet@samba.org>2013-07-19 22:12:58 +1000
commitf5fc593ff9aaadf33e08d1584d3b6e6da1d40420 (patch)
tree2ce31cf380960f89837a4956d7c059c8e5cd280a
parent1f146c049e0117e1a0d09c710de73b4b1c16208c (diff)
Imported Upstream version 1.2.12
-rw-r--r--ABI/tdb-1.2.12.sigs67
-rw-r--r--buildtools/compare_config_h3-exceptions.grep10
-rwxr-xr-xbuildtools/compare_config_h3.sh27
-rw-r--r--buildtools/wafadmin/Tools/python.py2
-rw-r--r--buildtools/wafsamba/samba3.py11
-rw-r--r--buildtools/wafsamba/samba_abi.py36
-rw-r--r--buildtools/wafsamba/samba_autoconf.py28
-rw-r--r--buildtools/wafsamba/samba_bundled.py4
-rw-r--r--buildtools/wafsamba/samba_conftests.py3
-rw-r--r--buildtools/wafsamba/samba_deps.py2
-rw-r--r--buildtools/wafsamba/samba_install.py2
-rw-r--r--buildtools/wafsamba/samba_patterns.py7
-rw-r--r--buildtools/wafsamba/samba_pidl.py32
-rw-r--r--buildtools/wafsamba/samba_python.py12
-rw-r--r--buildtools/wafsamba/samba_utils.py7
-rw-r--r--buildtools/wafsamba/symbols.py2
-rw-r--r--buildtools/wafsamba/tests/test_abi.py67
-rw-r--r--buildtools/wafsamba/wafsamba.py53
-rwxr-xr-xbuildtools/wafsamba/wscript15
-rw-r--r--common/check.c44
-rw-r--r--common/dump.c17
-rw-r--r--common/error.c2
-rw-r--r--common/freelist.c34
-rw-r--r--common/freelistcheck.c7
-rw-r--r--common/io.c154
-rw-r--r--common/lock.c167
-rw-r--r--common/open.c70
-rw-r--r--common/rescue.c6
-rw-r--r--common/summary.c14
-rw-r--r--common/tdb.c43
-rw-r--r--common/tdb_private.h12
-rw-r--r--common/transaction.c131
-rw-r--r--common/traverse.c20
-rw-r--r--include/tdb.h10
-rw-r--r--lib/replace/README1
-rw-r--r--lib/replace/crypt.m46
-rw-r--r--lib/replace/dlfcn.m431
-rw-r--r--lib/replace/getifaddrs.c28
-rw-r--r--lib/replace/getpass.c218
-rw-r--r--lib/replace/getpass.m424
-rwxr-xr-xlib/replace/install-sh238
-rw-r--r--lib/replace/libreplace.m4479
-rw-r--r--lib/replace/libreplace_cc.m4197
-rw-r--r--lib/replace/libreplace_ld.m4337
-rw-r--r--lib/replace/libreplace_macros.m4332
-rw-r--r--lib/replace/libreplace_network.m4503
-rw-r--r--lib/replace/repdir.m481
-rw-r--r--lib/replace/replace.c8
-rw-r--r--lib/replace/replace.h103
-rw-r--r--lib/replace/snprintf.c5
-rw-r--r--lib/replace/socket.c22
-rw-r--r--lib/replace/strptime.m416
-rw-r--r--lib/replace/system/config.m4145
-rw-r--r--lib/replace/system/passwd.h11
-rw-r--r--lib/replace/system/wait.h4
-rw-r--r--lib/replace/test/getifaddrs.c24
-rw-r--r--lib/replace/test/testsuite.c7
-rw-r--r--lib/replace/timegm.m41
-rw-r--r--lib/replace/win32.m420
-rw-r--r--lib/replace/wscript80
-rw-r--r--lib/replace/xattr.c15
-rw-r--r--libtdb.m441
-rw-r--r--man/tdbbackup.8.xml (renamed from manpages/tdbbackup.8.xml)11
-rw-r--r--man/tdbdump.8.xml (renamed from manpages/tdbdump.8.xml)8
-rw-r--r--man/tdbrestore.8.xml (renamed from manpages/tdbrestore.8.xml)0
-rw-r--r--man/tdbtool.8.xml (renamed from manpages/tdbtool.8.xml)4
-rw-r--r--pytdb.c17
-rw-r--r--test/lock-tracking.c11
-rw-r--r--tools/tdbbackup.c27
-rw-r--r--tools/tdbdump.c11
-rw-r--r--tools/tdbtest.c12
-rw-r--r--tools/tdbtool.c40
-rw-r--r--tools/tdbtorture.c9
-rw-r--r--wscript10
74 files changed, 1000 insertions, 3255 deletions
diff --git a/ABI/tdb-1.2.12.sigs b/ABI/tdb-1.2.12.sigs
new file mode 100644
index 0000000..d727f21
--- /dev/null
+++ b/ABI/tdb-1.2.12.sigs
@@ -0,0 +1,67 @@
+tdb_add_flags: void (struct tdb_context *, unsigned int)
+tdb_append: int (struct tdb_context *, TDB_DATA, TDB_DATA)
+tdb_chainlock: int (struct tdb_context *, TDB_DATA)
+tdb_chainlock_mark: int (struct tdb_context *, TDB_DATA)
+tdb_chainlock_nonblock: int (struct tdb_context *, TDB_DATA)
+tdb_chainlock_read: int (struct tdb_context *, TDB_DATA)
+tdb_chainlock_unmark: int (struct tdb_context *, TDB_DATA)
+tdb_chainunlock: int (struct tdb_context *, TDB_DATA)
+tdb_chainunlock_read: int (struct tdb_context *, TDB_DATA)
+tdb_check: int (struct tdb_context *, int (*)(TDB_DATA, TDB_DATA, void *), void *)
+tdb_close: int (struct tdb_context *)
+tdb_delete: int (struct tdb_context *, TDB_DATA)
+tdb_dump_all: void (struct tdb_context *)
+tdb_enable_seqnum: void (struct tdb_context *)
+tdb_error: enum TDB_ERROR (struct tdb_context *)
+tdb_errorstr: const char *(struct tdb_context *)
+tdb_exists: int (struct tdb_context *, TDB_DATA)
+tdb_fd: int (struct tdb_context *)
+tdb_fetch: TDB_DATA (struct tdb_context *, TDB_DATA)
+tdb_firstkey: TDB_DATA (struct tdb_context *)
+tdb_freelist_size: int (struct tdb_context *)
+tdb_get_flags: int (struct tdb_context *)
+tdb_get_logging_private: void *(struct tdb_context *)
+tdb_get_seqnum: int (struct tdb_context *)
+tdb_hash_size: int (struct tdb_context *)
+tdb_increment_seqnum_nonblock: void (struct tdb_context *)
+tdb_jenkins_hash: unsigned int (TDB_DATA *)
+tdb_lock_nonblock: int (struct tdb_context *, int, int)
+tdb_lockall: int (struct tdb_context *)
+tdb_lockall_mark: int (struct tdb_context *)
+tdb_lockall_nonblock: int (struct tdb_context *)
+tdb_lockall_read: int (struct tdb_context *)
+tdb_lockall_read_nonblock: int (struct tdb_context *)
+tdb_lockall_unmark: int (struct tdb_context *)
+tdb_log_fn: tdb_log_func (struct tdb_context *)
+tdb_map_size: size_t (struct tdb_context *)
+tdb_name: const char *(struct tdb_context *)
+tdb_nextkey: TDB_DATA (struct tdb_context *, TDB_DATA)
+tdb_null: dptr = 0xXXXX, dsize = 0
+tdb_open: struct tdb_context *(const char *, int, int, int, mode_t)
+tdb_open_ex: struct tdb_context *(const char *, int, int, int, mode_t, const struct tdb_logging_context *, tdb_hash_func)
+tdb_parse_record: int (struct tdb_context *, TDB_DATA, int (*)(TDB_DATA, TDB_DATA, void *), void *)
+tdb_printfreelist: int (struct tdb_context *)
+tdb_remove_flags: void (struct tdb_context *, unsigned int)
+tdb_reopen: int (struct tdb_context *)
+tdb_reopen_all: int (int)
+tdb_repack: int (struct tdb_context *)
+tdb_rescue: int (struct tdb_context *, void (*)(TDB_DATA, TDB_DATA, void *), void *)
+tdb_set_logging_function: void (struct tdb_context *, const struct tdb_logging_context *)
+tdb_set_max_dead: void (struct tdb_context *, int)
+tdb_setalarm_sigptr: void (struct tdb_context *, volatile sig_atomic_t *)
+tdb_store: int (struct tdb_context *, TDB_DATA, TDB_DATA, int)
+tdb_summary: char *(struct tdb_context *)
+tdb_transaction_cancel: int (struct tdb_context *)
+tdb_transaction_commit: int (struct tdb_context *)
+tdb_transaction_prepare_commit: int (struct tdb_context *)
+tdb_transaction_start: int (struct tdb_context *)
+tdb_transaction_start_nonblock: int (struct tdb_context *)
+tdb_transaction_write_lock_mark: int (struct tdb_context *)
+tdb_transaction_write_lock_unmark: int (struct tdb_context *)
+tdb_traverse: int (struct tdb_context *, tdb_traverse_func, void *)
+tdb_traverse_read: int (struct tdb_context *, tdb_traverse_func, void *)
+tdb_unlock: int (struct tdb_context *, int, int)
+tdb_unlockall: int (struct tdb_context *)
+tdb_unlockall_read: int (struct tdb_context *)
+tdb_validate_freelist: int (struct tdb_context *, int *)
+tdb_wipe_all: int (struct tdb_context *)
diff --git a/buildtools/compare_config_h3-exceptions.grep b/buildtools/compare_config_h3-exceptions.grep
deleted file mode 100644
index aa8851f..0000000
--- a/buildtools/compare_config_h3-exceptions.grep
+++ /dev/null
@@ -1,10 +0,0 @@
-^.define HAVE_.*KRB5
-^.define HAVE_.*KEYTAB
-^.define HAVE__ET_LIST
-^.define HAVE_LIBK5CRYPTO
-^.define HAVE_GSS
-^.define static
-^.define STATIC
-^.define PACKAGE
-^.define STRING_STATIC_MODULES
-^.define perfcount_test_init
diff --git a/buildtools/compare_config_h3.sh b/buildtools/compare_config_h3.sh
deleted file mode 100755
index 45be1ec..0000000
--- a/buildtools/compare_config_h3.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/sh
-
-# compare the generated config.h from a waf build with existing samba
-# build
-
-OLD_CONFIG=source3/include/autoconf/config.h
-if test "x$1" != "x" ; then
- OLD_CONFIG=$1
-fi
-
-NEW_CONFIG=bin/default/include/config.h
-if test "x$2" != "x" ; then
- NEW_CONFIG=$2
-fi
-
-EXCEPTIONS=`dirname $0`/compare_config_h3-exceptions.grep
-
-if test "x$DIFF" = "x" ; then
- DIFF="comm -23"
-fi
-
-grep "^.define" $NEW_CONFIG | egrep -v -f $EXCEPTIONS | sort > waf-config.h
-grep "^.define" $OLD_CONFIG | egrep -v -f $EXCEPTIONS | sort > old-config.h
-
-$DIFF old-config.h waf-config.h
-rm -f old-config.h waf-config.h
-
diff --git a/buildtools/wafadmin/Tools/python.py b/buildtools/wafadmin/Tools/python.py
index c2af312..a15e1f6 100644
--- a/buildtools/wafadmin/Tools/python.py
+++ b/buildtools/wafadmin/Tools/python.py
@@ -259,7 +259,7 @@ MACOSX_DEPLOYMENT_TARGET = %r
includes = []
if python_config:
- for incstr in Utils.cmd_output("%s %s --includes" % (python, python_config)).strip().split():
+ for incstr in Utils.cmd_output("%s --includes" % (python_config,)).strip().split():
# strip the -I or /I
if (incstr.startswith('-I')
or incstr.startswith('/I')):
diff --git a/buildtools/wafsamba/samba3.py b/buildtools/wafsamba/samba3.py
index 476d8fc..fd063ad 100644
--- a/buildtools/wafsamba/samba3.py
+++ b/buildtools/wafsamba/samba3.py
@@ -8,8 +8,17 @@ from samba_autoconf import library_flags
def SAMBA3_ADD_OPTION(opt, option, help=(), dest=None, default=True,
with_name="with", without_name="without"):
+ if default is None:
+ default_str="auto"
+ elif default == True:
+ default_str="yes"
+ elif default == False:
+ default_str="no"
+ else:
+ default_str=str(default)
+
if help == ():
- help = ("Build with %s support" % option)
+ help = ("Build with %s support (default=%s)" % (option, default_str))
if dest is None:
dest = "with_%s" % option.replace('-', '_')
diff --git a/buildtools/wafsamba/samba_abi.py b/buildtools/wafsamba/samba_abi.py
index ed977ba..76acd00 100644
--- a/buildtools/wafsamba/samba_abi.py
+++ b/buildtools/wafsamba/samba_abi.py
@@ -50,13 +50,15 @@ def parse_sigs(sigs, abi_match):
sa = s.split(':')
if abi_match:
matched = False
+ negative = False
for p in abi_match:
if p[0] == '!' and fnmatch.fnmatch(sa[0], p[1:]):
+ negative = True
break
elif fnmatch.fnmatch(sa[0], p):
matched = True
break
- if not matched:
+ if (not matched) and negative:
continue
Logs.debug("%s -> %s" % (sa[1], normalise_signature(sa[1])))
ret[sa[0]] = normalise_signature(sa[1])
@@ -152,22 +154,23 @@ def abi_process_file(fname, version, symmap):
symmap[symname] = version
f.close()
-def abi_write_vscript(vscript, libname, current_version, versions, symmap, abi_match):
- '''write a vscript file for a library in --version-script format
- :param vscript: Path to the vscript file
+def abi_write_vscript(f, libname, current_version, versions, symmap, abi_match):
+ """Write a vscript file for a library in --version-script format.
+
+ :param f: File-like object to write to
:param libname: Name of the library, uppercased
:param current_version: Current version
:param versions: Versions to consider
:param symmap: Dictionary mapping symbols -> version
- :param abi_match: List of symbols considered to be public in the current version
- '''
+ :param abi_match: List of symbols considered to be public in the current
+ version
+ """
invmap = {}
for s in symmap:
invmap.setdefault(symmap[s], []).append(s)
- f = open(vscript, mode='w')
last_key = ""
versions = sorted(versions, key=version_key)
for k in versions:
@@ -175,8 +178,8 @@ def abi_write_vscript(vscript, libname, current_version, versions, symmap, abi_m
if symver == current_version:
break
f.write("%s {\n" % symver)
- if k in invmap:
- f.write("\tglobal: \n")
+ if k in sorted(invmap.keys()):
+ f.write("\tglobal:\n")
for s in invmap.get(k, []):
f.write("\t\t%s;\n" % s);
f.write("}%s;\n\n" % last_key)
@@ -190,14 +193,13 @@ def abi_write_vscript(vscript, libname, current_version, versions, symmap, abi_m
f.write("\t\t%s;\n" % x)
else:
f.write("\t\t*;\n")
- if len(local_abi) > 0:
+ if abi_match != ["*"]:
f.write("\tlocal:\n")
for x in local_abi:
f.write("\t\t%s;\n" % x[1:])
- elif abi_match != ["*"]:
- f.write("\tlocal: *;\n")
+ if len(global_abi) > 0:
+ f.write("\t\t*;\n")
f.write("};\n")
- f.close()
def abi_build_vscript(task):
@@ -213,8 +215,12 @@ def abi_build_vscript(task):
version = basename[len(task.env.LIBNAME)+1:-len(".sigs")]
versions.append(version)
abi_process_file(fname, version, symmap)
- abi_write_vscript(tgt, task.env.LIBNAME, task.env.VERSION, versions, symmap,
- task.env.ABI_MATCH)
+ f = open(tgt, mode='w')
+ try:
+ abi_write_vscript(f, task.env.LIBNAME, task.env.VERSION, versions,
+ symmap, task.env.ABI_MATCH)
+ finally:
+ f.close()
def ABI_VSCRIPT(bld, libname, abi_directory, version, vscript, abi_match=None):
diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
index 5d3cc5a..fe110bd 100644
--- a/buildtools/wafsamba/samba_autoconf.py
+++ b/buildtools/wafsamba/samba_autoconf.py
@@ -62,8 +62,8 @@ def COMPOUND_END(conf, result):
conf.check_message_1 = conf.saved_check_message_1
conf.check_message_2 = conf.saved_check_message_2
p = conf.check_message_2
- if result:
- p('ok ')
+ if result is True:
+ p('ok')
elif not result:
p('not found', 'YELLOW')
else:
@@ -323,7 +323,25 @@ def CHECK_SIZEOF(conf, vars, headers=None, define=None):
ret = False
return ret
-
+@conf
+def CHECK_VALUEOF(conf, v, headers=None, define=None):
+ '''check the value of a variable/define'''
+ ret = True
+ v_define = define
+ if v_define is None:
+ v_define = 'VALUEOF_%s' % v.upper().replace(' ', '_')
+ if CHECK_CODE(conf,
+ 'printf("%%u", (unsigned)(%s))' % v,
+ define=v_define,
+ execute=True,
+ define_ret=True,
+ quote=False,
+ headers=headers,
+ local_include=False,
+ msg="Checking value of %s" % v):
+ return int(conf.env[v_define])
+
+ return None
@conf
def CHECK_CODE(conf, code, define,
@@ -758,9 +776,9 @@ def SETUP_CONFIGURE_CACHE(conf, enable):
def SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS(conf):
# we don't want any libraries or modules to rely on runtime
# resolution of symbols
- if sys.platform != "openbsd4" and sys.platform != "openbsd5":
+ if not sys.platform.startswith("openbsd"):
conf.env.undefined_ldflags = conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
- if sys.platform != "openbsd4" and sys.platform != "openbsd5" and conf.env.undefined_ignore_ldflags == []:
+ if not sys.platform.startswith("openbsd") and conf.env.undefined_ignore_ldflags == []:
if conf.CHECK_LDFLAGS(['-undefined', 'dynamic_lookup']):
conf.env.undefined_ignore_ldflags = ['-undefined', 'dynamic_lookup']
diff --git a/buildtools/wafsamba/samba_bundled.py b/buildtools/wafsamba/samba_bundled.py
index b8a4101..afcf708 100644
--- a/buildtools/wafsamba/samba_bundled.py
+++ b/buildtools/wafsamba/samba_bundled.py
@@ -30,8 +30,6 @@ def target_in_list(target, lst, default):
def BUILTIN_LIBRARY(bld, name):
'''return True if a library should be builtin
instead of being built as a shared lib'''
- if bld.env.DISABLE_SHARED:
- return True
return target_in_list(name, bld.env.BUILTIN_LIBRARIES, False)
Build.BuildContext.BUILTIN_LIBRARY = BUILTIN_LIBRARY
@@ -249,8 +247,6 @@ def CHECK_BUNDLED_SYSTEM_PYTHON(conf, libname, modulename, minversion='0.0.0'):
def NONSHARED_BINARY(bld, name):
'''return True if a binary should be built without non-system shared libs'''
- if bld.env.DISABLE_SHARED:
- return True
return target_in_list(name, bld.env.NONSHARED_BINARIES, False)
Build.BuildContext.NONSHARED_BINARY = NONSHARED_BINARY
diff --git a/buildtools/wafsamba/samba_conftests.py b/buildtools/wafsamba/samba_conftests.py
index 0274f66..ec98ba0 100644
--- a/buildtools/wafsamba/samba_conftests.py
+++ b/buildtools/wafsamba/samba_conftests.py
@@ -503,3 +503,6 @@ def CHECK_XSLTPROC_MANPAGES(conf):
msg='Checking for stylesheet %s' % s,
define='XSLTPROC_MANPAGES', on_target=False,
boolean=True)
+ if not conf.CONFIG_SET('XSLTPROC_MANPAGES'):
+ print "A local copy of the docbook.xsl wasn't found on your system" \
+ " consider installing package like docbook-xsl"
diff --git a/buildtools/wafsamba/samba_deps.py b/buildtools/wafsamba/samba_deps.py
index 3220f35..74a70cf 100644
--- a/buildtools/wafsamba/samba_deps.py
+++ b/buildtools/wafsamba/samba_deps.py
@@ -224,7 +224,7 @@ def add_init_functions(self):
sname = sname.replace('/','_')
cflags.append('-DSTATIC_%s_MODULES=%s' % (sname, sentinel))
if sentinel == 'NULL':
- cflags.append('-DSTATIC_%s_MODULES_PROTO' % sname)
+ cflags.append('-DSTATIC_%s_MODULES_PROTO=' % sname)
self.ccflags = cflags
return
diff --git a/buildtools/wafsamba/samba_install.py b/buildtools/wafsamba/samba_install.py
index 5e53989..aa7f143 100644
--- a/buildtools/wafsamba/samba_install.py
+++ b/buildtools/wafsamba/samba_install.py
@@ -103,6 +103,8 @@ def install_library(self):
if getattr(self, 'samba_realname', None):
install_name = self.samba_realname
install_link = None
+ if getattr(self, 'soname', ''):
+ install_link = self.soname
if getattr(self, 'samba_type', None) == 'PYTHON':
inst_name = bld.make_libname(t.target, nolibprefix=True, python=True)
else:
diff --git a/buildtools/wafsamba/samba_patterns.py b/buildtools/wafsamba/samba_patterns.py
index 615d918..55ed540 100644
--- a/buildtools/wafsamba/samba_patterns.py
+++ b/buildtools/wafsamba/samba_patterns.py
@@ -21,11 +21,15 @@ def write_version_header(task):
def SAMBA_MKVERSION(bld, target):
'''generate the version.h header for Samba'''
+
+ # We only force waf to re-generate this file if we are installing,
+ # because only then is information not included in the deps (the
+ # git revision) included in the version.
t = bld.SAMBA_GENERATOR('VERSION',
rule=write_version_header,
source= 'VERSION',
target=target,
- always=True)
+ always=bld.is_install)
t.env.is_install = bld.is_install
Build.BuildContext.SAMBA_MKVERSION = SAMBA_MKVERSION
@@ -110,7 +114,6 @@ def write_build_options_header(fp):
fp.write(" output(screen,\"\\nPaths:\\n\");\n")
fp.write(" output(screen,\" SBINDIR: %s\\n\", get_dyn_SBINDIR());\n")
fp.write(" output(screen,\" BINDIR: %s\\n\", get_dyn_BINDIR());\n")
- fp.write(" output(screen,\" SWATDIR: %s\\n\", get_dyn_SWATDIR());\n")
fp.write(" output(screen,\" CONFIGFILE: %s\\n\", get_dyn_CONFIGFILE());\n")
fp.write(" output(screen,\" LOGFILEBASE: %s\\n\", get_dyn_LOGFILEBASE());\n")
fp.write(" output(screen,\" LMHOSTSFILE: %s\\n\",get_dyn_LMHOSTSFILE());\n")
diff --git a/buildtools/wafsamba/samba_pidl.py b/buildtools/wafsamba/samba_pidl.py
index ff13971..2393c72 100644
--- a/buildtools/wafsamba/samba_pidl.py
+++ b/buildtools/wafsamba/samba_pidl.py
@@ -7,7 +7,6 @@ from samba_utils import *
def SAMBA_PIDL(bld, pname, source,
options='',
output_dir='.',
- symlink=False,
generate_tables=True):
'''Build a IDL file using pidl.
This will produce up to 13 output files depending on the options used'''
@@ -60,9 +59,9 @@ def SAMBA_PIDL(bld, pname, source,
# the cd .. is needed because pidl currently is sensitive to the directory it is run in
cpp = ""
cc = ""
- if bld.CONFIG_SET("CPP"):
+ if bld.CONFIG_SET("CPP") and bld.CONFIG_GET("CPP") != "":
if isinstance(bld.CONFIG_GET("CPP"), list):
- cpp = 'CPP="%s"' % bld.CONFIG_GET("CPP")[0]
+ cpp = 'CPP="%s"' % " ".join(bld.CONFIG_GET("CPP"))
else:
cpp = 'CPP="%s"' % bld.CONFIG_GET("CPP")
@@ -72,7 +71,7 @@ def SAMBA_PIDL(bld, pname, source,
if bld.CONFIG_SET("CC"):
if isinstance(bld.CONFIG_GET("CC"), list):
- cc = 'CC="%s"' % bld.CONFIG_GET("CC")[0]
+ cc = 'CC="%s"' % " ".join(bld.CONFIG_GET("CC"))
else:
cc = 'CC="%s"' % bld.CONFIG_GET("CC")
@@ -91,27 +90,7 @@ def SAMBA_PIDL(bld, pname, source,
t.env.PIDL = os.path.join(bld.srcnode.abspath(), 'pidl/pidl')
t.env.OPTIONS = TO_LIST(options)
-
- # this rather convoluted set of path calculations is to cope with the possibility
- # that gen_ndr is a symlink into the source tree. By doing this for the source3
- # gen_ndr directory we end up generating identical output in gen_ndr for the old
- # build system and the new one. That makes keeping things in sync much easier.
- # eventually we should drop the gen_ndr files in git, but in the meanwhile this works
-
- found_dir = bld.path.find_dir(output_dir)
- if not 'abspath' in dir(found_dir):
- Logs.error('Unable to find pidl output directory %s' %
- os.path.normpath(os.path.join(bld.curdir, output_dir)))
- sys.exit(1)
-
- outdir = bld.path.find_dir(output_dir).abspath(t.env)
-
- if symlink and not os.path.lexists(outdir):
- link_source = os.path.normpath(os.path.join(bld.curdir,output_dir))
- os.symlink(link_source, outdir)
-
- real_outputdir = os.path.realpath(outdir)
- t.env.OUTPUTDIR = os_path_relpath(real_outputdir, os.path.dirname(bld.env.BUILD_DIRECTORY))
+ t.env.OUTPUTDIR = bld.bldnode.name + '/' + bld.path.find_dir(output_dir).bldpath(t.env)
if generate_tables and table_header_idx is not None:
pidl_headers = LOCAL_CACHE(bld, 'PIDL_HEADERS')
@@ -124,11 +103,10 @@ Build.BuildContext.SAMBA_PIDL = SAMBA_PIDL
def SAMBA_PIDL_LIST(bld, name, source,
options='',
output_dir='.',
- symlink=False,
generate_tables=True):
'''A wrapper for building a set of IDL files'''
for p in TO_LIST(source):
- bld.SAMBA_PIDL(name, p, options=options, output_dir=output_dir, symlink=symlink, generate_tables=generate_tables)
+ bld.SAMBA_PIDL(name, p, options=options, output_dir=output_dir, generate_tables=generate_tables)
Build.BuildContext.SAMBA_PIDL_LIST = SAMBA_PIDL_LIST
diff --git a/buildtools/wafsamba/samba_python.py b/buildtools/wafsamba/samba_python.py
index 6bc32f0..aee9547 100644
--- a/buildtools/wafsamba/samba_python.py
+++ b/buildtools/wafsamba/samba_python.py
@@ -5,6 +5,16 @@ from samba_utils import *
from samba_autoconf import *
from Configure import conf
+
+@conf
+def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,4,2)):
+ # enable tool to build python extensions
+ conf.find_program('python', var='PYTHON', mandatory=mandatory)
+ conf.check_tool('python')
+ path_python = conf.find_program('python')
+ conf.env.PYTHON_SPECIFIED = (conf.env.PYTHON != path_python)
+ conf.check_python_version(version)
+
@conf
def SAMBA_CHECK_PYTHON_HEADERS(conf, mandatory=True):
if conf.env["python_headers_checked"] == []:
@@ -35,7 +45,7 @@ def SAMBA_PYTHON(bld, name,
source = bld.EXPAND_VARIABLES(source, vars=vars)
if realname is not None:
- link_name = 'python/%s' % realname
+ link_name = 'python_modules/%s' % realname
else:
link_name = None
diff --git a/buildtools/wafsamba/samba_utils.py b/buildtools/wafsamba/samba_utils.py
index c1869df..c1ac7e2 100644
--- a/buildtools/wafsamba/samba_utils.py
+++ b/buildtools/wafsamba/samba_utils.py
@@ -388,9 +388,16 @@ def RUN_COMMAND(cmd,
# make sure we have md5. some systems don't have it
try:
from hashlib import md5
+ # Even if hashlib.md5 exists, it may be unusable.
+ # Try to use MD5 function. In FIPS mode this will cause an exception
+ # and we'll get to the replacement code
+ foo = md5.md5('abcd')
except:
try:
import md5
+ # repeat the same check here, mere success of import is not enough.
+ # Try to use MD5 function. In FIPS mode this will cause an exception
+ foo = md5.md5('abcd')
except:
import Constants
Constants.SIG_NIL = hash('abcd')
diff --git a/buildtools/wafsamba/symbols.py b/buildtools/wafsamba/symbols.py
index 13d84b9..daa18b9 100644
--- a/buildtools/wafsamba/symbols.py
+++ b/buildtools/wafsamba/symbols.py
@@ -569,7 +569,7 @@ def symbols_whyneeded(task):
def report_duplicate(bld, binname, sym, libs, fail_on_error):
'''report duplicated symbols'''
- if sym in ['_init', '_fini']:
+ if sym in ['_init', '_fini', '_edata', '_end', '__bss_start']:
return
libnames = []
for lib in libs:
diff --git a/buildtools/wafsamba/tests/test_abi.py b/buildtools/wafsamba/tests/test_abi.py
index 0aa0d56..bba78c1 100644
--- a/buildtools/wafsamba/tests/test_abi.py
+++ b/buildtools/wafsamba/tests/test_abi.py
@@ -17,9 +17,12 @@
from wafsamba.tests import TestCase
from wafsamba.samba_abi import (
+ abi_write_vscript,
normalise_signature,
)
+from cStringIO import StringIO
+
class NormaliseSignatureTests(TestCase):
@@ -51,3 +54,67 @@ class NormaliseSignatureTests(TestCase):
'uuid = {time_low = 2324192516, time_mid = 7403, time_hi_and_version = 4553, clock_seq = "\\237\\350", node = "\\b\\000+\\020H`"}, if_version = 2',
normalise_signature('$244 = {uuid = {time_low = 2324192516, time_mid = 7403, time_hi_and_version = 4553, clock_seq = "\\237\\350", node = "\\b\\000+\\020H`"}, if_version = 2}'))
+
+class WriteVscriptTests(TestCase):
+
+ def test_one(self):
+ f = StringIO()
+ abi_write_vscript(f, "MYLIB", "1.0", [], {
+ "old": "1.0",
+ "new": "1.0"}, ["*"])
+ self.assertEquals(f.getvalue(), """\
+1.0 {
+\tglobal:
+\t\t*;
+};
+""")
+
+ def test_simple(self):
+ # No restrictions.
+ f = StringIO()
+ abi_write_vscript(f, "MYLIB", "1.0", ["0.1"], {
+ "old": "0.1",
+ "new": "1.0"}, ["*"])
+ self.assertEquals(f.getvalue(), """\
+MYLIB_0.1 {
+\tglobal:
+\t\told;
+};
+
+1.0 {
+\tglobal:
+\t\t*;
+};
+""")
+
+ def test_exclude(self):
+ f = StringIO()
+ abi_write_vscript(f, "MYLIB", "1.0", [], {
+ "exc_old": "0.1",
+ "old": "0.1",
+ "new": "1.0"}, ["!exc_*"])
+ self.assertEquals(f.getvalue(), """\
+1.0 {
+\tglobal:
+\t\t*;
+\tlocal:
+\t\texc_*;
+};
+""")
+
+ def test_excludes_and_includes(self):
+ f = StringIO()
+ abi_write_vscript(f, "MYLIB", "1.0", [], {
+ "pub_foo": "1.0",
+ "exc_bar": "1.0",
+ "other": "1.0"
+ }, ["pub_*", "!exc_*"])
+ self.assertEquals(f.getvalue(), """\
+1.0 {
+\tglobal:
+\t\tpub_*;
+\tlocal:
+\t\texc_*;
+\t\t*;
+};
+""")
diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py
index 59d3a2c..aaa0939 100644
--- a/buildtools/wafsamba/wafsamba.py
+++ b/buildtools/wafsamba/wafsamba.py
@@ -64,10 +64,10 @@ def SAMBA_BUILD_ENV(conf):
# this allows all of the bin/shared and bin/python targets
# to be expressed in terms of build directory paths
mkdir_p(os.path.join(conf.blddir, 'default'))
- for p in ['python','shared', 'modules']:
- link_target = os.path.join(conf.blddir, 'default/' + p)
+ for (source, target) in [('shared', 'shared'), ('modules', 'modules'), ('python', 'python_modules')]:
+ link_target = os.path.join(conf.blddir, 'default/' + target)
if not os.path.lexists(link_target):
- os.symlink('../' + p, link_target)
+ os.symlink('../' + source, link_target)
# get perl to put the blib files in the build directory
blib_bld = os.path.join(conf.blddir, 'default/pidl/blib')
@@ -110,7 +110,7 @@ def SAMBA_LIBRARY(bld, libname, source,
realname=None,
autoproto=None,
autoproto_extra_source='',
- group='libraries',
+ group='main',
depends_on='',
local_include=True,
global_include=True,
@@ -287,7 +287,7 @@ def SAMBA_LIBRARY(bld, libname, source,
if (manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and
bld.env['XSLTPROC_MANPAGES']):
- bld.MANPAGES(manpages)
+ bld.MANPAGES(manpages, install)
Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
@@ -306,7 +306,7 @@ def SAMBA_BINARY(bld, binname, source,
use_hostcc=False,
use_global_deps=True,
compiler=None,
- group='binaries',
+ group='main',
manpages=None,
local_include=True,
global_include=True,
@@ -342,6 +342,13 @@ def SAMBA_BINARY(bld, binname, source,
else:
subsystem_group = group
+ # only specify PIE flags for binaries
+ pie_cflags = cflags
+ pie_ldflags = TO_LIST(ldflags)
+ if bld.env['ENABLE_PIE'] == True:
+ pie_cflags += ' -fPIE'
+ pie_ldflags.extend(TO_LIST('-pie'))
+
# first create a target for building the object files for this binary
# by separating in this way, we avoid recompiling the C files
# separately for the install binary and the build binary
@@ -349,7 +356,7 @@ def SAMBA_BINARY(bld, binname, source,
source = source,
deps = deps,
includes = includes,
- cflags = cflags,
+ cflags = pie_cflags,
group = subsystem_group,
autoproto = autoproto,
subsystem_name = subsystem_name,
@@ -379,11 +386,11 @@ def SAMBA_BINARY(bld, binname, source,
install_path = None,
samba_inst_path= install_path,
samba_install = install,
- samba_ldflags = TO_LIST(ldflags)
+ samba_ldflags = pie_ldflags
)
if manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and bld.env['XSLTPROC_MANPAGES']:
- bld.MANPAGES(manpages)
+ bld.MANPAGES(manpages, install)
Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
@@ -629,8 +636,6 @@ def SETUP_BUILD_GROUPS(bld):
bld.add_group('headers')
bld.add_group('main')
bld.add_group('symbolcheck')
- bld.add_group('libraries')
- bld.add_group('binaries')
bld.add_group('syslibcheck')
bld.add_group('final')
Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
@@ -696,14 +701,25 @@ def copy_and_fix_python_path(task):
replacement="""sys.path.insert(0, "%s")
sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"])
+ shebang = None
+
+ if task.env["PYTHON"][0] == "/":
+ replacement_shebang = "#!%s\n" % task.env["PYTHON"]
+ else:
+ replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PYTHON"]
+
installed_location=task.outputs[0].bldpath(task.env)
source_file = open(task.inputs[0].srcpath(task.env))
installed_file = open(installed_location, 'w')
+ lineno = 0
for line in source_file:
newline = line
- if pattern in line:
+ if lineno == 0 and task.env["PYTHON_SPECIFIED"] == True and line[:2] == "#!":
+ newline = replacement_shebang
+ elif pattern in line:
newline = line.replace(pattern, replacement)
installed_file.write(newline)
+ lineno = lineno + 1
installed_file.close()
os.chmod(installed_location, 0755)
return 0
@@ -727,6 +743,8 @@ def install_file(bld, destdir, file, chmod=MODE_644, flat=False,
target=inst_file)
bld.add_manual_dependency(bld.path.find_or_declare(inst_file), bld.env["PYTHONARCHDIR"])
bld.add_manual_dependency(bld.path.find_or_declare(inst_file), bld.env["PYTHONDIR"])
+ bld.add_manual_dependency(bld.path.find_or_declare(inst_file), str(bld.env["PYTHON_SPECIFIED"]))
+ bld.add_manual_dependency(bld.path.find_or_declare(inst_file), bld.env["PYTHON"])
file = inst_file
if base_name:
file = os.path.join(base_name, file)
@@ -771,7 +789,7 @@ def INSTALL_DIRS(bld, destdir, dirs):
Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
-def MANPAGES(bld, manpages):
+def MANPAGES(bld, manpages, install):
'''build and install manual pages'''
bld.env.MAN_XSL = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
for m in manpages.split():
@@ -782,21 +800,24 @@ def MANPAGES(bld, manpages):
group='final',
rule='${XSLTPROC} --xinclude -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
)
- bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
+ if install:
+ bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
Build.BuildContext.MANPAGES = MANPAGES
def SAMBAMANPAGES(bld, manpages):
'''build and install manual pages'''
bld.env.SAMBA_EXPAND_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/expand-sambadoc.xsl'
bld.env.SAMBA_MAN_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/man.xsl'
- bld.env.SAMBA_CATALOGS = 'file:///etc/xml/catalog file://' + bld.srcnode.abspath() + '/bin/default/docs-xml/build/catalog.xml'
+ bld.env.SAMBA_CATALOGS = 'file:///etc/xml/catalog file:///usr/local/share/xml/catalog file://' + bld.srcnode.abspath() + '/bin/default/docs-xml/build/catalog.xml'
+
for m in manpages.split():
source = m + '.xml'
bld.SAMBA_GENERATOR(m,
source=source,
target=m,
group='final',
- rule='''export XML_CATALOG_FILES="${SAMBA_CATALOGS}"
+ rule='''XML_CATALOG_FILES="${SAMBA_CATALOGS}"
+ export XML_CATALOG_FILES
${XSLTPROC} --xinclude --stringparam noreference 0 -o ${TGT}.xml --nonet ${SAMBA_EXPAND_XSL} ${SRC}
${XSLTPROC} --nonet -o ${TGT} ${SAMBA_MAN_XSL} ${TGT}.xml'''
)
diff --git a/buildtools/wafsamba/wscript b/buildtools/wafsamba/wscript
index 5e1898c..17aef27 100755
--- a/buildtools/wafsamba/wscript
+++ b/buildtools/wafsamba/wscript
@@ -50,9 +50,6 @@ def set_options(opt):
help=("list of minimum system library versions (LIBNAME1:version,LIBNAME2:version)"),
action="store", dest='MINIMUM_LIBRARY_VERSION', default='')
- gr.add_option('--disable-shared',
- help=("Disable all use of shared libraries"),
- action="store_true", dest='disable_shared', default=False)
gr.add_option('--disable-rpath',
help=("Disable use of rpath for build binaries"),
action="store_true", dest='disable_rpath_build', default=False)
@@ -248,7 +245,6 @@ def configure(conf):
conf.env.BUNDLED_LIBS = Options.options.BUNDLED_LIBS.split(',')
conf.env.PRIVATE_LIBS = Options.options.PRIVATE_LIBS.split(',')
conf.env.BUILTIN_LIBRARIES = Options.options.BUILTIN_LIBRARIES.split(',')
- conf.env.DISABLE_SHARED = Options.options.disable_shared
conf.env.NONSHARED_BINARIES = Options.options.NONSHARED_BINARIES.split(',')
conf.env.PRIVATE_EXTENSION = Options.options.PRIVATE_EXTENSION
@@ -297,12 +293,8 @@ def configure(conf):
headers='stdio.h',
msg='Checking simple C program')
- # see if we can build shared libs
- if not conf.CHECK_LIBRARY_SUPPORT():
- conf.env.DISABLE_SHARED = True
-
# check for rpath
- if not conf.env.DISABLE_SHARED and conf.CHECK_LIBRARY_SUPPORT(rpath=True):
+ if conf.CHECK_LIBRARY_SUPPORT(rpath=True):
support_rpath = True
conf.env.RPATH_ON_BUILD = not Options.options.disable_rpath_build
conf.env.RPATH_ON_INSTALL = (conf.env.RPATH_ON_BUILD and
@@ -322,8 +314,7 @@ def configure(conf):
# the user can of course always override it.
conf.env.PRIVATELIBDIR = conf.env.LIBDIR
- if (not conf.env.DISABLE_SHARED and
- not Options.options.disable_symbol_versions and
+ if (not Options.options.disable_symbol_versions and
conf.CHECK_LIBRARY_SUPPORT(rpath=support_rpath,
version_script=True,
msg='-Wl,--version-script support')):
@@ -331,7 +322,7 @@ def configure(conf):
else:
conf.env.HAVE_LD_VERSION_SCRIPT = False
- if sys.platform == "aix5":
+ if sys.platform == "aix5" or sys.platform == "aix6":
conf.DEFINE('_ALL_SOURCE', 1, add_to_cflags=True)
# Might not be needed if ALL_SOURCE is defined
# conf.DEFINE('_XOPEN_SOURCE', 600, add_to_cflags=True)
diff --git a/common/check.c b/common/check.c
index 313f55c..9f9d870 100644
--- a/common/check.c
+++ b/common/check.c
@@ -50,11 +50,11 @@ static bool tdb_check_header(struct tdb_context *tdb, tdb_off_t *recovery)
if (hdr.hash_size == 0)
goto corrupt;
- if (hdr.hash_size != tdb->header.hash_size)
+ if (hdr.hash_size != tdb->hash_size)
goto corrupt;
if (hdr.recovery_start != 0 &&
- hdr.recovery_start < TDB_DATA_START(tdb->header.hash_size))
+ hdr.recovery_start < TDB_DATA_START(tdb->hash_size))
goto corrupt;
*recovery = hdr.recovery_start;
@@ -74,21 +74,21 @@ static bool tdb_check_record(struct tdb_context *tdb,
tdb_off_t tailer;
/* Check rec->next: 0 or points to record offset, aligned. */
- if (rec->next > 0 && rec->next < TDB_DATA_START(tdb->header.hash_size)){
+ if (rec->next > 0 && rec->next < TDB_DATA_START(tdb->hash_size)){
TDB_LOG((tdb, TDB_DEBUG_ERROR,
- "Record offset %d too small next %d\n",
+ "Record offset %u too small next %u\n",
off, rec->next));
goto corrupt;
}
if (rec->next + sizeof(*rec) < rec->next) {
TDB_LOG((tdb, TDB_DEBUG_ERROR,
- "Record offset %d too large next %d\n",
+ "Record offset %u too large next %u\n",
off, rec->next));
goto corrupt;
}
if ((rec->next % TDB_ALIGNMENT) != 0) {
TDB_LOG((tdb, TDB_DEBUG_ERROR,
- "Record offset %d misaligned next %d\n",
+ "Record offset %u misaligned next %u\n",
off, rec->next));
goto corrupt;
}
@@ -98,14 +98,14 @@ static bool tdb_check_record(struct tdb_context *tdb,
/* Check rec_len: similar to rec->next, implies next record. */
if ((rec->rec_len % TDB_ALIGNMENT) != 0) {
TDB_LOG((tdb, TDB_DEBUG_ERROR,
- "Record offset %d misaligned length %d\n",
+ "Record offset %u misaligned length %u\n",
off, rec->rec_len));
goto corrupt;
}
/* Must fit tailer. */
if (rec->rec_len < sizeof(tailer)) {
TDB_LOG((tdb, TDB_DEBUG_ERROR,
- "Record offset %d too short length %d\n",
+ "Record offset %u too short length %u\n",
off, rec->rec_len));
goto corrupt;
}
@@ -119,7 +119,7 @@ static bool tdb_check_record(struct tdb_context *tdb,
goto corrupt;
if (tailer != sizeof(*rec) + rec->rec_len) {
TDB_LOG((tdb, TDB_DEBUG_ERROR,
- "Record offset %d invalid tailer\n", off));
+ "Record offset %u invalid tailer\n", off));
goto corrupt;
}
@@ -247,7 +247,7 @@ static bool tdb_check_used_record(struct tdb_context *tdb,
/* key + data + tailer must fit in record */
if (rec->key_len + rec->data_len + sizeof(tdb_off_t) > rec->rec_len) {
TDB_LOG((tdb, TDB_DEBUG_ERROR,
- "Record offset %d too short for contents\n", off));
+ "Record offset %u too short for contents\n", off));
return false;
}
@@ -257,7 +257,7 @@ static bool tdb_check_used_record(struct tdb_context *tdb,
if (tdb->hash_fn(&key) != rec->full_hash) {
TDB_LOG((tdb, TDB_DEBUG_ERROR,
- "Record offset %d has incorrect hash\n", off));
+ "Record offset %u has incorrect hash\n", off));
goto fail_put_key;
}
@@ -352,7 +352,7 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb,
goto unlock;
/* We should have the whole header, too. */
- if (tdb->map_size < TDB_DATA_START(tdb->header.hash_size)) {
+ if (tdb->map_size < TDB_DATA_START(tdb->hash_size)) {
tdb->ecode = TDB_ERR_CORRUPT;
TDB_LOG((tdb, TDB_DEBUG_ERROR, "File too short for hashes\n"));
goto unlock;
@@ -360,20 +360,20 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb,
/* One big malloc: pointers then bit arrays. */
hashes = (unsigned char **)calloc(
- 1, sizeof(hashes[0]) * (1+tdb->header.hash_size)
- + BITMAP_BITS / CHAR_BIT * (1+tdb->header.hash_size));
+ 1, sizeof(hashes[0]) * (1+tdb->hash_size)
+ + BITMAP_BITS / CHAR_BIT * (1+tdb->hash_size));
if (!hashes) {
tdb->ecode = TDB_ERR_OOM;
goto unlock;
}
/* Initialize pointers */
- hashes[0] = (unsigned char *)(&hashes[1+tdb->header.hash_size]);
- for (h = 1; h < 1+tdb->header.hash_size; h++)
+ hashes[0] = (unsigned char *)(&hashes[1+tdb->hash_size]);
+ for (h = 1; h < 1+tdb->hash_size; h++)
hashes[h] = hashes[h-1] + BITMAP_BITS / CHAR_BIT;
/* Freelist and hash headers are all in a row: read them. */
- for (h = 0; h < 1+tdb->header.hash_size; h++) {
+ for (h = 0; h < 1+tdb->hash_size; h++) {
if (tdb_ofs_read(tdb, FREELIST_TOP + h*sizeof(tdb_off_t),
&off) == -1)
goto free;
@@ -382,7 +382,7 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb,
}
/* For each record, read it in and check it's ok. */
- for (off = TDB_DATA_START(tdb->header.hash_size);
+ for (off = TDB_DATA_START(tdb->hash_size);
off < tdb->map_size;
off += sizeof(rec) + rec.rec_len) {
if (tdb->methods->tdb_read(tdb, off, &rec, sizeof(rec),
@@ -411,14 +411,14 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb,
goto corrupt;
TDB_LOG((tdb, TDB_DEBUG_ERROR,
- "Dead space at %d-%d (of %u)\n",
+ "Dead space at %u-%u (of %u)\n",
off, off + dead, tdb->map_size));
rec.rec_len = dead - sizeof(rec);
break;
case TDB_RECOVERY_MAGIC:
if (recovery_start != off) {
TDB_LOG((tdb, TDB_DEBUG_ERROR,
- "Unexpected recovery record at offset %d\n",
+ "Unexpected recovery record at offset %u\n",
off));
goto free;
}
@@ -428,7 +428,7 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb,
corrupt:
tdb->ecode = TDB_ERR_CORRUPT;
TDB_LOG((tdb, TDB_DEBUG_ERROR,
- "Bad magic 0x%x at offset %d\n",
+ "Bad magic 0x%x at offset %u\n",
rec.magic, off));
goto free;
}
@@ -436,7 +436,7 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb,
/* Now, hashes should all be empty: each record exists and is referred
* to by one other. */
- for (h = 0; h < 1+tdb->header.hash_size; h++) {
+ for (h = 0; h < 1+tdb->hash_size; h++) {
unsigned int i;
for (i = 0; i < BITMAP_BITS / CHAR_BIT; i++) {
if (hashes[h][i] != 0) {
diff --git a/common/dump.c b/common/dump.c
index 67de04e..7193c1e 100644
--- a/common/dump.c
+++ b/common/dump.c
@@ -1,4 +1,4 @@
- /*
+ /*
Unix SMB/CIFS implementation.
trivial database library
@@ -33,14 +33,14 @@ static tdb_off_t tdb_dump_record(struct tdb_context *tdb, int hash,
struct tdb_record rec;
tdb_off_t tailer_ofs, tailer;
- if (tdb->methods->tdb_read(tdb, offset, (char *)&rec,
+ if (tdb->methods->tdb_read(tdb, offset, (char *)&rec,
sizeof(rec), DOCONV()) == -1) {
printf("ERROR: failed to read record at %u\n", offset);
return 0;
}
- printf(" rec: hash=%d offset=0x%08x next=0x%08x rec_len=%d "
- "key_len=%d data_len=%d full_hash=0x%x magic=0x%x\n",
+ printf(" rec: hash=%d offset=0x%08x next=0x%08x rec_len=%u "
+ "key_len=%u data_len=%u full_hash=0x%x magic=0x%x\n",
hash, offset, rec.next, rec.rec_len, rec.key_len, rec.data_len,
rec.full_hash, rec.magic);
@@ -83,7 +83,7 @@ static int tdb_dump_chain(struct tdb_context *tdb, int i)
_PUBLIC_ void tdb_dump_all(struct tdb_context *tdb)
{
int i;
- for (i=0;i<tdb->header.hash_size;i++) {
+ for (i=0;i<tdb->hash_size;i++) {
tdb_dump_chain(tdb, i);
}
printf("freelist:\n");
@@ -110,7 +110,7 @@ _PUBLIC_ int tdb_printfreelist(struct tdb_context *tdb)
printf("freelist top=[0x%08x]\n", rec_ptr );
while (rec_ptr) {
- if (tdb->methods->tdb_read(tdb, rec_ptr, (char *)&rec,
+ if (tdb->methods->tdb_read(tdb, rec_ptr, (char *)&rec,
sizeof(rec), DOCONV()) == -1) {
tdb_unlock(tdb, -1, F_WRLCK);
return -1;
@@ -122,15 +122,14 @@ _PUBLIC_ int tdb_printfreelist(struct tdb_context *tdb)
return -1;
}
- printf("entry offset=[0x%08x], rec.rec_len = [0x%08x (%d)] (end = 0x%08x)\n",
+ printf("entry offset=[0x%08x], rec.rec_len = [0x%08x (%u)] (end = 0x%08x)\n",
rec_ptr, rec.rec_len, rec.rec_len, rec_ptr + rec.rec_len);
total_free += rec.rec_len;
/* move to the next record */
rec_ptr = rec.next;
}
- printf("total rec_len = [0x%08x (%d)]\n", (int)total_free,
- (int)total_free);
+ printf("total rec_len = [0x%08lx (%lu)]\n", total_free, total_free);
return tdb_unlock(tdb, -1, F_WRLCK);
}
diff --git a/common/error.c b/common/error.c
index 2aaaa81..478eb88 100644
--- a/common/error.c
+++ b/common/error.c
@@ -1,4 +1,4 @@
- /*
+ /*
Unix SMB/CIFS implementation.
trivial database library
diff --git a/common/freelist.c b/common/freelist.c
index 6358f64..ea14dd0 100644
--- a/common/freelist.c
+++ b/common/freelist.c
@@ -1,4 +1,4 @@
- /*
+ /*
Unix SMB/CIFS implementation.
trivial database library
@@ -28,7 +28,7 @@
#include "tdb_private.h"
/* 'right' merges can involve O(n^2) cost when combined with a
- traverse, so they are disabled until we find a way to do them in
+ traverse, so they are disabled until we find a way to do them in
O(1) time
*/
#define USE_RIGHT_MERGES 0
@@ -42,17 +42,17 @@ int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, struct tdb_record
if (rec->magic == TDB_MAGIC) {
/* this happens when a app is showdown while deleting a record - we should
not completely fail when this happens */
- TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read non-free magic 0x%x at offset=%d - fixing\n",
+ TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read non-free magic 0x%x at offset=%u - fixing\n",
rec->magic, off));
rec->magic = TDB_FREE_MAGIC;
- if (tdb->methods->tdb_write(tdb, off, rec, sizeof(*rec)) == -1)
+ if (tdb_rec_write(tdb, off, rec) == -1)
return -1;
}
if (rec->magic != TDB_FREE_MAGIC) {
/* Ensure ecode is set for log fn. */
tdb->ecode = TDB_ERR_CORRUPT;
- TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read bad magic 0x%x at offset=%d\n",
+ TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read bad magic 0x%x at offset=%u\n",
rec->magic, off));
return -1;
}
@@ -79,7 +79,7 @@ static int remove_from_freelist(struct tdb_context *tdb, tdb_off_t off, tdb_off_
last_ptr = i;
}
tdb->ecode = TDB_ERR_CORRUPT;
- TDB_LOG((tdb, TDB_DEBUG_FATAL,"remove_from_freelist: not on list at off=%d\n", off));
+ TDB_LOG((tdb, TDB_DEBUG_FATAL,"remove_from_freelist: not on list at off=%u\n", off));
return -1;
}
#endif
@@ -139,7 +139,7 @@ left:
#endif
/* Look left */
- if (offset - sizeof(tdb_off_t) > TDB_DATA_START(tdb->header.hash_size)) {
+ if (offset - sizeof(tdb_off_t) > TDB_DATA_START(tdb->hash_size)) {
tdb_off_t left = offset - sizeof(tdb_off_t);
struct tdb_record l;
tdb_off_t leftsize;
@@ -158,7 +158,7 @@ left:
left = offset - leftsize;
if (leftsize > offset ||
- left < TDB_DATA_START(tdb->header.hash_size)) {
+ left < TDB_DATA_START(tdb->hash_size)) {
goto update;
}
@@ -170,7 +170,7 @@ left:
/* If it's free, expand to include it. */
if (l.magic == TDB_FREE_MAGIC) {
- /* we now merge the new record into the left record, rather than the other
+ /* we now merge the new record into the left record, rather than the other
way around. This makes the operation O(1) instead of O(n). This change
prevents traverse from being O(n^2) after a lot of deletes */
l.rec_len += sizeof(*rec) + rec->rec_len;
@@ -195,7 +195,7 @@ update:
if (tdb_ofs_read(tdb, FREELIST_TOP, &rec->next) == -1 ||
tdb_rec_write(tdb, offset, rec) == -1 ||
tdb_ofs_write(tdb, FREELIST_TOP, &offset) == -1) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free record write failed at offset=%d\n", offset));
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free record write failed at offset=%u\n", offset));
goto fail;
}
@@ -210,7 +210,7 @@ update:
-/*
+/*
the core of tdb_allocate - called when we have decided which
free list entry to use
@@ -218,7 +218,7 @@ update:
not the beginning. This is so the left merge in a free is more likely to be
able to free up the record without fragmentation
*/
-static tdb_off_t tdb_allocate_ofs(struct tdb_context *tdb,
+static tdb_off_t tdb_allocate_ofs(struct tdb_context *tdb,
tdb_len_t length, tdb_off_t rec_ptr,
struct tdb_record *rec, tdb_off_t last_ptr)
{
@@ -250,7 +250,7 @@ static tdb_off_t tdb_allocate_ofs(struct tdb_context *tdb,
}
/* and setup the new record */
- rec_ptr += sizeof(*rec) + rec->rec_len;
+ rec_ptr += sizeof(*rec) + rec->rec_len;
memset(rec, '\0', sizeof(*rec));
rec->rec_len = length;
@@ -303,7 +303,7 @@ tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct tdb_rec
bestfit.last_ptr = 0;
bestfit.rec_len = 0;
- /*
+ /*
this is a best fit allocation strategy. Originally we used
a first fit strategy, but it suffered from massive fragmentation
issues when faced with a slowly increasing record size.
@@ -347,7 +347,7 @@ tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct tdb_rec
goto fail;
}
- newrec_ptr = tdb_allocate_ofs(tdb, length, bestfit.rec_ptr,
+ newrec_ptr = tdb_allocate_ofs(tdb, length, bestfit.rec_ptr,
rec, bestfit.last_ptr);
tdb_unlock(tdb, -1, F_WRLCK);
return newrec_ptr;
@@ -364,8 +364,8 @@ tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct tdb_rec
-/*
- return the size of the freelist - used to decide if we should repack
+/*
+ return the size of the freelist - used to decide if we should repack
*/
_PUBLIC_ int tdb_freelist_size(struct tdb_context *tdb)
{
diff --git a/common/freelistcheck.c b/common/freelistcheck.c
index ab6e78f..c6bfeaa 100644
--- a/common/freelistcheck.c
+++ b/common/freelistcheck.c
@@ -35,12 +35,11 @@
static int seen_insert(struct tdb_context *mem_tdb, tdb_off_t rec_ptr)
{
- TDB_DATA key, data;
+ TDB_DATA key;
- memset(&data, '\0', sizeof(data));
key.dptr = (unsigned char *)&rec_ptr;
key.dsize = sizeof(rec_ptr);
- return tdb_store(mem_tdb, key, data, TDB_INSERT);
+ return tdb_store(mem_tdb, key, tdb_null, TDB_INSERT);
}
_PUBLIC_ int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries)
@@ -52,7 +51,7 @@ _PUBLIC_ int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries)
*pnum_entries = 0;
- mem_tdb = tdb_open("flval", tdb->header.hash_size,
+ mem_tdb = tdb_open("flval", tdb->hash_size,
TDB_INTERNAL, O_RDWR, 0600);
if (!mem_tdb) {
return -1;
diff --git a/common/io.c b/common/io.c
index 25968bf..11dfefd 100644
--- a/common/io.c
+++ b/common/io.c
@@ -1,4 +1,4 @@
- /*
+ /*
Unix SMB/CIFS implementation.
trivial database library
@@ -30,7 +30,7 @@
/* check for an out of bounds access - if it is out of bounds then
see if the database has been expanded by someone else and expand
- if necessary
+ if necessary
*/
static int tdb_oob(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len,
int probe)
@@ -40,8 +40,8 @@ static int tdb_oob(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len,
if (!probe) {
/* Ensure ecode is set for log fn. */
tdb->ecode = TDB_ERR_IO;
- TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_oob off %d len %d wrap\n",
- (int)off, (int)len));
+ TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_oob off %u len %u wrap\n",
+ off, len));
}
return -1;
}
@@ -84,7 +84,7 @@ static int tdb_oob(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len,
}
tdb->map_size = st.st_size;
if (tdb_mmap(tdb) != 0) {
- return - 1;
+ return -1;
}
if (st.st_size < (size_t)off + len) {
@@ -100,7 +100,7 @@ static int tdb_oob(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len,
}
/* write a lump of data at a specified offset */
-static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
+static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
const void *buf, tdb_len_t len)
{
if (len == 0) {
@@ -127,8 +127,8 @@ static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
/* try once more */
tdb->ecode = TDB_ERR_IO;
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: wrote only "
- "%d of %d bytes at %d, trying once more\n",
- (int)written, len, off));
+ "%zi of %u bytes at %u, trying once more\n",
+ written, len, off));
written = pwrite(tdb->fd, (const char *)buf+written,
len-written,
off+written);
@@ -136,13 +136,13 @@ static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
if (written == -1) {
/* Ensure ecode is set for log fn. */
tdb->ecode = TDB_ERR_IO;
- TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %d "
- "len=%d (%s)\n", off, len, strerror(errno)));
+ TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %u "
+ "len=%u (%s)\n", off, len, strerror(errno)));
return -1;
} else if (written != (ssize_t)len) {
tdb->ecode = TDB_ERR_IO;
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: failed to "
- "write %d bytes at %d in two attempts\n",
+ "write %u bytes at %u in two attempts\n",
len, off));
return -1;
}
@@ -162,7 +162,7 @@ void *tdb_convert(void *buf, uint32_t size)
/* read a lump of data at a specified offset, maybe convert */
-static int tdb_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
+static int tdb_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
tdb_len_t len, int cv)
{
if (tdb->methods->tdb_oob(tdb, off, len, 0) != 0) {
@@ -180,10 +180,10 @@ static int tdb_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
if (ret != (ssize_t)len) {
/* Ensure ecode is set for log fn. */
tdb->ecode = TDB_ERR_IO;
- TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_read failed at %d "
- "len=%d ret=%d (%s) map_size=%d\n",
- (int)off, (int)len, (int)ret, strerror(errno),
- (int)tdb->map_size));
+ TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_read failed at %u "
+ "len=%u ret=%zi (%s) map_size=%u\n",
+ off, len, ret, strerror(errno),
+ tdb->map_size));
return -1;
}
#endif
@@ -199,19 +199,19 @@ static int tdb_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
/*
do an unlocked scan of the hash table heads to find the next non-zero head. The value
will then be confirmed with the lock held
-*/
+*/
static void tdb_next_hash_chain(struct tdb_context *tdb, uint32_t *chain)
{
uint32_t h = *chain;
if (tdb->map_ptr) {
- for (;h < tdb->header.hash_size;h++) {
+ for (;h < tdb->hash_size;h++) {
if (0 != *(uint32_t *)(TDB_HASH_TOP(h) + (unsigned char *)tdb->map_ptr)) {
break;
}
}
} else {
uint32_t off=0;
- for (;h < tdb->header.hash_size;h++) {
+ for (;h < tdb->hash_size;h++) {
if (tdb_ofs_read(tdb, TDB_HASH_TOP(h), &off) != 0 || off != 0) {
break;
}
@@ -256,8 +256,8 @@ int tdb_mmap(struct tdb_context *tdb)
#ifdef HAVE_MMAP
if (should_mmap(tdb)) {
- tdb->map_ptr = mmap(NULL, tdb->map_size,
- PROT_READ|(tdb->read_only? 0:PROT_WRITE),
+ tdb->map_ptr = mmap(NULL, tdb->map_size,
+ PROT_READ|(tdb->read_only? 0:PROT_WRITE),
MAP_SHARED|MAP_FILE, tdb->fd, 0);
/*
@@ -266,7 +266,7 @@ int tdb_mmap(struct tdb_context *tdb)
if (tdb->map_ptr == MAP_FAILED) {
tdb->map_ptr = NULL;
- TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_mmap failed for size %d (%s)\n",
+ TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_mmap failed for size %u (%s)\n",
tdb->map_size, strerror(errno)));
#ifdef HAVE_INCOHERENT_MMAP
tdb->ecode = TDB_ERR_IO;
@@ -287,26 +287,37 @@ int tdb_mmap(struct tdb_context *tdb)
static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t addition)
{
char buf[8192];
+ tdb_off_t new_size;
if (tdb->read_only || tdb->traverse_read) {
tdb->ecode = TDB_ERR_RDONLY;
return -1;
}
- if (ftruncate(tdb->fd, size+addition) == -1) {
+ if (!tdb_add_off_t(size, addition, &new_size)) {
+ tdb->ecode = TDB_ERR_OOM;
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write "
+ "overflow detected current size[%u] addition[%u]!\n",
+ (unsigned)size, (unsigned)addition));
+ errno = ENOSPC;
+ return -1;
+ }
+
+ if (ftruncate(tdb->fd, new_size) == -1) {
char b = 0;
- ssize_t written = pwrite(tdb->fd, &b, 1, (size+addition) - 1);
+ ssize_t written = pwrite(tdb->fd, &b, 1, new_size - 1);
if (written == 0) {
/* try once more, potentially revealing errno */
- written = pwrite(tdb->fd, &b, 1, (size+addition) - 1);
+ written = pwrite(tdb->fd, &b, 1, new_size - 1);
}
if (written == 0) {
/* again - give up, guessing errno */
errno = ENOSPC;
}
if (written != 1) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file to %d failed (%s)\n",
- size+addition, strerror(errno)));
+ tdb->ecode = TDB_ERR_OOM;
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file to %u failed (%s)\n",
+ (unsigned)new_size, strerror(errno)));
return -1;
}
}
@@ -324,19 +335,23 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad
}
if (written == 0) {
/* give up, trying to provide a useful errno */
+ tdb->ecode = TDB_ERR_OOM;
TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write "
"returned 0 twice: giving up!\n"));
errno = ENOSPC;
return -1;
- } else if (written == -1) {
+ }
+ if (written == -1) {
+ tdb->ecode = TDB_ERR_OOM;
TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write of "
- "%d bytes failed (%s)\n", (int)n,
+ "%u bytes failed (%s)\n", (int)n,
strerror(errno)));
return -1;
- } else if (written != n) {
+ }
+ if (written != n) {
TDB_LOG((tdb, TDB_DEBUG_WARNING, "expand_file: wrote "
- "only %d of %d bytes - retrying\n", (int)written,
- (int)n));
+ "only %zu of %zi bytes - retrying\n", written,
+ n));
}
addition -= written;
size += written;
@@ -348,14 +363,32 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad
/* You need 'size', this tells you how much you should expand by. */
tdb_off_t tdb_expand_adjust(tdb_off_t map_size, tdb_off_t size, int page_size)
{
- tdb_off_t new_size, top_size;
+ tdb_off_t new_size, top_size, increment;
+ tdb_off_t max_size = UINT32_MAX - map_size;
+
+ if (size > max_size) {
+ /*
+ * We can't round up anymore, just give back
+ * what we're asked for.
+ *
+ * The caller has to take care of the ENOSPC handling.
+ */
+ return size;
+ }
/* limit size in order to avoid using up huge amounts of memory for
* in memory tdbs if an oddball huge record creeps in */
if (size > 100 * 1024) {
- top_size = map_size + size * 2;
+ increment = size * 2;
} else {
- top_size = map_size + size * 100;
+ increment = size * 100;
+ }
+ if (increment < size) {
+ goto overflow;
+ }
+
+ if (!tdb_add_off_t(map_size, increment, &top_size)) {
+ goto overflow;
}
/* always make room for at least top_size more records, and at
@@ -366,10 +399,26 @@ tdb_off_t tdb_expand_adjust(tdb_off_t map_size, tdb_off_t size, int page_size)
} else {
new_size = map_size * 1.25;
}
+ if (new_size < map_size) {
+ goto overflow;
+ }
/* Round the database up to a multiple of the page size */
new_size = MAX(top_size, new_size);
+
+ if (new_size + page_size < new_size) {
+ /* There's a "+" in TDB_ALIGN that might overflow... */
+ goto overflow;
+ }
+
return TDB_ALIGN(new_size, page_size) - map_size;
+
+overflow:
+ /*
+ * Somewhere in between we went over 4GB. Make one big jump to
+ * exactly 4GB database size.
+ */
+ return max_size;
}
/* expand the database at least size bytes by expanding the underlying
@@ -378,6 +427,7 @@ int tdb_expand(struct tdb_context *tdb, tdb_off_t size)
{
struct tdb_record rec;
tdb_off_t offset;
+ tdb_off_t new_size;
if (tdb_lock(tdb, -1, F_WRLCK) == -1) {
TDB_LOG((tdb, TDB_DEBUG_ERROR, "lock failed in tdb_expand\n"));
@@ -389,10 +439,12 @@ int tdb_expand(struct tdb_context *tdb, tdb_off_t size)
size = tdb_expand_adjust(tdb->map_size, size, tdb->page_size);
- /* expand the file itself */
- if (!(tdb->flags & TDB_INTERNAL)) {
- if (tdb->methods->tdb_expand_file(tdb, tdb->map_size, size) != 0)
- goto fail;
+ if (!tdb_add_off_t(tdb->map_size, size, &new_size)) {
+ tdb->ecode = TDB_ERR_OOM;
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_expand "
+ "overflow detected current map_size[%u] size[%u]!\n",
+ (unsigned)tdb->map_size, (unsigned)size));
+ goto fail;
}
/* form a new freelist record */
@@ -401,18 +453,30 @@ int tdb_expand(struct tdb_context *tdb, tdb_off_t size)
rec.rec_len = size - sizeof(rec);
if (tdb->flags & TDB_INTERNAL) {
- char *new_map_ptr = (char *)realloc(tdb->map_ptr,
- tdb->map_size + size);
+ char *new_map_ptr;
+
+ new_map_ptr = (char *)realloc(tdb->map_ptr, new_size);
if (!new_map_ptr) {
+ tdb->ecode = TDB_ERR_OOM;
goto fail;
}
tdb->map_ptr = new_map_ptr;
- tdb->map_size += size;
+ tdb->map_size = new_size;
} else {
+ int ret;
+
+ /*
+ * expand the file itself
+ */
+ ret = tdb->methods->tdb_expand_file(tdb, tdb->map_size, size);
+ if (ret != 0) {
+ goto fail;
+ }
+
/* Explicitly remap: if we're in a transaction, this won't
* happen automatically! */
tdb_munmap(tdb);
- tdb->map_size += size;
+ tdb->map_size = new_size;
if (tdb_mmap(tdb) != 0) {
goto fail;
}
@@ -452,7 +516,7 @@ unsigned char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len
if (!(buf = (unsigned char *)malloc(len ? len : 1))) {
/* Ensure ecode is set for log fn. */
tdb->ecode = TDB_ERR_OOM;
- TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_alloc_read malloc failed len=%d (%s)\n",
+ TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_alloc_read malloc failed len=%u (%s)\n",
len, strerror(errno)));
return NULL;
}
@@ -505,7 +569,7 @@ int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *r
if (TDB_BAD_MAGIC(rec)) {
/* Ensure ecode is set for log fn. */
tdb->ecode = TDB_ERR_CORRUPT;
- TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_rec_read bad magic 0x%x at offset=%d\n", rec->magic, offset));
+ TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_rec_read bad magic 0x%x at offset=%u\n", rec->magic, offset));
return -1;
}
return tdb->methods->tdb_oob(tdb, rec->next, sizeof(*rec), 0);
diff --git a/common/lock.c b/common/lock.c
index 260fab6..4dfefd5 100644
--- a/common/lock.c
+++ b/common/lock.c
@@ -1,4 +1,4 @@
- /*
+ /*
Unix SMB/CIFS implementation.
trivial database library
@@ -36,6 +36,7 @@ static int fcntl_lock(struct tdb_context *tdb,
int rw, off_t off, off_t len, bool waitflag)
{
struct flock fl;
+ int cmd;
fl.l_type = rw;
fl.l_whence = SEEK_SET;
@@ -43,10 +44,9 @@ static int fcntl_lock(struct tdb_context *tdb,
fl.l_len = len;
fl.l_pid = 0;
- if (waitflag)
- return fcntl(tdb->fd, F_SETLKW, &fl);
- else
- return fcntl(tdb->fd, F_SETLK, &fl);
+ cmd = waitflag ? F_SETLKW : F_SETLK;
+
+ return fcntl(tdb->fd, cmd, &fl);
}
static int fcntl_unlock(struct tdb_context *tdb, int rw, off_t off, off_t len)
@@ -126,10 +126,10 @@ static tdb_off_t lock_offset(int list)
}
/* a byte range locking function - return 0 on success
- this functions locks/unlocks 1 byte at the specified offset.
+ this functions locks/unlocks "len" byte at the specified offset.
On error, errno is also set so that errors are passed back properly
- through tdb_open().
+ through tdb_open().
note that a len of zero means lock to end of file
*/
@@ -169,8 +169,8 @@ int tdb_brlock(struct tdb_context *tdb,
* EAGAIN is an expected return from non-blocking
* locks. */
if (!(flags & TDB_LOCK_PROBE) && errno != EAGAIN) {
- TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d flags=%d len=%d\n",
- tdb->fd, offset, rw_type, flags, (int)len));
+ TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brlock failed (fd=%d) at offset %u rw_type=%d flags=%d len=%zu\n",
+ tdb->fd, offset, rw_type, flags, len));
}
return -1;
}
@@ -191,21 +191,49 @@ int tdb_brunlock(struct tdb_context *tdb,
} while (ret == -1 && errno == EINTR);
if (ret == -1) {
- TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brunlock failed (fd=%d) at offset %d rw_type=%d len=%d\n",
- tdb->fd, offset, rw_type, (int)len));
+ TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brunlock failed (fd=%d) at offset %u rw_type=%u len=%zu\n",
+ tdb->fd, offset, rw_type, len));
}
return ret;
}
/*
- upgrade a read lock to a write lock. This needs to be handled in a
- special way as some OSes (such as solaris) have too conservative
- deadlock detection and claim a deadlock when progress can be
- made. For those OSes we may loop for a while.
+ * Do a tdb_brlock in a loop. Some OSes (such as solaris) have too
+ * conservative deadlock detection and claim a deadlock when progress can be
+ * made. For those OSes we may loop for a while.
+ */
+
+static int tdb_brlock_retry(struct tdb_context *tdb,
+ int rw_type, tdb_off_t offset, size_t len,
+ enum tdb_lock_flags flags)
+{
+ int count = 1000;
+
+ while (count--) {
+ struct timeval tv;
+ int ret;
+
+ ret = tdb_brlock(tdb, rw_type, offset, len, flags);
+ if (ret == 0) {
+ return 0;
+ }
+ if (errno != EDEADLK) {
+ break;
+ }
+ /* sleep for as short a time as we can - more portable than usleep() */
+ tv.tv_sec = 0;
+ tv.tv_usec = 1;
+ select(0, NULL, NULL, NULL, &tv);
+ }
+ return -1;
+}
+
+/*
+ upgrade a read lock to a write lock.
*/
int tdb_allrecord_upgrade(struct tdb_context *tdb)
{
- int count = 1000;
+ int ret;
if (tdb->allrecord_lock.count != 1) {
TDB_LOG((tdb, TDB_DEBUG_ERROR,
@@ -220,21 +248,12 @@ int tdb_allrecord_upgrade(struct tdb_context *tdb)
return -1;
}
- while (count--) {
- struct timeval tv;
- if (tdb_brlock(tdb, F_WRLCK, FREELIST_TOP, 0,
- TDB_LOCK_WAIT|TDB_LOCK_PROBE) == 0) {
- tdb->allrecord_lock.ltype = F_WRLCK;
- tdb->allrecord_lock.off = 0;
- return 0;
- }
- if (errno != EDEADLK) {
- break;
- }
- /* sleep for as short a time as we can - more portable than usleep() */
- tv.tv_sec = 0;
- tv.tv_usec = 1;
- select(0, NULL, NULL, NULL, &tv);
+ ret = tdb_brlock_retry(tdb, F_WRLCK, FREELIST_TOP, 0,
+ TDB_LOCK_WAIT|TDB_LOCK_PROBE);
+ if (ret == 0) {
+ tdb->allrecord_lock.ltype = F_WRLCK;
+ tdb->allrecord_lock.off = 0;
+ return 0;
}
TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_allrecord_upgrade failed\n"));
return -1;
@@ -259,7 +278,7 @@ int tdb_nest_lock(struct tdb_context *tdb, uint32_t offset, int ltype,
{
struct tdb_lock_type *new_lck;
- if (offset >= lock_offset(tdb->header.hash_size)) {
+ if (offset >= lock_offset(tdb->hash_size)) {
tdb->ecode = TDB_ERR_LOCK;
TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_lock: invalid offset %u for ltype=%d\n",
offset, ltype));
@@ -334,34 +353,60 @@ static bool have_data_locks(const struct tdb_context *tdb)
return false;
}
+/*
+ * A allrecord lock allows us to avoid per chain locks. Check if the allrecord
+ * lock is strong enough.
+ */
+static int tdb_lock_covered_by_allrecord_lock(struct tdb_context *tdb,
+ int ltype)
+{
+ if (ltype == F_RDLCK) {
+ /*
+ * The allrecord_lock is equal (F_RDLCK) or stronger
+ * (F_WRLCK). Pass.
+ */
+ return 0;
+ }
+
+ if (tdb->allrecord_lock.ltype == F_RDLCK) {
+ /*
+ * We ask for ltype==F_WRLCK, but the allrecord_lock
+ * is too weak. We can't upgrade here, so fail.
+ */
+ tdb->ecode = TDB_ERR_LOCK;
+ return -1;
+ }
+
+ /*
+ * Asking for F_WRLCK, allrecord is F_WRLCK as well. Pass.
+ */
+ return 0;
+}
+
static int tdb_lock_list(struct tdb_context *tdb, int list, int ltype,
enum tdb_lock_flags waitflag)
{
int ret;
bool check = false;
- /* a allrecord lock allows us to avoid per chain locks */
- if (tdb->allrecord_lock.count &&
- (ltype == tdb->allrecord_lock.ltype || ltype == F_RDLCK)) {
- return 0;
+ if (tdb->allrecord_lock.count) {
+ return tdb_lock_covered_by_allrecord_lock(tdb, ltype);
}
- if (tdb->allrecord_lock.count) {
- tdb->ecode = TDB_ERR_LOCK;
- ret = -1;
- } else {
- /* Only check when we grab first data lock. */
- check = !have_data_locks(tdb);
- ret = tdb_nest_lock(tdb, lock_offset(list), ltype, waitflag);
+ /*
+ * Check for recoveries: Someone might have kill -9'ed a process
+ * during a commit.
+ */
+ check = !have_data_locks(tdb);
+ ret = tdb_nest_lock(tdb, lock_offset(list), ltype, waitflag);
- if (ret == 0 && check && tdb_needs_recovery(tdb)) {
- tdb_nest_unlock(tdb, lock_offset(list), ltype, false);
+ if (ret == 0 && check && tdb_needs_recovery(tdb)) {
+ tdb_nest_unlock(tdb, lock_offset(list), ltype, false);
- if (tdb_lock_and_recover(tdb) == -1) {
- return -1;
- }
- return tdb_lock_list(tdb, list, ltype, waitflag);
+ if (tdb_lock_and_recover(tdb) == -1) {
+ return -1;
}
+ return tdb_lock_list(tdb, list, ltype, waitflag);
}
return ret;
}
@@ -396,8 +441,8 @@ int tdb_nest_unlock(struct tdb_context *tdb, uint32_t offset, int ltype,
return 0;
/* Sanity checks */
- if (offset >= lock_offset(tdb->header.hash_size)) {
- TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: offset %u invalid (%d)\n", offset, tdb->header.hash_size));
+ if (offset >= lock_offset(tdb->hash_size)) {
+ TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: offset %u invalid (%d)\n", offset, tdb->hash_size));
return ret;
}
@@ -441,21 +486,15 @@ int tdb_nest_unlock(struct tdb_context *tdb, uint32_t offset, int ltype,
}
if (ret)
- TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: An error occurred unlocking!\n"));
+ TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: An error occurred unlocking!\n"));
return ret;
}
_PUBLIC_ int tdb_unlock(struct tdb_context *tdb, int list, int ltype)
{
/* a global lock allows us to avoid per chain locks */
- if (tdb->allrecord_lock.count &&
- (ltype == tdb->allrecord_lock.ltype || ltype == F_RDLCK)) {
- return 0;
- }
-
if (tdb->allrecord_lock.count) {
- tdb->ecode = TDB_ERR_LOCK;
- return -1;
+ return tdb_lock_covered_by_allrecord_lock(tdb, ltype);
}
return tdb_nest_unlock(tdb, lock_offset(list), ltype, false);
@@ -568,15 +607,15 @@ int tdb_allrecord_lock(struct tdb_context *tdb, int ltype,
* It is (1) which cause the starvation problem, so we're only
* gradual for that. */
if (tdb_chainlock_gradual(tdb, ltype, flags, FREELIST_TOP,
- tdb->header.hash_size * 4) == -1) {
+ tdb->hash_size * 4) == -1) {
return -1;
}
/* Grab individual record locks. */
- if (tdb_brlock(tdb, ltype, lock_offset(tdb->header.hash_size), 0,
+ if (tdb_brlock(tdb, ltype, lock_offset(tdb->hash_size), 0,
flags) == -1) {
tdb_brunlock(tdb, ltype, FREELIST_TOP,
- tdb->header.hash_size * 4);
+ tdb->hash_size * 4);
return -1;
}
@@ -840,7 +879,7 @@ void tdb_release_transaction_locks(struct tdb_context *tdb)
unsigned int i, active = 0;
if (tdb->allrecord_lock.count != 0) {
- tdb_brunlock(tdb, tdb->allrecord_lock.ltype, FREELIST_TOP, 0);
+ tdb_allrecord_unlock(tdb, tdb->allrecord_lock.ltype, false);
tdb->allrecord_lock.count = 0;
}
@@ -863,12 +902,14 @@ void tdb_release_transaction_locks(struct tdb_context *tdb)
/* Following functions are added specifically to support CTDB. */
/* Don't do actual fcntl locking, just mark tdb locked */
+int tdb_transaction_write_lock_mark(struct tdb_context *tdb);
_PUBLIC_ int tdb_transaction_write_lock_mark(struct tdb_context *tdb)
{
return tdb_transaction_lock(tdb, F_WRLCK, TDB_LOCK_MARK_ONLY);
}
/* Don't do actual fcntl unlocking, just mark tdb unlocked */
+int tdb_transaction_write_lock_unmark(struct tdb_context *tdb);
_PUBLIC_ int tdb_transaction_write_lock_unmark(struct tdb_context *tdb)
{
return tdb_nest_unlock(tdb, TRANSACTION_LOCK, F_WRLCK, true);
diff --git a/common/open.c b/common/open.c
index d9f76f0..05d7cae 100644
--- a/common/open.c
+++ b/common/open.c
@@ -1,4 +1,4 @@
- /*
+ /*
Unix SMB/CIFS implementation.
trivial database library
@@ -51,7 +51,8 @@ void tdb_header_hash(struct tdb_context *tdb,
}
/* initialise a new database with a specified hash size */
-static int tdb_new_database(struct tdb_context *tdb, int hash_size)
+static int tdb_new_database(struct tdb_context *tdb, struct tdb_header *header,
+ int hash_size)
{
struct tdb_header *newdb;
size_t size;
@@ -78,7 +79,7 @@ static int tdb_new_database(struct tdb_context *tdb, int hash_size)
if (tdb->flags & TDB_INTERNAL) {
tdb->map_size = size;
tdb->map_ptr = (char *)newdb;
- memcpy(&tdb->header, newdb, sizeof(tdb->header));
+ memcpy(header, newdb, sizeof(*header));
/* Convert the `ondisk' version if asked. */
CONVERT(*newdb);
return 0;
@@ -91,13 +92,14 @@ static int tdb_new_database(struct tdb_context *tdb, int hash_size)
/* This creates an endian-converted header, as if read from disk */
CONVERT(*newdb);
- memcpy(&tdb->header, newdb, sizeof(tdb->header));
+ memcpy(header, newdb, sizeof(*header));
/* Don't endian-convert the magic food! */
memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1);
- /* we still have "ret == -1" here */
- if (tdb_write_all(tdb->fd, newdb, size))
- ret = 0;
+ if (!tdb_write_all(tdb->fd, newdb, size))
+ goto fail;
+
+ ret = 0;
fail:
SAFE_FREE(newdb);
return ret;
@@ -119,13 +121,13 @@ static int tdb_already_open(dev_t device,
return 0;
}
-/* open the database, creating it if necessary
+/* open the database, creating it if necessary
The open_flags and mode are passed straight to the open call on the
database file. A flags value of O_WRONLY is invalid. The hash size
is advisory, use zero for a default value.
- Return is NULL on error, in which case errno is also set. Don't
+ Return is NULL on error, in which case errno is also set. Don't
try to call tdb_error or tdb_errname, just do strerror(errno).
@param name may be NULL for internal databases. */
@@ -142,11 +144,12 @@ static void null_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, con
}
static bool check_header_hash(struct tdb_context *tdb,
+ struct tdb_header *header,
bool default_hash, uint32_t *m1, uint32_t *m2)
{
tdb_header_hash(tdb, m1, m2);
- if (tdb->header.magic1_hash == *m1 &&
- tdb->header.magic2_hash == *m2) {
+ if (header->magic1_hash == *m1 &&
+ header->magic2_hash == *m2) {
return true;
}
@@ -159,7 +162,7 @@ static bool check_header_hash(struct tdb_context *tdb,
tdb->hash_fn = tdb_jenkins_hash;
else
tdb->hash_fn = tdb_old_hash;
- return check_header_hash(tdb, false, m1, m2);
+ return check_header_hash(tdb, header, false, m1, m2);
}
_PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
@@ -167,6 +170,7 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
const struct tdb_logging_context *log_ctx,
tdb_hash_func hash_fn)
{
+ struct tdb_header header;
struct tdb_context *tdb;
struct stat st;
int rev = 0, locked = 0;
@@ -176,6 +180,8 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
const char *hash_alg;
uint32_t magic1, magic2;
+ ZERO_STRUCT(header);
+
if (!(tdb = (struct tdb_context *)calloc(1, sizeof *tdb))) {
/* Can't log this */
errno = ENOMEM;
@@ -209,7 +215,7 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
goto fail;
}
- /* now make a copy of the name, as the caller memory might went away */
+ /* now make a copy of the name, as the caller memory might go away */
if (!(tdb->name = (char *)strdup(name))) {
/*
* set the name as the given string, so that tdb_name() will
@@ -285,10 +291,11 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
if (tdb->flags & TDB_INTERNAL) {
tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP);
tdb->flags &= ~TDB_CLEAR_IF_FIRST;
- if (tdb_new_database(tdb, hash_size) != 0) {
+ if (tdb_new_database(tdb, &header, hash_size) != 0) {
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: tdb_new_database failed!"));
goto fail;
}
+ tdb->hash_size = hash_size;
goto internal;
}
@@ -322,7 +329,7 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
name, strerror(errno)));
goto fail;
}
- ret = tdb_new_database(tdb, hash_size);
+ ret = tdb_new_database(tdb, &header, hash_size);
if (ret == -1) {
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
"tdb_new_database failed for %s: %s\n",
@@ -347,22 +354,23 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
}
errno = 0;
- if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header)
- || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0) {
- if (!(open_flags & O_CREAT) || tdb_new_database(tdb, hash_size) == -1) {
+ if (read(tdb->fd, &header, sizeof(header)) != sizeof(header)
+ || strcmp(header.magic_food, TDB_MAGIC_FOOD) != 0) {
+ if (!(open_flags & O_CREAT) ||
+ tdb_new_database(tdb, &header, hash_size) == -1) {
if (errno == 0) {
errno = EIO; /* ie bad format or something */
}
goto fail;
}
rev = (tdb->flags & TDB_CONVERT);
- } else if (tdb->header.version != TDB_VERSION
- && !(rev = (tdb->header.version==TDB_BYTEREV(TDB_VERSION)))) {
+ } else if (header.version != TDB_VERSION
+ && !(rev = (header.version==TDB_BYTEREV(TDB_VERSION)))) {
/* wrong version */
errno = EIO;
goto fail;
}
- vp = (unsigned char *)&tdb->header.version;
+ vp = (unsigned char *)&header.version;
vertest = (((uint32_t)vp[0]) << 24) | (((uint32_t)vp[1]) << 16) |
(((uint32_t)vp[2]) << 8) | (uint32_t)vp[3];
tdb->flags |= (vertest==TDB_VERSION) ? TDB_BIGENDIAN : 0;
@@ -370,31 +378,33 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
tdb->flags &= ~TDB_CONVERT;
else {
tdb->flags |= TDB_CONVERT;
- tdb_convert(&tdb->header, sizeof(tdb->header));
+ tdb_convert(&header, sizeof(header));
}
if (fstat(tdb->fd, &st) == -1)
goto fail;
- if (tdb->header.rwlocks != 0 &&
- tdb->header.rwlocks != TDB_HASH_RWLOCK_MAGIC) {
+ if (header.rwlocks != 0 &&
+ header.rwlocks != TDB_HASH_RWLOCK_MAGIC) {
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: spinlocks no longer supported\n"));
goto fail;
}
+ tdb->hash_size = header.hash_size;
- if ((tdb->header.magic1_hash == 0) && (tdb->header.magic2_hash == 0)) {
+ if ((header.magic1_hash == 0) && (header.magic2_hash == 0)) {
/* older TDB without magic hash references */
tdb->hash_fn = tdb_old_hash;
- } else if (!check_header_hash(tdb, !hash_fn, &magic1, &magic2)) {
+ } else if (!check_header_hash(tdb, &header, !hash_fn,
+ &magic1, &magic2)) {
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
"%s was not created with %s hash function we are using\n"
"magic1_hash[0x%08X %s 0x%08X] "
"magic2_hash[0x%08X %s 0x%08X]\n",
name, hash_alg,
- tdb->header.magic1_hash,
- (tdb->header.magic1_hash == magic1) ? "==" : "!=",
+ header.magic1_hash,
+ (header.magic1_hash == magic1) ? "==" : "!=",
magic1,
- tdb->header.magic2_hash,
- (tdb->header.magic2_hash == magic2) ? "==" : "!=",
+ header.magic2_hash,
+ (header.magic2_hash == magic2) ? "==" : "!=",
magic2));
errno = EINVAL;
goto fail;
diff --git a/common/rescue.c b/common/rescue.c
index 03ae8d6..17e7ed8 100644
--- a/common/rescue.c
+++ b/common/rescue.c
@@ -57,7 +57,7 @@ static bool looks_like_valid_record(struct tdb_context *tdb,
return false;
/* Next pointer must make some sense. */
- if (rec->next > 0 && rec->next < TDB_DATA_START(tdb->header.hash_size))
+ if (rec->next > 0 && rec->next < TDB_DATA_START(tdb->hash_size))
return false;
if (tdb->methods->tdb_oob(tdb, rec->next, sizeof(*rec), 1))
@@ -234,7 +234,7 @@ _PUBLIC_ int tdb_rescue(struct tdb_context *tdb,
tdb->log.log_fn = logging_suppressed;
/* Now walk entire db looking for records. */
- for (off = TDB_DATA_START(tdb->header.hash_size);
+ for (off = TDB_DATA_START(tdb->hash_size);
off < tdb->map_size;
off += TDB_ALIGNMENT) {
if (tdb->methods->tdb_read(tdb, off, &rec, sizeof(rec),
@@ -249,7 +249,7 @@ _PUBLIC_ int tdb_rescue(struct tdb_context *tdb,
}
/* Walk hash chains to positive vet. */
- for (h = 0; h < 1+tdb->header.hash_size; h++) {
+ for (h = 0; h < 1+tdb->hash_size; h++) {
bool slow_chase = false;
tdb_off_t slow_off = FREELIST_TOP + h*sizeof(tdb_off_t);
diff --git a/common/summary.c b/common/summary.c
index 171a1a2..3c6f755 100644
--- a/common/summary.c
+++ b/common/summary.c
@@ -1,7 +1,7 @@
- /*
+ /*
Trivial Database: human-readable summary code
Copyright (C) Rusty Russell 2010
-
+
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
@@ -20,6 +20,7 @@
#define SUMMARY_FORMAT \
"Size of file/data: %u/%zu\n" \
"Number of records: %zu\n" \
+ "Incompatible hash: %s\n" \
"Smallest/average/largest keys: %zu/%zu/%zu\n" \
"Smallest/average/largest data: %zu/%zu/%zu\n" \
"Smallest/average/largest padding: %zu/%zu/%zu\n" \
@@ -116,7 +117,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
tally_init(&hash);
tally_init(&uncoal);
- for (off = TDB_DATA_START(tdb->header.hash_size);
+ for (off = TDB_DATA_START(tdb->hash_size);
off < tdb->map_size - 1;
off += sizeof(rec) + rec.rec_len) {
if (tdb->methods->tdb_read(tdb, off, &rec, sizeof(rec),
@@ -151,7 +152,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
break;
default:
TDB_LOG((tdb, TDB_DEBUG_ERROR,
- "Unexpected record magic 0x%x at offset %d\n",
+ "Unexpected record magic 0x%x at offset %u\n",
rec.magic, off));
goto unlock;
}
@@ -159,7 +160,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
if (unc > 1)
tally_add(&uncoal, unc - 1);
- for (off = 0; off < tdb->header.hash_size; off++)
+ for (off = 0; off < tdb->hash_size; off++)
tally_add(&hash, get_hash_length(tdb, off));
/* 20 is max length of a %zu. */
@@ -171,6 +172,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
snprintf(ret, len, SUMMARY_FORMAT,
tdb->map_size, keys.total+data.total,
keys.num,
+ (tdb->hash_fn == tdb_jenkins_hash)?"yes":"no",
keys.min, tally_mean(&keys), keys.max,
data.min, tally_mean(&data), data.max,
extra.min, tally_mean(&extra), extra.max,
@@ -190,7 +192,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
(keys.num + freet.num + dead.num)
* (sizeof(struct tdb_record) + sizeof(uint32_t))
* 100.0 / tdb->map_size,
- tdb->header.hash_size * sizeof(tdb_off_t)
+ tdb->hash_size * sizeof(tdb_off_t)
* 100.0 / tdb->map_size);
unlock:
diff --git a/common/tdb.c b/common/tdb.c
index fc1f560..6256a05 100644
--- a/common/tdb.c
+++ b/common/tdb.c
@@ -1,4 +1,4 @@
- /*
+ /*
Unix SMB/CIFS implementation.
trivial database library
@@ -152,7 +152,7 @@ static int tdb_update_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash,
/* it could be an exact duplicate of what is there - this is
* surprisingly common (eg. with a ldb re-index). */
- if (rec.key_len == key.dsize &&
+ if (rec.key_len == key.dsize &&
rec.data_len == dbuf.dsize &&
rec.full_hash == hash &&
tdb_parse_record(tdb, key, tdb_update_hash_cmp, &dbuf) == 0) {
@@ -258,7 +258,7 @@ _PUBLIC_ int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key,
return ret;
}
-/* check if an entry in the database exists
+/* check if an entry in the database exists
note that 1 is returned if the key is found and 0 is returned if not found
this doesn't match the conventions in the rest of this module, but is
@@ -713,7 +713,7 @@ _PUBLIC_ int tdb_get_seqnum(struct tdb_context *tdb)
_PUBLIC_ int tdb_hash_size(struct tdb_context *tdb)
{
- return tdb->header.hash_size;
+ return tdb->hash_size;
}
_PUBLIC_ size_t tdb_map_size(struct tdb_context *tdb)
@@ -777,7 +777,7 @@ _PUBLIC_ void tdb_enable_seqnum(struct tdb_context *tdb)
/*
- add a region of the file to the freelist. Length is the size of the region in bytes,
+ add a region of the file to the freelist. Length is the size of the region in bytes,
which includes the free list header that needs to be added
*/
static int tdb_free_region(struct tdb_context *tdb, tdb_off_t offset, ssize_t length)
@@ -789,7 +789,7 @@ static int tdb_free_region(struct tdb_context *tdb, tdb_off_t offset, ssize_t le
}
if (length + offset > tdb->map_size) {
TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_free_region: adding region beyond end of file\n"));
- return -1;
+ return -1;
}
memset(&rec,'\0',sizeof(rec));
rec.rec_len = length - sizeof(rec);
@@ -835,12 +835,12 @@ _PUBLIC_ int tdb_wipe_all(struct tdb_context *tdb)
if (tdb->methods->tdb_read(tdb, recovery_head, &rec, sizeof(rec), DOCONV()) == -1) {
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_wipe_all: failed to read recovery record\n"));
return -1;
- }
+ }
recovery_size = rec.rec_len + sizeof(rec);
}
/* wipe the hashes */
- for (i=0;i<tdb->header.hash_size;i++) {
+ for (i=0;i<tdb->hash_size;i++) {
if (tdb_ofs_write(tdb, TDB_HASH_TOP(i), &offset) == -1) {
TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_wipe_all: failed to write hash %d\n", i));
goto failed;
@@ -853,25 +853,25 @@ _PUBLIC_ int tdb_wipe_all(struct tdb_context *tdb)
goto failed;
}
- /* add all the rest of the file to the freelist, possibly leaving a gap
+ /* add all the rest of the file to the freelist, possibly leaving a gap
for the recovery area */
if (recovery_size == 0) {
/* the simple case - the whole file can be used as a freelist */
- data_len = (tdb->map_size - TDB_DATA_START(tdb->header.hash_size));
- if (tdb_free_region(tdb, TDB_DATA_START(tdb->header.hash_size), data_len) != 0) {
+ data_len = (tdb->map_size - TDB_DATA_START(tdb->hash_size));
+ if (tdb_free_region(tdb, TDB_DATA_START(tdb->hash_size), data_len) != 0) {
goto failed;
}
} else {
/* we need to add two freelist entries - one on either
- side of the recovery area
+ side of the recovery area
Note that we cannot shift the recovery area during
this operation. Only the transaction.c code may
move the recovery area or we risk subtle data
corruption
*/
- data_len = (recovery_head - TDB_DATA_START(tdb->header.hash_size));
- if (tdb_free_region(tdb, TDB_DATA_START(tdb->header.hash_size), data_len) != 0) {
+ data_len = (recovery_head - TDB_DATA_START(tdb->hash_size));
+ if (tdb_free_region(tdb, TDB_DATA_START(tdb->hash_size), data_len) != 0) {
goto failed;
}
/* and the 2nd free list entry after the recovery area - if any */
@@ -942,7 +942,7 @@ _PUBLIC_ int tdb_repack(struct tdb_context *tdb)
TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to traverse copying out\n"));
tdb_transaction_cancel(tdb);
tdb_close(tmp_db);
- return -1;
+ return -1;
}
if (state.error) {
@@ -966,7 +966,7 @@ _PUBLIC_ int tdb_repack(struct tdb_context *tdb)
TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to traverse copying back\n"));
tdb_transaction_cancel(tdb);
tdb_close(tmp_db);
- return -1;
+ return -1;
}
if (state.error) {
@@ -1000,6 +1000,17 @@ bool tdb_write_all(int fd, const void *buf, size_t count)
return true;
}
+bool tdb_add_off_t(tdb_off_t a, tdb_off_t b, tdb_off_t *pret)
+{
+ tdb_off_t ret = a + b;
+
+ if ((ret < a) || (ret < b)) {
+ return false;
+ }
+ *pret = ret;
+ return true;
+}
+
#ifdef TDB_TRACE
static void tdb_trace_write(struct tdb_context *tdb, const char *str)
{
diff --git a/common/tdb_private.h b/common/tdb_private.h
index 0441fb2..ce92188 100644
--- a/common/tdb_private.h
+++ b/common/tdb_private.h
@@ -1,6 +1,6 @@
#ifndef TDB_PRIVATE_H
#define TDB_PRIVATE_H
- /*
+ /*
Unix SMB/CIFS implementation.
trivial database library - private includes
@@ -61,7 +61,7 @@ typedef uint32_t tdb_off_t;
#define TDB_DEAD(r) ((r)->magic == TDB_DEAD_MAGIC)
#define TDB_BAD_MAGIC(r) ((r)->magic != TDB_MAGIC && !TDB_DEAD(r))
#define TDB_HASH_TOP(hash) (FREELIST_TOP + (BUCKET(hash)+1)*sizeof(tdb_off_t))
-#define TDB_HASHTABLE_SIZE(tdb) ((tdb->header.hash_size+1)*sizeof(tdb_off_t))
+#define TDB_HASHTABLE_SIZE(tdb) ((tdb->hash_size+1)*sizeof(tdb_off_t))
#define TDB_DATA_START(hash_size) (TDB_HASH_TOP(hash_size-1) + sizeof(tdb_off_t))
#define TDB_RECOVERY_HEAD offsetof(struct tdb_header, recovery_start)
#define TDB_SEQNUM_OFS offsetof(struct tdb_header, sequence_number)
@@ -114,7 +114,7 @@ void tdb_trace_2rec_retrec(struct tdb_context *tdb, const char *op,
#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0)
#endif
-#define BUCKET(hash) ((hash) % tdb->header.hash_size)
+#define BUCKET(hash) ((hash) % tdb->hash_size)
#define DOCONV() (tdb->flags & TDB_CONVERT)
#define CONVERT(x) (DOCONV() ? tdb_convert(&x, sizeof(x)) : &x)
@@ -198,7 +198,7 @@ struct tdb_context {
int num_lockrecs;
struct tdb_lock_type *lockrecs; /* only real locks, all with count>0 */
enum TDB_ERROR ecode; /* error code for last tdb error */
- struct tdb_header header; /* a cached copy of the header */
+ uint32_t hash_size;
uint32_t flags; /* the flags passed to tdb_open */
struct tdb_traverse_lock travlocks; /* current traversal locks */
struct tdb_context *next; /* all tdbs to avoid multiple opens */
@@ -282,4 +282,8 @@ void tdb_header_hash(struct tdb_context *tdb,
uint32_t *magic1_hash, uint32_t *magic2_hash);
unsigned int tdb_old_hash(TDB_DATA *key);
size_t tdb_dead_space(struct tdb_context *tdb, tdb_off_t off);
+bool tdb_add_off_t(tdb_off_t a, tdb_off_t b, tdb_off_t *pret);
+
+/* tdb_off_t and tdb_len_t right now are both uint32_t */
+#define tdb_add_len_t tdb_add_off_t
#endif /* TDB_PRIVATE_H */
diff --git a/common/transaction.c b/common/transaction.c
index f18b4c2..a2c3bbd 100644
--- a/common/transaction.c
+++ b/common/transaction.c
@@ -1,4 +1,4 @@
- /*
+ /*
Unix SMB/CIFS implementation.
trivial database library
@@ -148,7 +148,7 @@ struct tdb_transaction {
read while in a transaction. We need to check first if the data is in our list
of transaction elements, then if not do a real read
*/
-static int transaction_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
+static int transaction_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
tdb_len_t len, int cv)
{
uint32_t blk;
@@ -195,7 +195,7 @@ static int transaction_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
return 0;
fail:
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_read: failed at off=%d len=%d\n", off, len));
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_read: failed at off=%u len=%u\n", off, len));
tdb->ecode = TDB_ERR_IO;
tdb->transaction->transaction_error = 1;
return -1;
@@ -205,7 +205,7 @@ fail:
/*
write while in a transaction
*/
-static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
+static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
const void *buf, tdb_len_t len)
{
uint32_t blk;
@@ -249,19 +249,13 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
if (tdb->transaction->num_blocks <= blk) {
uint8_t **new_blocks;
/* expand the blocks array */
- if (tdb->transaction->blocks == NULL) {
- new_blocks = (uint8_t **)malloc(
- (blk+1)*sizeof(uint8_t *));
- } else {
- new_blocks = (uint8_t **)realloc(
- tdb->transaction->blocks,
- (blk+1)*sizeof(uint8_t *));
- }
+ new_blocks = (uint8_t **)realloc(tdb->transaction->blocks,
+ (blk+1)*sizeof(uint8_t *));
if (new_blocks == NULL) {
tdb->ecode = TDB_ERR_OOM;
goto fail;
}
- memset(&new_blocks[tdb->transaction->num_blocks], 0,
+ memset(&new_blocks[tdb->transaction->num_blocks], 0,
(1+(blk - tdb->transaction->num_blocks))*sizeof(uint8_t *));
tdb->transaction->blocks = new_blocks;
tdb->transaction->num_blocks = blk+1;
@@ -274,23 +268,23 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
if (tdb->transaction->blocks[blk] == NULL) {
tdb->ecode = TDB_ERR_OOM;
tdb->transaction->transaction_error = 1;
- return -1;
+ return -1;
}
if (tdb->transaction->old_map_size > blk * tdb->transaction->block_size) {
tdb_len_t len2 = tdb->transaction->block_size;
if (len2 + (blk * tdb->transaction->block_size) > tdb->transaction->old_map_size) {
len2 = tdb->transaction->old_map_size - (blk * tdb->transaction->block_size);
}
- if (tdb->transaction->io_methods->tdb_read(tdb, blk * tdb->transaction->block_size,
- tdb->transaction->blocks[blk],
+ if (tdb->transaction->io_methods->tdb_read(tdb, blk * tdb->transaction->block_size,
+ tdb->transaction->blocks[blk],
len2, 0) != 0) {
- SAFE_FREE(tdb->transaction->blocks[blk]);
+ SAFE_FREE(tdb->transaction->blocks[blk]);
tdb->ecode = TDB_ERR_IO;
goto fail;
}
if (blk == tdb->transaction->num_blocks-1) {
tdb->transaction->last_block_size = len2;
- }
+ }
}
}
@@ -309,7 +303,7 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
return 0;
fail:
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_write: failed at off=%d len=%d\n",
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_write: failed at off=%u len=%u\n",
(blk*tdb->transaction->block_size) + off, len));
tdb->transaction->transaction_error = 1;
return -1;
@@ -317,10 +311,10 @@ fail:
/*
- write while in a transaction - this varient never expands the transaction blocks, it only
+ write while in a transaction - this variant never expands the transaction blocks, it only
updates existing blocks. This means it cannot change the recovery size
*/
-static int transaction_write_existing(struct tdb_context *tdb, tdb_off_t off,
+static int transaction_write_existing(struct tdb_context *tdb, tdb_off_t off,
const void *buf, tdb_len_t len)
{
uint32_t blk;
@@ -371,7 +365,7 @@ static int transaction_write_existing(struct tdb_context *tdb, tdb_off_t off,
static void transaction_next_hash_chain(struct tdb_context *tdb, uint32_t *chain)
{
uint32_t h = *chain;
- for (;h < tdb->header.hash_size;h++) {
+ for (;h < tdb->hash_size;h++) {
/* the +1 takes account of the freelist */
if (0 != tdb->transaction->hash_heads[h+1]) {
break;
@@ -396,7 +390,7 @@ static int transaction_oob(struct tdb_context *tdb, tdb_off_t off,
/*
transaction version of tdb_expand().
*/
-static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t size,
+static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t size,
tdb_off_t addition)
{
/* add a write to the transaction elements, so subsequent
@@ -440,7 +434,7 @@ static int _tdb_transaction_start(struct tdb_context *tdb,
return -1;
}
tdb->transaction->nesting++;
- TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_start: nesting %d\n",
+ TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_start: nesting %d\n",
tdb->transaction->nesting));
return 0;
}
@@ -495,7 +489,7 @@ static int _tdb_transaction_start(struct tdb_context *tdb,
/* setup a copy of the hash table heads so the hash scan in
traverse can be fast */
tdb->transaction->hash_heads = (uint32_t *)
- calloc(tdb->header.hash_size+1, sizeof(uint32_t));
+ calloc(tdb->hash_size+1, sizeof(uint32_t));
if (tdb->transaction->hash_heads == NULL) {
tdb->ecode = TDB_ERR_OOM;
goto fail;
@@ -545,7 +539,7 @@ _PUBLIC_ int tdb_transaction_start_nonblock(struct tdb_context *tdb)
sync to disk
*/
static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t length)
-{
+{
if (tdb->flags & TDB_NOSYNC) {
return 0;
}
@@ -562,7 +556,7 @@ static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t
#ifdef HAVE_MMAP
if (tdb->map_ptr) {
tdb_off_t moffset = offset & ~(tdb->page_size-1);
- if (msync(moffset + (char *)tdb->map_ptr,
+ if (msync(moffset + (char *)tdb->map_ptr,
length + (offset - moffset), MS_SYNC) != 0) {
tdb->ecode = TDB_ERR_IO;
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction: msync failed - %s\n",
@@ -576,7 +570,7 @@ static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t
static int _tdb_transaction_cancel(struct tdb_context *tdb)
-{
+{
int i, ret = 0;
if (tdb->transaction == NULL) {
@@ -588,7 +582,7 @@ static int _tdb_transaction_cancel(struct tdb_context *tdb)
tdb->transaction->transaction_error = 1;
tdb->transaction->nesting--;
return 0;
- }
+ }
tdb->map_size = tdb->transaction->old_map_size;
@@ -636,28 +630,37 @@ _PUBLIC_ int tdb_transaction_cancel(struct tdb_context *tdb)
/*
work out how much space the linearised recovery data will consume
*/
-static tdb_len_t tdb_recovery_size(struct tdb_context *tdb)
+static bool tdb_recovery_size(struct tdb_context *tdb, tdb_len_t *result)
{
tdb_len_t recovery_size = 0;
int i;
recovery_size = sizeof(uint32_t);
for (i=0;i<tdb->transaction->num_blocks;i++) {
+ tdb_len_t block_size;
if (i * tdb->transaction->block_size >= tdb->transaction->old_map_size) {
break;
}
if (tdb->transaction->blocks[i] == NULL) {
continue;
}
- recovery_size += 2*sizeof(tdb_off_t);
+ if (!tdb_add_len_t(recovery_size, 2*sizeof(tdb_off_t),
+ &recovery_size)) {
+ return false;
+ }
if (i == tdb->transaction->num_blocks-1) {
- recovery_size += tdb->transaction->last_block_size;
+ block_size = tdb->transaction->last_block_size;
} else {
- recovery_size += tdb->transaction->block_size;
+ block_size = tdb->transaction->block_size;
+ }
+ if (!tdb_add_len_t(recovery_size, block_size,
+ &recovery_size)) {
+ return false;
}
- }
+ }
- return recovery_size;
+ *result = recovery_size;
+ return true;
}
int tdb_recovery_area(struct tdb_context *tdb,
@@ -692,7 +695,7 @@ int tdb_recovery_area(struct tdb_context *tdb,
allocate the recovery area, or use an existing recovery area if it is
large enough
*/
-static int tdb_recovery_allocate(struct tdb_context *tdb,
+static int tdb_recovery_allocate(struct tdb_context *tdb,
tdb_len_t *recovery_size,
tdb_off_t *recovery_offset,
tdb_len_t *recovery_max_size)
@@ -706,7 +709,11 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
return -1;
}
- *recovery_size = tdb_recovery_size(tdb);
+ if (!tdb_recovery_size(tdb, recovery_size)) {
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: "
+ "overflow recovery size\n"));
+ return -1;
+ }
/* Existing recovery area? */
if (recovery_head != 0 && *recovery_size <= rec.rec_len) {
@@ -734,7 +741,12 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
/* the tdb_free() call might have increased
* the recovery size */
- *recovery_size = tdb_recovery_size(tdb);
+ if (!tdb_recovery_size(tdb, recovery_size)) {
+ TDB_LOG((tdb, TDB_DEBUG_FATAL,
+ "tdb_recovery_allocate: "
+ "overflow recovery size\n"));
+ return -1;
+ }
}
/* New head will be at end of file. */
@@ -750,9 +762,14 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
tdb->page_size)
- sizeof(rec);
- new_end = recovery_head + sizeof(rec) + *recovery_max_size;
+ if (!tdb_add_off_t(recovery_head, sizeof(rec), &new_end) ||
+ !tdb_add_off_t(new_end, *recovery_max_size, &new_end)) {
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: "
+ "overflow recovery area\n"));
+ return -1;
+ }
- if (methods->tdb_expand_file(tdb, tdb->transaction->old_map_size,
+ if (methods->tdb_expand_file(tdb, tdb->transaction->old_map_size,
new_end - tdb->transaction->old_map_size)
== -1) {
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to create recovery area\n"));
@@ -769,7 +786,7 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
/* write the recovery header offset and sync - we can sync without a race here
as the magic ptr in the recovery record has not been set */
CONVERT(recovery_head);
- if (methods->tdb_write(tdb, TDB_RECOVERY_HEAD,
+ if (methods->tdb_write(tdb, TDB_RECOVERY_HEAD,
&recovery_head, sizeof(tdb_off_t)) == -1) {
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to write recovery head\n"));
return -1;
@@ -786,7 +803,7 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
/*
setup the recovery data that will be used on a crash during commit
*/
-static int transaction_setup_recovery(struct tdb_context *tdb,
+static int transaction_setup_recovery(struct tdb_context *tdb,
tdb_off_t *magic_offset)
{
tdb_len_t recovery_size;
@@ -801,7 +818,7 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
/*
check that the recovery area has enough space
*/
- if (tdb_recovery_allocate(tdb, &recovery_size,
+ if (tdb_recovery_allocate(tdb, &recovery_size,
&recovery_offset, &recovery_max_size) == -1) {
return -1;
}
@@ -919,7 +936,7 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
}
static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
-{
+{
const struct tdb_methods *methods;
if (tdb->transaction == NULL) {
@@ -944,7 +961,7 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
if (tdb->transaction->nesting != 0) {
return 0;
- }
+ }
/* check for a null transaction */
if (tdb->transaction->blocks == NULL) {
@@ -988,8 +1005,8 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
/* expand the file to the new size if needed */
if (tdb->map_size != tdb->transaction->old_map_size) {
- if (methods->tdb_expand_file(tdb, tdb->transaction->old_map_size,
- tdb->map_size -
+ if (methods->tdb_expand_file(tdb, tdb->transaction->old_map_size,
+ tdb->map_size -
tdb->transaction->old_map_size) == -1) {
tdb->ecode = TDB_ERR_IO;
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_prepare_commit: expansion failed\n"));
@@ -1101,7 +1118,7 @@ _PUBLIC_ int tdb_transaction_commit(struct tdb_context *tdb)
possibly expanded the file, so we need to
run the crash recovery code */
tdb->methods = methods;
- tdb_transaction_recover(tdb);
+ tdb_transaction_recover(tdb);
_tdb_transaction_cancel(tdb);
@@ -1109,7 +1126,7 @@ _PUBLIC_ int tdb_transaction_commit(struct tdb_context *tdb)
return -1;
}
SAFE_FREE(tdb->transaction->blocks[i]);
- }
+ }
/* Do this before we drop lock or blocks. */
if (tdb->transaction->expanded) {
@@ -1176,9 +1193,9 @@ int tdb_transaction_recover(struct tdb_context *tdb)
}
/* read the recovery record */
- if (tdb->methods->tdb_read(tdb, recovery_head, &rec,
+ if (tdb->methods->tdb_read(tdb, recovery_head, &rec,
sizeof(rec), DOCONV()) == -1) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery record\n"));
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery record\n"));
tdb->ecode = TDB_ERR_IO;
return -1;
}
@@ -1198,7 +1215,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
data = (unsigned char *)malloc(rec.data_len);
if (data == NULL) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to allocate recovery data\n"));
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to allocate recovery data\n"));
tdb->ecode = TDB_ERR_OOM;
return -1;
}
@@ -1206,7 +1223,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
/* read the full recovery data */
if (tdb->methods->tdb_read(tdb, recovery_head + sizeof(rec), data,
rec.data_len, 0) == -1) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery data\n"));
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery data\n"));
tdb->ecode = TDB_ERR_IO;
return -1;
}
@@ -1223,7 +1240,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
if (tdb->methods->tdb_write(tdb, ofs, p+8, len) == -1) {
free(data);
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to recover %d bytes at offset %d\n", len, ofs));
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to recover %u bytes at offset %u\n", len, ofs));
tdb->ecode = TDB_ERR_IO;
return -1;
}
@@ -1243,7 +1260,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
if (tdb_ofs_write(tdb, TDB_RECOVERY_HEAD, &zero) == -1) {
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to remove recovery head\n"));
tdb->ecode = TDB_ERR_IO;
- return -1;
+ return -1;
}
}
@@ -1252,7 +1269,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
&zero) == -1) {
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to remove recovery magic\n"));
tdb->ecode = TDB_ERR_IO;
- return -1;
+ return -1;
}
if (transaction_sync(tdb, 0, recovery_eof) == -1) {
@@ -1261,7 +1278,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
return -1;
}
- TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_recover: recovered %d byte database\n",
+ TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_recover: recovered %u byte database\n",
recovery_eof));
/* all done */
diff --git a/common/traverse.c b/common/traverse.c
index 517fecb..a843359 100644
--- a/common/traverse.c
+++ b/common/traverse.c
@@ -1,4 +1,4 @@
- /*
+ /*
Unix SMB/CIFS implementation.
trivial database library
@@ -37,7 +37,7 @@ static tdb_off_t tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock
int want_next = (tlock->off != 0);
/* Lock each chain from the start one. */
- for (; tlock->hash < tdb->header.hash_size; tlock->hash++) {
+ for (; tlock->hash < tdb->hash_size; tlock->hash++) {
if (!tlock->off && tlock->hash != 0) {
/* this is an optimisation for the common case where
the hash chain is empty, which is particularly
@@ -68,7 +68,7 @@ static tdb_off_t tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock
system (testing using ldbtest).
*/
tdb->methods->next_hash_chain(tdb, &tlock->hash);
- if (tlock->hash == tdb->header.hash_size) {
+ if (tlock->hash == tdb->hash_size) {
continue;
}
}
@@ -117,7 +117,7 @@ static tdb_off_t tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock
/* Try to clean dead ones from old traverses */
current = tlock->off;
tlock->off = rec->next;
- if (!(tdb->read_only || tdb->traverse_read) &&
+ if (!(tdb->read_only || tdb->traverse_read) &&
tdb_do_delete(tdb, current, rec) != 0)
goto fail;
}
@@ -140,7 +140,7 @@ static tdb_off_t tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock
if fn is NULL then it is not called
a non-zero return value from fn() indicates that the traversal should stop
*/
-static int tdb_traverse_internal(struct tdb_context *tdb,
+static int tdb_traverse_internal(struct tdb_context *tdb,
tdb_traverse_func fn, void *private_data,
struct tdb_traverse_lock *tl)
{
@@ -149,7 +149,7 @@ static int tdb_traverse_internal(struct tdb_context *tdb,
int ret = 0, count = 0;
tdb_off_t off;
- /* This was in the initializaton, above, but the IRIX compiler
+ /* This was in the initialization, above, but the IRIX compiler
* did not like it. crh
*/
tl->next = tdb->travlocks.next;
@@ -165,7 +165,7 @@ static int tdb_traverse_internal(struct tdb_context *tdb,
}
count++;
/* now read the full record */
- key.dptr = tdb_alloc_read(tdb, tl->off + sizeof(rec),
+ key.dptr = tdb_alloc_read(tdb, tl->off + sizeof(rec),
rec.key_len + rec.data_len);
if (!key.dptr) {
ret = -1;
@@ -210,9 +210,9 @@ out:
/*
- a write style traverse - temporarily marks the db read only
+ a read style traverse - temporarily marks the db read only
*/
-_PUBLIC_ int tdb_traverse_read(struct tdb_context *tdb,
+_PUBLIC_ int tdb_traverse_read(struct tdb_context *tdb,
tdb_traverse_func fn, void *private_data)
{
struct tdb_traverse_lock tl = { NULL, 0, 0, F_RDLCK };
@@ -241,7 +241,7 @@ _PUBLIC_ int tdb_traverse_read(struct tdb_context *tdb,
WARNING: The data buffer given to the callback fn does NOT meet the
alignment restrictions malloc gives you.
*/
-_PUBLIC_ int tdb_traverse(struct tdb_context *tdb,
+_PUBLIC_ int tdb_traverse(struct tdb_context *tdb,
tdb_traverse_func fn, void *private_data)
{
struct tdb_traverse_lock tl = { NULL, 0, 0, F_WRLCK };
diff --git a/include/tdb.h b/include/tdb.h
index d19439e..e371e33 100644
--- a/include/tdb.h
+++ b/include/tdb.h
@@ -212,9 +212,12 @@ void tdb_set_max_dead(struct tdb_context *tdb, int max_dead);
* This can be used after a fork to ensure that we have an independent seek
* pointer from our parent and to re-establish locks.
*
- * @param[in] tdb The database to reopen.
+ * @param[in] tdb The database to reopen. It will be free'd on error!
*
* @return 0 on success, -1 on error.
+ *
+ * @note Don't call tdb_error() after this function cause the tdb context will
+ * be freed on error.
*/
int tdb_reopen(struct tdb_context *tdb);
@@ -361,9 +364,12 @@ int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
/**
* @brief Close a database.
*
- * @param[in] tdb The database to close.
+ * @param[in] tdb The database to close. The context will be free'd.
*
* @return 0 for success, -1 on error.
+ *
+ * @note Don't call tdb_error() after this function cause the tdb context will
+ * be freed on error.
*/
int tdb_close(struct tdb_context *tdb);
diff --git a/lib/replace/README b/lib/replace/README
index e960dc8..9dd4f73 100644
--- a/lib/replace/README
+++ b/lib/replace/README
@@ -49,7 +49,6 @@ pread
pwrite
chown
lchown
-getpass
readline (the library)
inet_ntoa
inet_ntop
diff --git a/lib/replace/crypt.m4 b/lib/replace/crypt.m4
deleted file mode 100644
index fae2a58..0000000
--- a/lib/replace/crypt.m4
+++ /dev/null
@@ -1,6 +0,0 @@
-###############################################
-# test for where we get crypt() from
-AC_CHECK_HEADERS(crypt.h)
-AC_SEARCH_LIBS_EXT(crypt, [crypt], CRYPT_LIBS,
- [ AC_DEFINE(HAVE_CRYPT,1,[Whether the system has the crypt() function]) ],
- [ LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/crypt.o" ])
diff --git a/lib/replace/dlfcn.m4 b/lib/replace/dlfcn.m4
deleted file mode 100644
index 722e024..0000000
--- a/lib/replace/dlfcn.m4
+++ /dev/null
@@ -1,31 +0,0 @@
-dnl dummies provided by dlfcn.c if not available
-save_LIBS="$LIBS"
-LIBS=""
-
-libreplace_cv_dlfcn=no
-AC_SEARCH_LIBS(dlopen, dl)
-
-AC_CHECK_HEADERS(dlfcn.h)
-AC_CHECK_FUNCS([dlopen dlsym dlerror dlclose],[],[libreplace_cv_dlfcn=yes])
-
-libreplace_cv_shl=no
-AC_SEARCH_LIBS(shl_load, sl)
-AC_CHECK_HEADERS(dl.h)
-AC_CHECK_FUNCS([shl_load shl_unload shl_findsym],[],[libreplace_cv_shl=yes])
-
-AC_VERIFY_C_PROTOTYPE([void *dlopen(const char* filename, unsigned int flags)],
- [
- return 0;
- ],[
- AC_DEFINE(DLOPEN_TAKES_UNSIGNED_FLAGS, 1, [Whether dlopen takes unsigned int flags])
- ],[],[
- #include <dlfcn.h>
- ])
-
-if test x"${libreplace_cv_dlfcn}" = x"yes";then
- LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/dlfcn.o"
-fi
-
-LIBDL="$LIBS"
-AC_SUBST(LIBDL)
-LIBS="$save_LIBS"
diff --git a/lib/replace/getifaddrs.c b/lib/replace/getifaddrs.c
index 84d7906..8da022f 100644
--- a/lib/replace/getifaddrs.c
+++ b/lib/replace/getifaddrs.c
@@ -4,19 +4,23 @@
Copyright (C) Andrew Tridgell 1998
Copyright (C) Jeremy Allison 2007
Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
-
- 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 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+
+ ** NOTE! The following LGPL license applies to the replace
+ ** library. This does NOT imply that all of Samba is released
+ ** under the LGPL
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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, see <http://www.gnu.org/licenses/>.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#define SOCKET_WRAPPER_NOT_REPLACE
diff --git a/lib/replace/getpass.c b/lib/replace/getpass.c
deleted file mode 100644
index f95109f..0000000
--- a/lib/replace/getpass.c
+++ /dev/null
@@ -1,218 +0,0 @@
-/* Copyright (C) 1992-1998 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
-
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public License as
-published by the Free Software Foundation; either version 3 of the
-License, or (at your option) any later version.
-
-The GNU C Library 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
-Library General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, see <http://www.gnu.org/licenses/>. */
-
-/* Modified to use with samba by Jeremy Allison, 8th July 1995. */
-
-#include "replace.h"
-#include "system/filesys.h"
-#include "system/wait.h"
-#include "system/terminal.h"
-#include "system/passwd.h"
-
-/*
- * Define additional missing types
- */
-#ifndef HAVE_SIG_ATOMIC_T_TYPE
-typedef int sig_atomic_t;
-#endif
-
-#ifndef SIGCLD
-#define SIGCLD SIGCHLD
-#endif
-
-#ifdef SYSV_TERMIO
-
-/* SYSTEM V TERMIO HANDLING */
-
-static struct termio t;
-
-#define ECHO_IS_ON(t) ((t).c_lflag & ECHO)
-#define TURN_ECHO_OFF(t) ((t).c_lflag &= ~ECHO)
-#define TURN_ECHO_ON(t) ((t).c_lflag |= ECHO)
-
-#ifndef TCSAFLUSH
-#define TCSAFLUSH 1
-#endif
-
-#ifndef TCSANOW
-#define TCSANOW 0
-#endif
-
-static int tcgetattr(int fd, struct termio *_t)
-{
- return ioctl(fd, TCGETA, _t);
-}
-
-static int tcsetattr(int fd, int flags, struct termio *_t)
-{
- if(flags & TCSAFLUSH)
- ioctl(fd, TCFLSH, TCIOFLUSH);
- return ioctl(fd, TCSETS, _t);
-}
-
-#elif !defined(TCSAFLUSH)
-
-/* BSD TERMIO HANDLING */
-
-static struct sgttyb t;
-
-#define ECHO_IS_ON(t) ((t).sg_flags & ECHO)
-#define TURN_ECHO_OFF(t) ((t).sg_flags &= ~ECHO)
-#define TURN_ECHO_ON(t) ((t).sg_flags |= ECHO)
-
-#define TCSAFLUSH 1
-#define TCSANOW 0
-
-static int tcgetattr(int fd, struct sgttyb *_t)
-{
- return ioctl(fd, TIOCGETP, (char *)_t);
-}
-
-static int tcsetattr(int fd, int flags, struct sgttyb *_t)
-{
- return ioctl(fd, TIOCSETP, (char *)_t);
-}
-
-#else /* POSIX TERMIO HANDLING */
-#define ECHO_IS_ON(t) ((t).c_lflag & ECHO)
-#define TURN_ECHO_OFF(t) ((t).c_lflag &= ~ECHO)
-#define TURN_ECHO_ON(t) ((t).c_lflag |= ECHO)
-
-static struct termios t;
-#endif /* SYSV_TERMIO */
-
-static void catch_signal(int signum, void (*handler)(int ))
-{
-#ifdef HAVE_SIGACTION
- struct sigaction act;
- struct sigaction oldact;
-
- memset(&act, 0, sizeof(act));
-
- act.sa_handler = handler;
-#ifdef SA_RESTART
- /*
- * We *want* SIGALRM to interrupt a system call.
- */
- if(signum != SIGALRM)
- act.sa_flags = SA_RESTART;
-#endif
- sigemptyset(&act.sa_mask);
- sigaddset(&act.sa_mask,signum);
- sigaction(signum,&act,&oldact);
-#else /* !HAVE_SIGACTION */
- /* FIXME: need to handle sigvec and systems with broken signal() */
- signal(signum, handler);
-#endif
-}
-
-static sig_atomic_t gotintr;
-static int in_fd = -1;
-
-/***************************************************************
- Signal function to tell us were ^C'ed.
-****************************************************************/
-
-static void gotintr_sig(int signum)
-{
- gotintr = 1;
- if (in_fd != -1)
- close(in_fd); /* Safe way to force a return. */
- in_fd = -1;
-}
-
-char *rep_getpass(const char *prompt)
-{
- FILE *in, *out;
- int echo_off;
- static char buf[256];
- static size_t bufsize = sizeof(buf);
- size_t nread;
-
- /* Catch problematic signals */
- catch_signal(SIGINT, gotintr_sig);
-
- /* Try to write to and read from the terminal if we can.
- If we can't open the terminal, use stderr and stdin. */
-
- in = fopen ("/dev/tty", "w+");
- if (in == NULL) {
- in = stdin;
- out = stderr;
- } else {
- out = in;
- }
-
- setvbuf(in, NULL, _IONBF, 0);
-
- /* Turn echoing off if it is on now. */
-
- if (tcgetattr (fileno (in), &t) == 0) {
- if (ECHO_IS_ON(t)) {
- TURN_ECHO_OFF(t);
- echo_off = tcsetattr (fileno (in), TCSAFLUSH, &t) == 0;
- TURN_ECHO_ON(t);
- } else {
- echo_off = 0;
- }
- } else {
- echo_off = 0;
- }
-
- /* Write the prompt. */
- fputs(prompt, out);
- fflush(out);
-
- /* Read the password. */
- buf[0] = 0;
- if (!gotintr) {
- in_fd = fileno(in);
- if (fgets(buf, bufsize, in) == NULL) {
- buf[0] = 0;
- }
- }
- nread = strlen(buf);
- if (nread) {
- if (buf[nread - 1] == '\n')
- buf[nread - 1] = '\0';
- }
-
- /* Restore echoing. */
- if (echo_off) {
- if (gotintr && in_fd == -1) {
- in = fopen ("/dev/tty", "w+");
- }
- if (in != NULL)
- tcsetattr (fileno (in), TCSANOW, &t);
- }
-
- fprintf(out, "\n");
- fflush(out);
-
- if (in && in != stdin) /* We opened the terminal; now close it. */
- fclose(in);
-
- /* Catch problematic signals */
- catch_signal(SIGINT, SIG_DFL);
-
- if (gotintr) {
- printf("Interrupted by signal.\n");
- fflush(stdout);
- exit(1);
- }
- return buf;
-}
diff --git a/lib/replace/getpass.m4 b/lib/replace/getpass.m4
deleted file mode 100644
index 78a0afe..0000000
--- a/lib/replace/getpass.m4
+++ /dev/null
@@ -1,24 +0,0 @@
-AC_CHECK_FUNC(getpass, libreplace_cv_HAVE_GETPASS=yes)
-AC_CHECK_FUNC(getpassphrase, libreplace_cv_HAVE_GETPASSPHRASE=yes)
-if test x"$libreplace_cv_HAVE_GETPASS" = x"yes" -a x"$libreplace_cv_HAVE_GETPASSPHRASE" = x"yes"; then
- AC_DEFINE(REPLACE_GETPASS_BY_GETPASSPHRASE, 1, [getpass returns <9 chars where getpassphrase returns <265 chars])
- AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced])
- LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/getpass.o"
-else
-
-AC_CACHE_CHECK([whether getpass should be replaced],libreplace_cv_REPLACE_GETPASS,[
-SAVE_CPPFLAGS="$CPPFLAGS"
-CPPFLAGS="$CPPFLAGS -I$libreplacedir/"
-AC_TRY_COMPILE([
-#include "confdefs.h"
-#define NO_CONFIG_H
-#include "$libreplacedir/getpass.c"
-],[],libreplace_cv_REPLACE_GETPASS=yes,libreplace_cv_REPLACE_GETPASS=no)
-CPPFLAGS="$SAVE_CPPFLAGS"
-])
-if test x"$libreplace_cv_REPLACE_GETPASS" = x"yes"; then
- AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced])
- LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/getpass.o"
-fi
-
-fi
diff --git a/lib/replace/install-sh b/lib/replace/install-sh
deleted file mode 100755
index 5871924..0000000
--- a/lib/replace/install-sh
+++ /dev/null
@@ -1,238 +0,0 @@
-#! /bin/sh
-#
-# install - install a program, script, or datafile
-# This comes from X11R5.
-#
-# Calling this script install-sh is preferred over install.sh, to prevent
-# `make' implicit rules from creating a file called install from it
-# when there is no Makefile.
-#
-# This script is compatible with the BSD install script, but was written
-# from scratch.
-#
-
-
-# set DOITPROG to echo to test this script
-
-# Don't use :- since 4.3BSD and earlier shells don't like it.
-doit="${DOITPROG-}"
-
-
-# put in absolute paths if you don't have them in your path; or use env. vars.
-
-mvprog="${MVPROG-mv}"
-cpprog="${CPPROG-cp}"
-chmodprog="${CHMODPROG-chmod}"
-chownprog="${CHOWNPROG-chown}"
-chgrpprog="${CHGRPPROG-chgrp}"
-stripprog="${STRIPPROG-strip}"
-rmprog="${RMPROG-rm}"
-mkdirprog="${MKDIRPROG-mkdir}"
-
-transformbasename=""
-transform_arg=""
-instcmd="$mvprog"
-chmodcmd="$chmodprog 0755"
-chowncmd=""
-chgrpcmd=""
-stripcmd=""
-rmcmd="$rmprog -f"
-mvcmd="$mvprog"
-src=""
-dst=""
-dir_arg=""
-
-while [ x"$1" != x ]; do
- case $1 in
- -c) instcmd="$cpprog"
- shift
- continue;;
-
- -d) dir_arg=true
- shift
- continue;;
-
- -m) chmodcmd="$chmodprog $2"
- shift
- shift
- continue;;
-
- -o) chowncmd="$chownprog $2"
- shift
- shift
- continue;;
-
- -g) chgrpcmd="$chgrpprog $2"
- shift
- shift
- continue;;
-
- -s) stripcmd="$stripprog"
- shift
- continue;;
-
- -t=*) transformarg=`echo $1 | sed 's/-t=//'`
- shift
- continue;;
-
- -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
- shift
- continue;;
-
- *) if [ x"$src" = x ]
- then
- src=$1
- else
- # this colon is to work around a 386BSD /bin/sh bug
- :
- dst=$1
- fi
- shift
- continue;;
- esac
-done
-
-if [ x"$src" = x ]
-then
- echo "install: no input file specified"
- exit 1
-else
- true
-fi
-
-if [ x"$dir_arg" != x ]; then
- dst=$src
- src=""
-
- if [ -d $dst ]; then
- instcmd=:
- else
- instcmd=mkdir
- fi
-else
-
-# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
-# might cause directories to be created, which would be especially bad
-# if $src (and thus $dsttmp) contains '*'.
-
- if [ -f $src -o -d $src ]
- then
- true
- else
- echo "install: $src does not exist"
- exit 1
- fi
-
- if [ x"$dst" = x ]
- then
- echo "install: no destination specified"
- exit 1
- else
- true
- fi
-
-# If destination is a directory, append the input filename; if your system
-# does not like double slashes in filenames, you may need to add some logic
-
- if [ -d $dst ]
- then
- dst="$dst"/`basename $src`
- else
- true
- fi
-fi
-
-## this sed command emulates the dirname command
-dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
-
-# Make sure that the destination directory exists.
-# this part is taken from Noah Friedman's mkinstalldirs script
-
-# Skip lots of stat calls in the usual case.
-if [ ! -d "$dstdir" ]; then
-defaultIFS='
-'
-IFS="${IFS-${defaultIFS}}"
-
-oIFS="${IFS}"
-# Some sh's can't handle IFS=/ for some reason.
-IFS='%'
-set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
-IFS="${oIFS}"
-
-pathcomp=''
-
-while [ $# -ne 0 ] ; do
- pathcomp="${pathcomp}${1}"
- shift
-
- if [ ! -d "${pathcomp}" ] ;
- then
- $mkdirprog "${pathcomp}"
- else
- true
- fi
-
- pathcomp="${pathcomp}/"
-done
-fi
-
-if [ x"$dir_arg" != x ]
-then
- $doit $instcmd $dst &&
-
- if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
- if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
- if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
- if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
-else
-
-# If we're going to rename the final executable, determine the name now.
-
- if [ x"$transformarg" = x ]
- then
- dstfile=`basename $dst`
- else
- dstfile=`basename $dst $transformbasename |
- sed $transformarg`$transformbasename
- fi
-
-# don't allow the sed command to completely eliminate the filename
-
- if [ x"$dstfile" = x ]
- then
- dstfile=`basename $dst`
- else
- true
- fi
-
-# Make a temp file name in the proper directory.
-
- dsttmp=$dstdir/#inst.$$#
-
-# Move or copy the file name to the temp name
-
- $doit $instcmd $src $dsttmp &&
-
- trap "rm -f ${dsttmp}" 0 &&
-
-# and set any options; do chmod last to preserve setuid bits
-
-# If any of these fail, we abort the whole thing. If we want to
-# ignore errors from any of these, just make sure not to ignore
-# errors from the above "$doit $instcmd $src $dsttmp" command.
-
- if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
- if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
- if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
- if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
-
-# Now rename the file to the real destination.
-
- $doit $rmcmd -f $dstdir/$dstfile &&
- $doit $mvcmd $dsttmp $dstdir/$dstfile
-
-fi &&
-
-
-exit 0
diff --git a/lib/replace/libreplace.m4 b/lib/replace/libreplace.m4
deleted file mode 100644
index 796069c..0000000
--- a/lib/replace/libreplace.m4
+++ /dev/null
@@ -1,479 +0,0 @@
-AC_DEFUN_ONCE(AC_LIBREPLACE_LOCATION_CHECKS,
-[
-echo "LIBREPLACE_LOCATION_CHECKS: START"
-
-dnl find the libreplace sources. This is meant to work both for
-dnl libreplace standalone builds, and builds of packages using libreplace
-libreplacedir=""
-libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace"
-for d in $libreplacepaths; do
- if test -f "$d/replace.c"; then
- libreplacedir="$d"
- AC_SUBST(libreplacedir)
- break;
- fi
-done
-if test x"$libreplacedir" = "x"; then
- AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
-fi
-LIBREPLACEOBJ="$libreplacedir/replace.o"
-AC_SUBST(LIBREPLACEOBJ)
-
-AC_CANONICAL_BUILD
-AC_CANONICAL_HOST
-AC_CANONICAL_TARGET
-
-echo "LIBREPLACE_LOCATION_CHECKS: END"
-]) dnl end AC_LIBREPLACE_LOCATION_CHECKS
-
-
-AC_DEFUN_ONCE(AC_LIBREPLACE_BROKEN_CHECKS,
-[
-echo "LIBREPLACE_BROKEN_CHECKS: START"
-
-dnl find the libreplace sources. This is meant to work both for
-dnl libreplace standalone builds, and builds of packages using libreplace
-libreplacedir=""
-libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace"
-for d in $libreplacepaths; do
- if test -f "$d/replace.c"; then
- libreplacedir="$d"
- AC_SUBST(libreplacedir)
- break;
- fi
-done
-if test x"$libreplacedir" = "x"; then
- AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
-fi
-
-LIBREPLACEOBJ="$libreplacedir/replace.o"
-AC_SUBST(LIBREPLACEOBJ)
-
-LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/snprintf.o $libreplacedir/xattr.o"
-
-AC_TYPE_UID_T
-AC_TYPE_MODE_T
-AC_TYPE_OFF_T
-AC_TYPE_SIZE_T
-AC_TYPE_PID_T
-AC_STRUCT_ST_RDEV
-AC_CHECK_TYPE(ino_t,unsigned)
-AC_CHECK_TYPE(loff_t,off_t)
-AC_CHECK_TYPE(offset_t,loff_t)
-AC_CHECK_TYPE(blksize_t,long)
-AC_CHECK_TYPE(blkcnt_t,long)
-
-AC_FUNC_MEMCMP
-
-AC_CHECK_FUNCS([pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp utime utimes])
-
-AC_CHECK_HEADERS(stdbool.h stdint.h sys/select.h)
-AC_CHECK_HEADERS(setjmp.h utime.h)
-
-LIBREPLACE_PROVIDE_HEADER([stdint.h])
-LIBREPLACE_PROVIDE_HEADER([stdbool.h])
-
-AC_DEFINE(HAVE_LIBREPLACE, 1, [We have libreplace])
-
-AC_CHECK_TYPE(bool,
-[AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
-[
-AC_INCLUDES_DEFAULT
-#ifdef HAVE_STDBOOL_H
-#include <stdbool.h>
-#endif]
-)
-
-AC_CHECK_TYPE(_Bool,
-[AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
-[
-AC_INCLUDES_DEFAULT
-#ifdef HAVE_STDBOOL_H
-#include <stdbool.h>
-#endif]
-)
-
-AC_CHECK_HEADERS(linux/types.h)
-
-AC_CACHE_CHECK([for working mmap],libreplace_cv_HAVE_MMAP,[
-AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
- libreplace_cv_HAVE_MMAP=yes,libreplace_cv_HAVE_MMAP=no,libreplace_cv_HAVE_MMAP=cross)])
-if test x"$libreplace_cv_HAVE_MMAP" = x"yes"; then
- AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
-fi
-
-AC_CACHE_CHECK([for working mremap],libreplace_cv_HAVE_MREMAP,[
-AC_TRY_RUN([#include "$libreplacedir/test/shared_mremap.c"],
- libreplace_cv_HAVE_MREMAP=yes,libreplace_cv_HAVE_MREMAP=no,libreplace_cv_HAVE_MREMAP=cross)])
-if test x"$libreplace_cv_HAVE_MREMAP" = x"yes"; then
- AC_DEFINE(HAVE_MREMAP,1,[Whether mremap works])
-fi
-
-AC_CACHE_CHECK([for incoherent mmap],libreplace_cv_HAVE_INCOHERENT_MMAP,[
-AC_TRY_RUN([#include "$libreplacedir/test/incoherent_mmap.c"],
- libreplace_cv_HAVE_INCOHERENT_MMAP=yes,libreplace_cv_HAVE_INCOHERENT_MMAP=no,libreplace_cv_HAVE_INCOHERENT_MMAP=cross)])
-if test x"$libreplace_cv_HAVE_INCOHERENT_MMAP" = x"yes"; then
- AC_DEFINE(HAVE_INCOHERENT_MMAP,1,[Whether mmap is incoherent against write])
-fi
-
-
-AC_CHECK_HEADERS(sys/syslog.h syslog.h)
-AC_CHECK_HEADERS(sys/time.h time.h)
-AC_CHECK_HEADERS(stdarg.h vararg.h)
-AC_CHECK_HEADERS(sys/mount.h mntent.h)
-AC_CHECK_HEADERS(stropts.h)
-AC_CHECK_HEADERS(unix.h)
-AC_CHECK_HEADERS(malloc.h)
-AC_CHECK_HEADERS(syscall.h)
-AC_CHECK_HEADERS(sys/syscall.h)
-
-AC_CHECK_FUNCS(syscall setuid seteuid setreuid setresuid setgid setegid setregid setresgid setgroups)
-AC_CHECK_FUNCS(chroot bzero strerror strerror_r memalign posix_memalign getpagesize)
-AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
-AC_CHECK_FUNCS(waitpid wait4 strlcpy strlcat initgroups memmove strdup)
-AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2 dprintf vdprintf)
-AC_CHECK_FUNCS(isatty chown lchown link readlink symlink realpath)
-AC_CHECK_FUNCS(fdatasync,,[
- # if we didn't find it, look in librt (Solaris hides it there...)
- AC_CHECK_LIB(rt, fdatasync,
- [libreplace_cv_HAVE_FDATASYNC_IN_LIBRT=yes
- AC_DEFINE(HAVE_FDATASYNC, 1, Define to 1 if there is support for fdatasync)])
-])
-AC_HAVE_DECL(fdatasync, [#include <unistd.h>])
-AC_CHECK_FUNCS(clock_gettime,libreplace_cv_have_clock_gettime=yes,[
- AC_CHECK_LIB(rt, clock_gettime,
- [libreplace_cv_HAVE_CLOCK_GETTIME_IN_LIBRT=yes
- libreplace_cv_have_clock_gettime=yes
- AC_DEFINE(HAVE_CLOCK_GETTIME, 1, Define to 1 if there is support for clock_gettime)])
-])
-
-AC_CHECK_HEADERS(sys/attributes.h attr/xattr.h sys/xattr.h sys/extattr.h sys/uio.h)
-AC_CHECK_HEADERS(sys/ea.h sys/proplist.h)
-
-LIBREPLACE_FILESYS_LIBS=""
-
-############################################
-# Check for EA implementations
-case "$host_os" in
- *freebsd4* | *dragonfly* )
- AC_DEFINE(BROKEN_EXTATTR, 1, [Does extattr API work])
- ;;
- *)
- AC_SEARCH_LIBS(getxattr, [attr])
- AC_CHECK_FUNCS(attr_get attr_getf attr_list attr_listf attropen attr_remove)
- AC_CHECK_FUNCS(attr_removef attr_set attr_setf extattr_delete_fd extattr_delete_file)
- AC_CHECK_FUNCS(extattr_get_fd extattr_get_file extattr_list_fd extattr_list_file)
- AC_CHECK_FUNCS(extattr_set_fd extattr_set_file fgetea fgetxattr flistea flistxattr)
- AC_CHECK_FUNCS(fremoveea fremovexattr fsetea fsetxattr getea getxattr listea)
- AC_CHECK_FUNCS(listxattr removeea removexattr setea setxattr)
-
- AC_CHECK_LIB_EXT(attr, LIBREPLACE_FILESYS_LIBS, flistea)
- AC_CHECK_LIB_EXT(attr, LIBREPLACE_FILESYS_LIBS, flistxattr)
- AC_CHECK_LIB_EXT(attr, LIBREPLACE_FILESYS_LIBS, attr_listf)
- AC_CHECK_LIB_EXT(attr, LIBREPLACE_FILESYS_LIBS, extattr_list_fd)
-
- ;;
-esac
-
-
-########################################################
-# Do xattr functions take additional options like on Darwin?
-if test x"$ac_cv_func_getxattr" = x"yes" ; then
- AC_CACHE_CHECK([whether xattr interface takes additional options], smb_attr_cv_xattr_add_opt, [
- old_LIBS=$LIBS
- LIBS="$LIBS $LIBREPLACE_FILESYS_LIBS"
- AC_TRY_COMPILE([
- #include <sys/types.h>
- #if HAVE_ATTR_XATTR_H
- #include <attr/xattr.h>
- #elif HAVE_SYS_XATTR_H
- #include <sys/xattr.h>
- #endif
- ],[
- getxattr(0, 0, 0, 0, 0, 0);
- ],
- [smb_attr_cv_xattr_add_opt=yes],
- [smb_attr_cv_xattr_add_opt=no;LIBS=$old_LIBS])
- ])
- if test x"$smb_attr_cv_xattr_add_opt" = x"yes"; then
- AC_DEFINE(XATTR_ADDITIONAL_OPTIONS, 1, [xattr functions have additional options])
- fi
-fi
-
-AC_CHECK_FUNCS(get_current_dir_name)
-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],libreplace_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";
- char tpl2[20]="/tmp/test.XXXXXX";
- int fd = mkstemp(tpl);
- int fd2 = mkstemp(tpl2);
- if (fd == -1) {
- if (fd2 != -1) {
- unlink(tpl2);
- }
- exit(1);
- }
- if (fd2 == -1) exit(1);
- unlink(tpl);
- unlink(tpl2);
- if (fstat(fd, &st) != 0) exit(1);
- if ((st.st_mode & 0777) != 0600) exit(1);
- if (strcmp(tpl, "/tmp/test.XXXXXX") == 0) {
- exit(1);
- }
- if (strcmp(tpl, tpl2) == 0) {
- exit(1);
- }
- exit(0);
-}],
-libreplace_cv_HAVE_SECURE_MKSTEMP=yes,
-libreplace_cv_HAVE_SECURE_MKSTEMP=no,
-libreplace_cv_HAVE_SECURE_MKSTEMP=cross)])
-if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
- AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
-fi
-
-dnl Provided by snprintf.c:
-AC_CHECK_HEADERS(stdio.h strings.h)
-AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
-AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
-
-AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[
-AC_TRY_RUN([
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.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(2);
-
- if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
-
- if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
- if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
- if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
- if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
-
- exit(0);
-}
-main() { foo("hello"); }
-],
-libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)])
-if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
- AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
-fi
-
-
-dnl VA_COPY
-AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[
-AC_TRY_LINK([#include <stdarg.h>
-va_list ap1,ap2;], [va_copy(ap1,ap2);],
-libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)])
-if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then
- AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
-fi
-
-if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then
-AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[
-AC_TRY_LINK([#include <stdarg.h>
-va_list ap1,ap2;], [__va_copy(ap1,ap2);],
-libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)])
-if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then
- AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
-fi
-fi
-
-dnl __FUNCTION__ macro
-AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[
-AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
-libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)])
-if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
- AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
-else
- dnl __func__ macro
- AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[
- AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
- libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)])
- if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then
- AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
- fi
-fi
-
-AC_CHECK_HEADERS([sys/param.h limits.h])
-
-AC_CHECK_TYPE(comparison_fn_t,
-[AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
-
-AC_HAVE_DECL(setenv, [#include <stdlib.h>])
-AC_CHECK_FUNCS(setenv unsetenv)
-AC_HAVE_DECL(environ, [#include <unistd.h>])
-
-AC_CHECK_FUNCS(strnlen)
-AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
-
-AC_CHECK_FUNCS(memmem)
-
-# this test disabled as we don't actually need __VA_ARGS__ yet
-AC_TRY_CPP([
-#define eprintf(...) fprintf(stderr, __VA_ARGS__)
-eprintf("bla", "bar");
-], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
-
-
-AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [
- AC_TRY_COMPILE([
-#include <sys/types.h>
-#if STDC_HEADERS
-#include <stdlib.h>
-#include <stddef.h>
-#endif
-#include <signal.h>],[sig_atomic_t i = 0],
- libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)])
-if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then
- AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
-fi
-
-
-AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[
-AC_TRY_COMPILE([
-#include <unistd.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif],
-[int fd = open("/dev/null", O_DIRECT);],
-libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)])
-if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
- AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
-fi
-
-
-dnl Check if the C compiler understands volatile (it should, being ANSI).
-AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [
- AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
- libreplace_cv_volatile=yes,libreplace_cv_volatile=no)])
-if test x"$libreplace_cv_volatile" = x"yes"; then
- AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
-fi
-
-m4_include(system/config.m4)
-
-m4_include(dlfcn.m4)
-m4_include(getpass.m4)
-m4_include(strptime.m4)
-m4_include(win32.m4)
-m4_include(timegm.m4)
-m4_include(repdir.m4)
-m4_include(crypt.m4)
-
-if test x$libreplace_cv_have_clock_gettime = xyes ; then
- SMB_CHECK_CLOCK_ID(CLOCK_MONOTONIC)
- SMB_CHECK_CLOCK_ID(CLOCK_PROCESS_CPUTIME_ID)
- SMB_CHECK_CLOCK_ID(CLOCK_REALTIME)
-fi
-
-AC_CACHE_CHECK([for struct timespec type],libreplace_cv_struct_timespec, [
- AC_TRY_COMPILE([
-#include <sys/types.h>
-#if STDC_HEADERS
-#include <stdlib.h>
-#include <stddef.h>
-#endif
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
-#endif
-],[struct timespec ts;],
- libreplace_cv_struct_timespec=yes,libreplace_cv_struct_timespec=no)])
-if test x"$libreplace_cv_struct_timespec" = x"yes"; then
- AC_DEFINE(HAVE_STRUCT_TIMESPEC,1,[Whether we have struct timespec])
-fi
-
-AC_CHECK_FUNCS([printf memset memcpy],,[AC_MSG_ERROR([Required function not found])])
-
-echo "LIBREPLACE_BROKEN_CHECKS: END"
-]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
-
-AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
-[
-#LIBREPLACE_ALL_CHECKS: START"
-])
-AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
-[
-#LIBREPLACE_ALL_CHECKS: END"
-])
-m4_define(AC_LIBREPLACE_ALL_CHECKS,
-[
-AC__LIBREPLACE_ALL_CHECKS_START
-AC_LIBREPLACE_LOCATION_CHECKS
-AC_LIBREPLACE_CC_CHECKS
-AC_LIBREPLACE_BROKEN_CHECKS
-AC__LIBREPLACE_ALL_CHECKS_END
-CFLAGS="$CFLAGS -I$libreplacedir"
-])
-
-m4_include(libreplace_cc.m4)
-m4_include(libreplace_ld.m4)
-m4_include(libreplace_network.m4)
-m4_include(libreplace_macros.m4)
-
-
-dnl SMB_CHECK_CLOCK_ID(clockid)
-dnl Test whether the specified clock_gettime clock ID is available. If it
-dnl is, we define HAVE_clockid
-AC_DEFUN([SMB_CHECK_CLOCK_ID],
-[
- AC_MSG_CHECKING(for $1)
- AC_TRY_LINK([
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
-#endif
- ],
- [
-clockid_t clk = $1;
- ],
- [
- AC_MSG_RESULT(yes)
- AC_DEFINE(HAVE_$1, 1,
- [Whether the clock_gettime clock ID $1 is available])
- ],
- [
- AC_MSG_RESULT(no)
- ])
-])
-m4_ifndef([AC_USE_SYSTEM_EXTENSIONS],[m4_include(autoconf-2.60.m4)])
diff --git a/lib/replace/libreplace_cc.m4 b/lib/replace/libreplace_cc.m4
deleted file mode 100644
index 50cb735..0000000
--- a/lib/replace/libreplace_cc.m4
+++ /dev/null
@@ -1,197 +0,0 @@
-
-AC_DEFUN_ONCE(AC__LIBREPLACE_ONLY_CC_CHECKS_START,
-[
-echo "LIBREPLACE_CC_CHECKS: START"
-])
-
-AC_DEFUN_ONCE(AC__LIBREPLACE_ONLY_CC_CHECKS_END,
-[
-echo "LIBREPLACE_CC_CHECKS: END"
-])
-
-dnl
-dnl
-dnl AC_LIBREPLACE_CC_CHECKS
-dnl
-dnl Note: we need to use m4_define instead of AC_DEFUN because
-dnl of the ordering of tests
-dnl
-dnl
-m4_define(AC_LIBREPLACE_CC_CHECKS,
-[
-AC__LIBREPLACE_ONLY_CC_CHECKS_START
-
-dnl stop the C89 attempt by autoconf - if autoconf detects -Ae it will enable it
-dnl which conflicts with C99 on HPUX
-ac_cv_prog_cc_Ae=no
-
-savedCFLAGS=$CFLAGS
-AC_PROG_CC
-CFLAGS=$savedCFLAGS
-
-dnl don't try for C99 if we are using gcc, as otherwise we
-dnl lose immediate structure constants
-if test x"$GCC" != x"yes" ; then
-AC_PROG_CC_C99
-fi
-
-if test x"$GCC" = x"yes" ; then
- AC_MSG_CHECKING([for version of gcc])
- GCC_VERSION=`$CC -dumpversion`
- AC_MSG_RESULT(${GCC_VERSION})
-fi
-AC_USE_SYSTEM_EXTENSIONS
-AC_C_BIGENDIAN
-AC_C_INLINE
-LIBREPLACE_C99_STRUCT_INIT([],[AC_MSG_WARN([c99 structure initializer are not supported])])
-
-AC_PROG_INSTALL
-
-AC_ISC_POSIX
-AC_N_DEFINE(_XOPEN_SOURCE_EXTENDED)
-
-AC_MSG_CHECKING(checking getconf LFS_CFLAGS for large file support flags)
-LFS_CFLAGS=`(getconf LFS_CFLAGS) 2>/dev/null` || LFS_CFLAGS=""
-
-AC_MSG_RESULT(${LFS_CFLAGS})
-if test "x$LFS_CFLAGS" != 'x-1' || test "x$LFS_CFLAGS" != "xundefined"; then
- CFLAGS="$CFLAGS $LFS_CFLAGS"
-fi
-
-AC_SYS_LARGEFILE
-
-dnl Add #include for broken IRIX header files
-case "$host_os" in
- *irix6*) AC_ADD_INCLUDE(<standards.h>)
- AC_N_DEFINE(_XOPEN_SOURCE,600)
- AC_N_DEFINE(_BSD_TYPES)
- ;;
- *hpux*)
- # mmap on HPUX is completely broken...
- AC_DEFINE(MMAP_BLACKLIST, 1, [Whether MMAP is broken])
- if test "`uname -r`" = "B.11.00" -o "`uname -r`" = "B.11.11"; then
- AC_MSG_WARN([Enabling HPUX 11.00/11.11 header bug workaround])
- CFLAGS="$CFLAGS -Dpread=pread64 -Dpwrite=pwrite64"
- fi
- if test "`uname -r`" = "B.11.23"; then
- AC_MSG_WARN([Enabling HPUX 11.23 machine/sys/getppdp.h bug workaround])
- CFLAGS="$CFLAGS -D_MACHINE_SYS_GETPPDP_INCLUDED"
- fi
- ;;
- *aix*)
- AC_DEFINE(BROKEN_STRNDUP, 1, [Whether strndup is broken])
- AC_DEFINE(BROKEN_STRNLEN, 1, [Whether strnlen is broken])
- if test "${GCC}" != "yes"; then
- ## for funky AIX compiler using strncpy()
- CFLAGS="$CFLAGS -D_LINUX_SOURCE_COMPAT -qmaxmem=32000"
- fi
- ;;
- *osf*)
- # this brings in socklen_t
- AC_N_DEFINE(_XOPEN_SOURCE,600)
- AC_N_DEFINE(_OSF_SOURCE)
- ;;
- #
- # VOS may need to have POSIX support and System V compatibility enabled.
- #
- *vos*)
- case "$CFLAGS" in
- *-D_POSIX_C_SOURCE*);;
- *)
- CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112L"
- AC_DEFINE(_POSIX_C_SOURCE, 200112L, [Whether to enable POSIX support])
- ;;
- esac
- case "$CFLAGS" in
- *-D_SYSV*|*-D_SVID_SOURCE*);;
- *)
- CFLAGS="$CFLAGS -D_SYSV"
- AC_DEFINE(_SYSV, 1, [Whether to enable System V compatibility])
- ;;
- esac
- ;;
-esac
-
-# Do not check for standards.h on darwin, we get nasty warnings on
-# OS/X Lion. Probably a positive-list of OS'es like IRIX and AIX
-# would be the better choice, but this seems to work fine
-
-case "$host_os" in
- *darwin*)
- ;;
- *)
- AC_CHECK_HEADERS([standards.h])
- ;;
-esac
-
-# Solaris needs HAVE_LONG_LONG defined
-AC_CHECK_TYPES(long long)
-
-AC_CHECK_SIZEOF(int)
-AC_CHECK_SIZEOF(char)
-AC_CHECK_SIZEOF(short)
-AC_CHECK_SIZEOF(long)
-AC_CHECK_SIZEOF(long long)
-
-AC_CHECK_TYPE(int8_t, char)
-AC_CHECK_TYPE(uint8_t, unsigned char)
-AC_CHECK_TYPE(int16_t, short)
-AC_CHECK_TYPE(uint16_t, unsigned short)
-
-if test $ac_cv_sizeof_int -eq 4 ; then
-AC_CHECK_TYPE(int32_t, int)
-AC_CHECK_TYPE(uint32_t, unsigned int)
-elif test $ac_cv_size_long -eq 4 ; then
-AC_CHECK_TYPE(int32_t, long)
-AC_CHECK_TYPE(uint32_t, unsigned long)
-else
-AC_MSG_ERROR([LIBREPLACE no 32-bit type found])
-fi
-
-AC_CHECK_TYPE(int64_t, long long)
-AC_CHECK_TYPE(uint64_t, unsigned long long)
-
-AC_CHECK_TYPE(size_t, unsigned int)
-AC_CHECK_TYPE(ssize_t, int)
-
-AC_CHECK_SIZEOF(off_t)
-AC_CHECK_SIZEOF(size_t)
-AC_CHECK_SIZEOF(ssize_t)
-
-AC_CHECK_TYPES([intptr_t, uintptr_t, ptrdiff_t])
-
-if test x"$ac_cv_type_long_long" != x"yes";then
- AC_MSG_ERROR([LIBREPLACE needs type 'long long'])
-fi
-if test $ac_cv_sizeof_long_long -lt 8;then
- AC_MSG_ERROR([LIBREPLACE needs sizeof(long long) >= 8])
-fi
-
-############################################
-# check if the compiler can do immediate structures
-AC_SUBST(libreplace_cv_immediate_structures)
-AC_CACHE_CHECK([for immediate structures],libreplace_cv_immediate_structures,[
- AC_TRY_COMPILE([
- #include <stdio.h>
- ],[
- typedef struct {unsigned x;} FOOBAR;
- #define X_FOOBAR(x) ((FOOBAR) { x })
- #define FOO_ONE X_FOOBAR(1)
- FOOBAR f = FOO_ONE;
- static const struct {
- FOOBAR y;
- } f2[] = {
- {FOO_ONE}
- };
- static const FOOBAR f3[] = {FOO_ONE};
- ],
- libreplace_cv_immediate_structures=yes,
- libreplace_cv_immediate_structures=no,
- libreplace_cv_immediate_structures=cross)
-])
-if test x"$libreplace_cv_immediate_structures" = x"yes"; then
- AC_DEFINE(HAVE_IMMEDIATE_STRUCTURES,1,[Whether the compiler supports immediate structures])
-fi
-
-AC__LIBREPLACE_ONLY_CC_CHECKS_END
-]) dnl end AC_LIBREPLACE_CC_CHECKS
diff --git a/lib/replace/libreplace_ld.m4 b/lib/replace/libreplace_ld.m4
deleted file mode 100644
index bf0df61..0000000
--- a/lib/replace/libreplace_ld.m4
+++ /dev/null
@@ -1,337 +0,0 @@
-#
-# This offers a nice overview how to build shared libraries on all platforms
-# http://www.fortran-2000.com/ArnaudRecipes/sharedlib.html
-#
-
-AC_DEFUN([AC_LIBREPLACE_STLD],
-[
- AC_PATH_PROG(PROG_AR, ar)
-
- STLD=${PROG_AR}
-
- AC_SUBST(STLD)
-])
-
-AC_DEFUN([AC_LIBREPLACE_STLD_FLAGS],
-[
- STLD_FLAGS="-rcs"
- AC_SUBST(STLD_FLAGS)
-])
-
-AC_DEFUN([AC_LD_EXPORT_DYNAMIC],
-[
-saved_LDFLAGS="$LDFLAGS"
-if AC_TRY_COMMAND([${CC-cc} $CFLAGS -Wl,--version 2>&1 | grep "GNU ld" >/dev/null]); then
- LD_EXPORT_DYNAMIC="-Wl,-export-dynamic"
-else
- case "$host_os" in
- hpux* )
- LD_EXPORT_DYNAMIC="-Wl,-E"
- ;;
- *)
- LD_EXPORT_DYNAMIC=""
- ;;
- esac
-fi
-AC_SUBST(LD_EXPORT_DYNAMIC)
-LDFLAGS="$saved_LDFLAGS"
-])
-
-AC_DEFUN([AC_LD_PICFLAG],
-[
-case "$host_os" in
- *linux*|*gnu*)
- PICFLAG="-fPIC"
- ;;
- *solaris*)
- if test "${GCC}" = "yes"; then
- PICFLAG="-fPIC"
- else
- PICFLAG="-KPIC"
- fi
- ;;
- *sunos*)
- PICFLAG="-KPIC" # Is this correct for SunOS
- ;;
- *netbsd* | *freebsd* | *dragonfly* )
- PICFLAG="-fPIC -DPIC"
- ;;
- *openbsd*)
- PICFLAG="-fPIC"
- ;;
- *irix*)
- if test "${GCC}" = "yes"; then
- PICFLAG="-fPIC"
- else
- PICFLAG="-KPIC"
- fi
- ;;
- *aix*)
- # as AIX code is always position independent...
- PICFLAG="-O2"
- ;;
- *hpux*)
- if test "${GCC}" = "yes"; then
- PICFLAG="-fPIC"
- elif test "$host_cpu" = "ia64"; then
- PICFLAG="+z"
- elif test $ac_cv_prog_cc_Ae = yes; then
- PICFLAG="+z +ESnolit"
- fi
- ;;
- *osf*)
- PICFLAG="-fPIC"
- ;;
- *unixware*)
- PICFLAG="-KPIC"
- ;;
- *darwin*)
- PICFLAG="-fno-common"
- ;;
-esac
-AC_SUBST(PICFLAG)
-])
-
-AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_LINKER],
-[
- LD_SHLIB_LINKER="${CC}"
-
- case "$host_os" in
- *irix*)
- LD_SHLIB_LINKER="${PROG_LD}"
- ;;
- esac
-
- AC_SUBST(LD_SHLIB_LINKER)
-])
-
-AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_FLAGS],
-[
- LD_SHLIB_FLAGS="-shared"
-
- case "$host_os" in
- *linux*|*gnu*)
- LD_SHLIB_FLAGS="-shared -Wl,-Bsymbolic"
- ;;
- *solaris*)
- LD_SHLIB_FLAGS="-G"
- if test "${GCC}" = "no"; then
- ## ${CFLAGS} added for building 64-bit shared
- ## libs using Sun's Compiler
- LD_SHLIB_FLAGS="-G \${CFLAGS}"
- fi
- ;;
- *sunos*)
- LD_SHLIB_FLAGS="-G"
- ;;
- *irix*)
- LD_SHLIB_FLAGS="-shared"
- ;;
- *aix*)
- LD_SHLIB_FLAGS="-Wl,-G,-bexpall,-bbigtoc"
- ;;
- *hpux*)
- if test "${GCC}" = "yes"; then
- LD_SHLIB_FLAGS="-shared"
- else
- LD_SHLIB_FLAGS="-b"
- fi
- ;;
- *osf*)
- LD_SHLIB_FLAGS="-shared"
- ;;
- *darwin*)
- LD_SHLIB_FLAGS="-dynamiclib -Wl,-search_paths_first"
- ;;
- esac
-
- AC_SUBST(LD_SHLIB_FLAGS)
-])
-
-AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_DISALLOW_UNDEF_FLAG],
-[
- LD_SHLIB_DISALLOW_UNDEF_FLAG=""
-
- #
- # TODO: enforce error not only warnings
- #
- # NOTE: -Wl,--no-allow-shlib-undefined isn't what we want...
- # as it bails out on broken system libraries
- #
- case "$host_os" in
- *osf*)
- LD_SHLIB_DISALLOW_UNDEF_FLAG="-warning_unresolved"
- ;;
- *darwin*)
- LD_SHLIB_DISALLOW_UNDEF_FLAG="-undefined error"
- ;;
- esac
-
- AC_SUBST(LD_SHLIB_DISALLOW_UNDEF_FLAG)
-])
-
-AC_DEFUN([AC_LIBREPLACE_SHLD],
-[
- AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_LINKER])
- SHLD="$LD_SHLIB_LINKER"
- AC_SUBST(SHLD)
-])
-
-AC_DEFUN([AC_LIBREPLACE_SHLD_FLAGS],
-[
- AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_FLAGS])
- AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_DISALLOW_UNDEF_FLAG])
- SHLD_FLAGS="$LD_SHLIB_FLAGS $LD_SHLIB_DISALLOW_UNDEF_FLAG"
- AC_SUBST(SHLD_FLAGS)
-])
-
-AC_DEFUN([AC_LD_SHLIBEXT],
-[
- SHLIBEXT="so"
- case "$host_os" in
- *hpux*)
- if test "$host_cpu" = "ia64"; then
- SHLIBEXT="so"
- else
- SHLIBEXT="sl"
- fi
- ;;
- *darwin*)
- SHLIBEXT="dylib"
- ;;
- esac
- AC_SUBST(SHLIBEXT)
-])
-
-AC_DEFUN([AC_LD_SONAMEFLAG],
-[
- AC_SUBST(SONAMEFLAG)
- SONAMEFLAG=""
- case "$host_os" in
- *linux*|*gnu*|*qnx*)
- SONAMEFLAG="-Wl,-soname="
- ;;
- *solaris*)
- SONAMEFLAG="-h "
- if test "${GCC}" = "yes"; then
- SONAMEFLAG="-Wl,-soname="
- fi
- ;;
- *sunos*)
- SONAMEFLAG="-Wl,-h,"
- ;;
- *netbsd* | *freebsd* | *dragonfly* )
- SONAMEFLAG="-Wl,-soname,"
- ;;
- *openbsd*)
- SONAMEFLAG="-Wl,-soname,"
- ;;
- *irix*)
- SONAMEFLAG="-Wl,-soname,"
- ;;
- *hpux*)
- SONAMEFLAG="-Wl,+h,"
- ;;
- *osf*)
- SONAMEFLAG="-Wl,-soname,"
- ;;
- *unixware*)
- SONAMEFLAG="-Wl,-soname,"
- ;;
- *darwin*)
- SONAMEFLAG="#"
- ;;
- *aix*)
- # Not supported
- SONAMEFLAG="#"
- ;;
- esac
-])
-
-AC_DEFUN([AC_LD_VERSIONSCRIPT],
-[
- AC_SUBST(VERSIONSCRIPT)
- VERSIONSCRIPT=""
- case "$host_os" in
- *linux*|*gnu*)
- VERSIONSCRIPT="-Wl,--version-script"
- ;;
- *solaris*)
- if test "${GCC}" = "yes"; then
- VERSIONSCRIPT="-Wl,--version-script"
- fi
- ;;
- esac
-])
-
-AC_DEFUN([AC_LIBREPLACE_MDLD],
-[
- AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_LINKER])
- MDLD="$LD_SHLIB_LINKER"
- AC_SUBST(MDLD)
-])
-
-AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_ALLOW_UNDEF_FLAG],
-[
- LD_ALLOW_SHLIB_UNDEF_FLAG=""
-
- case "$host_os" in
- *linux*|*gnu*)
- LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,--allow-shlib-undefined"
- ;;
- *osf*)
- LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,-expect_unresolved,\"*\""
- ;;
- *darwin*)
- LD_SHLIB_ALLOW_UNDEF_FLAG="-undefined dynamic_lookup"
- ;;
- *aix*)
- LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,-bnoentry"
- ;;
- esac
-
- AC_SUBST(LD_SHLIB_ALLOW_UNDEF_FLAG)
-])
-
-AC_DEFUN([AC_LIBREPLACE_MDLD_FLAGS],
-[
- AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_FLAGS])
- AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_ALLOW_UNDEF_FLAG])
- MDLD_FLAGS="$LD_SHLIB_FLAGS $LD_SHLIB_ALLOW_UNDEF_FLAG"
- AC_SUBST(MDLD_FLAGS)
-])
-
-AC_DEFUN([AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR],
-[
- case "$host_os" in
- *linux*|*gnu*)
- LIB_PATH_VAR=LD_LIBRARY_PATH
- ;;
- *bsd*)
- LIB_PATH_VAR=LD_LIBRARY_PATH
- ;;
- *solaris*)
- LIB_PATH_VAR=LD_LIBRARY_PATH
- ;;
- *hpux*)
- LIB_PATH_VAR=SHLIB_PATH
- ;;
- *osf*)
- LIB_PATH_VAR=LD_LIBRARY_PATH
- ;;
- *aix*)
- LIB_PATH_VAR=LIBPATH
- ;;
- *irix*)
- LIB_PATH_VAR=LD_LIBRARY_PATH
- ;;
- *darwin*)
- LIB_PATH_VAR=DYLD_LIBRARY_PATH
- ;;
- *)
- LIB_PATH_VAR=LD_LIBRARY_PATH
- ;;
- esac
-
- AC_SUBST(LIB_PATH_VAR)
-])
diff --git a/lib/replace/libreplace_macros.m4 b/lib/replace/libreplace_macros.m4
deleted file mode 100644
index 42b8847..0000000
--- a/lib/replace/libreplace_macros.m4
+++ /dev/null
@@ -1,332 +0,0 @@
-#
-# This is a collection of useful autoconf macros
-#
-
-############################################
-# Check if the compiler handles c99 struct initialization, and if not try -AC99 and -c99 flags
-# Usage: LIBREPLACE_C99_STRUCT_INIT(success-action,failure-action)
-# changes CFLAGS to add -AC99 or -c99 if needed
-AC_DEFUN([LIBREPLACE_C99_STRUCT_INIT],
-[
-saved_CFLAGS="$CFLAGS";
-c99_init=no
-if test x"$c99_init" = x"no"; then
- AC_MSG_CHECKING(for C99 designated initializers)
- CFLAGS="$saved_CFLAGS";
- AC_TRY_COMPILE([#include <stdio.h>],
- [ struct foo {int x;char y;};
- struct foo bar = { .y = 'X', .x = 1 };
- ],
- [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
-fi
-if test x"$c99_init" = x"no"; then
- AC_MSG_CHECKING(for C99 designated initializers with -AC99)
- CFLAGS="$saved_CFLAGS -AC99";
- AC_TRY_COMPILE([#include <stdio.h>],
- [ struct foo {int x;char y;};
- struct foo bar = { .y = 'X', .x = 1 };
- ],
- [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
-fi
-if test x"$c99_init" = x"no"; then
- AC_MSG_CHECKING(for C99 designated initializers with -qlanglvl=extc99)
- CFLAGS="$saved_CFLAGS -qlanglvl=extc99";
- AC_TRY_COMPILE([#include <stdio.h>],
- [ struct foo {int x;char y;};
- struct foo bar = { .y = 'X', .x = 1 };
- ],
- [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
-fi
-if test x"$c99_init" = x"no"; then
- AC_MSG_CHECKING(for C99 designated initializers with -qlanglvl=stdc99)
- CFLAGS="$saved_CFLAGS -qlanglvl=stdc99";
- AC_TRY_COMPILE([#include <stdio.h>],
- [ struct foo {int x;char y;};
- struct foo bar = { .y = 'X', .x = 1 };
- ],
- [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
-fi
-if test x"$c99_init" = x"no"; then
- AC_MSG_CHECKING(for C99 designated initializers with -c99)
- CFLAGS="$saved_CFLAGS -c99"
- AC_TRY_COMPILE([#include <stdio.h>],
- [ struct foo {int x;char y;};
- struct foo bar = { .y = 'X', .x = 1 };
- ],
- [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
-fi
-
-if test "`uname`" = "HP-UX"; then
- if test "$ac_cv_c_compiler_gnu" = no; then
- # special override for broken HP-UX compiler - I can't find a way to test
- # this properly (its a compiler bug)
- CFLAGS="$CFLAGS -AC99";
- c99_init=yes;
- fi
-fi
-
-if test x"$c99_init" = x"yes"; then
- saved_CFLAGS=""
- $1
-else
- CFLAGS="$saved_CFLAGS"
- saved_CFLAGS=""
- $2
-fi
-])
-
-dnl AC_PROG_CC_FLAG(flag)
-AC_DEFUN(AC_PROG_CC_FLAG,
-[AC_CACHE_CHECK(whether ${CC-cc} accepts -$1, ac_cv_prog_cc_$1,
-[echo 'void f(){}' > conftest.c
-if test -z "`${CC-cc} -$1 -c conftest.c 2>&1`"; then
- ac_cv_prog_cc_$1=yes
-else
- ac_cv_prog_cc_$1=no
-fi
-rm -f conftest*
-])])
-
-dnl see if a declaration exists for a function or variable
-dnl defines HAVE_function_DECL if it exists
-dnl AC_HAVE_DECL(var, includes)
-AC_DEFUN(AC_HAVE_DECL,
-[
- AC_CACHE_CHECK([for $1 declaration],ac_cv_have_$1_decl,[
- AC_TRY_COMPILE([$2],[int i = (int)$1],
- ac_cv_have_$1_decl=yes,ac_cv_have_$1_decl=no)])
- if test x"$ac_cv_have_$1_decl" = x"yes"; then
- AC_DEFINE([HAVE_]translit([$1], [a-z], [A-Z])[_DECL],1,[Whether $1() is available])
- fi
-])
-
-
-# AC_CHECK_LIB_EXT(LIBRARY, [EXT_LIBS], [FUNCTION],
-# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
-# [ADD-ACTION-IF-FOUND],[OTHER-LIBRARIES])
-# ------------------------------------------------------
-#
-# Use a cache variable name containing both the library and function name,
-# because the test really is for library $1 defining function $3, not
-# just for library $1. Separate tests with the same $1 and different $3s
-# may have different results.
-#
-# Note that using directly AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$3])
-# is asking for trouble, since AC_CHECK_LIB($lib, fun) would give
-# ac_cv_lib_$lib_fun, which is definitely not what was meant. Hence
-# the AS_LITERAL_IF indirection.
-#
-# FIXME: This macro is extremely suspicious. It DEFINEs unconditionally,
-# whatever the FUNCTION, in addition to not being a *S macro. Note
-# that the cache does depend upon the function we are looking for.
-#
-# It is on purpose we used `ac_check_lib_ext_save_LIBS' and not just
-# `ac_save_LIBS': there are many macros which don't want to see `LIBS'
-# changed but still want to use AC_CHECK_LIB_EXT, so they save `LIBS'.
-# And ``ac_save_LIBS' is too tempting a name, so let's leave them some
-# freedom.
-AC_DEFUN([AC_CHECK_LIB_EXT],
-[
-AH_CHECK_LIB_EXT([$1])
-ac_check_lib_ext_save_LIBS=$LIBS
-LIBS="-l$1 $$2 $7 $LIBS"
-AS_LITERAL_IF([$1],
- [AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1])],
- [AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1''])])dnl
-
-m4_ifval([$3],
- [
- AH_CHECK_FUNC_EXT([$3])
- AS_LITERAL_IF([$1],
- [AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1_$3])],
- [AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1''_$3])])dnl
- AC_CACHE_CHECK([for $3 in -l$1], ac_Lib_func,
- [AC_TRY_LINK_FUNC($3,
- [AS_VAR_SET(ac_Lib_func, yes);
- AS_VAR_SET(ac_Lib_ext, yes)],
- [AS_VAR_SET(ac_Lib_func, no);
- AS_VAR_SET(ac_Lib_ext, no)])
- ])
- AS_IF([test AS_VAR_GET(ac_Lib_func) = yes],
- [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$3))])dnl
- AS_VAR_POPDEF([ac_Lib_func])dnl
- ],[
- AC_CACHE_CHECK([for -l$1], ac_Lib_ext,
- [AC_TRY_LINK_FUNC([main],
- [AS_VAR_SET(ac_Lib_ext, yes)],
- [AS_VAR_SET(ac_Lib_ext, no)])
- ])
- ])
-LIBS=$ac_check_lib_ext_save_LIBS
-
-AS_IF([test AS_VAR_GET(ac_Lib_ext) = yes],
- [m4_default([$4],
- [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
- case "$$2" in
- *-l$1*)
- ;;
- *)
- $2="-l$1 $$2"
- ;;
- esac])
- [$6]
- ],
- [$5])dnl
-AS_VAR_POPDEF([ac_Lib_ext])dnl
-])# AC_CHECK_LIB_EXT
-
-# AH_CHECK_LIB_EXT(LIBNAME)
-# ---------------------
-m4_define([AH_CHECK_LIB_EXT],
-[AH_TEMPLATE(AS_TR_CPP(HAVE_LIB$1),
- [Define to 1 if you have the `]$1[' library (-l]$1[).])])
-
-dnl AC_SEARCH_LIBS_EXT(FUNCTION, SEARCH-LIBS, EXT_LIBS,
-dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
-dnl [OTHER-LIBRARIES])
-dnl --------------------------------------------------------
-dnl Search for a library defining FUNC, if it's not already available.
-AC_DEFUN([AC_SEARCH_LIBS_EXT],
-[AC_CACHE_CHECK([for library containing $1], [ac_cv_search_ext_$1],
-[
-ac_func_search_ext_save_LIBS=$LIBS
-ac_cv_search_ext_$1=no
-AC_LINK_IFELSE([AC_LANG_CALL([], [$1])],
- [ac_cv_search_ext_$1="none required"])
-if test "$ac_cv_search_ext_$1" = no; then
- for ac_lib in $2; do
- LIBS="-l$ac_lib $$3 $6 $ac_func_search_save_ext_LIBS"
- AC_LINK_IFELSE([AC_LANG_CALL([], [$1])],
- [ac_cv_search_ext_$1="-l$ac_lib"
-break])
- done
-fi
-LIBS=$ac_func_search_ext_save_LIBS])
-AS_IF([test "$ac_cv_search_ext_$1" != no],
- [test "$ac_cv_search_ext_$1" = "none required" || $3="$ac_cv_search_ext_$1 $$3"
- $4],
- [$5])dnl
-])
-
-dnl check for a function in a $LIBS and $OTHER_LIBS libraries variable.
-dnl AC_CHECK_FUNC_EXT(func,OTHER_LIBS,IF-TRUE,IF-FALSE)
-AC_DEFUN([AC_CHECK_FUNC_EXT],
-[
- AH_CHECK_FUNC_EXT($1)
- ac_check_func_ext_save_LIBS=$LIBS
- LIBS="$2 $LIBS"
- AS_VAR_PUSHDEF([ac_var], [ac_cv_func_ext_$1])dnl
- AC_CACHE_CHECK([for $1], ac_var,
- [AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY([$1])],
- [AS_VAR_SET(ac_var, yes)],
- [AS_VAR_SET(ac_var, no)])])
- LIBS=$ac_check_func_ext_save_LIBS
- AS_IF([test AS_VAR_GET(ac_var) = yes],
- [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1])) $3],
- [$4])dnl
-AS_VAR_POPDEF([ac_var])dnl
-])# AC_CHECK_FUNC
-
-# AH_CHECK_FUNC_EXT(FUNCNAME)
-# ---------------------
-m4_define([AH_CHECK_FUNC_EXT],
-[AH_TEMPLATE(AS_TR_CPP(HAVE_$1),
- [Define to 1 if you have the `]$1[' function.])])
-
-dnl Define an AC_DEFINE with ifndef guard.
-dnl AC_N_DEFINE(VARIABLE [, VALUE])
-AC_DEFUN([AC_N_DEFINE],
-[
-AH_VERBATIM([$1], [
-#ifndef $1
-# undef $1
-#endif
-])
-
- cat >>confdefs.h <<\EOF
-#ifndef $1
-[#define] $1 m4_if($#, 1, 1, [$2])
-#endif
-EOF
-])
-
-dnl Add an #include
-dnl AC_ADD_INCLUDE(VARIABLE)
-define(AC_ADD_INCLUDE,
-[cat >> confdefs.h <<\EOF
-[#include] $1
-EOF
-])
-
-dnl remove an #include
-dnl AC_REMOVE_INCLUDE(VARIABLE)
-define(AC_REMOVE_INCLUDE,
-[
-grep -v '[#include] $1' confdefs.h >confdefs.h.tmp
-cat confdefs.h.tmp > confdefs.h
-rm confdefs.h.tmp
-])
-
-dnl remove an #define
-dnl AC_REMOVE_DEFINE(VARIABLE)
-define(AC_REMOVE_DEFINE,
-[
-grep -v '[#define] $1 ' confdefs.h |grep -v '[#define] $1[$]'>confdefs.h.tmp
-cat confdefs.h.tmp > confdefs.h
-rm confdefs.h.tmp
-])
-
-dnl AS_HELP_STRING is not available in autoconf 2.57, and AC_HELP_STRING is deprecated
-dnl in autoconf 2.59, so define AS_HELP_STRING to be AC_HELP_STRING unless it is already
-dnl defined.
-m4_ifdef([AS_HELP_STRING], , [m4_define([AS_HELP_STRING], m4_defn([AC_HELP_STRING]))])
-
-dnl check if the prototype in the header matches the given one
-dnl AC_VERIFY_C_PROTOTYPE(prototype,functionbody,[IF-TRUE].[IF-FALSE],[extraheaders])
-AC_DEFUN(AC_VERIFY_C_PROTOTYPE,
-[AC_CACHE_CHECK([for prototype $1], AS_TR_SH([ac_cv_c_prototype_$1]),
- AC_COMPILE_IFELSE([AC_LANG_SOURCE([
- AC_INCLUDES_DEFAULT
- $5
- $1
- {
- $2
- }
- ])],[
- eval AS_TR_SH([ac_cv_c_prototype_$1])=yes
- ],[
- eval AS_TR_SH([ac_cv_c_prototype_$1])=no
- ])
-)
-AS_IF([eval test $AS_TR_SH([ac_cv_c_prototype_$1]) = yes],[$3],[$4])
-])
-
-AC_DEFUN(LIBREPLACE_PROVIDE_HEADER,
-[AC_CHECK_HEADER([$1],
- [ AC_CONFIG_COMMANDS(rm-$1, [rm -f $libreplacedir/$1], [libreplacedir=$libreplacedir]) ],
- [ AC_CONFIG_COMMANDS(mk-$1, [echo "#include \"replace.h\"" > $libreplacedir/$1], [libreplacedir=$libreplacedir]) ]
- )
-])
-
-dnl AC_HAVE_TYPE(TYPE,INCLUDES)
-AC_DEFUN([AC_HAVE_TYPE], [
-AC_REQUIRE([AC_HEADER_STDC])
-cv=`echo "$1" | sed 'y%./+- %__p__%'`
-AC_MSG_CHECKING(for $1)
-AC_CACHE_VAL([ac_cv_type_$cv],
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
-AC_INCLUDES_DEFAULT
-$2]],
-[[$1 foo;]])],
-[eval "ac_cv_type_$cv=yes"],
-[eval "ac_cv_type_$cv=no"]))dnl
-ac_foo=`eval echo \\$ac_cv_type_$cv`
-AC_MSG_RESULT($ac_foo)
-if test "$ac_foo" = yes; then
- ac_tr_hdr=HAVE_`echo $1 | sed 'y%abcdefghijklmnopqrstuvwxyz./- %ABCDEFGHIJKLMNOPQRSTUVWXYZ____%'`
-if false; then
- AC_CHECK_TYPES($1)
-fi
- AC_DEFINE_UNQUOTED($ac_tr_hdr, 1, [Define if you have type `$1'])
-fi
-])
diff --git a/lib/replace/libreplace_network.m4 b/lib/replace/libreplace_network.m4
deleted file mode 100644
index bb2a843..0000000
--- a/lib/replace/libreplace_network.m4
+++ /dev/null
@@ -1,503 +0,0 @@
-AC_DEFUN_ONCE(AC_LIBREPLACE_NETWORK_CHECKS,
-[
-echo "LIBREPLACE_NETWORK_CHECKS: START"
-
-AC_DEFINE(LIBREPLACE_NETWORK_CHECKS, 1, [LIBREPLACE_NETWORK_CHECKS were used])
-LIBREPLACE_NETWORK_OBJS=""
-LIBREPLACE_NETWORK_LIBS=""
-
-AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h)
-AC_CHECK_HEADERS(netinet/in_systm.h)
-AC_CHECK_HEADERS([netinet/ip.h], [], [],[
- #include <sys/types.h>
- #ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
- #endif
- #ifdef HAVE_NETINET_IN_SYSTM_H
- #include <netinet/in_systm.h>
- #endif
-])
-AC_CHECK_HEADERS(netinet/tcp.h netinet/in_ip.h)
-AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
-AC_CHECK_HEADERS(sys/uio.h)
-
-dnl we need to check that net/if.h really can be used, to cope with hpux
-dnl where including it always fails
-AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
- AC_COMPILE_IFELSE([AC_LANG_SOURCE([
- AC_INCLUDES_DEFAULT
- #if HAVE_SYS_SOCKET_H
- # include <sys/socket.h>
- #endif
- #include <net/if.h>
- int main(void) {return 0;}])],
- [libreplace_cv_USABLE_NET_IF_H=yes],
- [libreplace_cv_USABLE_NET_IF_H=no]
- )
-])
-if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
- AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
-fi
-
-AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
-AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
-AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
-AC_HAVE_TYPE([struct sockaddr], [#include <sys/socket.h>])
-AC_HAVE_TYPE([struct sockaddr_storage], [
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-])
-AC_HAVE_TYPE([struct sockaddr_in6], [
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-])
-
-if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then
-AC_CHECK_MEMBER(struct sockaddr_storage.ss_family,
- AC_DEFINE(HAVE_SS_FAMILY, 1, [Defined if struct sockaddr_storage has ss_family field]),,
- [
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netinet/in.h>
- ])
-
-if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then
-AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family,
- AC_DEFINE(HAVE___SS_FAMILY, 1, [Defined if struct sockaddr_storage has __ss_family field]),,
- [
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netinet/in.h>
- ])
-fi
-fi
-
-AC_CACHE_CHECK([for sin_len in sock],libreplace_cv_HAVE_SOCK_SIN_LEN,[
- AC_TRY_COMPILE(
- [
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
- ],[
-struct sockaddr_in sock; sock.sin_len = sizeof(sock);
- ],[
- libreplace_cv_HAVE_SOCK_SIN_LEN=yes
- ],[
- libreplace_cv_HAVE_SOCK_SIN_LEN=no
- ])
-])
-if test x"$libreplace_cv_HAVE_SOCK_SIN_LEN" = x"yes"; then
- AC_DEFINE(HAVE_SOCK_SIN_LEN,1,[Whether the sockaddr_in struct has a sin_len property])
-fi
-
-############################################
-# check for unix domain sockets
-AC_CACHE_CHECK([for unix domain sockets],libreplace_cv_HAVE_UNIXSOCKET,[
- AC_TRY_COMPILE([
-#include <sys/types.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <sys/socket.h>
-#include <sys/un.h>
- ],[
-struct sockaddr_un sunaddr;
-sunaddr.sun_family = AF_UNIX;
- ],[
- libreplace_cv_HAVE_UNIXSOCKET=yes
- ],[
- libreplace_cv_HAVE_UNIXSOCKET=no
- ])
-])
-if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then
- AC_DEFINE(HAVE_UNIXSOCKET,1,[If we need to build with unixscoket support])
-fi
-
-dnl The following test is roughly taken from the cvs sources.
-dnl
-dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
-dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
-dnl libsocket.so which has a bad implementation of gethostbyname (it
-dnl only looks in /etc/hosts), so we only look for -lsocket if we need
-dnl it.
-AC_CHECK_FUNCS(connect)
-if test x"$ac_cv_func_connect" = x"no"; then
- AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, connect)
- AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, connect)
- AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, connect)
- AC_CHECK_LIB_EXT(inet, LIBREPLACE_NETWORK_LIBS, connect)
- dnl We can't just call AC_CHECK_FUNCS(connect) here,
- dnl because the value has been cached.
- if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" ||
- test x"$ac_cv_lib_ext_nsl_connect" = x"yes" ||
- test x"$ac_cv_lib_ext_socket_connect" = x"yes" ||
- test x"$ac_cv_lib_ext_inet_connect" = x"yes"
- then
- AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
- fi
-fi
-
-AC_CHECK_FUNCS(gethostbyname)
-if test x"$ac_cv_func_gethostbyname" = x"no"; then
- AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, gethostbyname)
- AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, gethostbyname)
- AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, gethostbyname)
- dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here,
- dnl because the value has been cached.
- if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" ||
- test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" ||
- test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes"
- then
- AC_DEFINE(HAVE_GETHOSTBYNAME,1,
- [Whether the system has gethostbyname()])
- fi
-fi
-
-dnl HP-UX has if_nametoindex in -lipv6
-AC_CHECK_FUNCS(if_nametoindex)
-if test x"$ac_cv_func_if_nametoindex" = x"no"; then
- AC_CHECK_LIB_EXT(ipv6, LIBREPLACE_NETWORK_LIBS, if_nametoindex)
- dnl We can't just call AC_CHECK_FUNCS(if_nametoindex) here,
- dnl because the value has been cached.
- if test x"$ac_cv_lib_ext_ipv6_if_nametoindex" = x"yes"
- then
- AC_DEFINE(HAVE_IF_NAMETOINDEX, 1,
- [Whether the system has if_nametoindex()])
- fi
-fi
-
-# The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}"
-old_LIBS=$LIBS
-LIBS="${LIBREPLACE_NETWORK_LIBS}"
-libreplace_SAVE_CPPFLAGS="$CPPFLAGS"
-CPPFLAGS="$CPPFLAGS -I$libreplacedir"
-
-AC_CHECK_FUNCS(socketpair,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/socketpair.o"])
-
-AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
-AC_TRY_RUN([
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-main() { struct in_addr ip; ip.s_addr = 0x12345678;
-if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
- strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
-exit(1);}],
- libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
-
-AC_CHECK_FUNCS(inet_ntoa,[],[libreplace_cv_REPLACE_INET_NTOA=yes])
-if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
- AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
- LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_ntoa.o"
-fi
-
-AC_CHECK_FUNCS(inet_aton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_aton.o"])
-
-AC_CHECK_FUNCS(inet_ntop,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_ntop.o"])
-
-AC_CHECK_FUNCS(inet_pton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_pton.o"])
-
-dnl test for getaddrinfo/getnameinfo
-AC_CACHE_CHECK([for getaddrinfo],libreplace_cv_HAVE_GETADDRINFO,[
-AC_TRY_LINK([
-#include <sys/types.h>
-#if STDC_HEADERS
-#include <stdlib.h>
-#include <stddef.h>
-#endif
-#include <sys/socket.h>
-#include <netdb.h>],
-[
-struct sockaddr sa;
-struct addrinfo *ai = NULL;
-int ret = getaddrinfo(NULL, NULL, NULL, &ai);
-if (ret != 0) {
- const char *es = gai_strerror(ret);
-}
-freeaddrinfo(ai);
-ret = getnameinfo(&sa, sizeof(sa),
- NULL, 0,
- NULL, 0, 0);
-
-],
-libreplace_cv_HAVE_GETADDRINFO=yes,libreplace_cv_HAVE_GETADDRINFO=no)])
-
-if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
- # getaddrinfo is broken on some AIX systems
- # see bug 5910, use our replacements if we detect
- # a broken system.
- AC_TRY_RUN([
- #include <stddef.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netdb.h>
- int main(int argc, const char *argv[])
- {
- struct addrinfo hints = {0,};
- struct addrinfo *ppres;
- const char hostname1[] = "0.0.0.0";
- const char hostname2[] = "127.0.0.1";
- const char hostname3[] = "::";
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_family = AF_UNSPEC;
- hints.ai_flags =
- AI_NUMERICHOST|AI_PASSIVE|AI_ADDRCONFIG;
- /* Test for broken flag combination on AIX. */
- if (getaddrinfo(hostname1, NULL, &hints, &ppres) == EAI_BADFLAGS) {
- /* This fails on an IPv6-only box, but not with
- the EAI_BADFLAGS error. */
- return 1;
- }
- if (getaddrinfo(hostname2, NULL, &hints, &ppres) == 0) {
- /* IPv4 lookup works - good enough. */
- return 0;
- }
- /* Uh-oh, no IPv4. Are we IPv6-only ? */
- return getaddrinfo(hostname3, NULL, &hints, &ppres) != 0 ? 1 : 0;
- }],
- libreplace_cv_HAVE_GETADDRINFO=yes,
- libreplace_cv_HAVE_GETADDRINFO=no)
-fi
-
-if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
- AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo])
- AC_DEFINE(HAVE_GETNAMEINFO,1,[Whether the system has getnameinfo])
- AC_DEFINE(HAVE_FREEADDRINFO,1,[Whether the system has freeaddrinfo])
- AC_DEFINE(HAVE_GAI_STRERROR,1,[Whether the system has gai_strerror])
-else
- LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/getaddrinfo.o"
-fi
-
-AC_CHECK_HEADERS([ifaddrs.h])
-
-dnl Used when getifaddrs is not available
-AC_CHECK_MEMBERS([struct sockaddr.sa_len],
- [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])],
- [],
- [#include <sys/socket.h>])
-
-dnl test for getifaddrs and freeifaddrs
-AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[
-AC_TRY_LINK([
-#include <sys/types.h>
-#if STDC_HEADERS
-#include <stdlib.h>
-#include <stddef.h>
-#endif
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <ifaddrs.h>
-#include <netdb.h>],
-[
-struct ifaddrs *ifp = NULL;
-int ret = getifaddrs (&ifp);
-freeifaddrs(ifp);
-],
-libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)])
-if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then
- AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs])
- AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs])
- AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available])
-fi
-
-##################
-# look for a method of finding the list of network interfaces
-iface=no;
-AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[
-AC_TRY_RUN([
-#define HAVE_IFACE_GETIFADDRS 1
-#define NO_CONFIG_H 1
-#define AUTOCONF_TEST 1
-#define SOCKET_WRAPPER_NOT_REPLACE
-#include "$libreplacedir/replace.c"
-#include "$libreplacedir/inet_ntop.c"
-#include "$libreplacedir/snprintf.c"
-#include "$libreplacedir/getifaddrs.c"
-#define getifaddrs_test main
-#include "$libreplacedir/test/getifaddrs.c"],
- libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
-if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
- iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
-else
- LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/getifaddrs.o"
-fi
-
-
-if test $iface = no; then
-AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[
-AC_TRY_RUN([
-#define HAVE_IFACE_AIX 1
-#define NO_CONFIG_H 1
-#define AUTOCONF_TEST 1
-#undef _XOPEN_SOURCE_EXTENDED
-#define SOCKET_WRAPPER_NOT_REPLACE
-#include "$libreplacedir/replace.c"
-#include "$libreplacedir/inet_ntop.c"
-#include "$libreplacedir/snprintf.c"
-#include "$libreplacedir/getifaddrs.c"
-#define getifaddrs_test main
-#include "$libreplacedir/test/getifaddrs.c"],
- libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
-if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
- iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
-fi
-fi
-
-
-if test $iface = no; then
-AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[
-AC_TRY_RUN([
-#define HAVE_IFACE_IFCONF 1
-#define NO_CONFIG_H 1
-#define AUTOCONF_TEST 1
-#define SOCKET_WRAPPER_NOT_REPLACE
-#include "$libreplacedir/replace.c"
-#include "$libreplacedir/inet_ntop.c"
-#include "$libreplacedir/snprintf.c"
-#include "$libreplacedir/getifaddrs.c"
-#define getifaddrs_test main
-#include "$libreplacedir/test/getifaddrs.c"],
- libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
-if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
- iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
-fi
-fi
-
-if test $iface = no; then
-AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[
-AC_TRY_RUN([
-#define HAVE_IFACE_IFREQ 1
-#define NO_CONFIG_H 1
-#define AUTOCONF_TEST 1
-#define SOCKET_WRAPPER_NOT_REPLACE
-#include "$libreplacedir/replace.c"
-#include "$libreplacedir/inet_ntop.c"
-#include "$libreplacedir/snprintf.c"
-#include "$libreplacedir/getifaddrs.c"
-#define getifaddrs_test main
-#include "$libreplacedir/test/getifaddrs.c"],
- libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
-if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
- iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
-fi
-fi
-
-dnl Some old Linux systems have broken header files and
-dnl miss the IPV6_V6ONLY define in netinet/in.h,
-dnl but have it in linux/in6.h.
-dnl We can't include both files so we just check if the value
-dnl if defined and do the replacement in system/network.h
-AC_CACHE_CHECK([for IPV6_V6ONLY support],libreplace_cv_HAVE_IPV6_V6ONLY,[
- AC_TRY_COMPILE([
-#include <stdlib.h> /* for NULL */
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netdb.h>
-#include <netinet/in.h>
- ],
- [
-#ifndef IPV6_V6ONLY
-#error no IPV6_V6ONLY
-#endif
- ],[
- libreplace_cv_HAVE_IPV6_V6ONLY=yes
- ],[
- libreplace_cv_HAVE_IPV6_V6ONLY=no
- ])
-])
-if test x"$libreplace_cv_HAVE_IPV6_V6ONLY" != x"yes"; then
- dnl test for IPV6_V6ONLY
- AC_CACHE_CHECK([for IPV6_V6ONLY in linux/in6.h],libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26,[
- AC_TRY_COMPILE([
- #include <linux/in6.h>
- ],
- [
- #if (IPV6_V6ONLY != 26)
- #error no linux IPV6_V6ONLY
- #endif
- ],[
- libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26=yes
- ],[
- libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26=no
- ])
- ])
- if test x"$libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26" = x"yes"; then
- AC_DEFINE(HAVE_LINUX_IPV6_V6ONLY_26,1,[Whether the system has IPV6_V6ONLY in linux/in6.h])
- fi
-fi
-
-dnl test for ipv6
-AC_CACHE_CHECK([for ipv6 support],libreplace_cv_HAVE_IPV6,[
- AC_TRY_LINK([
-#include <stdlib.h> /* for NULL */
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netdb.h>
-#include <netinet/in.h>
- ],
- [
-struct sockaddr_storage sa_store;
-struct addrinfo *ai = NULL;
-struct in6_addr in6addr;
-int idx = if_nametoindex("iface1");
-int s = socket(AF_INET6, SOCK_STREAM, 0);
-int ret = getaddrinfo(NULL, NULL, NULL, &ai);
-if (ret != 0) {
- const char *es = gai_strerror(ret);
-}
-freeaddrinfo(ai);
-{
- int val = 1;
- #ifdef HAVE_LINUX_IPV6_V6ONLY_26
- #define IPV6_V6ONLY 26
- #endif
- ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
- (const void *)&val, sizeof(val));
-}
- ],[
- libreplace_cv_HAVE_IPV6=yes
- ],[
- libreplace_cv_HAVE_IPV6=no
- ])
-])
-if test x"$libreplace_cv_HAVE_IPV6" = x"yes"; then
- AC_DEFINE(HAVE_IPV6,1,[Whether the system has IPv6 support])
-fi
-
-LIBS=$old_LIBS
-CPPFLAGS="$libreplace_SAVE_CPPFLAGS"
-
-AC_CACHE_CHECK([for SO_PEERCRED],libreplace_cv_HAVE_PEERCRED,[
-AC_TRY_COMPILE([#include <sys/types.h>
-#include <sys/socket.h>],
-[struct ucred cred;
- socklen_t cred_len;
- int ret = getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len);
-],
-libreplace_cv_HAVE_PEERCRED=yes,libreplace_cv_HAVE_PEERCRED=no,libreplace_cv_HAVE_PEERCRED=cross)])
-if test x"$libreplace_cv_HAVE_PEERCRED" = x"yes"; then
- AC_DEFINE(HAVE_PEERCRED,1,[Whether we can use SO_PEERCRED to get socket credentials])
-fi
-
-AC_CACHE_CHECK([for getpeereid],libreplace_cv_HAVE_GETPEEREID,[
-AC_TRY_LINK([#include <sys/types.h>
-#include <unistd.h>],
-[uid_t uid; gid_t gid; int ret;
- ret = getpeereid(0, &uid, &gid);
-],
-libreplace_cv_HAVE_GETPEEREID=yes,libreplace_cv_HAVE_GETPEEREID=no)])
-if test x"$libreplace_cv_HAVE_GETPEEREID" = xyes; then
- AC_DEFINE(HAVE_GETPEEREID,1,
- [Whether we have getpeereid to get socket credentials])
-fi
-
-LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}"
-
-echo "LIBREPLACE_NETWORK_CHECKS: END"
-]) dnl end AC_LIBREPLACE_NETWORK_CHECKS
diff --git a/lib/replace/repdir.m4 b/lib/replace/repdir.m4
deleted file mode 100644
index 682ab44..0000000
--- a/lib/replace/repdir.m4
+++ /dev/null
@@ -1,81 +0,0 @@
-AC_CACHE_CHECK([for broken readdir],libreplace_cv_READDIR_NEEDED,[
- AC_TRY_RUN([
-#define test_readdir_os2_delete main
-#include "$libreplacedir/test/os2_delete.c"],
- [libreplace_cv_READDIR_NEEDED=no],
- [libreplace_cv_READDIR_NEEDED=yes],
- [libreplace_cv_READDIR_NEEDED="assuming not"])
-])
-
-AC_CHECK_FUNCS(dirfd)
-AC_HAVE_DECL(dirfd, [#include <dirent.h>])
-
-#
-# try to replace with getdirentries() if needed
-#
-if test x"$libreplace_cv_READDIR_NEEDED" = x"yes"; then
-AC_CHECK_FUNCS(getdirentries)
-AC_VERIFY_C_PROTOTYPE([long telldir(const DIR *dir)],
- [
- return 0;
- ],[
- AC_DEFINE(TELLDIR_TAKES_CONST_DIR, 1, [Whether telldir takes a const pointer])
- ],[],[
- #include <dirent.h>
- ])
-
-AC_VERIFY_C_PROTOTYPE([int seekdir(DIR *dir, long ofs)],
- [
- return 0;
- ],[
- AC_DEFINE(SEEKDIR_RETURNS_INT, 1, [Whether seekdir returns an int])
- ],[],[
- #include <dirent.h>
- ])
-AC_CACHE_CHECK([for replacing readdir using getdirentries()],libreplace_cv_READDIR_GETDIRENTRIES,[
- AC_TRY_RUN([
-#define _LIBREPLACE_REPLACE_H
-#include "$libreplacedir/repdir_getdirentries.c"
-#define test_readdir_os2_delete main
-#include "$libreplacedir/test/os2_delete.c"],
- [libreplace_cv_READDIR_GETDIRENTRIES=yes],
- [libreplace_cv_READDIR_GETDIRENTRIES=no])
-])
-fi
-if test x"$libreplace_cv_READDIR_GETDIRENTRIES" = x"yes"; then
- AC_DEFINE(REPLACE_READDIR,1,[replace readdir])
- AC_DEFINE(REPLACE_READDIR_GETDIRENTRIES,1,[replace readdir using getdirentries()])
- LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/repdir_getdirentries.o"
- libreplace_cv_READDIR_NEEDED=no
-fi
-
-#
-# try to replace with getdents() if needed
-#
-if test x"$libreplace_cv_READDIR_NEEDED" = x"yes"; then
-AC_CHECK_FUNCS(getdents)
-AC_CACHE_CHECK([for replacing readdir using getdents()],libreplace_cv_READDIR_GETDENTS,[
- AC_TRY_RUN([
-#define _LIBREPLACE_REPLACE_H
-#error _donot_use_getdents_replacement_anymore
-#include "$libreplacedir/repdir_getdents.c"
-#define test_readdir_os2_delete main
-#include "$libreplacedir/test/os2_delete.c"],
- [libreplace_cv_READDIR_GETDENTS=yes],
- [libreplace_cv_READDIR_GETDENTS=no])
-])
-fi
-if test x"$libreplace_cv_READDIR_GETDENTS" = x"yes"; then
- AC_DEFINE(REPLACE_READDIR,1,[replace readdir])
- AC_DEFINE(REPLACE_READDIR_GETDENTS,1,[replace readdir using getdents()])
- LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/repdir_getdents.o"
- libreplace_cv_READDIR_NEEDED=no
-fi
-
-AC_MSG_CHECKING([a usable readdir()])
-if test x"$libreplace_cv_READDIR_NEEDED" = x"yes"; then
- AC_MSG_RESULT(no)
- AC_MSG_WARN([the provided readdir() is broken])
-else
- AC_MSG_RESULT(yes)
-fi
diff --git a/lib/replace/replace.c b/lib/replace/replace.c
index e461471..37edb31 100644
--- a/lib/replace/replace.c
+++ b/lib/replace/replace.c
@@ -405,7 +405,7 @@ int rep_mkstemp(char *template)
mktemp(template);
if (template[0] == 0)
return -1;
- return open(p, O_CREAT|O_EXCL|O_RDWR, 0600);
+ return open(template, O_CREAT|O_EXCL|O_RDWR, 0600);
}
#endif
@@ -741,7 +741,7 @@ void *rep_memmem(const void *haystack, size_t haystacklen,
}
#endif
-#ifndef HAVE_VDPRINTF
+#if !defined(HAVE_VDPRINTF) || !defined(HAVE_C99_VSNPRINTF)
int rep_vdprintf(int fd, const char *format, va_list ap)
{
char *s = NULL;
@@ -758,7 +758,7 @@ int rep_vdprintf(int fd, const char *format, va_list ap)
}
#endif
-#ifndef HAVE_DPRINTF
+#if !defined(HAVE_DPRINTF) || !defined(HAVE_C99_VSNPRINTF)
int rep_dprintf(int fd, const char *format, ...)
{
int ret;
@@ -785,7 +785,7 @@ char *rep_get_current_dir_name(void)
}
#endif
-#if !defined(HAVE_STRERROR_R) || !defined(STRERROR_R_PROTO_COMPATIBLE)
+#ifndef HAVE_STRERROR_R
int rep_strerror_r(int errnum, char *buf, size_t buflen)
{
char *s = strerror(errnum);
diff --git a/lib/replace/replace.h b/lib/replace/replace.h
index bbea0fc..c0b7997 100644
--- a/lib/replace/replace.h
+++ b/lib/replace/replace.h
@@ -46,14 +46,14 @@
#endif
-#ifdef HAVE_STDINT_H
+#ifdef HAVE_INTTYPES_H
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+#elif HAVE_STDINT_H
#include <stdint.h>
/* force off HAVE_INTTYPES_H so that roken doesn't try to include both,
which causes a warning storm on irix */
#undef HAVE_INTTYPES_H
-#elif HAVE_INTTYPES_H
-#define __STDC_FORMAT_MACROS
-#include <inttypes.h>
#endif
#ifdef HAVE_MALLOC_H
@@ -108,6 +108,45 @@
# define PRIu64 __PRI64_PREFIX "u"
#endif
+#ifndef SCNd8
+# define SCNd8 "hhd"
+#endif
+#ifndef SCNd16
+# define SCNd16 "hd"
+#endif
+#ifndef SCNd32
+# define SCNd32 "d"
+#endif
+#ifndef SCNd64
+# define SCNd64 __PRI64_PREFIX "d"
+#endif
+
+#ifndef SCNi8
+# define SCNi8 "hhi"
+#endif
+#ifndef SCNi16
+# define SCNi16 "hi"
+#endif
+#ifndef SCNi32
+# define SCNi32 "i"
+#endif
+#ifndef SCNi64
+# define SCNi64 __PRI64_PREFIX "i"
+#endif
+
+#ifndef SCNu8
+# define SCNu8 "hhu"
+#endif
+#ifndef SCNu16
+# define SCNu16 "hu"
+#endif
+#ifndef SCNu32
+# define SCNu32 "u"
+#endif
+#ifndef SCNu64
+# define SCNu64 __PRI64_PREFIX "u"
+#endif
+
#ifdef HAVE_BSD_STRING_H
#include <bsd/string.h>
#endif
@@ -376,16 +415,6 @@ int rep_dlclose(void *handle);
/* prototype is in system/network.h */
#endif
-#ifndef HAVE_VDPRINTF
-#define vdprintf rep_vdprintf
-int rep_vdprintf(int fd, const char *format, va_list ap);
-#endif
-
-#ifndef HAVE_DPRINTF
-#define dprintf rep_dprintf
-int rep_dprintf(int fd, const char *format, ...);
-#endif
-
#ifndef PRINTF_ATTRIBUTE
#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
/** Use gcc attribute to check printf fns. a1 is the 1-based index of
@@ -406,7 +435,17 @@ int rep_dprintf(int fd, const char *format, ...);
#endif
#endif
-#ifndef HAVE_VASPRINTF
+#if !defined(HAVE_VDPRINTF) || !defined(HAVE_C99_VSNPRINTF)
+#define vdprintf rep_vdprintf
+int rep_vdprintf(int fd, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
+#endif
+
+#if !defined(HAVE_DPRINTF) || !defined(HAVE_C99_VSNPRINTF)
+#define dprintf rep_dprintf
+int rep_dprintf(int fd, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
+#endif
+
+#if !defined(HAVE_VASPRINTF) || !defined(HAVE_C99_VSNPRINTF)
#define vasprintf rep_vasprintf
int rep_vasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
#endif
@@ -421,11 +460,29 @@ int rep_snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
int rep_vsnprintf(char *,size_t ,const char *, va_list ap) PRINTF_ATTRIBUTE(3,0);
#endif
-#ifndef HAVE_ASPRINTF
+#if !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_VSNPRINTF)
#define asprintf rep_asprintf
int rep_asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
#endif
+#if !defined(HAVE_C99_VSNPRINTF)
+#ifdef REPLACE_BROKEN_PRINTF
+/*
+ * We do not redefine printf by default
+ * as it breaks the build if system headers
+ * use __attribute__((format(printf, 3, 0)))
+ * instead of __attribute__((format(__printf__, 3, 0)))
+ */
+#define printf rep_printf
+#endif
+int rep_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2);
+#endif
+
+#if !defined(HAVE_C99_VSNPRINTF)
+#define fprintf rep_fprintf
+int rep_fprintf(FILE *stream, const char *, ...) PRINTF_ATTRIBUTE(2,3);
+#endif
+
#ifndef HAVE_VSYSLOG
#ifdef HAVE_SYSLOG
#define vsyslog rep_vsyslog
@@ -552,8 +609,7 @@ ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset)
char *rep_get_current_dir_name(void);
#endif
-#if !defined(HAVE_STRERROR_R) || !defined(STRERROR_R_PROTO_COMPATIBLE)
-#undef strerror_r
+#ifndef HAVE_STRERROR_R
#define strerror_r rep_strerror_r
int rep_strerror_r(int errnum, char *buf, size_t buflen);
#endif
@@ -827,17 +883,6 @@ int fdatasync(int );
/* prototype is in "system/network.h" */
#endif
-#if !defined(getpass)
-#ifdef REPLACE_GETPASS
-#if defined(REPLACE_GETPASS_BY_GETPASSPHRASE)
-#define getpass(prompt) getpassphrase(prompt)
-#else
-#define getpass(prompt) rep_getpass(prompt)
-char *rep_getpass(const char *prompt);
-#endif
-#endif
-#endif
-
#ifndef HAVE_GETPEEREID
#define getpeereid rep_getpeereid
int rep_getpeereid(int s, uid_t *uid, gid_t *gid);
diff --git a/lib/replace/snprintf.c b/lib/replace/snprintf.c
index 877d2a1..6b4a711 100644
--- a/lib/replace/snprintf.c
+++ b/lib/replace/snprintf.c
@@ -1256,7 +1256,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list,
#endif
-#ifndef HAVE_VASPRINTF
+#if !defined(HAVE_VASPRINTF) || !defined(HAVE_C99_VSNPRINTF)
int rep_vasprintf(char **ptr, const char *format, va_list ap)
{
int ret;
@@ -1278,8 +1278,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list,
}
#endif
-
-#ifndef HAVE_ASPRINTF
+#if !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_VSNPRINTF)
int rep_asprintf(char **ptr, const char *format, ...)
{
va_list ap;
diff --git a/lib/replace/socket.c b/lib/replace/socket.c
index 35e975f..4cd9d2e 100644
--- a/lib/replace/socket.c
+++ b/lib/replace/socket.c
@@ -5,18 +5,22 @@
*
* Copyright (C) Michael Adam <obnox@samba.org> 2008
*
- * 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 3 of the License, or
- * (at your option) any later version.
+ * ** NOTE! The following LGPL license applies to the replace
+ * ** library. This does NOT imply that all of Samba is released
+ * ** under the LGPL
*
- * This program is distributed in the hope that it will be useful,
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library 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.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "replace.h"
diff --git a/lib/replace/strptime.m4 b/lib/replace/strptime.m4
deleted file mode 100644
index 8ac22f6..0000000
--- a/lib/replace/strptime.m4
+++ /dev/null
@@ -1,16 +0,0 @@
-AC_CHECK_FUNCS(strptime)
-AC_CHECK_DECLS(strptime, [], [], [#include <time.h>])
-AC_CACHE_CHECK([whether strptime is available and works],libreplace_cv_STRPTIME_OK,[
- AC_TRY_RUN([
- #define LIBREPLACE_CONFIGURE_TEST_STRPTIME
- #include "$libreplacedir/test/strptime.c"
- ],
- [libreplace_cv_STRPTIME_OK=yes],
- [libreplace_cv_STRPTIME_OK=no],
- [libreplace_cv_STRPTIME_OK="assuming not"])
-])
-if test x"$libreplace_cv_STRPTIME_OK" != x"yes"; then
- LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/strptime.o"
-else
- AC_DEFINE(HAVE_WORKING_STRPTIME,1,[Whether strptime is working correct])
-fi
diff --git a/lib/replace/system/config.m4 b/lib/replace/system/config.m4
deleted file mode 100644
index b7cdf14..0000000
--- a/lib/replace/system/config.m4
+++ /dev/null
@@ -1,145 +0,0 @@
-# filesys
-AC_HEADER_DIRENT
-AC_CHECK_HEADERS(fcntl.h sys/fcntl.h sys/resource.h sys/ioctl.h sys/mode.h sys/filio.h sys/fs/s5param.h sys/filsys.h)
-AC_CHECK_HEADERS(sys/acl.h acl/libacl.h sys/file.h)
-
-# select
-AC_CHECK_HEADERS(sys/select.h)
-
-# poll
-AC_CHECK_HEADERS(poll.h)
-AC_CHECK_FUNCS(poll,[],[LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/poll.o"])
-
-# time
-AC_CHECK_HEADERS(sys/time.h utime.h)
-AC_HEADER_TIME
-AC_CHECK_FUNCS(utime utimes)
-
-AC_CACHE_CHECK([if gettimeofday takes TZ argument],libreplace_cv_HAVE_GETTIMEOFDAY_TZ,[
-AC_TRY_RUN([
-#include <sys/time.h>
-#include <unistd.h>
-main() { struct timeval tv; exit(gettimeofday(&tv, NULL));}],
- libreplace_cv_HAVE_GETTIMEOFDAY_TZ=yes,libreplace_cv_HAVE_GETTIMEOFDAY_TZ=no,libreplace_cv_HAVE_GETTIMEOFDAY_TZ=yes)])
-if test x"$libreplace_cv_HAVE_GETTIMEOFDAY_TZ" = x"yes"; then
- AC_DEFINE(HAVE_GETTIMEOFDAY_TZ,1,[Whether gettimeofday() is available])
-fi
-
-# wait
-AC_HEADER_SYS_WAIT
-
-# capability
-AC_CHECK_HEADERS(sys/capability.h)
-
-case "$host_os" in
-*linux*)
-AC_CACHE_CHECK([for broken RedHat 7.2 system header files],libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS,[
-AC_TRY_COMPILE([
- #ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
- #endif
- #ifdef HAVE_SYS_CAPABILITY_H
- #include <sys/capability.h>
- #endif
- ],[
- int i;
- ],
- libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=no,
- libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=yes
-)])
-if test x"$libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS" = x"yes"; then
- AC_DEFINE(BROKEN_REDHAT_7_SYSTEM_HEADERS,1,[Broken RedHat 7.2 system header files])
-fi
-
-AC_CACHE_CHECK([for broken RHEL5 sys/capability.h],libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER,[
-AC_TRY_COMPILE([
- #ifdef HAVE_SYS_CAPABILITY_H
- #include <sys/capability.h>
- #endif
- #include <linux/types.h>
- ],[
- __s8 i;
- ],
- libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER=no,
- libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER=yes
-)])
-if test x"$libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER" = x"yes"; then
- AC_DEFINE(BROKEN_RHEL5_SYS_CAP_HEADER,1,[Broken RHEL5 sys/capability.h])
-fi
-;;
-esac
-
-# passwd
-AC_CHECK_HEADERS(grp.h sys/id.h compat.h shadow.h sys/priv.h pwd.h sys/security.h)
-AC_CHECK_FUNCS(getpwnam_r getpwuid_r getpwent_r)
-AC_HAVE_DECL(getpwent_r, [
- #include <unistd.h>
- #include <pwd.h>
- ])
-AC_VERIFY_C_PROTOTYPE([struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)],
- [
- #ifndef HAVE_GETPWENT_R_DECL
- #error missing getpwent_r prototype
- #endif
- return NULL;
- ],[
- AC_DEFINE(SOLARIS_GETPWENT_R, 1, [getpwent_r solaris function prototype])
- ],[],[
- #include <unistd.h>
- #include <pwd.h>
- ])
-AC_VERIFY_C_PROTOTYPE([struct passwd *getpwent_r(struct passwd *src, char *buf, size_t buflen)],
- [
- #ifndef HAVE_GETPWENT_R_DECL
- #error missing getpwent_r prototype
- #endif
- return NULL;
- ],[
- AC_DEFINE(SOLARIS_GETPWENT_R, 1, [getpwent_r irix (similar to solaris) function prototype])
- ],[],[
- #include <unistd.h>
- #include <pwd.h>
- ])
-AC_CHECK_FUNCS(getgrnam_r getgrgid_r getgrent_r)
-AC_HAVE_DECL(getgrent_r, [
- #include <unistd.h>
- #include <grp.h>
- ])
-AC_VERIFY_C_PROTOTYPE([struct group *getgrent_r(struct group *src, char *buf, int buflen)],
- [
- #ifndef HAVE_GETGRENT_R_DECL
- #error missing getgrent_r prototype
- #endif
- return NULL;
- ],[
- AC_DEFINE(SOLARIS_GETGRENT_R, 1, [getgrent_r solaris function prototype])
- ],[],[
- #include <unistd.h>
- #include <grp.h>
- ])
-
-AC_VERIFY_C_PROTOTYPE([struct group *getgrent_r(struct group *src, char *buf, size_t buflen)],
- [
- #ifndef HAVE_GETGRENT_R_DECL
- #error missing getgrent_r prototype
- #endif
- return NULL;
- ],[
- AC_DEFINE(SOLARIS_GETGRENT_R, 1, [getgrent_r irix (similar to solaris) function prototype])
- ],[],[
- #include <unistd.h>
- #include <grp.h>
- ])
-AC_CHECK_FUNCS(getgrouplist)
-
-# locale
-AC_CHECK_HEADERS(ctype.h locale.h langinfo.h)
-
-# glob
-AC_CHECK_HEADERS(fnmatch.h)
-
-# shmem
-AC_CHECK_HEADERS(sys/ipc.h sys/mman.h sys/shm.h )
-
-# terminal
-AC_CHECK_HEADERS(termios.h termio.h sys/termio.h )
diff --git a/lib/replace/system/passwd.h b/lib/replace/system/passwd.h
index 223324c..8257e06 100644
--- a/lib/replace/system/passwd.h
+++ b/lib/replace/system/passwd.h
@@ -67,17 +67,6 @@
#include <compat.h>
#endif
-#if !defined(getpass)
-#ifdef REPLACE_GETPASS
-#if defined(REPLACE_GETPASS_BY_GETPASSPHRASE)
-#define getpass(prompt) getpassphrase(prompt)
-#else
-#define getpass(prompt) rep_getpass(prompt)
-char *rep_getpass(const char *prompt);
-#endif
-#endif
-#endif
-
#ifndef NGROUPS_MAX
#define NGROUPS_MAX 32 /* Guess... */
#endif
diff --git a/lib/replace/system/wait.h b/lib/replace/system/wait.h
index f0c3bdc..146c61a 100644
--- a/lib/replace/system/wait.h
+++ b/lib/replace/system/wait.h
@@ -40,6 +40,10 @@
#include <setjmp.h>
#endif
+#ifdef HAVE_SYS_UCONTEXT_H
+#include <sys/ucontext.h>
+#endif
+
#if !defined(HAVE_SIG_ATOMIC_T_TYPE)
typedef int sig_atomic_t;
#endif
diff --git a/lib/replace/test/getifaddrs.c b/lib/replace/test/getifaddrs.c
index d325d8b..8d575af 100644
--- a/lib/replace/test/getifaddrs.c
+++ b/lib/replace/test/getifaddrs.c
@@ -5,18 +5,22 @@
*
* Copyright (C) Michael Adam <obnox@samba.org> 2008
*
- * 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 3 of the License, or
- * (at your option) any later version.
+ * ** NOTE! The following LGPL license applies to the replace
+ * ** library. This does NOT imply that all of Samba is released
+ * ** under the LGPL
*
- * 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.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
*
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AUTOCONF_TEST
diff --git a/lib/replace/test/testsuite.c b/lib/replace/test/testsuite.c
index 04658be..52629ec 100644
--- a/lib/replace/test/testsuite.c
+++ b/lib/replace/test/testsuite.c
@@ -463,12 +463,6 @@ static int test_pwrite(void)
return true;
}
-static int test_getpass(void)
-{
- /* FIXME */
- return true;
-}
-
static int test_inet_ntoa(void)
{
/* FIXME */
@@ -1089,7 +1083,6 @@ bool torture_local_replace(struct torture_context *ctx)
ret &= test_mkstemp();
ret &= test_pread();
ret &= test_pwrite();
- ret &= test_getpass();
ret &= test_inet_ntoa();
ret &= test_strtoll();
ret &= test_strtoull();
diff --git a/lib/replace/timegm.m4 b/lib/replace/timegm.m4
deleted file mode 100644
index 9b76d0c..0000000
--- a/lib/replace/timegm.m4
+++ /dev/null
@@ -1 +0,0 @@
-AC_CHECK_FUNCS(timegm,[],[LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/timegm.o"])
diff --git a/lib/replace/win32.m4 b/lib/replace/win32.m4
deleted file mode 100644
index eb364e2..0000000
--- a/lib/replace/win32.m4
+++ /dev/null
@@ -1,20 +0,0 @@
-AC_CHECK_HEADERS(direct.h windows.h winsock2.h ws2tcpip.h)
-
-#######################################
-# Check for mkdir mode
-AC_CACHE_CHECK( [whether mkdir supports mode], libreplace_cv_mkdir_has_mode,
- AC_TRY_COMPILE([
- #include <stdio.h>
- #ifdef HAVE_DIRECT_H
- #include <direct.h>
- #endif],[
- mkdir("foo",0777);
- return 0;
- ],
- libreplace_cv_mkdir_has_mode="yes",
- libreplace_cv_mkdir_has_mode="no") )
-
-if test "$libreplace_cv_mkdir_has_mode" = "yes"
-then
- AC_DEFINE(HAVE_MKDIR_MODE, 1, [Define if target mkdir supports mode option])
-fi
diff --git a/lib/replace/wscript b/lib/replace/wscript
index 732c664..2117f56 100644
--- a/lib/replace/wscript
+++ b/lib/replace/wscript
@@ -53,8 +53,16 @@ struct foo bar = { .y = 'X', .x = 1 };
conf.ADD_CFLAGS(f)
break
+ if conf.CHECK_CFLAGS(['-fstack-protector']) and conf.CHECK_LDFLAGS(['-fstack-protector']):
+ conf.ADD_CFLAGS('-fstack-protector')
+ conf.ADD_LDFLAGS('-fstack-protector')
+
# Try to find the right extra flags for -Werror behaviour
- for f in ["-Werror", "-w2", "-errwarn"]:
+ for f in ["-Werror", # GCC
+ "-errwarn=%all", # Sun Studio
+ "-qhalt=w", # IBM xlc
+ "-w2", # Tru64
+ ]:
if conf.CHECK_CFLAGS([f], '''
'''):
if not 'WERROR_CFLAGS' in conf.env:
@@ -72,7 +80,7 @@ struct foo bar = { .y = 'X', .x = 1 };
conf.CHECK_HEADERS('sys/id.h sys/ioctl.h sys/ipc.h sys/mman.h sys/mode.h sys/ndir.h sys/priv.h')
conf.CHECK_HEADERS('sys/resource.h sys/security.h sys/shm.h sys/statfs.h sys/statvfs.h sys/termio.h')
conf.CHECK_HEADERS('sys/vfs.h sys/xattr.h termio.h termios.h sys/file.h')
- conf.CHECK_HEADERS('sys/wait.h sys/stat.h malloc.h grp.h')
+ conf.CHECK_HEADERS('sys/ucontext.h sys/wait.h sys/stat.h malloc.h grp.h')
conf.CHECK_HEADERS('sys/select.h setjmp.h utime.h sys/syslog.h syslog.h')
conf.CHECK_HEADERS('stdarg.h vararg.h sys/mount.h mntent.h')
conf.CHECK_HEADERS('stropts.h unix.h string.h strings.h sys/param.h limits.h')
@@ -87,15 +95,41 @@ struct foo bar = { .y = 'X', .x = 1 };
conf.CHECK_HEADERS('security/pam_appl.h zlib.h asm/unistd.h')
conf.CHECK_HEADERS('aio.h sys/unistd.h rpc/rpc.h rpc/nettype.h alloca.h float.h')
- conf.CHECK_HEADERS('rpcsvc/nis.h rpcsvc/ypclnt.h sys/prctl.h sys/sysctl.h')
+ conf.CHECK_HEADERS('rpcsvc/nis.h rpcsvc/ypclnt.h sys/sysctl.h')
conf.CHECK_HEADERS('sys/fileio.h sys/filesys.h sys/dustat.h sys/sysmacros.h')
- conf.CHECK_HEADERS('xfs/libxfs.h netgroup.h rpcsvc/yp_prot.h')
+ conf.CHECK_HEADERS('xfs/libxfs.h netgroup.h')
+
+ conf.CHECK_CODE('', headers='rpc/rpc.h rpcsvc/yp_prot.h', define='HAVE_RPCSVC_YP_PROT_H')
+
conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h valgrind/memcheck.h')
conf.CHECK_HEADERS('nss_common.h nsswitch.h ns_api.h')
conf.CHECK_HEADERS('sys/extattr.h sys/ea.h sys/proplist.h sys/cdefs.h')
conf.CHECK_HEADERS('utmp.h utmpx.h lastlog.h malloc.h')
conf.CHECK_HEADERS('syscall.h sys/syscall.h inttypes.h')
+ # Check for process set name support
+ conf.CHECK_CODE('''
+ #include <sys/prctl.h>
+ int main(void) {
+ prctl(0);
+ return 0;
+ }
+ ''',
+ 'HAVE_PRCTL',
+ headers='sys/prctl.h',
+ msg='Checking for prctl syscall')
+
+ conf.CHECK_CODE('''
+ #include <unistd.h>
+ #ifdef HAVE_FCNTL_H
+ #include <fcntl.h>
+ #endif
+ int main(void) { int fd = open("/dev/null", O_DIRECT); }
+ ''',
+ define='HAVE_OPEN_O_DIRECT',
+ addmain=False,
+ msg='Checking for O_DIRECT flag to open(2)')
+
conf.CHECK_TYPES('"long long" intptr_t uintptr_t ptrdiff_t comparison_fn_t')
conf.CHECK_TYPE('_Bool', define='HAVE__Bool')
conf.CHECK_TYPE('bool', define='HAVE_BOOL')
@@ -182,9 +216,31 @@ struct foo bar = { .y = 'X', .x = 1 };
lib='nsl socket',
headers='sys/socket.h netdb.h netinet/in.h')
+ if conf.CONFIG_SET('HAVE_SYS_UCONTEXT_H') and conf.CONFIG_SET('HAVE_SIGNAL_H'):
+ conf.CHECK_CODE('''
+ ucontext_t uc;
+ sigaddset(&uc.uc_sigmask, SIGUSR1);
+ ''',
+ 'HAVE_UCONTEXT_T',
+ msg="Checking whether we have ucontext_t",
+ headers='signal.h sys/ucontext.h')
+
# these may be builtins, so we need the link=False strategy
conf.CHECK_FUNCS('strdup memmem printf memset memcpy memmove strcpy strncpy bzero', link=False)
+ # See https://bugzilla.samba.org/show_bug.cgi?id=1097
+ #
+ # Ported in from autoconf where it was added with this commit:
+ # commit 804cfb20a067b4b687089dc72a8271b3abf20f31
+ # Author: Simo Sorce <idra@samba.org>
+ # Date: Wed Aug 25 14:24:16 2004 +0000
+ # r2070: Let's try to overload srnlen and strndup for AIX where they are natly broken.
+
+ host_os = sys.platform
+ if host_os.rfind('aix') > -1:
+ conf.DEFINE('BROKEN_STRNLEN', 1)
+ conf.DEFINE('BROKEN_STRNDUP', 1)
+
conf.CHECK_FUNCS('shl_load shl_unload shl_findsym')
conf.CHECK_FUNCS('pipe strftime srandom random srand rand usleep setbuffer')
conf.CHECK_FUNCS('lstat getpgrp utime utimes setuid seteuid setreuid setresuid setgid setegid')
@@ -195,6 +251,7 @@ struct foo bar = { .y = 'X', .x = 1 };
conf.CHECK_FUNCS('link readlink symlink realpath snprintf vsnprintf')
conf.CHECK_FUNCS('asprintf vasprintf setenv unsetenv strnlen strtoull __strtoull')
conf.CHECK_FUNCS('strtouq strtoll __strtoll strtoq memalign posix_memalign')
+ conf.CHECK_FUNCS('prctl')
# libbsd on some platforms provides strlcpy and strlcat
if not conf.CHECK_FUNCS('strlcpy strlcat'):
@@ -227,7 +284,6 @@ struct foo bar = { .y = 'X', .x = 1 };
msg="Checking correct behavior of strtoll",
headers = 'errno.h',
execute = True,
- define_ret = True,
define = 'HAVE_BSD_STRTOLL',
)
conf.CHECK_FUNCS('if_nametoindex strerror_r')
@@ -254,7 +310,7 @@ listxattr removexattr setxattr
attr_get attr_getf attr_list attr_listf attropen attr_remove
attr_removef attr_set attr_setf extattr_delete_fd extattr_delete_file
extattr_get_fd extattr_get_file extattr_list_fd extattr_list_file
-extattr_set_fd extattr_set_file fgetea flistea
+extattr_set_fd extattr_set_file fgetea
fremoveea fsetea getea listea
removeea setea
''', 'attr', checklibc=True, headers=xattr_headers)
@@ -473,17 +529,6 @@ removeea setea
execute=True):
break
- if conf.CHECK_FUNCS('getpass getpassphrase'):
- # if we have both, then we prefer getpassphrase
- conf.DEFINE('REPLACE_GETPASS_BY_GETPASSPHRASE', 1)
- conf.DEFINE('REPLACE_GETPASS', 1)
- else:
- conf.CHECK_CODE('''#include "getpass.c"
- int main(void) { return 0; }''',
- addmain=False,
- define='REPLACE_GETPASS',
- cflags='-DNO_CONFIG_H')
-
conf.RECURSE('system')
conf.SAMBA_CONFIG_H()
@@ -533,7 +578,6 @@ def build(bld):
REPLACE_SOURCE = REPLACE_HOSTCC_SOURCE
- if bld.CONFIG_SET('REPLACE_GETPASS'): REPLACE_SOURCE += ' getpass.c'
if not bld.CONFIG_SET('HAVE_CRYPT'): REPLACE_SOURCE += ' crypt.c'
if not bld.CONFIG_SET('HAVE_DLOPEN'): REPLACE_SOURCE += ' dlfcn.c'
if not bld.CONFIG_SET('HAVE_POLL'): REPLACE_SOURCE += ' poll.c'
diff --git a/lib/replace/xattr.c b/lib/replace/xattr.c
index 8e1c989..a26ff67 100644
--- a/lib/replace/xattr.c
+++ b/lib/replace/xattr.c
@@ -71,7 +71,9 @@ ssize_t rep_getxattr (const char *path, const char *name, void *value, size_t si
* that the buffer is large enough to fit the returned value.
*/
if((retval=extattr_get_file(path, attrnamespace, attrname, NULL, 0)) >= 0) {
- if(retval > size) {
+ if (size == 0) {
+ return retval;
+ } else if (retval > size) {
errno = ERANGE;
return -1;
}
@@ -88,6 +90,9 @@ ssize_t rep_getxattr (const char *path, const char *name, void *value, size_t si
if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
+ if (size == 0 && retval == -1 && errno == E2BIG) {
+ return valuelength;
+ }
return retval ? retval : valuelength;
#elif defined(HAVE_ATTROPEN)
@@ -126,7 +131,9 @@ ssize_t rep_fgetxattr (int filedes, const char *name, void *value, size_t size)
const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1;
if((retval=extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0)) >= 0) {
- if(retval > size) {
+ if (size == 0) {
+ return retval;
+ } else if (retval > size) {
errno = ERANGE;
return -1;
}
@@ -143,7 +150,9 @@ ssize_t rep_fgetxattr (int filedes, const char *name, void *value, size_t size)
if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags);
-
+ if (size == 0 && retval == -1 && errno == E2BIG) {
+ return valuelength;
+ }
return retval ? retval : valuelength;
#elif defined(HAVE_ATTROPEN)
ssize_t ret = -1;
diff --git a/libtdb.m4 b/libtdb.m4
deleted file mode 100644
index 47f098e..0000000
--- a/libtdb.m4
+++ /dev/null
@@ -1,41 +0,0 @@
-dnl find the tdb sources. This is meant to work both for
-dnl tdb standalone builds, and builds of packages using tdb
-tdbdir=""
-tdbpaths=". lib/tdb tdb ../tdb ../lib/tdb"
-for d in $tdbpaths; do
- if test -f "$srcdir/$d/common/tdb.c"; then
- tdbdir="$d"
- AC_SUBST(tdbdir)
- break;
- fi
-done
-if test x"$tdbdir" = "x"; then
- AC_MSG_ERROR([cannot find tdb source in $tdbpaths])
-fi
-TDB_OBJ="common/tdb.o common/dump.o common/transaction.o common/error.o common/traverse.o"
-TDB_OBJ="$TDB_OBJ common/freelist.o common/freelistcheck.o common/io.o common/lock.o common/open.o common/check.o common/hash.o common/summary.o common/rescue.o"
-AC_SUBST(TDB_OBJ)
-AC_SUBST(LIBREPLACEOBJ)
-
-TDB_LIBS=""
-AC_SUBST(TDB_LIBS)
-
-TDB_DEPS=""
-if test x$libreplace_cv_HAVE_FDATASYNC_IN_LIBRT = xyes ; then
- TDB_DEPS="$TDB_DEPS -lrt"
-fi
-AC_SUBST(TDB_DEPS)
-
-TDB_CFLAGS="-I$tdbdir/include"
-AC_SUBST(TDB_CFLAGS)
-
-AC_CHECK_FUNCS(mmap pread pwrite getpagesize utime)
-AC_CHECK_HEADERS(getopt.h sys/select.h sys/time.h)
-
-AC_HAVE_DECL(pread, [#include <unistd.h>])
-AC_HAVE_DECL(pwrite, [#include <unistd.h>])
-
-if test x"$VERSIONSCRIPT" != "x"; then
- EXPORTSFILE=tdb.exports
- AC_SUBST(EXPORTSFILE)
-fi
diff --git a/manpages/tdbbackup.8.xml b/man/tdbbackup.8.xml
index 78fe32e..c15cc14 100644
--- a/manpages/tdbbackup.8.xml
+++ b/man/tdbbackup.8.xml
@@ -33,8 +33,8 @@
<para><command>tdbbackup</command> is a tool that may be used to backup samba .tdb
files. This tool may also be used to verify the integrity of the .tdb files prior
- to samba startup or during normal operation. If it finds file damage and it finds
- a prior backup the backup file will be restored.
+ to samba startup or during normal operation. If it finds file damage and it finds
+ a prior backup the backup file will be restored.
</para>
</refsect1>
@@ -92,6 +92,11 @@
<para>tdbbackup -v [-s suffix] *.tdb</para>
<para>
+ Note that Samba 4 can use .ntdb files instead, so you should
+ use <command>ntdbbackup</command> on those files.
+ </para>
+
+ <para>
Samba .tdb files are stored in various locations, be sure to run backup all
.tdb file on the system. Important files includes:
</para>
@@ -128,7 +133,7 @@
The original Samba software and related utilities were created by Andrew Tridgell.
Samba is now developed by the Samba Team as an Open Source project similar to the way
the Linux kernel is developed.
- </para>
+ </para>
<para>The tdbbackup man page was written by John H Terpstra.</para>
</refsect1>
diff --git a/manpages/tdbdump.8.xml b/man/tdbdump.8.xml
index 3420193..25fd432 100644
--- a/manpages/tdbdump.8.xml
+++ b/man/tdbdump.8.xml
@@ -32,12 +32,12 @@
<para>This tool is part of the <citerefentry><refentrytitle>samba</refentrytitle>
<manvolnum>1</manvolnum></citerefentry> suite.</para>
- <para><command>tdbdump</command> is a very simple utility that 'dumps' the
- contents of a TDB (Trivial DataBase) file to standard output in a
+ <para><command>tdbdump</command> is a very simple utility that 'dumps' the
+ contents of a TDB (Trivial DataBase) file to standard output in a
human-readable format.
</para>
- <para>This tool can be used when debugging problems with TDB files. It is
+ <para>This tool can be used when debugging problems with TDB files. It is
intended for those who are somewhat familiar with Samba internals.
</para>
</refsect1>
@@ -84,7 +84,7 @@
The original Samba software and related utilities were created by Andrew Tridgell.
Samba is now developed by the Samba Team as an Open Source project similar to the way
the Linux kernel is developed.
- </para>
+ </para>
<para>The tdbdump man page was written by Jelmer Vernooij.</para>
</refsect1>
diff --git a/manpages/tdbrestore.8.xml b/man/tdbrestore.8.xml
index 64c0ba2..64c0ba2 100644
--- a/manpages/tdbrestore.8.xml
+++ b/man/tdbrestore.8.xml
diff --git a/manpages/tdbtool.8.xml b/man/tdbtool.8.xml
index 9f96db2..bc5c001 100644
--- a/manpages/tdbtool.8.xml
+++ b/man/tdbtool.8.xml
@@ -7,7 +7,7 @@
<manvolnum>8</manvolnum>
<refmiscinfo class="source">Samba</refmiscinfo>
<refmiscinfo class="manual">System Administration tools</refmiscinfo>
- <refmiscinfo class="version">3.6</refmiscinfo>
+ <refmiscinfo class="version">4.0</refmiscinfo>
</refmeta>
@@ -122,7 +122,7 @@
<replaceable>KEY</replaceable>
<replaceable>TDBFILE</replaceable>
</term>
- <listitem><para>Move a record from the
+ <listitem><para>Move a record from the
current database into <replaceable>TDBFILE</replaceable>.
</para></listitem>
</varlistentry>
diff --git a/pytdb.c b/pytdb.c
index ae0e6f8..cf77a25 100644
--- a/pytdb.c
+++ b/pytdb.c
@@ -164,7 +164,14 @@ static PyObject *obj_reopen(PyTdbObject *self)
int ret;
PyErr_TDB_RAISE_IF_CLOSED(self);
ret = tdb_reopen(self->ctx);
- PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
+ if (ret != 0) {
+ self->closed = true;
+ PyErr_SetObject(PyExc_RuntimeError,
+ Py_BuildValue("(i,s)",
+ TDB_ERR_IO,
+ "Failed to reopen database"));
+ return NULL;
+ }
Py_RETURN_NONE;
}
@@ -209,7 +216,13 @@ static PyObject *obj_close(PyTdbObject *self)
Py_RETURN_NONE;
ret = tdb_close(self->ctx);
self->closed = true;
- PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
+ if (ret != 0) {
+ PyErr_SetObject(PyExc_RuntimeError,
+ Py_BuildValue("(i,s)",
+ TDB_ERR_IO,
+ "Failed to close database"));
+ return NULL;
+ }
Py_RETURN_NONE;
}
diff --git a/test/lock-tracking.c b/test/lock-tracking.c
index 90a07f8..b2f092c 100644
--- a/test/lock-tracking.c
+++ b/test/lock-tracking.c
@@ -65,6 +65,17 @@ int fcntl_with_lockcheck(int fd, int cmd, ... /* arg */ )
}
break;
}
+ if (((*l)->off == fl->l_start)
+ && ((*l)->len == 0)
+ && (ret == 0)) {
+ /*
+ * Remove a piece from the start of the
+ * allrecord_lock
+ */
+ old = *l;
+ (*l)->off += fl->l_len;
+ break;
+ }
}
if (!old && !suppress_lockcheck) {
diag("Unknown unlock %u@%u - %i",
diff --git a/tools/tdbbackup.c b/tools/tdbbackup.c
index 11ecaa0..276a281 100644
--- a/tools/tdbbackup.c
+++ b/tools/tdbbackup.c
@@ -1,4 +1,4 @@
-/*
+/*
Unix SMB/CIFS implementation.
low level tdb backup and restore utility
Copyright (C) Andrew Tridgell 2002
@@ -7,12 +7,12 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 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, see <http://www.gnu.org/licenses/>.
*/
@@ -61,7 +61,7 @@ static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const c
static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...)
{
va_list ap;
-
+
va_start(ap, format);
vfprintf(stdout, format, ap);
va_end(ap);
@@ -122,7 +122,7 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
}
/* open the old tdb */
- tdb = tdb_open_ex(old_name, 0, 0,
+ tdb = tdb_open_ex(old_name, 0, 0,
O_RDWR, 0, &log_ctx, NULL);
if (!tdb) {
printf("Failed to open %s\n", old_name);
@@ -132,10 +132,10 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
/* create the new tdb */
unlink(tmp_name);
- tdb_new = tdb_open_ex(tmp_name,
- hash_size ? hash_size : tdb_hash_size(tdb),
- TDB_DEFAULT,
- O_RDWR|O_CREAT|O_EXCL, st.st_mode & 0777,
+ tdb_new = tdb_open_ex(tmp_name,
+ hash_size ? hash_size : tdb_hash_size(tdb),
+ TDB_DEFAULT,
+ O_RDWR|O_CREAT|O_EXCL, st.st_mode & 0777,
&log_ctx, NULL);
if (!tdb_new) {
perror(tmp_name);
@@ -192,9 +192,9 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
/* close the new tdb and re-open read-only */
tdb_close(tdb_new);
- tdb_new = tdb_open_ex(tmp_name,
+ tdb_new = tdb_open_ex(tmp_name,
0,
- TDB_DEFAULT,
+ TDB_DEFAULT,
O_RDONLY, 0,
&log_ctx, NULL);
if (!tdb_new) {
@@ -204,7 +204,7 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
free(tmp_name);
return 1;
}
-
+
/* traverse the new tdb to confirm */
count2 = tdb_traverse(tdb_new, test_fn, NULL);
if (count2 != count1) {
@@ -237,7 +237,7 @@ static int verify_tdb(const char *fname, const char *bak_name)
int count = -1;
/* open the tdb */
- tdb = tdb_open_ex(fname, 0, 0,
+ tdb = tdb_open_ex(fname, 0, 0,
O_RDONLY, 0, &log_ctx, NULL);
/* traverse the tdb, then close it */
@@ -280,7 +280,6 @@ static void usage(void)
printf(" -v verify mode (restore if corrupt)\n");
printf(" -n hashsize set the new hash size for the backup\n");
}
-
int main(int argc, char *argv[])
{
diff --git a/tools/tdbdump.c b/tools/tdbdump.c
index bcd395f..e66ea56 100644
--- a/tools/tdbdump.c
+++ b/tools/tdbdump.c
@@ -1,4 +1,4 @@
-/*
+/*
Unix SMB/CIFS implementation.
simple tdb dump util
Copyright (C) Andrew Tridgell 2001
@@ -7,12 +7,12 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 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, see <http://www.gnu.org/licenses/>.
*/
@@ -55,9 +55,6 @@ static void log_stderr(struct tdb_context *tdb, enum tdb_debug_level level,
const char *fmt, ...)
{
va_list ap;
- char *ptr = NULL;
- int debuglevel = 0;
- int ret;
const char *name = tdb_name(tdb);
const char *prefix = "";
@@ -102,7 +99,7 @@ static int dump_tdb(const char *fname, const char *keyname, bool emergency)
TDB_CONTEXT *tdb;
TDB_DATA key, value;
struct tdb_logging_context logfn = { log_stderr };
-
+
tdb = tdb_open_ex(fname, 0, 0, O_RDONLY, 0, &logfn, NULL);
if (!tdb) {
printf("Failed to open %s\n", fname);
diff --git a/tools/tdbtest.c b/tools/tdbtest.c
index 44c78ef..0be35dc 100644
--- a/tools/tdbtest.c
+++ b/tools/tdbtest.c
@@ -24,7 +24,7 @@ static void _start_timer(void)
static double _end_timer(void)
{
gettimeofday(&tp2,NULL);
- return((tp2.tv_sec - tp1.tv_sec) +
+ return((tp2.tv_sec - tp1.tv_sec) +
(tp2.tv_usec - tp1.tv_usec)*1.0e-6);
}
@@ -40,7 +40,7 @@ static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...)
static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...)
{
va_list ap;
-
+
va_start(ap, format);
vfprintf(stdout, format, ap);
va_end(ap);
@@ -189,15 +189,15 @@ static void merge_test(void)
char keys[5][2];
char tdata[] = "test";
TDB_DATA key, data;
-
+
for (i = 0; i < 5; i++) {
snprintf(keys[i],2, "%d", i);
key.dptr = keys[i];
key.dsize = 2;
-
+
data.dptr = tdata;
data.dsize = 4;
-
+
if (tdb_store(db, key, data, TDB_REPLACE) != 0) {
fatal("tdb_store failed");
}
@@ -248,7 +248,7 @@ static char *test_path(const char *filename)
db = tdb_open(test_tdb, 0, TDB_CLEAR_IF_FIRST,
O_RDWR | O_CREAT | O_TRUNC, 0600);
- gdbm = gdbm_open(test_gdbm, 512, GDBM_WRITER|GDBM_NEWDB|GDBM_FAST,
+ gdbm = gdbm_open(test_gdbm, 512, GDBM_WRITER|GDBM_NEWDB|GDBM_FAST,
0600, NULL);
if (!db || !gdbm) {
diff --git a/tools/tdbtool.c b/tools/tdbtool.c
index dc5747f..d007796 100644
--- a/tools/tdbtool.c
+++ b/tools/tdbtool.c
@@ -1,4 +1,4 @@
-/*
+/*
Unix SMB/CIFS implementation.
Samba database functions
Copyright (C) Andrew Tridgell 1999-2000
@@ -10,12 +10,12 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 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, see <http://www.gnu.org/licenses/>.
*/
@@ -113,7 +113,7 @@ static void _start_timer(void)
static double _end_timer(void)
{
gettimeofday(&tp2,NULL);
- return((tp2.tv_sec - tp1.tv_sec) +
+ return((tp2.tv_sec - tp1.tv_sec) +
(tp2.tv_usec - tp1.tv_usec)*1.0e-6);
}
@@ -160,7 +160,7 @@ static void print_data(const char *buf,int len)
printf("%02X ",(int)((unsigned char)buf[i]));
i++;
if (i%8 == 0) printf(" ");
- if (i%16 == 0) {
+ if (i%16 == 0) {
print_asc(&buf[i-16],8); printf(" ");
print_asc(&buf[i-8],8); printf("\n");
if (i<len) printf("[%03X] ",i);
@@ -168,18 +168,18 @@ static void print_data(const char *buf,int len)
}
if (i%16) {
int n;
-
+
n = 16 - (i%16);
printf(" ");
if (n>8) printf(" ");
while (n--) printf(" ");
-
+
n = i%16;
if (n > 8) n = 8;
print_asc(&buf[i-(i%16)],n); printf(" ");
n = (i%16) - n;
- if (n>0) print_asc(&buf[i-n],n);
- printf("\n");
+ if (n>0) print_asc(&buf[i-n],n);
+ printf("\n");
}
}
@@ -309,11 +309,11 @@ static void show_tdb(char *keyname, size_t keylen)
terror("fetch failed");
return;
}
-
+
print_rec(tdb, key, dbuf, NULL);
-
+
free( dbuf.dptr );
-
+
return;
}
@@ -357,23 +357,23 @@ static void move_rec(char *keyname, size_t keylen, char* tdbname)
terror("fetch failed");
return;
}
-
+
print_rec(tdb, key, dbuf, NULL);
-
+
dst_tdb = tdb_open(tdbname, 0, 0, O_RDWR, 0600);
if ( !dst_tdb ) {
terror("unable to open destination tdb");
return;
}
-
+
if (tdb_store( dst_tdb, key, dbuf, TDB_REPLACE ) != 0) {
terror("failed to move record");
}
else
printf("record moved\n");
-
+
tdb_close( dst_tdb );
-
+
return;
}
@@ -520,7 +520,7 @@ static void first_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey)
{
TDB_DATA dbuf;
*pkey = tdb_firstkey(the_tdb);
-
+
dbuf = tdb_fetch(the_tdb, *pkey);
if (!dbuf.dptr) terror("fetch failed");
else {
@@ -532,9 +532,9 @@ static void next_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey)
{
TDB_DATA dbuf;
*pkey = tdb_nextkey(the_tdb, *pkey);
-
+
dbuf = tdb_fetch(the_tdb, *pkey);
- if (!dbuf.dptr)
+ if (!dbuf.dptr)
terror("fetch failed");
else
print_rec(the_tdb, *pkey, dbuf, NULL);
diff --git a/tools/tdbtorture.c b/tools/tdbtorture.c
index 64c5043..a23d154 100644
--- a/tools/tdbtorture.c
+++ b/tools/tdbtorture.c
@@ -1,5 +1,5 @@
/* this tests tdb by doing lots of ops from several simultaneous
- writers - that stresses the locking code.
+ writers - that stresses the locking code.
*/
#include "replace.h"
@@ -59,7 +59,7 @@ static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const c
system(ptr);
free(ptr);
}
-#endif
+#endif
}
static void fatal(const char *why)
@@ -438,10 +438,11 @@ done:
db = tdb_open_ex(test_tdb, hash_size, TDB_DEFAULT,
O_RDWR, 0, &log_ctx, NULL);
if (!db) {
- fatal("db open failed");
+ fatal("db open failed\n");
+ exit(1);
}
if (tdb_check(db, NULL, NULL) == -1) {
- printf("db check failed");
+ printf("db check failed\n");
exit(1);
}
tdb_close(db);
diff --git a/wscript b/wscript
index 9d309a0..00a1c34 100644
--- a/wscript
+++ b/wscript
@@ -1,7 +1,7 @@
#!/usr/bin/env python
APPNAME = 'tdb'
-VERSION = '1.2.11'
+VERSION = '1.2.12'
blddir = 'bin'
@@ -94,20 +94,20 @@ def build(bld):
bld.SAMBA_BINARY('tdbrestore',
'tools/tdbrestore.c',
- 'tdb', manpages='manpages/tdbrestore.8')
+ 'tdb', manpages='man/tdbrestore.8')
bld.SAMBA_BINARY('tdbdump',
'tools/tdbdump.c',
- 'tdb', manpages='manpages/tdbdump.8')
+ 'tdb', manpages='man/tdbdump.8')
bld.SAMBA_BINARY('tdbbackup',
'tools/tdbbackup.c',
'tdb',
- manpages='manpages/tdbbackup.8')
+ manpages='man/tdbbackup.8')
bld.SAMBA_BINARY('tdbtool',
'tools/tdbtool.c',
- 'tdb', manpages='manpages/tdbtool.8')
+ 'tdb', manpages='man/tdbtool.8')
# FIXME: This hardcoded list is stupid, stupid, stupid.
bld.SAMBA_SUBSYSTEM('tdb-test-helpers',