diff options
| author | Andrew Tridgell <tridge@samba.org> | 2011-08-01 12:24:13 +1000 | 
|---|---|---|
| committer | Andrew Tridgell <tridge@samba.org> | 2011-08-04 16:17:24 +1000 | 
| commit | 4ba8069e3d33dca53780521026c972425c1d66c5 (patch) | |
| tree | f05854d1aa7fd48d3f9601dca4b4154ad5856134 | |
| parent | ed59f21f65bf9c16422a01068535bf4a862372d7 (diff) | |
| download | samba-4ba8069e3d33dca53780521026c972425c1d66c5.tar.gz samba-4ba8069e3d33dca53780521026c972425c1d66c5.tar.bz2 samba-4ba8069e3d33dca53780521026c972425c1d66c5.zip | |
ldb: added ldb_dn_replace_components()
this allows you to replace the string part of a DN with the string
part from another DN. This is useful when you want to fix a DN that
has the right GUID but the wrong string part, because the target
object has moved.
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Pair-Programmed-With: Amitay Isaacs <amitay@gmail.com>
| -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 | 
