* Author: Stefan Metzmacher
*/
-#include "ldb_includes.h"
+#include "ldb.h"
#include "tools/cmdline.h"
-static void usage(void)
+static void usage(struct ldb_context *ldb)
{
printf("Usage: ldbrename [<options>] <olddn> <newdn>\n");
- printf("Options:\n");
- printf(" -H ldb_url choose the database (or $LDB_URL)\n");
- printf(" -o options pass options like modules to activate\n");
- printf(" e.g: -o modules:timestamps\n");
- printf("\n");
printf("Renames records in a ldb\n\n");
+ ldb_cmdline_help(ldb, "ldbmodify", stdout);
exit(1);
}
int ret;
struct ldb_cmdline *options;
struct ldb_dn *dn1, *dn2;
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
- ldb = ldb_init(NULL);
+ ldb = ldb_init(mem_ctx, NULL);
+ if (ldb == NULL) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
options = ldb_cmdline_process(ldb, argc, argv, usage);
if (options->argc < 2) {
- usage();
+ usage(ldb);
}
dn1 = ldb_dn_new(ldb, ldb, options->argv[0]);
dn2 = ldb_dn_new(ldb, ldb, options->argv[1]);
- if ( ! ldb_dn_validate(dn1)) {
- printf("Invalid DN1: %s\n", options->argv[0]);
- return -1;
- }
- if ( ! ldb_dn_validate(dn2)) {
- printf("Invalid DN2: %s\n", options->argv[1]);
- return -1;
- }
-
ret = ldb_rename(ldb, dn1, dn2);
- if (ret == 0) {
+ if (ret == LDB_SUCCESS) {
printf("Renamed 1 record\n");
} else {
printf("rename of '%s' to '%s' failed - %s\n",
options->argv[0], options->argv[1], ldb_errstring(ldb));
}
- talloc_free(ldb);
+ talloc_free(mem_ctx);
return ret;
}