]> git.sur5r.net Git - openldap/commitdiff
Implement slapcat -s <dn>: Only dump a subtree of the database.
authorHallvard Furuseth <hallvard@openldap.org>
Tue, 29 Apr 2003 20:47:21 +0000 (20:47 +0000)
committerHallvard Furuseth <hallvard@openldap.org>
Tue, 29 Apr 2003 20:47:21 +0000 (20:47 +0000)
doc/man/man8/slapcat.8
servers/slapd/tools/slapcat.c
servers/slapd/tools/slapcommon.c
servers/slapd/tools/slapcommon.h

index 1675ce5986d7b66cd6819ac6062199cc45ae10ba..26b51715eed28ead2edbe232f93c693b40bd3ea0 100644 (file)
@@ -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)
index 0cd0a3059744488df5ba805d95048b481aff7845..02130fdaf79aab6e4d298d4bd3c67eaaffe2a8f7 100644 (file)
@@ -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 ) {
index 61b6d6e08e7454f48409617bbb22f32b242d06a7..e8fe3dcbb8e527aba7a7db758693b4b82e646a81 100644 (file)
@@ -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;
 
index 4817aa86a551223481eedaaf14055029820cbd7b..3a1120ba98caac7a7a0669ab1c2e0be8770430b1 100644 (file)
@@ -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;