From: Hallvard Furuseth Date: Tue, 29 Apr 2003 20:47:21 +0000 (+0000) Subject: Implement slapcat -s : Only dump a subtree of the database. X-Git-Tag: OPENLDAP_REL_ENG_2_2_0ALPHA~211 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7e8ff6df6bcca258092ade97f26b888f7b6396e8;p=openldap Implement slapcat -s : Only dump a subtree of the database. --- diff --git a/doc/man/man8/slapcat.8 b/doc/man/man8/slapcat.8 index 1675ce5986..26b51715ee 100644 --- a/doc/man/man8/slapcat.8 +++ b/doc/man/man8/slapcat.8 @@ -11,6 +11,7 @@ slapcat \- SLAPD database to LDIF utility .B [\-d level] .B [\-b suffix] .B [\-n dbnum] +.B [\-s subtree-dn] .B [\-f slapd.conf] .B [\-l ldif-file] .B @@ -59,6 +60,14 @@ cannot be used in conjunction with the .B \-b option. .TP +.BI \-s " subtree-dn" +Only dump entries in the subtree specified by this DN. +Implies `-b subtree-dn' if no +.B \-b +or +.B \-n +option is given. +.TP .BI \-f " slapd.conf" specify an alternative .BR slapd.conf (5) diff --git a/servers/slapd/tools/slapcat.c b/servers/slapd/tools/slapcat.c index 0cd0a30597..02130fdaf7 100644 --- a/servers/slapd/tools/slapcat.c +++ b/servers/slapd/tools/slapcat.c @@ -47,6 +47,12 @@ main( int argc, char **argv ) char *data; int len; Entry* e = be->be_entry_get( be, id ); + op.o_bd = be; + + if( sub_ndn.bv_len && !dnIsSuffix( &e->e_nname, &sub_ndn ) ) { + be_entry_release_r( &op, e ); + continue; + } if( verbose ) { printf( "# id=%08lx\n", (long) id ); @@ -60,7 +66,6 @@ main( int argc, char **argv ) } data = entry2str( e, &len ); - op.o_bd = be; be_entry_release_r( &op, e ); if ( data == NULL ) { diff --git a/servers/slapd/tools/slapcommon.c b/servers/slapd/tools/slapcommon.c index 61b6d6e08e..e8fe3dcbb8 100644 --- a/servers/slapd/tools/slapcommon.c +++ b/servers/slapd/tools/slapcommon.c @@ -26,6 +26,7 @@ int verbose = 0; int continuemode = 0; int nosubordinates = 0; int dryrun = 0; +struct berval sub_ndn = { 0, NULL }; char *ldiffile = NULL; FILE *ldiffp = NULL; @@ -82,6 +83,7 @@ slap_tool_init( { char *options; struct berval base = { 0, NULL }; + char *subtree = NULL; int rc, i, dbnum; int mode = SLAP_TOOL_MODE; @@ -106,7 +108,7 @@ slap_tool_init( break; case SLAPCAT: - options = "b:cd:f:l:n:v"; + options = "b:cd:f:l:n:s:v"; break; default: @@ -145,6 +147,10 @@ slap_tool_init( dbnum = atoi( optarg ) - 1; break; + case 's': /* dump subtree */ + subtree = strdup( optarg ); + break; + case 't': /* turn on truncate */ truncatemode++; mode |= SLAP_TRUNCATE_MODE; @@ -229,6 +235,22 @@ slap_tool_init( exit( EXIT_FAILURE ); } + if( subtree ) { + struct berval val; + val.bv_val = subtree; + val.bv_len = strlen( subtree ); + rc = dnNormalize( 0, NULL, NULL, &val, &sub_ndn, NULL ); + if( rc != LDAP_SUCCESS ) { + fprintf( stderr, "Invalid subtree DN '%s'\n", optarg ); + exit( EXIT_FAILURE ); + } + + if( base.bv_val == NULL && dbnum == -1 ) + base = val; + else + free( subtree ); + } + if( base.bv_val != NULL ) { struct berval nbase; diff --git a/servers/slapd/tools/slapcommon.h b/servers/slapd/tools/slapcommon.h index 4817aa86a5..3a1120ba98 100644 --- a/servers/slapd/tools/slapcommon.h +++ b/servers/slapd/tools/slapcommon.h @@ -27,6 +27,7 @@ extern int verbose; extern int continuemode; extern int nosubordinates; extern int dryrun; +extern struct berval sub_ndn; extern char *ldiffile; extern FILE *ldiffp;