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
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 3 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, see <http://www.gnu.org/licenses/>.
28 * Component: ldbrename
30 * Description: utility to rename records - modelled on ldapmodrdn
32 * Author: Andrew Tridgell
33 * Author: Stefan Metzmacher
38 #include "tools/cmdline.h"
40 static void usage(struct ldb_context
*ldb
)
42 printf("Usage: ldbrename [<options>] <olddn> <newdn>\n");
43 printf("Renames records in a ldb\n\n");
44 ldb_cmdline_help(ldb
, "ldbmodify", stdout
);
45 exit(LDB_ERR_OPERATIONS_ERROR
);
49 int main(int argc
, const char **argv
)
51 struct ldb_context
*ldb
;
53 struct ldb_cmdline
*options
;
54 struct ldb_dn
*dn1
, *dn2
;
55 TALLOC_CTX
*mem_ctx
= talloc_new(NULL
);
57 ldb
= ldb_init(mem_ctx
, NULL
);
59 return LDB_ERR_OPERATIONS_ERROR
;
62 options
= ldb_cmdline_process(ldb
, argc
, argv
, usage
);
64 if (options
->argc
< 2) {
68 dn1
= ldb_dn_new(ldb
, ldb
, options
->argv
[0]);
69 dn2
= ldb_dn_new(ldb
, ldb
, options
->argv
[1]);
70 if ((dn1
== NULL
) || (dn2
== NULL
)) {
71 return LDB_ERR_OPERATIONS_ERROR
;
74 ret
= ldb_rename(ldb
, dn1
, dn2
);
75 if (ret
== LDB_SUCCESS
) {
76 printf("Renamed 1 record\n");
78 printf("rename of '%s' to '%s' failed - %s\n",
79 options
->argv
[0], options
->argv
[1], ldb_errstring(ldb
));