mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-27 03:20:22 +08:00
Implement slapcat -s <dn>: Only dump a subtree of the database.
This commit is contained in:
parent
b7fd633e8a
commit
7e8ff6df6b
@ -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)
|
||||
|
@ -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 ) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user