summaryrefslogtreecommitdiff
path: root/source4/dsdb/samdb/ldb_modules
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2009-11-07 12:07:06 +1100
committerAndrew Bartlett <abartlet@samba.org>2009-11-12 16:34:07 +1100
commit6fd6dc10897763670bf116746a6d8c2041b2bacd (patch)
treec409daee67a6de44f5f6e3f49a4e8637d298fb97 /source4/dsdb/samdb/ldb_modules
parent4e2b4be9d3bd406a303b74c8d5ebd56714a337ae (diff)
downloadsamba-6fd6dc10897763670bf116746a6d8c2041b2bacd.tar.gz
samba-6fd6dc10897763670bf116746a6d8c2041b2bacd.tar.bz2
samba-6fd6dc10897763670bf116746a6d8c2041b2bacd.zip
s4:dsdb Cosmetic fixes found by metze in review of dsdb_dn changes
These changes include reworking the code to call ldb_module_get_ctx() less often (avoid the function calls, particularly during the step into a complex function). Andrew Bartlett
Diffstat (limited to 'source4/dsdb/samdb/ldb_modules')
-rw-r--r--source4/dsdb/samdb/ldb_modules/extended_dn_out.c41
-rw-r--r--source4/dsdb/samdb/ldb_modules/extended_dn_store.c24
2 files changed, 36 insertions, 29 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/extended_dn_out.c b/source4/dsdb/samdb/ldb_modules/extended_dn_out.c
index c4ddf6781f..0f8c1ab1f1 100644
--- a/source4/dsdb/samdb/ldb_modules/extended_dn_out.c
+++ b/source4/dsdb/samdb/ldb_modules/extended_dn_out.c
@@ -327,10 +327,10 @@ static int extended_callback(struct ldb_request *req, struct ldb_reply *ares,
int ret, i, j;
struct ldb_message *msg = ares->message;
struct extended_dn_out_private *p;
-
+ struct ldb_context *ldb;
ac = talloc_get_type(req->context, struct extended_search_context);
p = talloc_get_type(ldb_module_get_private(ac->module), struct extended_dn_out_private);
-
+ ldb = ldb_module_get_ctx(ac->module);
if (!ares) {
return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_OPERATIONS_ERROR);
@@ -361,7 +361,7 @@ static int extended_callback(struct ldb_request *req, struct ldb_reply *ares,
if (ac->inject) {
/* for each record returned post-process to add any derived
attributes that have been asked for */
- ret = inject_extended_dn_out(ares, ldb_module_get_ctx(ac->module),
+ ret = inject_extended_dn_out(ares, ldb,
ac->extended_type, ac->remove_guid,
ac->remove_sid);
if (ret != LDB_SUCCESS) {
@@ -381,7 +381,7 @@ static int extended_callback(struct ldb_request *req, struct ldb_reply *ares,
ldb_dn_get_linearized(ares->message->dn));
}
if (ret != LDB_SUCCESS) {
- ldb_oom(ldb_module_get_ctx(ac->module));
+ ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
}
@@ -409,7 +409,7 @@ static int extended_callback(struct ldb_request *req, struct ldb_reply *ares,
* correct case */
msg->elements[i].name = talloc_strdup(msg->elements, attribute->lDAPDisplayName);
if (!msg->elements[i].name) {
- ldb_oom(ldb_module_get_ctx(ac->module));
+ ldb_oom(ldb);
return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR);
}
}
@@ -429,10 +429,10 @@ static int extended_callback(struct ldb_request *req, struct ldb_reply *ares,
struct ldb_dn *dn;
struct dsdb_dn *dsdb_dn = NULL;
struct ldb_val *plain_dn = &msg->elements[i].values[j];
- dsdb_dn = dsdb_dn_parse(msg, ldb_module_get_ctx(ac->module), plain_dn, attribute->syntax->ldap_oid);
+ dsdb_dn = dsdb_dn_parse(msg, ldb, plain_dn, attribute->syntax->ldap_oid);
if (!dsdb_dn || !ldb_dn_validate(dsdb_dn->dn)) {
- ldb_asprintf_errstring(ldb_module_get_ctx(ac->module),
+ ldb_asprintf_errstring(ldb,
"could not parse %.*s as a %s DN", (int)plain_dn->length, plain_dn->data,
attribute->syntax->ldap_oid);
talloc_free(dsdb_dn);
@@ -476,7 +476,7 @@ static int extended_callback(struct ldb_request *req, struct ldb_reply *ares,
}
if (!dn_str) {
- ldb_oom(ldb_module_get_ctx(ac->module));
+ ldb_oom(ldb);
talloc_free(dsdb_dn);
return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR);
}
@@ -508,6 +508,7 @@ static int extended_dn_out_search(struct ldb_module *module, struct ldb_request
struct ldb_request *down_req;
char **new_attrs;
const char * const *const_attrs;
+ struct ldb_context *ldb = ldb_module_get_ctx(module);
int ret;
struct extended_dn_out_private *p = talloc_get_type(ldb_module_get_private(module), struct extended_dn_out_private);
@@ -528,19 +529,19 @@ static int extended_dn_out_search(struct ldb_module *module, struct ldb_request
if (!control && storage_format_control && storage_format_control->data) {
extended_ctrl = talloc_get_type(storage_format_control->data, struct ldb_extended_dn_control);
if (!extended_ctrl) {
- ldb_set_errstring(ldb_module_get_ctx(module), "extended_dn_out: extended_ctrl was of the wrong data type");
+ ldb_set_errstring(ldb, "extended_dn_out: extended_ctrl was of the wrong data type");
return LDB_ERR_PROTOCOL_ERROR;
}
}
ac = talloc_zero(req, struct extended_search_context);
if (ac == NULL) {
- ldb_oom(ldb_module_get_ctx(module));
+ ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
ac->module = module;
- ac->schema = dsdb_get_schema(ldb_module_get_ctx(module));
+ ac->schema = dsdb_get_schema(ldb);
ac->req = req;
ac->inject = false;
ac->remove_guid = false;
@@ -571,7 +572,7 @@ static int extended_dn_out_search(struct ldb_module *module, struct ldb_request
if (ac->remove_guid || ac->remove_sid) {
new_attrs = copy_attrs(ac, req->op.search.attrs);
if (new_attrs == NULL) {
- ldb_oom(ldb_module_get_ctx(module));
+ ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -589,7 +590,7 @@ static int extended_dn_out_search(struct ldb_module *module, struct ldb_request
}
ret = ldb_build_search_req_ex(&down_req,
- ldb_module_get_ctx(module), ac,
+ ldb, ac,
req->op.search.base,
req->op.search.scope,
req->op.search.tree,
@@ -684,13 +685,13 @@ static int extended_dn_out_dereference_init(struct ldb_module *module, const cha
struct extended_dn_out_private *p = talloc_zero(module, struct extended_dn_out_private);
struct dsdb_openldap_dereference_control *dereference_control;
struct dsdb_attribute *cur;
-
+ struct ldb_context *ldb = ldb_module_get_ctx(module);
struct dsdb_schema *schema;
ldb_module_set_private(module, p);
if (!p) {
- ldb_oom(ldb_module_get_ctx(module));
+ ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -702,7 +703,7 @@ static int extended_dn_out_dereference_init(struct ldb_module *module, const cha
ret = ldb_mod_register_control(module, LDB_CONTROL_EXTENDED_DN_OID);
if (ret != LDB_SUCCESS) {
- ldb_debug(ldb_module_get_ctx(module), LDB_DEBUG_ERROR,
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
"extended_dn_out: Unable to register control with rootdse!\n");
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -713,7 +714,7 @@ static int extended_dn_out_dereference_init(struct ldb_module *module, const cha
return ret;
}
- schema = dsdb_get_schema(ldb_module_get_ctx(module));
+ schema = dsdb_get_schema(ldb);
if (!schema) {
/* No schema on this DB (yet) */
return LDB_SUCCESS;
@@ -723,7 +724,7 @@ static int extended_dn_out_dereference_init(struct ldb_module *module, const cha
= talloc_zero(p, struct dsdb_openldap_dereference_control);
if (!p->dereference_control) {
- ldb_oom(ldb_module_get_ctx(module));
+ ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -735,13 +736,13 @@ static int extended_dn_out_dereference_init(struct ldb_module *module, const cha
= talloc_realloc(p, dereference_control->dereference,
struct dsdb_openldap_dereference *, i + 2);
if (!dereference_control) {
- ldb_oom(ldb_module_get_ctx(module));
+ ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
dereference_control->dereference[i] = talloc(dereference_control->dereference,
struct dsdb_openldap_dereference);
if (!dereference_control->dereference[i]) {
- ldb_oom(ldb_module_get_ctx(module));
+ ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
dereference_control->dereference[i]->source_attribute = cur->lDAPDisplayName;
diff --git a/source4/dsdb/samdb/ldb_modules/extended_dn_store.c b/source4/dsdb/samdb/ldb_modules/extended_dn_store.c
index ef8532c82a..557acf2d82 100644
--- a/source4/dsdb/samdb/ldb_modules/extended_dn_store.c
+++ b/source4/dsdb/samdb/ldb_modules/extended_dn_store.c
@@ -58,6 +58,7 @@ struct extended_dn_replace_list {
struct extended_dn_context {
const struct dsdb_schema *schema;
struct ldb_module *module;
+ struct ldb_context *ldb;
struct ldb_request *req;
struct ldb_request *new_req;
@@ -70,15 +71,16 @@ static struct extended_dn_context *extended_dn_context_init(struct ldb_module *m
struct ldb_request *req)
{
struct extended_dn_context *ac;
-
+ struct ldb_context *ldb = ldb_module_get_ctx(module);
ac = talloc_zero(req, struct extended_dn_context);
if (ac == NULL) {
- ldb_oom(ldb_module_get_ctx(module));
+ ldb_oom(ldb);
return NULL;
}
ac->schema = dsdb_get_schema(ldb_module_get_ctx(module));
ac->module = module;
+ ac->ldb = ldb;
ac->req = req;
return ac;
@@ -127,7 +129,7 @@ static int extended_replace_dn(struct ldb_request *req, struct ldb_reply *ares)
if (ares->error == LDB_ERR_NO_SUCH_OBJECT) {
/* Don't worry too much about dangling references */
- ldb_reset_err_string(ldb_module_get_ctx(os->ac->module));
+ ldb_reset_err_string(os->ac->ldb);
if (os->next) {
struct extended_dn_replace_list *next;
@@ -238,10 +240,10 @@ static int extended_store_replace(struct extended_dn_context *ac,
os->mem_ctx = callback_mem_ctx;
- os->dsdb_dn = dsdb_dn_parse(os, ldb_module_get_ctx(ac->module), plain_dn, oid);
+ os->dsdb_dn = dsdb_dn_parse(os, ac->ldb, plain_dn, oid);
if (!os->dsdb_dn || !ldb_dn_validate(os->dsdb_dn->dn)) {
talloc_free(os);
- ldb_asprintf_errstring(ldb_module_get_ctx(ac->module),
+ ldb_asprintf_errstring(ac->ldb,
"could not parse %.*s as a %s DN", (int)plain_dn->length, plain_dn->data,
oid);
return LDB_ERR_INVALID_DN_SYNTAX;
@@ -264,7 +266,7 @@ static int extended_store_replace(struct extended_dn_context *ac,
* module in the stack will convert this into a normal DN for
* processing */
ret = ldb_build_search_req(&os->search_req,
- ldb_module_get_ctx(ac->module), os, os->dsdb_dn->dn, LDB_SCOPE_BASE, NULL,
+ ac->ldb, os, os->dsdb_dn->dn, LDB_SCOPE_BASE, NULL,
attrs, NULL, os, extended_replace_dn,
ac->req);
@@ -336,7 +338,7 @@ static int extended_dn_add(struct ldb_module *module, struct ldb_request *req)
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ldb_build_add_req(&ac->new_req, ldb_module_get_ctx(module), ac, msg, req->controls, ac, extended_final_callback, req);
+ ret = ldb_build_add_req(&ac->new_req, ac->ldb, ac, msg, req->controls, ac, extended_final_callback, req);
if (ret != LDB_SUCCESS) {
return ret;
}
@@ -385,6 +387,7 @@ static int extended_dn_modify(struct ldb_module *module, struct ldb_request *req
}
if (!ac->schema) {
+ talloc_free(ac);
/* without schema, this doesn't make any sense */
return ldb_next_request(module, req);
}
@@ -406,12 +409,14 @@ static int extended_dn_modify(struct ldb_module *module, struct ldb_request *req
if (!ac->new_req) {
struct ldb_message *msg = ldb_msg_copy(ac, req->op.mod.message);
if (!msg) {
- ldb_oom(ldb_module_get_ctx(module));
+ talloc_free(ac);
+ ldb_oom(ac->ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ldb_build_mod_req(&ac->new_req, ldb_module_get_ctx(module), ac, msg, req->controls, ac, extended_final_callback, req);
+ ret = ldb_build_mod_req(&ac->new_req, ac->ldb, ac, msg, req->controls, ac, extended_final_callback, req);
if (ret != LDB_SUCCESS) {
+ talloc_free(ac);
return ret;
}
}
@@ -428,6 +433,7 @@ static int extended_dn_modify(struct ldb_module *module, struct ldb_request *req
ret = extended_store_replace(ac, req->op.mod.message->elements, &el->values[j],
is_delete, schema_attr->syntax->ldap_oid);
if (ret != LDB_SUCCESS) {
+ talloc_free(ac);
return ret;
}
}