1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

r9392: Fix ldb_dn_compose to make build farm happy

Add ldb_dn_string_compose so that you can build a dn starting from a
struct ldb_dn base and a set of parameters to be composed in a format
string with the same syntax of printf
This commit is contained in:
Simo Sorce 2005-08-18 16:18:48 +00:00 committed by Gerald (Jerry) Carter
parent 692e35b779
commit 31c69d0655
7 changed files with 36 additions and 42 deletions

View File

@ -624,10 +624,9 @@ static krb5_error_code LDB_lookup_spn_alias(krb5_context context, struct ldb_con
int count;
struct ldb_message **msg;
struct ldb_message_element *spnmappings;
struct ldb_dn *service_dn = ldb_dn_compose_string_dn(mem_ctx,
struct ldb_dn *service_dn = ldb_dn_string_compose(mem_ctx, realm_dn,
"CN=Directory Service,CN=Windows NT"
",CN=Services,CN=Configuration",
realm_dn);
",CN=Services,CN=Configuration");
char *service_dn_str = ldb_dn_linearize(mem_ctx, service_dn);
const char *directory_attrs[] = {
"sPNMappings",

View File

@ -771,7 +771,9 @@ struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const str
new->comp_num = dn1->comp_num;
new->components = talloc_array(new, struct ldb_dn_component, new->comp_num);
} else {
new = ldb_dn_copy_partial(mem_ctx, dn2, dn2->comp_num + dn1?dn1->comp_num:0);
int comp_num = dn2->comp_num;
if (dn1 != NULL) comp_num += dn1->comp_num;
new = ldb_dn_copy_partial(mem_ctx, dn2, comp_num);
}
if (dn1 == NULL) {
@ -790,11 +792,26 @@ failed:
return NULL;
}
struct ldb_dn *ldb_dn_compose_string_dn(void *mem_ctx, const char *dn1, const struct ldb_dn *dn2)
struct ldb_dn *ldb_dn_string_compose(void *mem_ctx, const struct ldb_dn *base, const char *child_fmt, ...)
{
if (dn1 == NULL) return NULL;
struct ldb_dn *dn;
char *child_str;
va_list ap;
int ret;
return ldb_dn_compose(mem_ctx, ldb_dn_explode(mem_ctx, dn1), dn2);
if (child_fmt == NULL) return NULL;
va_start(ap, child_fmt);
ret = vasprintf(&child_str, child_fmt, ap);
va_end(ap);
if (ret <= 0) return NULL;
dn = ldb_dn_compose(mem_ctx, ldb_dn_explode(mem_ctx, child_str), base);
free(child_str);
return dn;
}
struct ldb_dn_component *ldb_dn_get_rdn(void *mem_ctx, const struct ldb_dn *dn)

View File

@ -371,7 +371,7 @@ struct ldb_dn *ldb_dn_make_child(void *mem_ctx,
const struct ldb_dn_component *component,
const struct ldb_dn *base);
struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const struct ldb_dn *dn2);
struct ldb_dn *ldb_dn_compose_string_dn(void *mem_ctx, const char *dn1, const struct ldb_dn *dn2);
struct ldb_dn *ldb_dn_string_compose(void *mem_ctx, const struct ldb_dn *base, const char *child_fmt, ...);
struct ldb_dn_component *ldb_dn_get_rdn(void *mem_ctx, const struct ldb_dn *dn);
/* useful functions for ldb_message structure manipulation */

View File

@ -337,11 +337,8 @@ static NTSTATUS samsync_ldb_handle_user(TALLOC_CTX *mem_ctx,
if (add) {
samdb_msg_add_string(state->sam_ldb, mem_ctx, msg,
"objectClass", obj_class);
msg->dn = ldb_dn_build_child(mem_ctx,
"CN", cn_name,
ldb_dn_build_child(mem_ctx,
"CN", container,
state->base_dn[database]));
msg->dn = ldb_dn_string_compose(mem_ctx, state->base_dn[database],
"CN=%s, CN=%s", cn_name, container);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}
@ -477,11 +474,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_build_child(mem_ctx,
"CN", cn_name,
ldb_dn_build_child(mem_ctx,
"CN", container,
state->base_dn[database]));
msg->dn = ldb_dn_string_compose(mem_ctx, state->base_dn[database],
"CN=%s, CN=%s", cn_name, container);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}
@ -694,11 +688,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_build_child(mem_ctx,
"CN", cn_name,
ldb_dn_build_child(mem_ctx,
"CN", container,
state->base_dn[database]));
msg->dn = ldb_dn_string_compose(mem_ctx, state->base_dn[database],
"CN=%s, CN=%s", cn_name, container);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}

View File

@ -710,11 +710,7 @@ static WERROR sptr_GetPrinterForm(struct ntptr_GenericHandle *printer, TALLOC_CT
* }
*/
base_dn = ldb_dn_compose_string_dn(mem_ctx,
"CN=Forms",
ldb_dn_build_child(mem_ctx,
"CN", printer->object_name,
ldb_dn_explode(mem_ctx, "CN=Printers")));
base_dn = ldb_dn_string_compose(mem_ctx, NULL, "CN=Forms, CN=%s, CN=Printers", printer->object_name);
W_ERROR_HAVE_NO_MEMORY(base_dn);
count = sptr_db_search(sptr_db, mem_ctx, base_dn, &msgs, NULL,

View File

@ -1774,10 +1774,7 @@ static NTSTATUS lsa_CreateSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
msg->dn = ldb_dn_build_child(mem_ctx,
"cn", name,
ldb_dn_build_child(mem_ctx,
"cn", "LSA Secrets", NULL));
msg->dn = ldb_dn_string_compose(mem_ctx, NULL, "cn=%s,cn=LSA Secrets", name);
samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "cn", name);
}

View File

@ -554,11 +554,8 @@ static NTSTATUS samr_CreateDomainGroup(struct dcesrv_call_state *dce_call, TALLO
}
/* add core elements to the ldb_message for the user */
msg->dn = ldb_dn_build_child(mem_ctx,
"CN", groupname,
ldb_dn_build_child(mem_ctx,
"CN", "Users",
d_state->domain_dn));
msg->dn = ldb_dn_string_compose(mem_ctx, d_state->domain_dn,
"CN=%s, CN=Users", groupname);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}
@ -991,11 +988,8 @@ static NTSTATUS samr_CreateDomAlias(struct dcesrv_call_state *dce_call, TALLOC_C
}
/* add core elements to the ldb_message for the alias */
msg->dn = ldb_dn_build_child(mem_ctx,
"CN", alias_name,
ldb_dn_build_child(mem_ctx,
"CN", "Users",
d_state->domain_dn));
msg->dn = ldb_dn_string_compose(mem_ctx, d_state->domain_dn,
"CN=%s, CN=Users", alias_name);
if (!msg->dn) {
return NT_STATUS_NO_MEMORY;
}