2004-10-20 19:28:02 +00:00
/*
ldb database library
Copyright ( C ) Andrew Tridgell 2004
Copyright ( C ) Stefan Metzmacher 2004
* * NOTE ! The following LGPL license applies to the ldb
* * library . This does NOT imply that all of Samba is released
* * under the LGPL
This library is free software ; you can redistribute it and / or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation ; either
version 2 of the License , or ( at your option ) any later version .
This library is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public
License along with this library ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
/*
* Name : ldb
*
* Component : ldbrename
*
* Description : utility to rename records - modelled on ldapmodrdn
*
* Author : Andrew Tridgell
* Author : Stefan Metzmacher
*/
# include "includes.h"
2006-01-10 16:48:32 +00:00
# include "ldb/include/includes.h"
2005-06-18 07:42:21 +00:00
# include "ldb/tools/cmdline.h"
2004-10-20 19:28:02 +00:00
static void usage ( void )
{
printf ( " Usage: ldbrename [<options>] <olddn> <newdn> \n " ) ;
printf ( " Options: \n " ) ;
printf ( " -H ldb_url choose the database (or $LDB_URL) \n " ) ;
2004-11-15 14:16:10 +00:00
printf ( " -o options pass options like modules to activate \n " ) ;
printf ( " e.g: -o modules:timestamps \n " ) ;
2004-10-20 19:28:02 +00:00
printf ( " \n " ) ;
printf ( " Renames records in a ldb \n \n " ) ;
exit ( 1 ) ;
}
2006-05-01 01:34:04 +00:00
int main ( int argc , const char * * argv )
2004-10-20 19:28:02 +00:00
{
struct ldb_context * ldb ;
2005-06-18 07:42:21 +00:00
int ret ;
struct ldb_cmdline * options ;
2006-11-22 00:59:34 +00:00
struct ldb_dn * dn1 , * dn2 ;
2004-10-20 19:28:02 +00:00
2006-03-02 16:32:53 +00:00
ldb_global_init ( ) ;
2005-06-18 07:42:21 +00:00
ldb = ldb_init ( NULL ) ;
2004-10-20 19:28:02 +00:00
2005-06-18 07:42:21 +00:00
options = ldb_cmdline_process ( ldb , argc , argv , usage ) ;
2004-10-20 19:28:02 +00:00
2005-06-18 07:42:21 +00:00
if ( options - > argc < 2 ) {
2004-10-20 19:28:02 +00:00
usage ( ) ;
}
2006-11-22 00:59:34 +00:00
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 ;
}
2005-06-18 07:42:21 +00:00
ret = ldb_rename ( ldb , dn1 , dn2 ) ;
2004-10-20 19:28:02 +00:00
if ( ret = = 0 ) {
printf ( " Renamed 1 record \n " ) ;
} else {
printf ( " rename of '%s' to '%s' failed - %s \n " ,
2005-08-18 15:02:01 +00:00
options - > argv [ 0 ] , options - > argv [ 1 ] , ldb_errstring ( ldb ) ) ;
2004-10-20 19:28:02 +00:00
}
2005-02-27 11:35:47 +00:00
talloc_free ( ldb ) ;
2004-10-20 19:28:02 +00:00
return ret ;
}