Patch: Implement 'slapcat -s subtree-dn' to dump a subtree of the database Description, from the slapcat(8) manpage: -s subtree-dn Only dump entries in the subtree specified by this DN. Implies `-b subtree-dn' if no -b or -n option is given. Hallvard B. Furuseth , Jan 2003. Index: doc/man/man8/slapcat.8 =================================================================== RCS file: /repo/OpenLDAP/pkg/ldap/doc/man/man8/slapcat.8,v retrieving revision 1.13 diff -u -2 -r1.13 slapcat.8 --- doc/man/man8/slapcat.8 3 Jan 2003 19:20:49 -0000 1.13 +++ doc/man/man8/slapcat.8 24 Jan 2003 15:06:13 -0000 @@ -12,4 +12,5 @@ .B [\-b suffix] .B [\-n dbnum] +.B [\-s subtree-dn] .B [\-f slapd.conf] .B [\-l ldif-file] @@ -59,4 +60,12 @@ .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" Index: servers/slapd/tools/slapcat.c =================================================================== RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/tools/slapcat.c,v retrieving revision 1.9 diff -u -2 -r1.9 slapcat.c --- servers/slapd/tools/slapcat.c 3 Jan 2003 19:20:59 -0000 1.9 +++ servers/slapd/tools/slapcat.c 24 Jan 2003 15:06:14 -0000 @@ -48,4 +48,9 @@ Entry* e = be->be_entry_get( be, id ); + if( sub_ndn.bv_len && !dnIsSuffix( &e->e_nname, &sub_ndn ) ) { + be_entry_release_r( be, 0L, 0L, e ); + continue; + } + if( verbose ) { printf( "# id=%08lx\n", (long) id ); Index: servers/slapd/tools/slapcommon.c =================================================================== RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/tools/slapcommon.c,v retrieving revision 1.31 diff -u -2 -r1.31 slapcommon.c --- servers/slapd/tools/slapcommon.c 20 Jan 2003 19:17:12 -0000 1.31 +++ servers/slapd/tools/slapcommon.c 24 Jan 2003 15:06:14 -0000 @@ -27,4 +27,5 @@ int nosubordinates = 0; int dryrun = 0; +struct berval sub_ndn = { 0, NULL }; char *ldiffile = NULL; @@ -83,4 +84,5 @@ char *options; struct berval base = { 0, NULL }; + char *subtree = NULL; int rc, i, dbnum; int mode = SLAP_TOOL_MODE; @@ -107,5 +109,5 @@ case SLAPCAT: - options = "b:cd:f:l:n:v"; + options = "b:cd:f:l:n:s:v"; break; @@ -146,4 +148,8 @@ break; + case 's': /* dump subtree */ + subtree = strdup( optarg ); + break; + case 't': /* turn on truncate */ truncatemode++; @@ -228,4 +234,21 @@ fprintf( stderr, "%s: slap_schema_prep failed!\n", progname ); exit( EXIT_FAILURE ); + } + + if( subtree ) { + struct berval val, sub_dn; + val.bv_val = subtree; + val.bv_len = strlen( subtree ); + rc = dnPrettyNormal( NULL, &val, &sub_dn, &sub_ndn ); + if( rc != LDAP_SUCCESS ) { + fprintf( stderr, "Invalid subtree DN '%s'\n", optarg ); + exit( EXIT_FAILURE ); + } + ber_memfree( sub_dn.bv_val ); + + if( base.bv_val == NULL && dbnum == -1 ) + base = val; + else + free( subtree ); } Index: servers/slapd/tools/slapcommon.h =================================================================== RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/tools/slapcommon.h,v retrieving revision 1.12 diff -u -2 -r1.12 slapcommon.h --- servers/slapd/tools/slapcommon.h 3 Jan 2003 19:20:59 -0000 1.12 +++ servers/slapd/tools/slapcommon.h 24 Jan 2003 15:06:14 -0000 @@ -28,4 +28,5 @@ extern int nosubordinates; extern int dryrun; +extern struct berval sub_ndn; extern char *ldiffile;