Commit bf91eb5a authored by Mathieu Parent's avatar Mathieu Parent

Update upstream source from tag 'upstream/1.4.2'

Update to upstream version '1.4.2'
with Debian dir b57de67ef3bcc717b7700abb585d662360ee08d9
parents a64143b3 4cd41985
This diff is collapsed.
pyldb_Dn_FromDn: PyObject *(struct ldb_dn *)
pyldb_Object_AsDn: bool (TALLOC_CTX *, PyObject *, struct ldb_context *, struct ldb_dn **)
pyldb_Dn_FromDn: PyObject *(struct ldb_dn *)
pyldb_Object_AsDn: bool (TALLOC_CTX *, PyObject *, struct ldb_context *, struct ldb_dn **)
......@@ -43,7 +43,7 @@ def process(tsk):
if tsk.__class__.stat: ret = tsk.__class__.stat(tsk)
# actual call to task's run() function
else: ret = tsk.call_run()
except Exception, e:
except Exception as e:
tsk.err_msg = Utils.ex_stack()
tsk.hasrun = EXCEPTION
......@@ -177,7 +177,7 @@ class Parallel(object):
try:
st = tsk.runnable_status()
except Exception, e:
except Exception as e:
self.processed += 1
if self.stop and not Options.options.keep:
tsk.hasrun = SKIPPED
......
......@@ -721,6 +721,10 @@ def SAMBA_CONFIG_H(conf, path=None):
testflags=True)
conf.ADD_CFLAGS('-Werror=uninitialized -Wuninitialized',
testflags=True)
conf.ADD_CFLAGS('-Wimplicit-fallthrough',
testflags=True)
conf.ADD_CFLAGS('-Werror=strict-overflow -Wstrict-overflow=2',
testflags=True)
conf.ADD_CFLAGS('-Wformat=2 -Wno-format-y2k', testflags=True)
conf.ADD_CFLAGS('-Wno-format-zero-length', testflags=True)
......
......@@ -85,6 +85,8 @@ def minimum_library_version(conf, libname, default):
@conf
def LIB_MAY_BE_BUNDLED(conf, libname):
if libname in conf.env.SYSTEM_LIBS:
return False
if libname in conf.env.BUNDLED_LIBS:
return True
if '!%s' % libname in conf.env.BUNDLED_LIBS:
......
......@@ -50,7 +50,7 @@ def check(self, *k, **kw):
ret = None
try:
ret = self.run_c_code(*k, **kw)
except Configure.ConfigurationError, e:
except Configure.ConfigurationError as e:
self.check_message_2(kw['errmsg'], 'YELLOW')
if 'mandatory' in kw and kw['mandatory']:
if Logs.verbose > 1:
......
......@@ -167,7 +167,7 @@ def dist(appname='', version=''):
absdir = os.path.join(srcdir, dir)
try:
files = vcs_dir_contents(absdir)
except Exception, e:
except Exception as e:
Logs.error('unable to get contents of %s: %s' % (absdir, e))
sys.exit(1)
add_files_to_tarball(tar, srcdir, dir, dist_base, destdir, blacklist, files)
......
......@@ -95,7 +95,7 @@ also accepted as dictionary entries here
self.VENDOR_SUFFIX=None
self.VENDOR_PATCH=None
for a, b in version_dict.iteritems():
for a, b in version_dict.items():
if a.startswith("SAMBA_VERSION_"):
setattr(self, a[14:], b)
else:
......
......@@ -353,6 +353,7 @@ def SAMBA_BINARY(bld, binname, source,
modules=None,
ldflags=None,
cflags='',
cflags_end=None,
autoproto=None,
use_hostcc=False,
use_global_deps=True,
......@@ -410,6 +411,7 @@ def SAMBA_BINARY(bld, binname, source,
deps = deps,
includes = includes,
cflags = pie_cflags,
cflags_end = cflags_end,
group = subsystem_group,
autoproto = autoproto,
subsystem_name = subsystem_name,
......@@ -458,6 +460,7 @@ def SAMBA_MODULE(bld, modname, source,
autoproto=None,
autoproto_extra_source='',
cflags='',
cflags_end=None,
internal_module=True,
local_include=True,
global_include=True,
......@@ -488,6 +491,7 @@ def SAMBA_MODULE(bld, modname, source,
autoproto=autoproto,
autoproto_extra_source=autoproto_extra_source,
cflags=cflags,
cflags_end=cflags_end,
local_include=local_include,
global_include=global_include,
allow_warnings=allow_warnings,
......@@ -527,6 +531,7 @@ def SAMBA_MODULE(bld, modname, source,
deps=deps,
includes=includes,
cflags=cflags,
cflags_end=cflags_end,
realname = realname,
autoproto = autoproto,
local_include=local_include,
......@@ -900,7 +905,7 @@ def INSTALL_DIR(bld, path, chmod=0o755, env=None):
try:
os.makedirs(destpath)
os.chmod(destpath, chmod)
except OSError, e:
except OSError as e:
if not os.path.isdir(destpath):
raise Utils.WafError("Cannot create the folder '%s' (error: %s)" % (path, e))
Build.BuildContext.INSTALL_DIR = INSTALL_DIR
......
......@@ -269,6 +269,7 @@ def configure(conf):
conf.env.MODULESDIR = Options.options.MODULESDIR
conf.env.PRIVATELIBDIR = Options.options.PRIVATELIBDIR
conf.env.BUNDLED_LIBS = Options.options.BUNDLED_LIBS.split(',')
conf.env.SYSTEM_LIBS = ()
conf.env.PRIVATE_LIBS = Options.options.PRIVATE_LIBS.split(',')
conf.env.BUILTIN_LIBRARIES = Options.options.BUILTIN_LIBRARIES.split(',')
conf.env.NONSHARED_BINARIES = Options.options.NONSHARED_BINARIES.split(',')
......
......@@ -379,6 +379,7 @@ int ldb_transaction_start(struct ldb_context *ldb)
"ldb transaction start: %s (%d)",
ldb_strerror(status),
status);
ldb->transaction_active--;
}
if ((next_module && next_module->ldb->flags & LDB_FLG_ENABLE_TRACING)) {
ldb_debug(next_module->ldb, LDB_DEBUG_TRACE, "start ldb transaction error: %s",
......@@ -424,6 +425,8 @@ int ldb_transaction_prepare_commit(struct ldb_context *ldb)
return LDB_SUCCESS;
}
ldb_reset_err_string(ldb);
status = next_module->ops->prepare_commit(next_module);
if (status != LDB_SUCCESS) {
ldb->transaction_active--;
......
......@@ -629,7 +629,8 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
l++;
break;
}
/* fall through */
FALL_THROUGH;
case '\"':
case '<':
case '>':
......
......@@ -216,7 +216,8 @@ static int fold_string(int (*fprintf_fn)(void *, const char *, ...), void *priva
const char *buf, size_t length, int start_pos)
{
size_t i;
int total=0, ret;
size_t total = 0;
int ret;
for (i=0;i<length;i++) {
ret = fprintf_fn(private_data, "%c", buf[i]);
......@@ -280,7 +281,8 @@ static int ldb_ldif_write_trace(struct ldb_context *ldb,
{
TALLOC_CTX *mem_ctx;
unsigned int i, j;
int total=0, ret;
size_t total = 0;
int ret;
char *p;
const struct ldb_message *msg;
const char * const * secret_attributes = ldb_get_opaque(ldb, LDB_SECRET_ATTRIBUTE_LIST_OPAQUE);
......
......@@ -1103,7 +1103,7 @@ static int ldb_modules_load_dir(const char *modules_dir, const char *version)
*/
void ldb_set_modules_dir(struct ldb_context *ldb, const char *path)
{
int ret = ldb_modules_load_path(path, LDB_VERSION);
int ret = ldb_modules_load_dir(path, LDB_VERSION);
if (ret != LDB_SUCCESS) {
ldb_asprintf_errstring(ldb, "Failed to load modules from: %s\n", path);
}
......
......@@ -59,9 +59,8 @@ typedef struct
#define CHAR_BIT 8
#endif
#define STACK_SIZE (CHAR_BIT * sizeof(size_t))
#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top))
#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi)))
#define STACK_NOT_EMPTY (stack < top)
#define PUSH(low, high) ((void) ((stack[i].lo = (low)), (stack[i].hi = (high)), i++))
#define POP(low, high) ((void) (i--, (low = stack[i].lo), (high = stack[i].hi)))
/* Order size using quicksort. This implementation incorporates
......@@ -104,11 +103,11 @@ void ldb_qsort (void *const pbase, size_t total_elems, size_t size,
char *lo = base_ptr;
char *hi = &lo[size * (total_elems - 1)];
stack_node stack[STACK_SIZE];
stack_node *top = stack;
size_t i = 0;
PUSH (NULL, NULL);
while (STACK_NOT_EMPTY)
do
{
char *left_ptr;
char *right_ptr;
......@@ -194,6 +193,7 @@ void ldb_qsort (void *const pbase, size_t total_elems, size_t size,
hi = right_ptr;
}
}
while (i > 0 && i < STACK_SIZE);
}
/* Once the BASE_PTR array is partially sorted by quicksort the rest
......
......@@ -54,18 +54,18 @@
#endif
/*
* Only Samba versions which expect ldb >= 1.2.0
* are compatible with read_[un]lock() behaviour.
* Only Samba versions which expect ldb >= 1.4.0
* reopen the ldb after each fork().
*
* See https://bugzilla.samba.org/show_bug.cgi?id=12859
* See https://bugzilla.samba.org/show_bug.cgi?id=13519
*/
#if EXPECTED_SYSTEM_LDB_VERSION_MAJOR > 1
#define __LDB_READ_LOCK_COMPATIBLE__ 1
#elif EXPECTED_SYSTEM_LDB_VERSION_MINOR > 1
#define __LDB_READ_LOCK_COMPATIBLE__ 1
#define __LDB_FORK_COMPATIBLE__ 1
#elif EXPECTED_SYSTEM_LDB_VERSION_MINOR > 3
#define __LDB_FORK_COMPATIBLE__ 1
#endif
#ifndef __LDB_READ_LOCK_COMPATIBLE__
#error "Samba < 4.7 is not compatible with this version of ldb due to assumptions around read locks"
#ifndef __LDB_FORK_COMPATIBLE__
#error "Samba < 4.9 is not compatible with this version of ldb due to assumptions around fork() behaviour"
#endif
#endif /* defined(_SAMBA_BUILD_) && defined(USING_SYSTEM_LDB) */
......
/*
* ldb connection and module initialisation
*
* Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
*
* 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,
* 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/>.
*
*/
#include "ldb_private.h"
#include "../ldb_tdb/ldb_tdb.h"
#ifdef HAVE_LMDB
#include "../ldb_mdb/ldb_mdb.h"
#endif /* HAVE_LMDB */
/*
connect to the database
*/
static int lldb_connect(struct ldb_context *ldb,
const char *url,
unsigned int flags,
const char *options[],
struct ldb_module **module)
{
const char *path;
int ret;
/*
* Check and remove the url prefix
*/
if (strchr(url, ':')) {
if (strncmp(url, "ldb://", 6) != 0) {
ldb_debug(ldb, LDB_DEBUG_ERROR,
"Invalid ldb URL '%s'", url);
return LDB_ERR_OPERATIONS_ERROR;
}
path = url+6;
} else {
path = url;
}
/*
* Don't create the database if it's not there
*/
flags |= LDB_FLG_DONT_CREATE_DB;
#ifdef HAVE_LMDB
/*
* Try opening the database as an lmdb
*/
ret = lmdb_connect(ldb, path, flags, options, module);
if (ret == LDB_SUCCESS) {
return ret;
}
if (ret != LDB_ERR_UNAVAILABLE) {
return ret;
}
/*
* Not mdb so try as tdb
*/
#endif /* HAVE_LMDB */
ret = ltdb_connect(ldb, path, flags, options, module);
return ret;
}
int ldb_ldb_init(const char *version)
{
LDB_MODULE_CHECK_VERSION(version);
return ldb_register_backend("ldb", lldb_connect, false);
}
......@@ -523,7 +523,8 @@ struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, struct
"used in DN!", ldb_dn_get_component_name(dn, i));
goto failed;
}
/* fall through */
FALL_THROUGH;
case LDB_MAP_KEEP:
case LDB_MAP_RENAME:
case LDB_MAP_RENDROP:
......@@ -599,7 +600,8 @@ struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, struc
"used in DN!", ldb_dn_get_component_name(dn, i));
goto failed;
}
/* fall through */
FALL_THROUGH;
case LDB_MAP_KEEP:
case LDB_MAP_RENAME:
case LDB_MAP_RENDROP:
......
......@@ -87,7 +87,8 @@ static int ldb_msg_el_partition(struct ldb_module *module, enum ldb_request_type
el = ldb_msg_el_map_local(module, remote, map, old);
break;
}
/* fall through */
FALL_THROUGH;
case LDB_MAP_IGNORE:
goto local;
......@@ -99,7 +100,8 @@ static int ldb_msg_el_partition(struct ldb_module *module, enum ldb_request_type
map->local_name);
goto local;
}
/* fall through */
FALL_THROUGH;
case LDB_MAP_KEEP:
case LDB_MAP_RENAME:
el = ldb_msg_el_map_local(module, remote, map, old);
......
......@@ -330,7 +330,8 @@ static int ldb_msg_el_merge(struct ldb_module *module, struct ldb_message *local
attr_name);
return LDB_SUCCESS;
}
/* fall through */
FALL_THROUGH;
case LDB_MAP_KEEP:
case LDB_MAP_RENAME:
case LDB_MAP_RENDROP:
......
This diff is collapsed.
/*
ldb database library using mdb back end - transaction operations
Copyright (C) Jakub Hrozek 2015
Copyright (C) Catalyst.Net Ltd 2017
** NOTE! The following LGPL license applies to the ldb
** 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
Lesser 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 _LDB_MDB_H_
#define _LDB_MDB_H_
#include "ldb_private.h"
#include <lmdb.h>
struct lmdb_private {
struct ldb_context *ldb;
MDB_env *env;
struct lmdb_trans *txlist;
struct ldb_mdb_metadata {
struct ldb_message *attributes;
unsigned seqnum;
} *meta;
int error;
MDB_txn *read_txn;
pid_t pid;
};
struct lmdb_trans {
struct lmdb_trans *next;
struct lmdb_trans *prev;
MDB_txn *tx;
};
int ldb_mdb_err_map(int lmdb_err);
int lmdb_connect(struct ldb_context *ldb, const char *url,
unsigned int flags, const char *options[],
struct ldb_module **_module);
#endif /* _LDB_MDB_H_ */
/*
ldb database library using mdb back end
Copyright (C) Jakub Hrozek 2014
Copyright (C) Catalyst.Net Ltd 2017
** NOTE! The following LGPL license applies to the ldb
** 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
Lesser 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/>.
*/
#include "ldb_mdb.h"
int ldb_mdb_init(const char *version)
{
LDB_MODULE_CHECK_VERSION(version);
return ldb_register_backend("mdb", lmdb_connect, false);
}
......@@ -238,7 +238,7 @@ static int ltdb_index_load(struct ldb_module *module,
{
struct ldb_context *ldb = ldb_module_get_ctx(module);
struct ldb_dn *indexlist_dn;
int r;
int r, lmdb_subdb_version;
if (ldb->schema.index_handler_override) {
/*
......@@ -291,6 +291,20 @@ static int ltdb_index_load(struct ldb_module *module,
= ldb_msg_find_attr_as_string(ltdb->cache->indexlist,
LTDB_IDX_DN_GUID, NULL);
lmdb_subdb_version
= ldb_msg_find_attr_as_int(ltdb->cache->indexlist,
LTDB_IDX_LMDB_SUBDB, 0);
if (lmdb_subdb_version != 0) {
ldb_set_errstring(ldb,
"FATAL: This ldb_mdb database has "
"been written in a new verson of LDB "
"using a sub-database index that "
"is not understood by ldb "
LDB_VERSION);
return -1;
}
return 0;
}
......@@ -386,13 +400,13 @@ int ltdb_cache_load(struct ldb_module *module)
uint64_t seq;
struct ldb_message *baseinfo = NULL, *options = NULL;
const struct ldb_schema_attribute *a;
bool have_write_txn = false;
int r;
ldb = ldb_module_get_ctx(module);
/* a very fast check to avoid extra database reads */
if (ltdb->cache != NULL &&
tdb_get_seqnum(ltdb->tdb) == ltdb->tdb_seqnum) {
if (ltdb->cache != NULL && !ltdb->kv_ops->has_changed(ltdb)) {
return 0;
}
......@@ -407,30 +421,42 @@ int ltdb_cache_load(struct ldb_module *module)
baseinfo_dn = ldb_dn_new(baseinfo, ldb, LTDB_BASEINFO);
if (baseinfo_dn == NULL) goto failed;
r = ltdb->kv_ops->lock_read(module);
if (r != LDB_SUCCESS) {
goto failed;
}
r= ltdb_search_dn1(module, baseinfo_dn, baseinfo, 0);
if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) {
goto failed;
goto failed_and_unlock;
}
/* possibly initialise the baseinfo */
if (r == LDB_ERR_NO_SUCH_OBJECT) {
if (tdb_transaction_start(ltdb->tdb) != 0) {
/* Give up the read lock, try again with a write lock */
r = ltdb->kv_ops->unlock_read(module);
if (r != LDB_SUCCESS) {
goto failed;
}
if (ltdb->kv_ops->begin_write(ltdb) != 0) {
goto failed;
}
have_write_txn = true;
/* error handling for ltdb_baseinfo_init() is by
looking for the record again. */
ltdb_baseinfo_init(module);
tdb_transaction_commit(ltdb->tdb);
if (ltdb_search_dn1(module, baseinfo_dn, baseinfo, 0) != LDB_SUCCESS) {
goto failed;
goto failed_and_unlock;
}
}
ltdb->tdb_seqnum = tdb_get_seqnum(ltdb->tdb);
/* Ignore the result, and update the sequence number */
ltdb->kv_ops->has_changed(ltdb);
/* if the current internal sequence number is the same as the one
in the database then assume the rest of the cache is OK */
......@@ -441,16 +467,17 @@ int ltdb_cache_load(struct ldb_module *module)
ltdb->sequence_number = seq;
/* Read an interpret database options */
options = ldb_msg_new(ltdb->cache);
if (options == NULL) goto failed;
if (options == NULL) goto failed_and_unlock;
options_dn = ldb_dn_new(options, ldb, LTDB_OPTIONS);
if (options_dn == NULL) goto failed;
if (options_dn == NULL) goto failed_and_unlock;
r= ltdb_search_dn1(module, options_dn, options, 0);
talloc_free(options_dn);
if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) {
goto failed;
goto failed_and_unlock;
}
/* set flags if they do exist */
......@@ -477,7 +504,7 @@ int ltdb_cache_load(struct ldb_module *module)
ltdb_attributes_unload(module);
if (ltdb_index_load(module, ltdb) == -1) {
goto failed;
goto failed_and_unlock;
}
/*
......@@ -486,7 +513,7 @@ int ltdb_cache_load(struct ldb_module *module)
* partition module.
*/
if (ltdb_attributes_load(module) == -1) {
goto failed;
goto failed_and_unlock;
}
ltdb->GUID_index_syntax = NULL;
......@@ -501,10 +528,25 @@ int ltdb_cache_load(struct ldb_module *module)
}
done:
if (have_write_txn) {
if (ltdb->kv_ops->finish_write(ltdb) != 0) {
goto failed;
}
} else {
ltdb->kv_ops->unlock_read(module);
}
talloc_free(options);
talloc_free(baseinfo);
return 0;
failed_and_unlock:
if (have_write_txn) {
ltdb->kv_ops->abort_write(ltdb);
} else {
ltdb->kv_ops->unlock_read(module);
}
failed:
talloc_free(options);
talloc_free(baseinfo);
......@@ -592,7 +634,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module)
/* updating the tdb_seqnum here avoids us reloading the cache
records due to our own modification */
ltdb->tdb_seqnum = tdb_get_seqnum(ltdb->tdb);
ltdb->kv_ops->has_changed(ltdb);
return ret;
}
......
This diff is collapsed.
......@@ -183,17 +183,15 @@ struct ltdb_parse_data_unpack_ctx {
unsigned int unpack_flags;
};
static int ltdb_parse_data_unpack(TDB_DATA key, TDB_DATA data,
static int ltdb_parse_data_unpack(struct ldb_val key,
struct ldb_val data,
void *private_data)
{
struct ltdb_parse_data_unpack_ctx *ctx = private_data;
unsigned int nb_elements_in_db;
int ret;
struct ldb_context *ldb = ldb_module_get_ctx(ctx->module);
struct ldb_val data_parse = {
.data = data.dptr,
.length = data.dsize
};
struct ldb_val data_parse = data;
if (ctx->unpack_flags & LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC) {
/*
......@@ -203,13 +201,13 @@ static int ltdb_parse_data_unpack(TDB_DATA key, TDB_DATA data,
* and the caller needs a stable result.
*/
data_parse.data = talloc_memdup(ctx->msg,
data.dptr,
data.dsize);
data.data,
data.length);
if (data_parse.data == NULL) {
ldb_debug(ldb, LDB_DEBUG_ERROR,
"Unable to allocate data(%d) for %*.*s\n",
(int)data.dsize,
(int)key.dsize, (int)key.dsize, key.dptr);
(int)data.length,
(int)key.length, (int)key.length, key.data);
return LDB_ERR_OPERATIONS_ERROR;
}
}
......@@ -220,13 +218,13 @@ static int ltdb_parse_data_unpack(TDB_DATA key, TDB_DATA data,