summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/common/ldb.c13
-rw-r--r--source4/lib/ldb/common/ldb_modules.c21
-rw-r--r--source4/lib/ldb/include/ldb_private.h21
-rw-r--r--source4/lib/ldb/ldb_ildap/ldb_ildap.c8
-rw-r--r--source4/lib/ldb/ldb_ldap/ldb_ldap.c8
-rw-r--r--source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c7
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c8
-rw-r--r--source4/lib/ldb/modules/objectclass.c4
-rw-r--r--source4/lib/ldb/modules/operational.c4
-rw-r--r--source4/lib/ldb/modules/paged_results.c37
-rw-r--r--source4/lib/ldb/modules/rdn_name.c4
-rw-r--r--source4/lib/ldb/modules/schema.c4
-rw-r--r--source4/lib/ldb/modules/skel.c16
-rw-r--r--source4/lib/ldb/modules/sort.c37
14 files changed, 116 insertions, 76 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 604f02a1f7..78e6a74425 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -121,6 +121,19 @@ static void ldb_reset_err_string(struct ldb_context *ldb)
} 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 ldb_transaction_start(struct ldb_context *ldb)
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 26a397dccc..715112a628 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -201,7 +201,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
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;
@@ -217,14 +217,9 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
}
/* 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);
@@ -239,7 +234,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
#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)
@@ -252,6 +247,12 @@ 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)
+{
+ 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);
diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h
index e8a4d1820a..4ef7c5a96d 100644
--- a/source4/lib/ldb/include/ldb_private.h
+++ b/source4/lib/ldb/include/ldb_private.h
@@ -60,6 +60,7 @@ struct ldb_module_ops {
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 *);
};
@@ -104,9 +105,7 @@ struct ldb_context {
};
/* 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]))
@@ -117,6 +116,9 @@ typedef struct ldb_module *(*ldb_module_init_t)(struct ldb_context *, int stage,
*/
#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[]);
@@ -124,6 +126,7 @@ 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);
void ldb_set_errstring(struct ldb_module *module, char *err_string);
@@ -149,12 +152,12 @@ 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, 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,
diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
index ff00a61163..2837296b68 100644
--- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c
+++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
@@ -441,12 +441,18 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req)
}
}
+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
};
diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
index 8207b5f592..dffd0e969c 100644
--- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c
+++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
@@ -514,12 +514,18 @@ 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
+ .del_transaction = lldb_del_trans,
+ .second_stage_init = lldb_init_2
};
diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
index 464c8ce69f..2e8b88a090 100644
--- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
+++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
@@ -1819,6 +1819,10 @@ static int lsqlite3_request(struct ldb_module *module, struct ldb_request *req)
}
}
+static int lsqlite3_init_2(struct ldb_module *module)
+{
+ return LDB_SUCCESS;
+}
/*
* Table of operations for the sqlite3 backend
@@ -1828,7 +1832,8 @@ static const struct ldb_module_ops lsqlite3_ops = {
.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
};
/*
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index 432c713336..0a9a99ccea 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -773,12 +773,18 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req)
}
}
+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
};
diff --git a/source4/lib/ldb/modules/objectclass.c b/source4/lib/ldb/modules/objectclass.c
index 7a037cc98a..c38b3167e8 100644
--- a/source4/lib/ldb/modules/objectclass.c
+++ b/source4/lib/ldb/modules/objectclass.c
@@ -305,12 +305,10 @@ static const struct ldb_module_ops objectclass_ops = {
.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;
diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c
index 09de0936a1..65d9f12e34 100644
--- a/source4/lib/ldb/modules/operational.c
+++ b/source4/lib/ldb/modules/operational.c
@@ -368,12 +368,10 @@ static const struct ldb_module_ops operational_ops = {
/* 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;
diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c
index 31b73d2ae4..8e9fc28348 100644
--- a/source4/lib/ldb/modules/paged_results.c
+++ b/source4/lib/ldb/modules/paged_results.c
@@ -248,32 +248,35 @@ static int paged_request(struct ldb_module *module, struct ldb_request *req)
}
}
+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;
diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c
index f6dbc38740..f35cff916c 100644
--- a/source4/lib/ldb/modules/rdn_name.c
+++ b/source4/lib/ldb/modules/rdn_name.c
@@ -214,12 +214,10 @@ static const struct ldb_module_ops rdn_name_ops = {
/* 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;
diff --git a/source4/lib/ldb/modules/schema.c b/source4/lib/ldb/modules/schema.c
index 778f52885c..9fb2efee30 100644
--- a/source4/lib/ldb/modules/schema.c
+++ b/source4/lib/ldb/modules/schema.c
@@ -484,12 +484,10 @@ static const struct ldb_module_ops schema_ops = {
.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;
diff --git a/source4/lib/ldb/modules/skel.c b/source4/lib/ldb/modules/skel.c
index dacbd6960e..10f730b2f9 100644
--- a/source4/lib/ldb/modules/skel.c
+++ b/source4/lib/ldb/modules/skel.c
@@ -123,25 +123,27 @@ static int skel_request(struct ldb_module *module, struct ldb_request *req)
}
}
+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;
diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c
index 2757647710..88b967b276 100644
--- a/source4/lib/ldb/modules/sort.c
+++ b/source4/lib/ldb/modules/sort.c
@@ -227,31 +227,34 @@ static int server_sort(struct ldb_module *module, struct ldb_request *req)
}
}
+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;