]> git.sur5r.net Git - openldap/commitdiff
Add "slapcat -a filter" support
authorKurt Zeilenga <kurt@openldap.org>
Wed, 8 Sep 2004 21:44:28 +0000 (21:44 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Wed, 8 Sep 2004 21:44:28 +0000 (21:44 +0000)
doc/man/man8/slapcat.8
servers/slapd/slapcat.c
servers/slapd/slapcommon.c
servers/slapd/slapcommon.h

index faa4fb468cad1bdffed4d3605f65800f703ce5a6..af82f2049591eafbe45c9abbabc6cea74d3a0c0c 100644 (file)
@@ -13,6 +13,7 @@ slapcat \- SLAPD database to LDIF utility
 .B [\-d level]
 .B [\-b suffix]
 .B [\-n dbnum]
+.B [\-a filter]
 .B [\-s subtree-dn]
 .B [\-f slapd.conf]
 .B [\-l ldif-file]
@@ -72,6 +73,9 @@ cannot be used in conjunction with the
 .B \-b
 option.
 .TP
+.BI \-a " filter"
+Only dump entries matching the asserted filter.  
+.TP
 .BI \-s " subtree-dn"
 Only dump entries in the subtree specified by this DN.
 Implies `-b subtree-dn' if no
index 665ee153886f1fde9d86837f16ed9bcf02367da4..7daeaa645a185f0c25be1699e3cbad8cc2c07793 100644 (file)
@@ -79,6 +79,14 @@ slapcat( int argc, char **argv )
                        continue;
                }
 
+               if( filter != NULL ) {
+                       int rc = test_filter( NULL, e, filter );
+                       if( rc != LDAP_COMPARE_TRUE ) {
+                               be_entry_release_r( &op, e );
+                               continue;
+                       }
+               }
+
                if ( retrieve_ctxcsn == 0 ) {
                        if ( is_entry_syncProviderSubentry( e ) ) {
                                be_entry_release_r( &op, e );
index dc64b8306571537ee1f9837bdfbd369fde405c83..8e151450751e904211cd8e20f8363aa410500c0f 100644 (file)
@@ -59,7 +59,8 @@ usage( int tool, const char *progname )
                break;
 
        case SLAPCAT:
-               options = "\t[-n databasenumber | -b suffix] [-l ldiffile] [-m] [-k]\n";
+               options = "\t[-n databasenumber | -b suffix]"
+                       " [-l ldiffile] [-a filter] [-m] [-k]\n";
                break;
 
        case SLAPDN:
@@ -75,7 +76,8 @@ usage( int tool, const char *progname )
                break;
 
        case SLAPACL:
-               options = "\t[-U authcID | -D authcDN] -b DN attr[/level][:value] [...]\n";
+               options = "\t[-U authcID | -D authcDN]"
+                       " -b DN attr[/level][:value] [...]\n";
                break;
        }
 
@@ -103,6 +105,7 @@ slap_tool_init(
        char *options;
        char *conffile = SLAPD_DEFAULT_CONFIGFILE;
        struct berval base = BER_BVNULL;
+       char *filterstr = NULL;
        char *subtree = NULL;
        char *ldiffile  = NULL;
        int rc, i, dbnum;
@@ -124,7 +127,7 @@ slap_tool_init(
                break;
 
        case SLAPCAT:
-               options = "b:cd:f:kl:mn:s:v";
+               options = "a:b:cd:f:kl:mn:s:v";
                mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
                break;
 
@@ -150,14 +153,17 @@ slap_tool_init(
                break;
 
        default:
-               fprintf( stderr, "%s: unknown tool mode (%d)\n",
-                        progname, tool );
+               fprintf( stderr, "%s: unknown tool mode (%d)\n", progname, tool );
                exit( EXIT_FAILURE );
        }
 
        dbnum = -1;
        while ( (i = getopt( argc, argv, options )) != EOF ) {
                switch ( i ) {
+               case 'a':
+                       filterstr = strdup( optarg );
+                       break;
+
                case 'b':
                        ber_str2bv( optarg, 0, 1, &base );
                        break;
@@ -319,7 +325,7 @@ slap_tool_init(
        if ( ldiffile == NULL ) {
                ldiffp = tool == SLAPCAT ? stdout : stdin;
 
-       } else if(ldiffp = fopen( ldiffile, tool == SLAPCAT ? "w" : "r" ))
+       } else if ((ldiffp = fopen( ldiffile, tool == SLAPCAT ? "w" : "r" ))
                == NULL )
        {
                perror( ldiffile );
@@ -410,19 +416,29 @@ slap_tool_init(
                break;
        }
 
+       if( filterstr ) {
+               filter = str2filter( filterstr );
+
+               if( filter == NULL ) {
+                       fprintf( stderr, "Invalid filter '%s'\n", filterstr );
+                       exit( EXIT_FAILURE );
+               }
+       }
+
        if( subtree ) {
                struct berval val;
                ber_str2bv( subtree, 0, 0, &val );
                rc = dnNormalize( 0, NULL, NULL, &val, &sub_ndn, NULL );
                if( rc != LDAP_SUCCESS ) {
-                       fprintf( stderr, "Invalid subtree DN '%s'\n", optarg );
+                       fprintf( stderr, "Invalid subtree DN '%s'\n", subtree );
                        exit( EXIT_FAILURE );
                }
 
-               if ( BER_BVISNULL( &base ) && dbnum == -1 )
+               if ( BER_BVISNULL( &base ) && dbnum == -1 ) {
                        base = val;
-               else
+               } else {
                        free( subtree );
+               }
        }
 
        if( base.bv_val != NULL ) {
@@ -485,7 +501,8 @@ slap_tool_init(
                
                if ( nosubordinates == 0 && dbnum > 0 ) {
                        Debug( LDAP_DEBUG_ANY,
-"The first database does not allow %s; using the first available one (%d)\n",
+                               "The first database does not allow %s;"
+                               " using the first available one (%d)\n",
                                progname, dbnum + 1, 0 );
                }
 
@@ -493,7 +510,7 @@ slap_tool_init(
                fprintf( stderr,
                        "Database number selected via -n is out of range\n"
                        "Must be in the range 1 to %d"
-                               " (number of databases in the config file)\n",
+                       " (number of databases in the config file)\n",
                        nbackends );
                exit( EXIT_FAILURE );
 
index 41fca6f4fba5598d6746c4d6c1554a2b6e8e341c..9dcd3eb936c31372304731bfe4f268ea429149e2 100644 (file)
@@ -50,6 +50,7 @@ typedef struct tool_vars {
        int tv_continuemode;
        int tv_nosubordinates;
        int tv_dryrun;
+       Filter *tv_filter;
        struct berval tv_sub_ndn;
        FILE    *tv_ldiffp;
        struct berval tv_authcDN;
@@ -73,6 +74,7 @@ extern tool_vars tool_globals;
 #define continuemode tool_globals.tv_continuemode
 #define nosubordinates tool_globals.tv_nosubordinates
 #define dryrun tool_globals.tv_dryrun
+#define filter tool_globals.tv_filter
 #define sub_ndn tool_globals.tv_sub_ndn
 #define ldiffp tool_globals.tv_ldiffp
 #define authcDN tool_globals.tv_authcDN