1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

r13786: [merge] Add registration functions for LDB modules

Applications that use LDB modules will now have to run ldb_global_init()
before they can use LDB.

The next step will be adding support for loading LDB modules from .so
files. This will also allow us to use one LDB without difference between the
standalone and the Samba-specific build
(This used to be commit 52a2356505)
This commit is contained in:
Jelmer Vernooij 2006-03-02 16:32:53 +00:00 committed by Gerald (Jerry) Carter
parent 0efc729318
commit 26af14c39b
44 changed files with 327 additions and 397 deletions

View File

@ -67,6 +67,8 @@ my $section_types = {
"MAJOR_VERSION" => "string",
"MINOR_VERSION" => "string",
"RELEASE_VERSION" => "string",
"INIT_FUNCTION_TYPE" => "string",
"OBJ_FILES" => "list",

View File

@ -30,13 +30,16 @@ sub _prepare_build_h($)
my $DEFINE = ();
next if ($key->{TYPE} ne "LIBRARY" and $key->{TYPE} ne "SUBSYSTEM");
next unless defined($key->{INIT_FUNCTIONS});
$DEFINE->{COMMENT} = "$key->{TYPE} $key->{NAME} INIT";
$DEFINE->{KEY} = "STATIC_$key->{NAME}_MODULES";
$DEFINE->{VAL} = "{ \\\n";
foreach (@{$key->{INIT_FUNCTIONS}}) {
$DEFINE->{VAL} .= "\t$_, \\\n";
$output .= "NTSTATUS $_(void);\n";
my $fn = $key->{INIT_FUNCTION_TYPE};
unless(defined($fn)) { $fn = "NTSTATUS (*) (void)"; }
$fn =~ s/\(\*\)/$_/;
$output .= "$fn;\n";
}
$DEFINE->{VAL} .= "\tNULL \\\n }";

View File

@ -97,6 +97,10 @@ sub check_library($$$)
return;
}
unless (defined($lib->{INIT_FUNCTION_TYPE})) {
$lib->{INIT_FUNCTION_TYPE} = "NTSTATUS (*) (void)";
}
$lib->{INSTALLDIR} = "LIBDIR";
}

View File

@ -2,6 +2,7 @@
# Start MODULE libldb_objectguid
[MODULE::libldb_objectguid]
SUBSYSTEM = LIBLDB
INIT_FUNCTION = objectguid_module_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
objectguid.o
@ -14,6 +15,7 @@ REQUIRED_SUBSYSTEMS = \
# Start MODULE libldb_samldb
[MODULE::libldb_samldb]
SUBSYSTEM = LIBLDB
INIT_FUNCTION = samldb_module_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
samldb.o
@ -26,6 +28,8 @@ REQUIRED_SUBSYSTEMS = SAMDB
# Start MODULE libldb_samba3sam
[MODULE::libldb_samba3sam]
SUBSYSTEM = LIBLDB
INIT_FUNCTION = ldb_samba3sam_module_init
ENABLE = NO
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
samba3sam.o
@ -37,6 +41,7 @@ OBJ_FILES = \
# Start MODULE libldb_proxy
[MODULE::libldb_proxy]
SUBSYSTEM = LIBLDB
INIT_FUNCTION = proxy_module_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
proxy.o
@ -49,6 +54,7 @@ OBJ_FILES = \
# Start MODULE libldb_rootdse
[MODULE::libldb_rootdse]
SUBSYSTEM = LIBLDB
INIT_FUNCTION = rootdse_module_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
rootdse.o
@ -60,6 +66,7 @@ OBJ_FILES = \
# Start MODULE libldb_password_hash
[MODULE::libldb_password_hash]
SUBSYSTEM = LIBLDB
INIT_FUNCTION = password_hash_module_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
password_hash.o
@ -73,6 +80,7 @@ REQUIRED_SUBSYSTEMS = \
# Start MODULE libldb_cludge_acl
[MODULE::libldb_kludge_acl]
SUBSYSTEM = LIBLDB
INIT_FUNCTION = ldb_kludge_acl_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
kludge_acl.o
@ -86,6 +94,7 @@ REQUIRED_SUBSYSTEMS = \
# Start MODULE libldb_extended_dn
[MODULE::libldb_extended_dn]
SUBSYSTEM = LIBLDB
INIT_FUNCTION = ldb_extended_dn_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
extended_dn.o

View File

@ -269,7 +269,7 @@ static int extended_request(struct ldb_module *module, struct ldb_request *req)
}
}
static int extended_init_2(struct ldb_module *module)
static int extended_init(struct ldb_module *module)
{
struct ldb_request request;
int ret;
@ -284,27 +284,16 @@ static int extended_init_2(struct ldb_module *module)
return LDB_ERR_OTHER;
}
return ldb_next_second_stage_init(module);
return ldb_next_init(module);
}
static const struct ldb_module_ops extended_dn_ops = {
.name = "extended_dn",
.request = extended_request,
.second_stage_init = extended_init_2
.init_context = extended_init
};
struct ldb_module *extended_dn_module_init(struct ldb_context *ldb, const char *options[])
int ldb_extended_dn_init(void)
{
struct ldb_module *ctx;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &extended_dn_ops;
ctx->private_data = NULL;
return ctx;
return ldb_register_module(&extended_dn_ops);
}

View File

@ -175,7 +175,7 @@ static int kludge_acl_request(struct ldb_module *module, struct ldb_request *req
}
}
static int kludge_acl_init_2(struct ldb_module *module)
static int kludge_acl_init(struct ldb_module *module)
{
int ret, i;
TALLOC_CTX *mem_ctx = talloc_new(module);
@ -184,8 +184,15 @@ static int kludge_acl_init_2(struct ldb_module *module)
struct ldb_message *msg;
struct ldb_message_element *password_attributes;
struct kludge_private_data *data = talloc_get_type(module->private_data, struct kludge_private_data);
struct kludge_private_data *data;
data = talloc(module, struct kludge_private_data);
if (data == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
data->password_attrs = NULL;
module->private_data = data;
if (!mem_ctx) {
return LDB_ERR_OPERATIONS_ERROR;
@ -227,7 +234,7 @@ static int kludge_acl_init_2(struct ldb_module *module)
done:
talloc_free(mem_ctx);
return ldb_next_second_stage_init(module);
return ldb_next_init(module);
}
static const struct ldb_module_ops kludge_acl_ops = {
@ -236,30 +243,10 @@ static const struct ldb_module_ops kludge_acl_ops = {
.start_transaction = kludge_acl_start_trans,
.end_transaction = kludge_acl_end_trans,
.del_transaction = kludge_acl_del_trans,
.second_stage_init = kludge_acl_init_2
.init_context = kludge_acl_init
};
struct ldb_module *kludge_acl_module_init(struct ldb_context *ldb, const char *options[])
int ldb_kludge_acl_init(void)
{
struct ldb_module *ctx;
struct kludge_private_data *data;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
data = talloc(ctx, struct kludge_private_data);
if (data == NULL) {
talloc_free(ctx);
return NULL;
}
data->password_attrs = NULL;
ctx->private_data = data;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &kludge_acl_ops;
return ctx;
return ldb_register_module(&kludge_acl_ops);
}

View File

@ -127,19 +127,7 @@ static const struct ldb_module_ops objectguid_ops = {
};
/* the init function */
struct ldb_module *objectguid_module_init(struct ldb_context *ldb, const char *options[])
int objectguid_module_init(void)
{
struct ldb_module *ctx;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
ctx->private_data = NULL;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &objectguid_ops;
return ctx;
return ldb_register_module(&objectguid_ops);
}

View File

@ -731,19 +731,7 @@ static const struct ldb_module_ops password_hash_ops = {
};
/* the init function */
struct ldb_module *password_hash_module_init(struct ldb_context *ldb, const char *options[])
int password_hash_module_init(void)
{
struct ldb_module *ctx;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
ctx->private_data = NULL;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &password_hash_ops;
return ctx;
return ldb_register_module(&password_hash_ops);
}

View File

@ -333,22 +333,7 @@ static const struct ldb_module_ops proxy_ops = {
.request = proxy_request
};
struct ldb_module *proxy_module_init(struct ldb_context *ldb, const char *options[])
int proxy_module_init(void)
{
struct ldb_module *ctx;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &proxy_ops;
ctx->private_data = talloc_zero(ctx, struct proxy_data);
if (ctx->private_data == NULL) {
return NULL;
}
return ctx;
return ldb_register_module(&proxy_ops);
}

View File

@ -199,34 +199,30 @@ static int rootdse_request(struct ldb_module *module, struct ldb_request *req)
return ldb_next_request(module, req);
}
static const struct ldb_module_ops rootdse_ops = {
.name = "rootdse",
.request = rootdse_request
};
struct ldb_module *rootdse_module_init(struct ldb_context *ldb, const char *options[])
static int rootdse_init(struct ldb_module *module)
{
struct ldb_module *ctx;
struct private_data *data;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
data = talloc(ctx, struct private_data);
data = talloc(module, struct private_data);
if (data == NULL) {
talloc_free(ctx);
return NULL;
return -1;
}
data->num_controls = 0;
data->controls = NULL;
ctx->private_data = data;
module->private_data = data;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &rootdse_ops;
return ctx;
return ldb_next_init(module);
}
static const struct ldb_module_ops rootdse_ops = {
.name = "rootdse",
.init_context = rootdse_init,
.request = rootdse_request
};
int rootdse_module_init(void)
{
return ldb_register_module(&rootdse_ops);
}

View File

@ -855,8 +855,8 @@ const struct ldb_map_attribute samba3_attributes[] =
}
};
/* the init function */
struct ldb_module *ldb_samba3sam_module_init(struct ldb_context *ldb, const char *options[])
/* the init function */
int ldb_samba3sam_module_init(void)
{
return ldb_map_init(ldb, samba3_attributes, samba3_objectclasses, "samba3sam");
}

View File

@ -819,27 +819,20 @@ static int samldb_request(struct ldb_module *module, struct ldb_request *req)
}
}
static int samldb_init(struct ldb_module *module)
{
talloc_set_destructor(module, samldb_destructor);
return ldb_next_init(module);
}
static const struct ldb_module_ops samldb_ops = {
.name = "samldb",
.init_context = samldb_init,
.request = samldb_request
};
/* the init function */
struct ldb_module *samldb_module_init(struct ldb_context *ldb, const char *options[])
int samldb_module_init(void)
{
struct ldb_module *ctx;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
ctx->private_data = NULL;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &samldb_ops;
talloc_set_destructor(ctx, samldb_destructor);
return ctx;
return ldb_register_module(&samldb_ops);
}

View File

@ -545,6 +545,8 @@ static void ldapsrv_task_init(struct task_server *task)
struct ldapsrv_service *ldap_service;
NTSTATUS status;
ldb_global_init();
ldap_service = talloc_zero(task, struct ldapsrv_service);
if (ldap_service == NULL) goto failed;

View File

@ -128,19 +128,6 @@ void ldb_reset_err_string(struct ldb_context *ldb)
if (module == NULL) return -1; \
} while (0)
/*
second stage init all modules loaded
*/
int ldb_second_stage_init(struct ldb_context *ldb)
{
struct ldb_module *module;
FIRST_OP(ldb, second_stage_init);
return module->ops->second_stage_init(module);
}
/*
start a transaction
*/

View File

@ -67,7 +67,7 @@ static char *talloc_strdup_no_spaces(struct ldb_context *ldb, const char *string
/* modules are called in inverse order on the stack.
Lets place them as an admin would think the right order is.
Modules order is imprtant */
Modules order is important */
static char **ldb_modules_list_from_string(struct ldb_context *ldb, const char *string)
{
char **modules = NULL;
@ -109,35 +109,79 @@ static char **ldb_modules_list_from_string(struct ldb_context *ldb, const char *
return modules;
}
static struct ops_list_entry {
const struct ldb_module_ops *ops;
struct ops_list_entry *next;
} *registered_modules = NULL;
static const struct ldb_module_ops *ldb_find_module_ops(const char *name)
{
struct ops_list_entry *e;
for (e = registered_modules; e; e = e->next) {
if (strcmp(e->ops->name, name) == 0)
return e->ops;
}
return NULL;
}
#ifndef STATIC_LIBLDB_MODULES
#define STATIC_LIBLDB_MODULES \
{ \
ldb_schema_init, \
ldb_operational_init, \
ldb_rdn_name_init, \
ldb_objectclass_init, \
ldb_paged_results_init, \
ldb_sort_init, \
NULL \
}
#endif
int ldb_global_init(void)
{
static int (*static_init_fns[])(void) = STATIC_LIBLDB_MODULES;
static int initialized = 0;
int ret = 0, i;
if (initialized)
return 0;
initialized = 1;
for (i = 0; static_init_fns[i]; i++) {
if (static_init_fns[i]() == -1)
ret = -1;
}
return ret;
}
int ldb_register_module(const struct ldb_module_ops *ops)
{
struct ops_list_entry *entry = talloc(talloc_autofree_context(), struct ops_list_entry);
if (ldb_find_module_ops(ops->name) != NULL)
return -1;
if (entry == NULL)
return -1;
entry->ops = ops;
entry->next = registered_modules;
registered_modules = entry;
return 0;
}
int ldb_load_modules(struct ldb_context *ldb, const char *options[])
{
char **modules = NULL;
struct ldb_module *module;
int i;
const struct {
const char *name;
ldb_module_init_t init;
} well_known_modules[] = {
{ "schema", schema_module_init },
{ "operational", operational_module_init },
{ "rdn_name", rdn_name_module_init },
{ "objectclass", objectclass_module_init },
{ "paged_results", paged_results_module_init },
{ "server_sort", server_sort_module_init },
{ "asq", asq_module_init },
#ifdef _SAMBA_BUILD_
{ "objectguid", objectguid_module_init },
{ "samldb", samldb_module_init },
{ "samba3sam", ldb_samba3sam_module_init },
{ "proxy", proxy_module_init },
{ "rootdse", rootdse_module_init },
{ "extended_dn", extended_dn_module_init },
{ "password_hash", password_hash_module_init },
{ "kludge_acl", kludge_acl_module_init },
{ "wins_ldb", wins_ldb_module_init },
#endif
{ NULL, NULL }
};
/* find out which modules we are requested to activate */
/* check if we have a custom module list passd as ldb option */
@ -149,7 +193,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
}
}
/* if not overloaded by options and the backend is not ldap try to load the modules list form ldb */
/* if not overloaded by options and the backend is not ldap try to load the modules list from ldb */
if ((modules == NULL) && (strcmp("ldap", ldb->modules->ops->name) != 0)) {
int ret;
const char * const attrs[] = { "@LIST" , NULL};
@ -191,27 +235,34 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
for (i = 0; modules[i] != NULL; i++) {
struct ldb_module *current;
int m;
for (m=0;well_known_modules[m].name;m++) {
if (strcmp(modules[i], well_known_modules[m].name) == 0) {
current = well_known_modules[m].init(ldb, options);
if (current == NULL) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "function 'init_module' in %s fails\n", modules[i]);
return -1;
}
DLIST_ADD(ldb->modules, current);
break;
}
}
if (well_known_modules[m].name == NULL) {
const struct ldb_module_ops *ops;
ops = ldb_find_module_ops(modules[i]);
if (ops == NULL) {
ldb_debug(ldb, LDB_DEBUG_WARNING, "WARNING: Module [%s] not found\n",
modules[i]);
continue;
}
current = talloc_zero(ldb, struct ldb_module);
if (current == NULL) {
return -1;
}
current->ldb = ldb;
current->ops = ops;
DLIST_ADD(ldb->modules, current);
}
/* second stage init */
if (ldb_second_stage_init(ldb) != LDB_SUCCESS) {
ldb_debug(ldb, LDB_DEBUG_ERROR, "ERROR: Second stage init failed!\n");
module = ldb->modules;
while (module && module->ops->init_context == NULL)
module = module->next;
if (module && module->ops->init_context &&
module->ops->init_context(module) != LDB_SUCCESS) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "module initialization failed\n");
return -1;
}
@ -240,10 +291,20 @@ int ldb_next_request(struct ldb_module *module, struct ldb_request *request)
return module->ops->request(module, request);
}
int ldb_next_second_stage_init(struct ldb_module *module)
int ldb_next_init(struct ldb_module *module)
{
FIND_OP(module, second_stage_init);
return module->ops->second_stage_init(module);
/* init is different in that it is not an error if modules
* do not require initialization */
module = module->next;
while (module && module->ops->init_context == NULL)
module = module->next;
if (module == NULL)
return LDB_SUCCESS;
return module->ops->init_context(module);
}
int ldb_next_start_trans(struct ldb_module *module)

View File

@ -1,6 +1,7 @@
################################################
# Start MODULE libldb_asq
[MODULE::libldb_asq]
INIT_FUNCTION = ldb_asq_init
SUBSYSTEM = LIBLDB
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
@ -11,6 +12,7 @@ OBJ_FILES = \
################################################
# Start MODULE libldb_sort
[MODULE::libldb_sort]
INIT_FUNCTION = ldb_sort_init
SUBSYSTEM = LIBLDB
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
@ -21,6 +23,7 @@ OBJ_FILES = \
################################################
# Start MODULE libldb_paged_results
[MODULE::libldb_paged_results]
INIT_FUNCTION = ldb_paged_results_init
SUBSYSTEM = LIBLDB
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
@ -32,6 +35,7 @@ OBJ_FILES = \
# Start MODULE libldb_operational
[MODULE::libldb_operational]
SUBSYSTEM = LIBLDB
INIT_FUNCTION = ldb_operational_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
modules/operational.o
@ -41,6 +45,7 @@ OBJ_FILES = \
################################################
# Start MODULE libldb_objectclass
[MODULE::libldb_objectclass]
INIT_FUNCTION = ldb_objectclass_init
SUBSYSTEM = LIBLDB
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
@ -52,6 +57,7 @@ OBJ_FILES = \
# Start MODULE libldb_rdn_name
[MODULE::libldb_rdn_name]
SUBSYSTEM = LIBLDB
INIT_FUNCTION = ldb_rdn_name_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
modules/rdn_name.o
@ -61,6 +67,7 @@ OBJ_FILES = \
################################################
# Start MODULE libldb_schema
[MODULE::libldb_schema]
INIT_FUNCTION = ldb_schema_init
SUBSYSTEM = LIBLDB
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
@ -94,6 +101,7 @@ OBJ_FILES = modules/ldb_map.o
# Start MODULE libldb_skel
[MODULE::libldb_skel]
SUBSYSTEM = LIBLDB
INIT_FUNCTION = ldb_skel_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = modules/skel.o
# End MODULE libldb_skel
@ -136,6 +144,7 @@ NOPROTO = YES
MAJOR_VERSION = 0
MINOR_VERSION = 0
DESCRIPTION = LDAP-like embedded database library
INIT_FUNCTION_TYPE = int (*) (void)
RELEASE_VERSION = 1
OBJ_FILES = \
common/ldb.o \

View File

@ -10,6 +10,8 @@
#include "system/iconv.h"
#include "system/time.h"
#include "build.h"
#else /*_SAMBA_BUILD_*/
#ifndef _GNU_SOURCE

View File

@ -665,6 +665,15 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *request);
int ldb_async_wait(struct ldb_context *ldb, struct ldb_async_handle *handle, enum ldb_async_wait_type type);
/**
Initialise ldbs' global information
This is required before any other LDB call
\return 0 if initialisation succeeded, -1 otherwise
*/
int ldb_global_init(void);
/**
Initialise an ldb context

View File

@ -56,11 +56,11 @@ struct ldb_module {
*/
struct ldb_module_ops {
const char *name;
int (*init_context) (struct ldb_module *);
int (*request)(struct ldb_module *, struct ldb_request *);
int (*start_transaction)(struct ldb_module *);
int (*end_transaction)(struct ldb_module *);
int (*del_transaction)(struct ldb_module *);
int (*second_stage_init)(struct ldb_module *);
};
@ -112,9 +112,6 @@ struct ldb_context {
uint64_t (*sequence_number)(struct ldb_context *);
};
/* the modules init function */
typedef struct ldb_module *(*ldb_module_init_t)(struct ldb_context *, const char **);
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
#endif
@ -124,9 +121,6 @@ typedef struct ldb_module *(*ldb_module_init_t)(struct ldb_context *, const char
*/
#define ldb_oom(ldb) ldb_debug_set(ldb, LDB_DEBUG_FATAL, "ldb out of memory at %s:%d\n", __FILE__, __LINE__)
/* The following definitions come from lib/ldb/common/ldb.c */
int ldb_second_stage_init(struct ldb_context *ldb);
/* The following definitions come from lib/ldb/common/ldb_modules.c */
int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
@ -134,11 +128,13 @@ int ldb_next_request(struct ldb_module *module, struct ldb_request *request);
int ldb_next_start_trans(struct ldb_module *module);
int ldb_next_end_trans(struct ldb_module *module);
int ldb_next_del_trans(struct ldb_module *module);
int ldb_next_second_stage_init(struct ldb_module *module);
int ldb_next_init(struct ldb_module *module);
void ldb_set_errstring(struct ldb_context *ldb, char *err_string);
void ldb_reset_err_string(struct ldb_context *ldb);
int ldb_register_module(const struct ldb_module_ops *);
/* The following definitions come from lib/ldb/common/ldb_debug.c */
void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level,
@ -161,14 +157,13 @@ int lsqlite3_connect(struct ldb_context *ldb,
const char *url,
unsigned int flags,
const char *options[]);
struct ldb_module *objectclass_module_init(struct ldb_context *ldb, const char *options[]);
struct ldb_module *operational_module_init(struct ldb_context *ldb, const char *options[]);
struct ldb_module *paged_results_module_init(struct ldb_context *ldb, const char *options[]);
struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *options[]);
struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *options[]);
struct ldb_module *server_sort_module_init(struct ldb_context *ldb, const char *options[]);
struct ldb_module *asq_module_init(struct ldb_context *ldb, const char *options[]);
int ldb_objectclass_init(void);
int ldb_operational_init(void);
int ldb_paged_results_init(void);
int ldb_rdn_name_init(void);
int ldb_schema_init(void);
int ldb_sort_init(void);
int ldb_match_msg(struct ldb_context *ldb,
struct ldb_message *msg,

View File

@ -898,7 +898,6 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req)
}
}
static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type)
{
struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context);
@ -939,7 +938,7 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_
/*
fetch the rootDSE for later use
*/
static int ildb_init_2(struct ldb_module *module)
static int ildb_init(struct ldb_module *module)
{
struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ldb_result *res = NULL;
@ -963,7 +962,7 @@ static const struct ldb_module_ops ildb_ops = {
.start_transaction = ildb_start_trans,
.end_transaction = ildb_end_trans,
.del_transaction = ildb_del_trans,
.second_stage_init = ildb_init_2
.init_context = ildb_init
};
/*

View File

@ -1006,18 +1006,12 @@ static int lldb_request(struct ldb_module *module, struct ldb_request *req)
}
}
static int lldb_init_2(struct ldb_module *module)
{
return LDB_SUCCESS;
}
static const struct ldb_module_ops lldb_ops = {
.name = "ldap",
.request = lldb_request,
.start_transaction = lldb_start_trans,
.end_transaction = lldb_end_trans,
.del_transaction = lldb_del_trans,
.second_stage_init = lldb_init_2
};

View File

@ -797,18 +797,12 @@ static uint64_t ltdb_sequence_number(struct ldb_context *ldb)
return seq_num;
}
static int ltdb_init_2(struct ldb_module *module)
{
return LDB_SUCCESS;
}
static const struct ldb_module_ops ltdb_ops = {
.name = "tdb",
.request = ltdb_request,
.start_transaction = ltdb_start_trans,
.end_transaction = ltdb_end_trans,
.del_transaction = ltdb_del_trans,
.second_stage_init = ltdb_init_2
.del_transaction = ltdb_del_trans
};

View File

@ -210,7 +210,7 @@ static int asq(struct ldb_module *module, struct ldb_request *req)
}
}
static int asq_init_2(struct ldb_module *module)
static int asq_init(struct ldb_module *module)
{
struct ldb_request request;
int ret;
@ -225,28 +225,17 @@ static int asq_init_2(struct ldb_module *module)
return LDB_ERR_OTHER;
}
return ldb_next_second_stage_init(module);
return ldb_next_init(module);
}
static const struct ldb_module_ops asq_ops = {
.name = "asq",
.request = asq,
.second_stage_init = asq_init_2
.init_context = asq_init
};
struct ldb_module *asq_module_init(struct ldb_context *ldb, const char *options[])
int ldb_asq_init(void)
{
struct ldb_module *ctx;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &asq_ops;
ctx->private_data = NULL;
return ctx;
return ldb_register_module(&asq_ops);
}

View File

@ -302,19 +302,7 @@ static const struct ldb_module_ops objectclass_ops = {
.request = objectclass_request,
};
struct ldb_module *objectclass_module_init(struct ldb_context *ldb, const char *options[])
int ldb_objectclass_init(void)
{
struct ldb_module *ctx;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
ctx->private_data = NULL;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &objectclass_ops;
return ctx;
return ldb_register_module(&objectclass_ops);
}

View File

@ -400,31 +400,24 @@ static int operational_request(struct ldb_module *module, struct ldb_request *re
}
}
static int operational_init(struct ldb_module *ctx)
{
/* setup some standard attribute handlers */
ldb_set_attrib_handler_syntax(ctx->ldb, "whenCreated", LDB_SYNTAX_UTC_TIME);
ldb_set_attrib_handler_syntax(ctx->ldb, "whenChanged", LDB_SYNTAX_UTC_TIME);
ldb_set_attrib_handler_syntax(ctx->ldb, "subschemaSubentry", LDB_SYNTAX_DN);
ldb_set_attrib_handler_syntax(ctx->ldb, "structuralObjectClass", LDB_SYNTAX_OBJECTCLASS);
return ldb_next_init(ctx);
}
static const struct ldb_module_ops operational_ops = {
.name = "operational",
.request = operational_request
.request = operational_request,
.init_context = operational_init
};
/* the init function */
struct ldb_module *operational_module_init(struct ldb_context *ldb, const char *options[])
int ldb_operational_init(void)
{
struct ldb_module *ctx;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
ctx->private_data = NULL;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &operational_ops;
/* setup some standard attribute handlers */
ldb_set_attrib_handler_syntax(ldb, "whenCreated", LDB_SYNTAX_UTC_TIME);
ldb_set_attrib_handler_syntax(ldb, "whenChanged", LDB_SYNTAX_UTC_TIME);
ldb_set_attrib_handler_syntax(ldb, "subschemaSubentry", LDB_SYNTAX_DN);
ldb_set_attrib_handler_syntax(ldb, "structuralObjectClass", LDB_SYNTAX_OBJECTCLASS);
return ctx;
return ldb_register_module(&operational_ops);
}

View File

@ -247,10 +247,20 @@ static int paged_request(struct ldb_module *module, struct ldb_request *req)
}
}
static int paged_request_init_2(struct ldb_module *module)
static int paged_request_init(struct ldb_module *module)
{
struct ldb_request request;
int ret;
struct private_data *data;
data = talloc(module, struct private_data);
if (data == NULL) {
return LDB_ERR_OTHER;
}
data->next_free_id = 1;
data->store = NULL;
module->private_data = data;
request.operation = LDB_REQ_REGISTER;
request.op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID;
@ -262,37 +272,17 @@ static int paged_request_init_2(struct ldb_module *module)
return LDB_ERR_OTHER;
}
return ldb_next_second_stage_init(module);
return ldb_next_init(module);
}
static const struct ldb_module_ops paged_ops = {
.name = "paged_results",
.request = paged_request,
.second_stage_init = paged_request_init_2
.name = "paged_results",
.request = paged_request,
.init_context = paged_request_init
};
struct ldb_module *paged_results_module_init(struct ldb_context *ldb, const char *options[])
int ldb_paged_results_init(void)
{
struct ldb_module *ctx;
struct private_data *data;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
data = talloc(ctx, struct private_data);
if (data == NULL) {
talloc_free(ctx);
return NULL;
}
data->next_free_id = 1;
data->store = NULL;
ctx->private_data = data;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &paged_ops;
return ctx;
return ldb_register_module(&paged_ops);
}

View File

@ -211,19 +211,7 @@ static const struct ldb_module_ops rdn_name_ops = {
};
/* the init function */
struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *options[])
int ldb_rdn_name_init(void)
{
struct ldb_module *ctx;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
ctx->private_data = NULL;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &rdn_name_ops;
return ctx;
return ldb_register_module(&rdn_name_ops);
}

View File

@ -482,19 +482,7 @@ static const struct ldb_module_ops schema_ops = {
.request = schema_request
};
struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *options[])
int ldb_schema_init(void)
{
struct ldb_module *ctx;
ctx = talloc(ldb, struct ldb_module);
if (!ctx) {
return NULL;
}
ctx->private_data = NULL;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &schema_ops;
return ctx;
return ldb_register_module(&schema_ops);
}

View File

@ -122,45 +122,33 @@ static int skel_request(struct ldb_module *module, struct ldb_request *req)
}
}
static int skel_init_2(struct ldb_module *module)
static int skel_init(struct ldb_module *ctx)
{
/* second stage init stuff */
/* see control modules as example */
return ldb_next_second_stage_init(module);
}
static const struct ldb_module_ops skel_ops = {
.name = "skel",
.request = skel_request,
.start_transaction = skel_start_trans,
.end_transaction = skel_end_trans,
.del_transaction = skel_del_trans,
.second_stage_init = skel_init_2
};
struct ldb_module *skel_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
struct private_data *data;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
data = talloc(ctx, struct private_data);
if (data == NULL) {
talloc_free(ctx);
return NULL;
return 1;
}
data->some_private_data = NULL;
ctx->private_data = data;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &skel_ops;
talloc_set_destructor (ctx, skel_destructor);
return ctx;
return ldb_next_init(ctx);
}
static const struct ldb_module_ops skel_ops = {
.name = "skel",
.init_context = skel_init,
.request = skel_request,
.start_transaction = skel_start_trans,
.end_transaction = skel_end_trans,
.del_transaction = skel_del_trans,
};
int ldb_skel_init(void)
{
return ldb_register_module(&skel_ops);
}

View File

@ -228,7 +228,7 @@ static int server_sort(struct ldb_module *module, struct ldb_request *req)
}
}
static int server_sort_init_2(struct ldb_module *module)
static int server_sort_init(struct ldb_module *module)
{
struct ldb_request request;
int ret;
@ -243,27 +243,16 @@ static int server_sort_init_2(struct ldb_module *module)
return LDB_ERR_OTHER;
}
return ldb_next_second_stage_init(module);
return ldb_next_init(module);
}
static const struct ldb_module_ops server_sort_ops = {
.name = "server_sort",
.request = server_sort,
.second_stage_init = server_sort_init_2
.init_context = server_sort_init
};
struct ldb_module *server_sort_module_init(struct ldb_context *ldb, const char *options[])
int ldb_sort_init(void)
{
struct ldb_module *ctx;
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &server_sort_ops;
ctx->private_data = NULL;
return ctx;
return ldb_register_module(&server_sort_ops);
}

View File

@ -71,6 +71,8 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
POPT_TABLEEND
};
ldb_global_init();
#ifdef _SAMBA_BUILD_
r = ldb_register_samba_handlers(ldb);
if (r != 0) {

View File

@ -84,12 +84,14 @@ static int process_file(struct ldb_context *ldb, FILE *f)
int main(int argc, const char **argv)
int main(int argc, const char **argv)
{
struct ldb_context *ldb;
int i, count=0;
struct ldb_cmdline *options;
ldb_global_init();
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);

View File

@ -79,6 +79,8 @@ static void usage(void)
int ret, i;
struct ldb_cmdline *options;
ldb_global_init();
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);

View File

@ -281,6 +281,8 @@ static void usage(void)
const char *expression = "(|(objectClass=*)(distinguishedName=*))";
const char * const * attrs = NULL;
ldb_global_init();
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);

View File

@ -91,6 +91,8 @@ static int process_file(struct ldb_context *ldb, FILE *f)
int i;
struct ldb_cmdline *options;
ldb_global_init();
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);

View File

@ -58,6 +58,8 @@ static void usage(void)
struct ldb_cmdline *options;
const struct ldb_dn *dn1, *dn2;
ldb_global_init();
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);

View File

@ -148,7 +148,7 @@ static int do_search(struct ldb_context *ldb,
return 0;
}
int main(int argc, const char **argv)
int main(int argc, const char **argv)
{
struct ldb_context *ldb;
struct ldb_dn *basedn = NULL;
@ -157,6 +157,8 @@ static int do_search(struct ldb_context *ldb,
int ret = -1;
const char *expression = "(|(objectClass=*)(distinguishedName=*))";
ldb_global_init();
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);

View File

@ -376,6 +376,8 @@ static void usage(void)
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct ldb_context *ldb;
ldb_global_init();
ldb = ldb_init(mem_ctx);
options = ldb_cmdline_process(ldb, argc, argv, usage);

View File

@ -583,6 +583,8 @@ static void usage(void)
FILE *in = stdin;
FILE *out = stdout;
ldb_global_init();
ctx = talloc_new(NULL);
ldb_ctx = ldb_init(ctx);

View File

@ -16,6 +16,7 @@ REQUIRED_SUBSYSTEMS = \
# Start MODULE libldb_wins_ldb
[MODULE::libldb_wins_ldb]
SUBSYSTEM = LIBLDB
INIT_FUNCTION = wins_ldb_module_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
wins/wins_ldb.o

View File

@ -89,27 +89,12 @@ call_next:
return ldb_next_request(module, req);
}
static const struct ldb_module_ops wins_ldb_ops = {
.name = "wins_ldb",
.request = wins_ldb_request
};
/* the init function */
struct ldb_module *wins_ldb_module_init(struct ldb_context *ldb, const char *options[])
static int wins_ldb_init(struct ldb_module *ctx)
{
struct ldb_module *ctx;
struct winsdb_handle *h;
const char *owner;
int ret;
ctx = talloc(ldb, struct ldb_module);
if (!ctx) return NULL;
ctx->private_data = NULL;
ctx->ldb = ldb;
ctx->prev = ctx->next = NULL;
ctx->ops = &wins_ldb_ops;
owner = lp_parm_string(-1, "winsdb", "local_owner");
if (!owner) {
@ -121,17 +106,27 @@ struct ldb_module *wins_ldb_module_init(struct ldb_context *ldb, const char *opt
h = talloc(ctx, struct winsdb_handle);
if (!h) goto failed;
h->ldb = ldb;
h->ldb = ctx->ldb;
h->caller = WINSDB_HANDLE_CALLER_ADMIN;
h->local_owner = talloc_strdup(h, owner);
if (!h->local_owner) goto failed;
ret = ldb_set_opaque(ldb, "winsdb_handle", h);
if (ret != LDB_SUCCESS) goto failed;
return ctx;
return ldb_set_opaque(ctx->ldb, "winsdb_handle", h);
failed:
talloc_free(ctx);
return NULL;
talloc_free(h);
return LDB_ERR_OTHER;
}
static const struct ldb_module_ops wins_ldb_ops = {
.name = "wins_ldb",
.request = wins_ldb_request,
.init_context = wins_ldb_init
};
/* the init function */
int wins_ldb_module_init(void)
{
return ldb_register_module(&wins_ldb_ops);
}

View File

@ -29,6 +29,7 @@
#include "libcli/composite/composite.h"
#include "smbd/service_task.h"
#include "lib/socket/socket.h"
#include "lib/ldb/include/ldb.h"
/*
work out the ttl we will use given a client requested ttl
@ -840,6 +841,8 @@ NTSTATUS nbtd_winsserver_init(struct nbtd_server *nbtsrv)
return NT_STATUS_OK;
}
ldb_global_init();
nbtsrv->winssrv = talloc_zero(nbtsrv, struct wins_server);
NT_STATUS_HAVE_NO_MEMORY(nbtsrv->winssrv);

View File

@ -26,6 +26,7 @@
#include "lib/appweb/ejs/ejsInternal.h"
#include "scripting/ejs/smbcalls.h"
#include "auth/gensec/gensec.h"
#include "ldb/include/ldb.h"
static EjsId eid;
@ -37,7 +38,7 @@ void ejs_exception(const char *reason)
exit(127);
}
int main(int argc, const char **argv)
int main(int argc, const char **argv)
{
EjsHandle handle = 0;
MprVar result;
@ -50,6 +51,9 @@ void ejs_exception(const char *reason)
int exit_status, i;
fault_setup(argv[0]);
ldb_global_init();
gensec_init();
mprSetCtx(mem_ctx);

View File

@ -35,7 +35,7 @@
#include "smb_server/smb_server.h"
#include "mutex.h"
/* For sepecifiying event context to GSSAPI below */
/* For specifying event context to GSSAPI below */
#include "system/kerberos.h"
#include "heimdal/lib/gssapi/gssapi_locl.h"