diff options
| -rw-r--r-- | lib/ldb/common/ldb_dn.c | 56 | ||||
| -rw-r--r-- | lib/ldb/include/ldb_module.h | 7 | 
2 files changed, 63 insertions, 0 deletions
| diff --git a/lib/ldb/common/ldb_dn.c b/lib/ldb/common/ldb_dn.c index 6b1ef0306f..b910489a8e 100644 --- a/lib/ldb/common/ldb_dn.c +++ b/lib/ldb/common/ldb_dn.c @@ -1684,6 +1684,62 @@ bool ldb_dn_remove_child_components(struct ldb_dn *dn, unsigned int num)  	return true;  } + +/* replace the components of a DN with those from another DN, without + * touching the extended components + * + * return true if successful and false if not + * if false is returned the dn may be marked invalid + */ +bool ldb_dn_replace_components(struct ldb_dn *dn, struct ldb_dn *new_dn) +{ +	int i; + +	if ( ! ldb_dn_validate(dn) || ! ldb_dn_validate(new_dn)) { +		return false; +	} + +	/* free components */ +	for (i = 0; i < dn->comp_num; i++) { +		LDB_FREE(dn->components[i].name); +		LDB_FREE(dn->components[i].value.data); +		LDB_FREE(dn->components[i].cf_name); +		LDB_FREE(dn->components[i].cf_value.data); +	} + +	dn->components = talloc_realloc(dn, +					dn->components, +					struct ldb_dn_component, +					new_dn->comp_num); +	if (dn->components == NULL) { +		ldb_dn_mark_invalid(dn); +		return false; +	} + +	dn->comp_num = new_dn->comp_num; +	dn->valid_case = new_dn->valid_case; + +	for (i = 0; i < dn->comp_num; i++) { +		dn->components[i] = ldb_dn_copy_component(dn->components, &new_dn->components[i]); +		if (dn->components[i].name == NULL) { +			ldb_dn_mark_invalid(dn); +			return false; +		} +	} +	if (new_dn->linearized == NULL) { +		dn->linearized = NULL; +	} else { +		dn->linearized = talloc_strdup(dn, new_dn->linearized); +		if (dn->linearized == NULL) { +			ldb_dn_mark_invalid(dn); +			return false; +		} +	} + +	return true; +} + +  struct ldb_dn *ldb_dn_get_parent(TALLOC_CTX *mem_ctx, struct ldb_dn *dn)  {  	struct ldb_dn *new_dn; diff --git a/lib/ldb/include/ldb_module.h b/lib/ldb/include/ldb_module.h index 6d6fff251c..22d24dbdea 100644 --- a/lib/ldb/include/ldb_module.h +++ b/lib/ldb/include/ldb_module.h @@ -340,5 +340,12 @@ int ldb_module_init_chain(struct ldb_context *ldb, struct ldb_module *module);   */  int ldb_init_module(const char *version); +/* replace the components of a DN with those from another DN, without + * touching the extended components + * + * return true if successful and false if not + * if false is returned the dn may be marked invalid + */ +bool ldb_dn_replace_components(struct ldb_dn *dn, struct ldb_dn *new_dn);  #endif | 
