}
}
+static int extended_init_2(struct ldb_module *module)
+{
+ struct ldb_request request;
+ int ret;
+
+ request.operation = LDB_REQ_REGISTER;
+ request.op.reg.oid = LDB_CONTROL_EXTENDED_DN_OID;
+ request.controls = NULL;
+
+ ret = ldb_request(module->ldb, &request);
+ if (ret != LDB_SUCCESS) {
+ ldb_debug(module->ldb, LDB_DEBUG_ERROR, "extended_dn: Unable to register control with rootdse!\n");
+ return LDB_ERR_OTHER;
+ }
+
+ return ldb_next_second_stage_init(module);
+}
+
static const struct ldb_module_ops extended_dn_ops = {
.name = "extended_dn",
.request = extended_request,
+ .second_stage_init = extended_init_2
};
-#ifdef HAVE_DLOPEN_DISABLED
-struct ldb_module *init_module(struct ldb_context *ldb, int stage, const char *options[])
-#else
-struct ldb_module *extended_dn_module_init(struct ldb_context *ldb, int stage, const char *options[])
-#endif
+struct ldb_module *extended_dn_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
- if (stage == LDB_MODULES_INIT_STAGE_2) {
- struct ldb_request request;
- int ret;
-
- request.operation = LDB_REQ_REGISTER;
- request.op.reg.oid = LDB_CONTROL_EXTENDED_DN_OID;
- request.controls = NULL;
-
- ret = ldb_request(ldb, &request);
- if (ret != LDB_SUCCESS) {
- ldb_debug(ldb, LDB_DEBUG_ERROR, "extended_dn: Unable to register control with rootdse!\n");
- }
-
- return NULL;
- }
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
/* the init function */
-struct ldb_module *objectguid_module_init(struct ldb_context *ldb, int stage, const char *options[])
+struct ldb_module *objectguid_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
- if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
/* the init function */
-struct ldb_module *password_hash_module_init(struct ldb_context *ldb, int stage, const char *options[])
+struct ldb_module *password_hash_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
- if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
.request = proxy_request
};
-struct ldb_module *proxy_module_init(struct ldb_context *ldb, int stage, const char *options[])
+struct ldb_module *proxy_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
- if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
.request = rootdse_request
};
-struct ldb_module *rootdse_module_init(struct ldb_context *ldb, int stage, const char *options[])
+struct ldb_module *rootdse_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
struct private_data *data;
- if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
};
/* the init function */
-struct ldb_module *ldb_samba3sam_module_init(struct ldb_context *ldb, int stage, const char *options[])
+struct ldb_module *ldb_samba3sam_module_init(struct ldb_context *ldb, const char *options[])
{
- if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
-
return ldb_map_init(ldb, samba3_attributes, samba3_objectclasses, "samba3sam");
}
/* the init function */
-struct ldb_module *samldb_module_init(struct ldb_context *ldb, int stage, const char *options[])
+struct ldb_module *samldb_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
- if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
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
*/
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, LDB_MODULES_INIT_STAGE_1, options);
+ 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;
}
/* second stage init */
- for (i = 0; modules[i] != NULL; i++) {
- int m;
- for (m = 0; well_known_modules[m].name; m++) {
- if (strcmp(modules[i], well_known_modules[m].name) == 0) {
- well_known_modules[m].init(ldb, LDB_MODULES_INIT_STAGE_2, options);
- break;
- }
- }
+ if (ldb_second_stage_init(ldb) != LDB_SUCCESS) {
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "ERROR: Second stage init failed!\n");
+ return -1;
}
talloc_free(modules);
#define FIND_OP(module, op) do { \
module = module->next; \
while (module && module->ops->op == NULL) module = module->next; \
- if (module == NULL) return -1; \
+ if (module == NULL) return LDB_ERR_OTHER; \
} while (0)
return module->ops->request(module, request);
}
+int ldb_next_second_stage_init(struct ldb_module *module)
+{
+ FIND_OP(module, second_stage_init);
+ return module->ops->second_stage_init(module);
+}
+
int ldb_next_start_trans(struct ldb_module *module)
{
FIND_OP(module, start_transaction);
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 *);
};
};
/* the modules init function */
-#define LDB_MODULES_INIT_STAGE_1 1
-#define LDB_MODULES_INIT_STAGE_2 2
-typedef struct ldb_module *(*ldb_module_init_t)(struct ldb_context *, int stage, const char **);
+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]))
*/
#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[]);
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);
void ldb_set_errstring(struct ldb_module *module, char *err_string);
const char *url,
unsigned int flags,
const char *options[]);
-struct ldb_module *objectclass_module_init(struct ldb_context *ldb, int stage, const char *options[]);
-struct ldb_module *operational_module_init(struct ldb_context *ldb, int stage, const char *options[]);
-struct ldb_module *paged_results_module_init(struct ldb_context *ldb, int stage, const char *options[]);
-struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, int stage, const char *options[]);
-struct ldb_module *schema_module_init(struct ldb_context *ldb, int stage, const char *options[]);
-struct ldb_module *server_sort_module_init(struct ldb_context *ldb, int stage, 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[]);
int ldb_match_msg(struct ldb_context *ldb,
}
}
+static int ildb_init_2(struct ldb_module *module)
+{
+ return LDB_SUCCESS;
+}
+
static const struct ldb_module_ops ildb_ops = {
.name = "ldap",
.request = ildb_request,
.start_transaction = ildb_start_trans,
.end_transaction = ildb_end_trans,
- .del_transaction = ildb_del_trans
+ .del_transaction = ildb_del_trans,
+ .second_stage_init = ildb_init_2
};
}
}
+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
+ .del_transaction = lldb_del_trans,
+ .second_stage_init = lldb_init_2
};
}
}
+static int lsqlite3_init_2(struct ldb_module *module)
+{
+ return LDB_SUCCESS;
+}
/*
* Table of operations for the sqlite3 backend
.request = lsqlite3_request,
.start_transaction = lsqlite3_start_trans,
.end_transaction = lsqlite3_end_trans,
- .del_transaction = lsqlite3_del_trans
+ .del_transaction = lsqlite3_del_trans,
+ .second_stage_init = lsqlite3_init_2
};
/*
}
}
+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
+ .del_transaction = ltdb_del_trans,
+ .second_stage_init = ltdb_init_2
};
.request = objectclass_request,
};
-struct ldb_module *objectclass_module_init(struct ldb_context *ldb, int stage, const char *options[])
+struct ldb_module *objectclass_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
- if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
/* the init function */
-struct ldb_module *operational_module_init(struct ldb_context *ldb, int stage, const char *options[])
+struct ldb_module *operational_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
- if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
}
}
+static int paged_request_init_2(struct ldb_module *module)
+{
+ struct ldb_request request;
+ int ret;
+
+ request.operation = LDB_REQ_REGISTER;
+ request.op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID;
+ request.controls = NULL;
+
+ ret = ldb_request(module->ldb, &request);
+ if (ret != LDB_SUCCESS) {
+ ldb_debug(module->ldb, LDB_DEBUG_ERROR, "paged_request: Unable to register control with rootdse!\n");
+ return LDB_ERR_OTHER;
+ }
+
+ return ldb_next_second_stage_init(module);
+}
+
static const struct ldb_module_ops paged_ops = {
.name = "paged_results",
.request = paged_request,
+ .second_stage_init = paged_request_init_2
};
-struct ldb_module *paged_results_module_init(struct ldb_context *ldb, int stage, const char *options[])
+struct ldb_module *paged_results_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
struct private_data *data;
- if (stage == LDB_MODULES_INIT_STAGE_2) {
- struct ldb_request request;
- int ret;
-
- request.operation = LDB_REQ_REGISTER;
- request.op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID;
- request.controls = NULL;
-
- ret = ldb_request(ldb, &request);
- if (ret != LDB_SUCCESS) {
- ldb_debug(ldb, LDB_DEBUG_ERROR, "paged_request: Unable to register control with rootdse!\n");
- }
-
- return NULL;
- }
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
/* the init function */
-struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, int stage, const char *options[])
+struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
- if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
.request = schema_request
};
-struct ldb_module *schema_module_init(struct ldb_context *ldb, int stage, const char *options[])
+struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
- if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx) {
return NULL;
}
}
+static int skel_init_2(struct ldb_module *module)
+{
+ /* 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, int stage, const char *options[])
+struct ldb_module *skel_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
struct private_data *data;
- if (stage == LDB_MODULES_INIT_STAGE_2) {
- /* second stage init stuff */
- /* see control modules as example */
- return NULL;
- }
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;
}
}
+static int server_sort_init_2(struct ldb_module *module)
+{
+ struct ldb_request request;
+ int ret;
+
+ request.operation = LDB_REQ_REGISTER;
+ request.op.reg.oid = LDB_CONTROL_SERVER_SORT_OID;
+ request.controls = NULL;
+
+ ret = ldb_request(module->ldb, &request);
+ if (ret != LDB_SUCCESS) {
+ ldb_debug(module->ldb, LDB_DEBUG_ERROR, "server_sort: Unable to register control with rootdse!\n");
+ return LDB_ERR_OTHER;
+ }
+
+ return ldb_next_second_stage_init(module);
+}
+
static const struct ldb_module_ops server_sort_ops = {
.name = "server_sort",
.request = server_sort,
+ .second_stage_init = server_sort_init_2
};
-struct ldb_module *server_sort_module_init(struct ldb_context *ldb, int stage, const char *options[])
+struct ldb_module *server_sort_module_init(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *ctx;
- if (stage == LDB_MODULES_INIT_STAGE_2) {
- struct ldb_request request;
- int ret;
-
- request.operation = LDB_REQ_REGISTER;
- request.op.reg.oid = LDB_CONTROL_SERVER_SORT_OID;
- request.controls = NULL;
-
- ret = ldb_request(ldb, &request);
- if (ret != LDB_SUCCESS) {
- ldb_debug(ldb, LDB_DEBUG_ERROR, "server_sort: Unable to register control with rootdse!\n");
- }
-
- return NULL;
- }
-
ctx = talloc(ldb, struct ldb_module);
if (!ctx)
return NULL;