summaryrefslogtreecommitdiff
path: root/source4/libnet
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2006-11-22 00:59:34 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:28:22 -0500
commit4889eb9f7aae9349e426d0f6d2217adff67eaebd (patch)
tree7eb63c32bcbd19bf64d5c315f01785f30d3a789c /source4/libnet
parentce0c2236b953dc977655dbceef40916825e843ae (diff)
downloadsamba-4889eb9f7aae9349e426d0f6d2217adff67eaebd.tar.gz
samba-4889eb9f7aae9349e426d0f6d2217adff67eaebd.tar.bz2
samba-4889eb9f7aae9349e426d0f6d2217adff67eaebd.zip
r19831: Big ldb_dn optimization and interfaces enhancement patch
This patch changes a lot of the code in ldb_dn.c, and also removes and add a number of manipulation functions around. The aim is to avoid validating a dn if not necessary as the validation code is necessarily slow. This is mainly to speed up internal operations where input is not user generated and so we can assume the DNs need no validation. The code is designed to keep the data as a string if possible. The code is not yet 100% perfect, but pass all the tests so far. A memleak is certainly present, I'll work on that next. Simo. (This used to be commit a580c871d3784602a9cce32d33419e63c8236e63)
Diffstat (limited to 'source4/libnet')
-rw-r--r--source4/libnet/libnet_join.c14
-rw-r--r--source4/libnet/libnet_samsync_ldb.c27
-rw-r--r--source4/libnet/libnet_site.c4
3 files changed, 24 insertions, 21 deletions
diff --git a/source4/libnet/libnet_join.c b/source4/libnet/libnet_join.c
index 01872eb7fc..e68b0d6235 100644
--- a/source4/libnet/libnet_join.c
+++ b/source4/libnet/libnet_join.c
@@ -62,7 +62,7 @@ static NTSTATUS libnet_JoinADSDomain(struct libnet_context *ctx, struct libnet_J
struct GUID drsuapi_bind_guid;
struct ldb_context *remote_ldb;
- const struct ldb_dn *account_dn;
+ struct ldb_dn *account_dn;
const char *account_dn_str;
const char *remote_ldb_url;
struct ldb_result *res;
@@ -219,8 +219,8 @@ static NTSTATUS libnet_JoinADSDomain(struct libnet_context *ctx, struct libnet_J
/* Store the DN of our machine account. */
account_dn_str = r_crack_names.out.ctr.ctr1->array[0].result_name;
- account_dn = ldb_dn_explode(tmp_ctx, account_dn_str);
- if (!account_dn) {
+ account_dn = ldb_dn_new(tmp_ctx, remote_ldb, account_dn_str);
+ if (! ldb_dn_validate(account_dn)) {
r->out.error_string = talloc_asprintf(r, "Invalid account dn: %s",
account_dn_str);
talloc_free(tmp_ctx);
@@ -855,7 +855,7 @@ static NTSTATUS libnet_Join_primary_domain(struct libnet_context *ctx,
struct libnet_JoinDomain *r2;
int ret, rtn;
struct ldb_context *ldb;
- const struct ldb_dn *base_dn;
+ struct ldb_dn *base_dn;
struct ldb_message **msgs, *msg;
const char *sct;
const char * const attrs[] = {
@@ -961,15 +961,15 @@ static NTSTATUS libnet_Join_primary_domain(struct libnet_context *ctx,
return NT_STATUS_NO_MEMORY;
}
- base_dn = ldb_dn_explode(tmp_mem, "cn=Primary Domains");
+ base_dn = ldb_dn_new(tmp_mem, ldb, "cn=Primary Domains");
if (!base_dn) {
r->out.error_string = NULL;
talloc_free(tmp_mem);
return NT_STATUS_NO_MEMORY;
}
- msg->dn = ldb_dn_build_child(tmp_mem, "flatname", r2->out.domain_name, base_dn);
- if (!msg->dn) {
+ msg->dn = ldb_dn_copy(tmp_mem, base_dn);
+ if ( ! ldb_dn_add_child_fmt(msg->dn, "flatname=%s", r2->out.domain_name)) {
r->out.error_string = NULL;
talloc_free(tmp_mem);
return NT_STATUS_NO_MEMORY;
diff --git a/source4/libnet/libnet_samsync_ldb.c b/source4/libnet/libnet_samsync_ldb.c
index a57e2735e7..3c34aca944 100644
--- a/source4/libnet/libnet_samsync_ldb.c
+++ b/source4/libnet/libnet_samsync_ldb.c
@@ -89,9 +89,9 @@ static NTSTATUS samsync_ldb_add_foreignSecurityPrincipal(TALLOC_CTX *mem_ctx,
}
/* add core elements to the ldb_message for the alias */
- msg->dn = ldb_dn_build_child(mem_ctx, "CN", sidstr, basedn);
- if (msg->dn == NULL)
- return NT_STATUS_NO_MEMORY;
+ msg->dn = basedn;
+ if ( ! ldb_dn_add_child_fmt(msg->dn, "CN=%s", sidstr))
+ return NT_STATUS_UNSUCCESSFUL;
samdb_msg_add_string(state->sam_ldb, mem_ctx, msg,
"objectClass",
@@ -128,7 +128,7 @@ static NTSTATUS samsync_ldb_handle_domain(TALLOC_CTX *mem_ctx,
}
if (database == SAM_DATABASE_DOMAIN) {
- const struct ldb_dn *partitions_basedn;
+ struct ldb_dn *partitions_basedn;
const char *domain_attrs[] = {"nETBIOSName", "nCName", NULL};
struct ldb_message **msgs_domain;
int ret_domain;
@@ -149,7 +149,7 @@ static NTSTATUS samsync_ldb_handle_domain(TALLOC_CTX *mem_ctx,
return NT_STATUS_NO_SUCH_DOMAIN;
}
- state->base_dn[database] = samdb_result_dn(state, msgs_domain[0], "nCName", NULL);
+ state->base_dn[database] = samdb_result_dn(state->sam_ldb, state, msgs_domain[0], "nCName", NULL);
if (state->dom_sid[database]) {
/* Update the domain sid with the incoming
@@ -181,7 +181,10 @@ static NTSTATUS samsync_ldb_handle_domain(TALLOC_CTX *mem_ctx,
fetching here */
const char *dnstring = samdb_search_string(state->sam_ldb, mem_ctx, NULL,
"distinguishedName", "objectClass=builtinDomain");
- state->base_dn[database] = ldb_dn_explode(state, dnstring);
+ state->base_dn[database] = ldb_dn_new(state, state->sam_ldb, dnstring);
+ if ( ! ldb_dn_validate(state->base_dn[database])) {
+ return NT_STATUS_INTERNAL_ERROR;
+ }
} else {
/* PRIVs DB */
return NT_STATUS_INVALID_PARAMETER;
@@ -418,8 +421,8 @@ static NTSTATUS samsync_ldb_handle_user(TALLOC_CTX *mem_ctx,
samdb_msg_add_string(state->sam_ldb, mem_ctx, msg,
"objectClass", obj_class);
if (!msg->dn) {
- msg->dn = ldb_dn_string_compose(mem_ctx, state->base_dn[database],
- "CN=%s, CN=%s", cn_name, container);
+ msg->dn = ldb_dn_copy(mem_ctx, state->base_dn[database]);
+ ldb_dn_add_child_fmt(msg->dn, "CN=%s,CN=%s", cn_name, container);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}
@@ -565,8 +568,8 @@ static NTSTATUS samsync_ldb_handle_group(TALLOC_CTX *mem_ctx,
if (add) {
samdb_msg_add_string(state->sam_ldb, mem_ctx, msg,
"objectClass", obj_class);
- msg->dn = ldb_dn_string_compose(mem_ctx, state->base_dn[database],
- "CN=%s, CN=%s", cn_name, container);
+ msg->dn = ldb_dn_copy(mem_ctx, state->base_dn[database]);
+ ldb_dn_add_child_fmt(msg->dn, "CN=%s,CN=%s", cn_name, container);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}
@@ -779,8 +782,8 @@ static NTSTATUS samsync_ldb_handle_alias(TALLOC_CTX *mem_ctx,
if (add) {
samdb_msg_add_string(state->sam_ldb, mem_ctx, msg,
"objectClass", obj_class);
- msg->dn = ldb_dn_string_compose(mem_ctx, state->base_dn[database],
- "CN=%s, CN=%s", cn_name, container);
+ msg->dn = ldb_dn_copy(mem_ctx, state->base_dn[database]);
+ ldb_dn_add_child_fmt(msg->dn, "CN=%s,CN=%s", cn_name, container);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}
diff --git a/source4/libnet/libnet_site.c b/source4/libnet/libnet_site.c
index ec4bb13290..0c42bf1c73 100644
--- a/source4/libnet/libnet_site.c
+++ b/source4/libnet/libnet_site.c
@@ -186,8 +186,8 @@ NTSTATUS libnet_JoinSite(struct ldb_context *remote_ldb,
return NT_STATUS_NO_MEMORY;
}
- server_dn = ldb_dn_explode(tmp_ctx, server_dn_str);
- if (server_dn == NULL) {
+ server_dn = ldb_dn_new(tmp_ctx, remote_ldb, server_dn_str);
+ if ( ! ldb_dn_validate(server_dn)) {
libnet_r->out.error_string = talloc_asprintf(libnet_r,
"Invalid server dn: %s",
server_dn_str);