source: branches/samba-3.5.x/source3/lib/ldb/tools/ldbrename.c

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 2.1 KB
Line 
1/*
2 ldb database library
3
4 Copyright (C) Andrew Tridgell 2004
5 Copyright (C) Stefan Metzmacher 2004
6
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
10
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.
15
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.
20
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/>.
23*/
24
25/*
26 * Name: ldb
27 *
28 * Component: ldbrename
29 *
30 * Description: utility to rename records - modelled on ldapmodrdn
31 *
32 * Author: Andrew Tridgell
33 * Author: Stefan Metzmacher
34 */
35
36#include "includes.h"
37#include "ldb/include/includes.h"
38#include "ldb/tools/cmdline.h"
39
40static void usage(void)
41{
42 printf("Usage: ldbrename [<options>] <olddn> <newdn>\n");
43 printf("Options:\n");
44 printf(" -H ldb_url choose the database (or $LDB_URL)\n");
45 printf(" -o options pass options like modules to activate\n");
46 printf(" e.g: -o modules:timestamps\n");
47 printf("\n");
48 printf("Renames records in a ldb\n\n");
49 exit(1);
50}
51
52
53int main(int argc, const char **argv)
54{
55 struct ldb_context *ldb;
56 int ret;
57 struct ldb_cmdline *options;
58 const struct ldb_dn *dn1, *dn2;
59
60 ldb_global_init();
61
62 ldb = ldb_init(NULL, NULL);
63
64 options = ldb_cmdline_process(ldb, argc, argv, usage);
65
66 if (options->argc < 2) {
67 usage();
68 }
69
70 dn1 = ldb_dn_explode(ldb, options->argv[0]);
71 dn2 = ldb_dn_explode(ldb, options->argv[1]);
72
73 ret = ldb_rename(ldb, dn1, dn2);
74 if (ret == 0) {
75 printf("Renamed 1 record\n");
76 } else {
77 printf("rename of '%s' to '%s' failed - %s\n",
78 options->argv[0], options->argv[1], ldb_errstring(ldb));
79 }
80
81 talloc_free(ldb);
82
83 return ret;
84}
Note: See TracBrowser for help on using the repository browser.