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
2007-07-10 02:46:15 +00:00
version 3 of the License , or ( at your option ) any later version .
2004-10-20 19:28:02 +00:00
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
2007-07-10 03:42:26 +00:00
License along with this library ; if not , see < http : //www.gnu.org/licenses/>.
2004-10-20 19:28:02 +00:00
*/
/*
* Name : ldb
*
* Component : ldbrename
*
* Description : utility to rename records - modelled on ldapmodrdn
*
* Author : Andrew Tridgell
* Author : Stefan Metzmacher
*/
2012-06-10 22:59:00 +02:00
# include "replace.h"
2009-01-29 18:39:30 -05:00
# include "ldb.h"
2007-05-05 18:50:56 +00:00
# include "tools/cmdline.h"
2004-10-20 19:28:02 +00:00
2010-11-01 18:45:25 +11:00
static void usage ( struct ldb_context * ldb )
2004-10-20 19:28:02 +00:00
{
printf ( " Usage: ldbrename [<options>] <olddn> <newdn> \n " ) ;
printf ( " Renames records in a ldb \n \n " ) ;
2010-11-01 18:45:25 +11:00
ldb_cmdline_help ( ldb , " ldbmodify " , stdout ) ;
2011-02-01 20:34:44 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-10-20 19:28:02 +00:00
}
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 ;
2010-05-02 15:53:14 +02:00
TALLOC_CTX * mem_ctx = talloc_new ( NULL ) ;
2004-10-20 19:28:02 +00:00
2010-05-02 15:53:14 +02:00
ldb = ldb_init ( mem_ctx , NULL ) ;
2011-02-01 20:26:12 +01:00
if ( ldb = = NULL ) {
return LDB_ERR_OPERATIONS_ERROR ;
}
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 ) {
2010-11-01 18:45:25 +11:00
usage ( ldb ) ;
2004-10-20 19:28:02 +00:00
}
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 ] ) ;
2011-03-04 10:49:47 +01:00
if ( ( dn1 = = NULL ) | | ( dn2 = = NULL ) ) {
return LDB_ERR_OPERATIONS_ERROR ;
2011-03-02 22:40:13 +01:00
}
2006-11-22 00:59:34 +00:00
2005-06-18 07:42:21 +00:00
ret = ldb_rename ( ldb , dn1 , dn2 ) ;
2011-01-14 12:38:10 +01:00
if ( ret = = LDB_SUCCESS ) {
2004-10-20 19:28:02 +00:00
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
}
2010-05-02 15:53:14 +02:00
talloc_free ( mem_ctx ) ;
2004-10-20 19:28:02 +00:00
return ret ;
}