LCOV - code coverage report
Current view: top level - lib/ldb/tools - ldbrename.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 19 24 79.2 %
Date: 2021-09-23 10:06:22 Functions: 2 2 100.0 %

          Line data    Source code
       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 "replace.h"
      37             : #include "ldb.h"
      38             : #include "tools/cmdline.h"
      39             : 
      40           1 : static void usage(struct ldb_context *ldb)
      41             : {
      42           1 :         printf("Usage: ldbrename [<options>] <olddn> <newdn>\n");
      43           1 :         printf("Renames records in a ldb\n\n");
      44           1 :         ldb_cmdline_help(ldb, "ldbmodify", stdout);
      45           1 :         exit(LDB_ERR_OPERATIONS_ERROR);
      46             : }
      47             : 
      48             : 
      49           6 : int main(int argc, const char **argv)
      50             : {
      51             :         struct ldb_context *ldb;
      52             :         int ret;
      53             :         struct ldb_cmdline *options;
      54             :         struct ldb_dn *dn1, *dn2;
      55           6 :         TALLOC_CTX *mem_ctx = talloc_new(NULL);
      56             : 
      57           6 :         ldb = ldb_init(mem_ctx, NULL);
      58           6 :         if (ldb == NULL) {
      59           0 :                 return LDB_ERR_OPERATIONS_ERROR;
      60             :         }
      61             : 
      62           6 :         options = ldb_cmdline_process(ldb, argc, argv, usage);
      63             : 
      64           4 :         if (options->argc < 2) {
      65           0 :                 usage(ldb);
      66             :         }
      67             : 
      68           4 :         dn1 = ldb_dn_new(ldb, ldb, options->argv[0]);
      69           4 :         dn2 = ldb_dn_new(ldb, ldb, options->argv[1]);
      70           4 :         if ((dn1 == NULL) || (dn2 == NULL)) {
      71           0 :                 return LDB_ERR_OPERATIONS_ERROR;
      72             :         }
      73             : 
      74           4 :         ret = ldb_rename(ldb, dn1, dn2);
      75           4 :         if (ret == LDB_SUCCESS) {
      76           3 :                 printf("Renamed 1 record\n");
      77             :         } else  {
      78           0 :                 printf("rename of '%s' to '%s' failed - %s\n", 
      79           0 :                         options->argv[0], options->argv[1], ldb_errstring(ldb));
      80             :         }
      81             : 
      82           4 :         talloc_free(mem_ctx);
      83             :         
      84           4 :         return ret;
      85             : }

Generated by: LCOV version 1.13