1
0
mirror of https://github.com/samba-team/samba.git synced 2025-11-05 04:23:51 +03:00

r12743: Remove the ugly way we had to make a second stage init and introduce

a second_stage_init private function for modules that need a second stage init.

Simo.
(This used to be commit 5e8b365fa2)
This commit is contained in:
Simo Sorce
2006-01-06 16:12:45 +00:00
committed by Gerald (Jerry) Carter
parent 8f4dc51345
commit dbef4d76de
21 changed files with 142 additions and 115 deletions

View File

@@ -266,35 +266,34 @@ static int extended_request(struct ldb_module *module, struct ldb_request *req)
} }
} }
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 = { static const struct ldb_module_ops extended_dn_ops = {
.name = "extended_dn", .name = "extended_dn",
.request = extended_request, .request = extended_request,
.second_stage_init = extended_init_2
}; };
#ifdef HAVE_DLOPEN_DISABLED struct ldb_module *extended_dn_module_init(struct ldb_context *ldb, const char *options[])
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 *ctx; 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); ctx = talloc(ldb, struct ldb_module);
if (!ctx) if (!ctx)
return NULL; return NULL;

View File

@@ -128,12 +128,10 @@ static const struct ldb_module_ops objectguid_ops = {
/* the init function */ /* 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; struct ldb_module *ctx;
if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
ctx = talloc(ldb, struct ldb_module); ctx = talloc(ldb, struct ldb_module);
if (!ctx) if (!ctx)
return NULL; return NULL;

View File

@@ -717,12 +717,10 @@ static const struct ldb_module_ops password_hash_ops = {
/* the init function */ /* 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; struct ldb_module *ctx;
if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
ctx = talloc(ldb, struct ldb_module); ctx = talloc(ldb, struct ldb_module);
if (!ctx) if (!ctx)
return NULL; return NULL;

View File

@@ -333,12 +333,10 @@ static const struct ldb_module_ops proxy_ops = {
.request = proxy_request .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; struct ldb_module *ctx;
if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
ctx = talloc(ldb, struct ldb_module); ctx = talloc(ldb, struct ldb_module);
if (!ctx) if (!ctx)
return NULL; return NULL;

View File

@@ -187,13 +187,11 @@ static const struct ldb_module_ops rootdse_ops = {
.request = rootdse_request .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 ldb_module *ctx;
struct private_data *data; struct private_data *data;
if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
ctx = talloc(ldb, struct ldb_module); ctx = talloc(ldb, struct ldb_module);
if (!ctx) if (!ctx)
return NULL; return NULL;

View File

@@ -878,9 +878,7 @@ const struct ldb_map_attribute samba3_attributes[] =
}; };
/* the init function */ /* 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"); return ldb_map_init(ldb, samba3_attributes, samba3_objectclasses, "samba3sam");
} }

View File

@@ -583,12 +583,10 @@ static const struct ldb_module_ops samldb_ops = {
/* the init function */ /* 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; struct ldb_module *ctx;
if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
ctx = talloc(ldb, struct ldb_module); ctx = talloc(ldb, struct ldb_module);
if (!ctx) if (!ctx)
return NULL; return NULL;

View File

@@ -120,6 +120,19 @@ static void ldb_reset_err_string(struct ldb_context *ldb)
if (module == NULL) return -1; \ if (module == NULL) return -1; \
} while (0) } 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 start a transaction
*/ */

View File

@@ -201,7 +201,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
int m; int m;
for (m=0;well_known_modules[m].name;m++) { for (m=0;well_known_modules[m].name;m++) {
if (strcmp(modules[i], well_known_modules[m].name) == 0) { 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) { if (current == NULL) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "function 'init_module' in %s fails\n", modules[i]); ldb_debug(ldb, LDB_DEBUG_FATAL, "function 'init_module' in %s fails\n", modules[i]);
return -1; return -1;
@@ -217,14 +217,9 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
} }
/* second stage init */ /* second stage init */
for (i = 0; modules[i] != NULL; i++) { if (ldb_second_stage_init(ldb) != LDB_SUCCESS) {
int m; ldb_debug(ldb, LDB_DEBUG_ERROR, "ERROR: Second stage init failed!\n");
for (m = 0; well_known_modules[m].name; m++) { return -1;
if (strcmp(modules[i], well_known_modules[m].name) == 0) {
well_known_modules[m].init(ldb, LDB_MODULES_INIT_STAGE_2, options);
break;
}
}
} }
talloc_free(modules); talloc_free(modules);
@@ -239,7 +234,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
#define FIND_OP(module, op) do { \ #define FIND_OP(module, op) do { \
module = module->next; \ module = module->next; \
while (module && module->ops->op == NULL) 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) } while (0)
@@ -252,6 +247,12 @@ int ldb_next_request(struct ldb_module *module, struct ldb_request *request)
return module->ops->request(module, 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) int ldb_next_start_trans(struct ldb_module *module)
{ {
FIND_OP(module, start_transaction); FIND_OP(module, start_transaction);

View File

@@ -60,6 +60,7 @@ struct ldb_module_ops {
int (*start_transaction)(struct ldb_module *); int (*start_transaction)(struct ldb_module *);
int (*end_transaction)(struct ldb_module *); int (*end_transaction)(struct ldb_module *);
int (*del_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 */ /* the modules init function */
#define LDB_MODULES_INIT_STAGE_1 1 typedef struct ldb_module *(*ldb_module_init_t)(struct ldb_context *, const char **);
#define LDB_MODULES_INIT_STAGE_2 2
typedef struct ldb_module *(*ldb_module_init_t)(struct ldb_context *, int stage, const char **);
#ifndef ARRAY_SIZE #ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) #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__) #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 */ /* The following definitions come from lib/ldb/common/ldb_modules.c */
int ldb_load_modules(struct ldb_context *ldb, const char *options[]); 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_start_trans(struct ldb_module *module);
int ldb_next_end_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_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); 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, const char *url,
unsigned int flags, unsigned int flags,
const char *options[]); const char *options[]);
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 *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 *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 *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 *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 *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[]);
int ldb_match_msg(struct ldb_context *ldb, int ldb_match_msg(struct ldb_context *ldb,

View File

@@ -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 = { static const struct ldb_module_ops ildb_ops = {
.name = "ldap", .name = "ldap",
.request = ildb_request, .request = ildb_request,
.start_transaction = ildb_start_trans, .start_transaction = ildb_start_trans,
.end_transaction = ildb_end_trans, .end_transaction = ildb_end_trans,
.del_transaction = ildb_del_trans .del_transaction = ildb_del_trans,
.second_stage_init = ildb_init_2
}; };

View File

@@ -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 = { static const struct ldb_module_ops lldb_ops = {
.name = "ldap", .name = "ldap",
.request = lldb_request, .request = lldb_request,
.start_transaction = lldb_start_trans, .start_transaction = lldb_start_trans,
.end_transaction = lldb_end_trans, .end_transaction = lldb_end_trans,
.del_transaction = lldb_del_trans .del_transaction = lldb_del_trans,
.second_stage_init = lldb_init_2
}; };

View File

@@ -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 * Table of operations for the sqlite3 backend
@@ -1828,7 +1832,8 @@ static const struct ldb_module_ops lsqlite3_ops = {
.request = lsqlite3_request, .request = lsqlite3_request,
.start_transaction = lsqlite3_start_trans, .start_transaction = lsqlite3_start_trans,
.end_transaction = lsqlite3_end_trans, .end_transaction = lsqlite3_end_trans,
.del_transaction = lsqlite3_del_trans .del_transaction = lsqlite3_del_trans,
.second_stage_init = lsqlite3_init_2
}; };
/* /*

View File

@@ -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 = { static const struct ldb_module_ops ltdb_ops = {
.name = "tdb", .name = "tdb",
.request = ltdb_request, .request = ltdb_request,
.start_transaction = ltdb_start_trans, .start_transaction = ltdb_start_trans,
.end_transaction = ltdb_end_trans, .end_transaction = ltdb_end_trans,
.del_transaction = ltdb_del_trans .del_transaction = ltdb_del_trans,
.second_stage_init = ltdb_init_2
}; };

View File

@@ -305,12 +305,10 @@ static const struct ldb_module_ops objectclass_ops = {
.request = objectclass_request, .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; struct ldb_module *ctx;
if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
ctx = talloc(ldb, struct ldb_module); ctx = talloc(ldb, struct ldb_module);
if (!ctx) if (!ctx)
return NULL; return NULL;

View File

@@ -368,12 +368,10 @@ static const struct ldb_module_ops operational_ops = {
/* the init function */ /* 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; struct ldb_module *ctx;
if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
ctx = talloc(ldb, struct ldb_module); ctx = talloc(ldb, struct ldb_module);
if (!ctx) if (!ctx)
return NULL; return NULL;

View File

@@ -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 = { static const struct ldb_module_ops paged_ops = {
.name = "paged_results", .name = "paged_results",
.request = paged_request, .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 ldb_module *ctx;
struct private_data *data; 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); ctx = talloc(ldb, struct ldb_module);
if (!ctx) if (!ctx)
return NULL; return NULL;

View File

@@ -214,12 +214,10 @@ static const struct ldb_module_ops rdn_name_ops = {
/* the init function */ /* 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; struct ldb_module *ctx;
if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
ctx = talloc(ldb, struct ldb_module); ctx = talloc(ldb, struct ldb_module);
if (!ctx) if (!ctx)
return NULL; return NULL;

View File

@@ -484,12 +484,10 @@ static const struct ldb_module_ops schema_ops = {
.request = schema_request .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; struct ldb_module *ctx;
if (stage != LDB_MODULES_INIT_STAGE_1) return NULL;
ctx = talloc(ldb, struct ldb_module); ctx = talloc(ldb, struct ldb_module);
if (!ctx) { if (!ctx) {
return NULL; return NULL;

View File

@@ -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 = { static const struct ldb_module_ops skel_ops = {
.name = "skel", .name = "skel",
.request = skel_request, .request = skel_request,
.start_transaction = skel_start_trans, .start_transaction = skel_start_trans,
.end_transaction = skel_end_trans, .end_transaction = skel_end_trans,
.del_transaction = skel_del_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 ldb_module *ctx;
struct private_data *data; 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); ctx = talloc(ldb, struct ldb_module);
if (!ctx) if (!ctx)
return NULL; return NULL;

View File

@@ -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 = { static const struct ldb_module_ops server_sort_ops = {
.name = "server_sort", .name = "server_sort",
.request = 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; 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); ctx = talloc(ldb, struct ldb_module);
if (!ctx) if (!ctx)
return NULL; return NULL;