From e57a23d23f8af229168935681bf3394108df29cd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 5 Apr 2011 14:42:06 +0200 Subject: [PATCH] s4:ldb/tools: add support for "modrdn" to ldbmodify Signed-off-by: Simo Sorce metze --- source4/lib/ldb/tools/ldbmodify.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 1e7aa80d835..2ca7b62b2c3 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -61,6 +61,11 @@ static int process_file(struct ldb_context *ldb, FILE *f, unsigned int *count) } while ((ldif = ldb_ldif_read_file(ldb, f))) { + struct ldb_dn *olddn; + bool deleteoldrdn = false; + struct ldb_dn *newdn; + const char *errstr = NULL; + switch (ldif->changetype) { case LDB_CHANGETYPE_NONE: case LDB_CHANGETYPE_ADD: @@ -72,11 +77,28 @@ static int process_file(struct ldb_context *ldb, FILE *f, unsigned int *count) case LDB_CHANGETYPE_MODIFY: ret = ldb_modify_ctrl(ldb, ldif->msg,req_ctrls); break; + case LDB_CHANGETYPE_MODRDN: + ret = ldb_ldif_parse_modrdn(ldb, ldif, ldif, &olddn, + NULL, &deleteoldrdn, + NULL, &newdn); + if (ret == LDB_SUCCESS) { + if (deleteoldrdn) { + ret = ldb_rename(ldb, olddn, newdn); + } else { + errstr = "modrdn: deleteoldrdn=0 " + "not supported."; + ret = LDB_ERR_CONSTRAINT_VIOLATION; + } + } + break; } if (ret != LDB_SUCCESS) { + if (errstr == NULL) { + errstr = ldb_errstring(ldb); + } fprintf(stderr, "ERR: (%s) \"%s\" on DN %s\n", ldb_strerror(ret), - ldb_errstring(ldb), ldb_dn_get_linearized(ldif->msg->dn)); + errstr, ldb_dn_get_linearized(ldif->msg->dn)); failures++; fun_ret = ret; } else {