r25068: Older samba3 DCs will return DCERPC_FAULT_OP_RNG_ERROR for every opcode on the
[Samba.git] / source / lib / ldb / tools / ldbrename.c
blob9c0870721d487fb6e85aece70c58ba5ab1e8385c
1 /*
2 ldb database library
4 Copyright (C) Andrew Tridgell 2004
5 Copyright (C) Stefan Metzmacher 2004
7 ** NOTE! The following LGPL license applies to the ldb
8 ** library. This does NOT imply that all of Samba is released
9 ** under the LGPL
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * Name: ldb
29 * Component: ldbrename
31 * Description: utility to rename records - modelled on ldapmodrdn
33 * Author: Andrew Tridgell
34 * Author: Stefan Metzmacher
37 #include "includes.h"
38 #include "ldb/include/includes.h"
39 #include "ldb/tools/cmdline.h"
41 static void usage(void)
43 printf("Usage: ldbrename [<options>] <olddn> <newdn>\n");
44 printf("Options:\n");
45 printf(" -H ldb_url choose the database (or $LDB_URL)\n");
46 printf(" -o options pass options like modules to activate\n");
47 printf(" e.g: -o modules:timestamps\n");
48 printf("\n");
49 printf("Renames records in a ldb\n\n");
50 exit(1);
54 int main(int argc, const char **argv)
56 struct ldb_context *ldb;
57 int ret;
58 struct ldb_cmdline *options;
59 const struct ldb_dn *dn1, *dn2;
61 ldb_global_init();
63 ldb = ldb_init(NULL);
65 options = ldb_cmdline_process(ldb, argc, argv, usage);
67 if (options->argc < 2) {
68 usage();
71 dn1 = ldb_dn_explode(ldb, options->argv[0]);
72 dn2 = ldb_dn_explode(ldb, options->argv[1]);
74 ret = ldb_rename(ldb, dn1, dn2);
75 if (ret == 0) {
76 printf("Renamed 1 record\n");
77 } else {
78 printf("rename of '%s' to '%s' failed - %s\n",
79 options->argv[0], options->argv[1], ldb_errstring(ldb));
82 talloc_free(ldb);
84 return ret;