]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapcommon.c
declare oc_bvfind_undef()
[openldap] / servers / slapd / slapcommon.c
index 05ba7e8e1916c26f6ba0df5c8cb38d5662da1c0b..fbae61c2abbdd0267db5dc5839e08a31dcfaffef 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:
@@ -71,11 +72,12 @@ usage( int tool, const char *progname )
                break;
 
        case SLAPAUTH:
-               options = "\t[-U authcID] [-X authzID] ID [...]\n";
+               options = "\t[-U authcID] [-X authzID] [-R realm] [-M mech] ID [...]\n";
                break;
 
        case SLAPACL:
-               options = "\t[-U authcID | -D authcDN] -b DN attr[/level][:value] [...]\n";
+               options = "\t[-U authcID | -D authcDN]"
+                       " -b DN [attr[/access][: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,17 +127,19 @@ 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;
 
        case SLAPDN:
        case SLAPTEST:
                options = "d:f:v";
+               mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
                break;
 
        case SLAPAUTH:
-               options = "d:f:U:vX:";
+               options = "d:f:M:R:U:vX:";
+               mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
                break;
 
        case SLAPINDEX:
@@ -144,17 +149,21 @@ slap_tool_init(
 
        case SLAPACL:
                options = "b:D:d:f:U:v";
+               mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
                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;
@@ -168,7 +177,7 @@ slap_tool_init(
                        break;
 
                case 'D':
-                       ber_str2bv( optarg, 0, 0, &authcDN );
+                       ber_str2bv( optarg, 0, 1, &authcDN );
                        break;
 
                case 'f':       /* specify a conf file */
@@ -181,7 +190,7 @@ slap_tool_init(
                                usage( tool, progname );
                                exit( EXIT_FAILURE );
                        }
-                       str2clist( &replica_id_strlist, replica_id_string, "," );
+                       slap_str2clist( &replica_id_strlist, replica_id_string, "," );
                        for ( i = 0; replica_id_strlist && replica_id_strlist[i]; i++ ) ;
                        replica_id_list = ch_calloc( i + 1, sizeof( int ) );
                        for ( i = 0; replica_id_strlist && replica_id_strlist[i]; i++ ) {
@@ -208,6 +217,10 @@ slap_tool_init(
                        retrieve_ctxcsn = 1;
                        break;
 
+               case 'M':
+                       ber_str2bv( optarg, 0, 0, &mech );
+                       break;
+
                case 'n':       /* which config file db to index */
                        dbnum = atoi( optarg ) - 1;
                        break;
@@ -220,6 +233,10 @@ slap_tool_init(
                        replica_demotion = 1;           
                        break;
 
+               case 'R':
+                       realm = optarg;
+                       break;
+
                case 's':       /* dump subtree */
                        subtree = strdup( optarg );
                        break;
@@ -297,9 +314,6 @@ slap_tool_init(
                break;
 
        case SLAPACL:
-               if ( argc == optind ) {
-                       usage( tool, progname );
-               }
                if ( !BER_BVISNULL( &authcDN ) && !BER_BVISNULL( &authcID ) ) {
                        usage( tool, progname );
                }
@@ -316,7 +330,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 );
@@ -348,6 +362,11 @@ slap_tool_init(
                exit( EXIT_FAILURE );
        }
 
+       if ( frontend_init() ) {
+               fprintf( stderr, "%s: frontend_init failed!\n", progname );
+               exit( EXIT_FAILURE );
+       }
+
        if ( overlay_init() ) {
                fprintf( stderr, "%s: overlay_init failed!\n", progname );
                exit( EXIT_FAILURE );
@@ -377,13 +396,6 @@ slap_tool_init(
                break;
        }
 
-       rc = glue_sub_init();
-
-       if ( rc != 0 ) {
-               fprintf( stderr, "Subordinate configuration error\n" );
-               exit( EXIT_FAILURE );
-       }
-
        rc = slap_schema_check();
 
        if ( rc != 0 ) {
@@ -394,8 +406,6 @@ slap_tool_init(
        switch ( tool ) {
        case SLAPDN:
        case SLAPTEST:
-               return;
-
        case SLAPAUTH:
                be = NULL;
                goto startup;
@@ -404,19 +414,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 ) {
@@ -432,8 +452,12 @@ slap_tool_init(
                be = select_backend( &nbase, 0, 0 );
                ber_memfree( nbase.bv_val );
 
-               if ( tool == SLAPACL ) {
+               switch ( tool ) {
+               case SLAPACL:
                        goto startup;
+
+               default:
+                       break;
                }
 
                if( be == NULL ) {
@@ -474,22 +498,17 @@ slap_tool_init(
                }
                
                if ( nosubordinates == 0 && dbnum > 0 ) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG( BACKEND, ERR, 
-"The first database does not allow %s; using the first available one (%d)\n",
-                               progname, dbnum + 1, 0 );
-#else
                        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 );
-#endif
                }
 
        } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
                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 );
 
@@ -503,7 +522,7 @@ startup:;
        mal_leaktrace(1);
 #endif
 
-       if ( slap_startup( be ) ) {
+       if ( !dryrun && slap_startup( be ) ) {
                fprintf( stderr, "slap_startup failed\n" );
                exit( EXIT_FAILURE );
        }
@@ -511,7 +530,9 @@ startup:;
 
 void slap_tool_destroy( void )
 {
-       slap_shutdown( be );
+       if ( !dryrun && be != NULL ) {
+               slap_shutdown( be );
+       }
        slap_destroy();
 #ifdef SLAPD_MODULES
        if ( slapMode == SLAP_SERVER_MODE ) {
@@ -529,4 +550,8 @@ void slap_tool_destroy( void )
 #ifdef CSRIMALLOC
        mal_dumpleaktrace( leakfile );
 #endif
+
+       if ( !BER_BVISNULL( &authcDN ) ) {
+               ch_free( authcDN.bv_val );
+       }
 }