]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapcommon.c
Multi-threaded slapindex
[openldap] / servers / slapd / slapcommon.c
index e3f94152f3df51233e28f6406d3e794a7c2d6558..0cf108c72c0afb49d940983db44d4f7ee224b363 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "slapcommon.h"
 #include "lutil.h"
+#include "ldif.h"
 
 tool_vars tool_globals;
 
@@ -44,6 +45,8 @@ static char *leakfilename;
 static FILE *leakfile;
 #endif
 
+static LDIFFP dummy;
+
 static void
 usage( int tool, const char *progname )
 {
@@ -54,13 +57,12 @@ usage( int tool, const char *progname )
 
        switch( tool ) {
        case SLAPACL:
-               options = "\n\t[-U authcID | -D authcDN]"
-                       " -b DN -o <var>[=<val>] [-u]"
-                       "\n\t[attr[/access][:value]] [...]\n";
+               options = "\n\t[-U authcID | -D authcDN] [-X authzID | -o authzDN=<DN>]"
+                       "\n\t-b DN -o <var>[=<val>] [-u] [attr[/access][:value]] [...]\n";
                break;
 
        case SLAPADD:
-               options = " [-c]\n\t[-n databasenumber | -b suffix]\n"
+               options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]\n"
                        "\t[-l ldiffile] [-q] [-u] [-w]\n";
                break;
 
@@ -69,7 +71,7 @@ usage( int tool, const char *progname )
                break;
 
        case SLAPCAT:
-               options = " [-c]\n\t[-n databasenumber | -b suffix]"
+               options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]"
                        " [-l ldiffile] [-a filter]\n";
                break;
 
@@ -78,7 +80,7 @@ usage( int tool, const char *progname )
                break;
 
        case SLAPINDEX:
-               options = " [-c]\n\t[-n databasenumber | -b suffix] [-q]\n";
+               options = " [-c]\n\t[-g] [-n databasenumber | -b suffix] [-q]\n";
                break;
 
        case SLAPTEST:
@@ -142,6 +144,9 @@ parse_slapacl( void )
        } else if ( strncasecmp( optarg, "sasl_ssf", len ) == 0 ) {
                sasl_ssf = atoi( p );
 
+       } else if ( strncasecmp( optarg, "authzDN", len ) == 0 ) {
+               ber_str2bv( p, 0, 1, &authzDN );
+
        } else {
                return -1;
        }
@@ -164,8 +169,8 @@ slap_tool_init(
        int argc, char **argv )
 {
        char *options;
-       char *conffile = SLAPD_DEFAULT_CONFIGFILE;
-       char *confdir = SLAPD_DEFAULT_CONFIGDIR;
+       char *conffile = NULL;
+       char *confdir = NULL;
        struct berval base = BER_BVNULL;
        char *filterstr = NULL;
        char *subtree = NULL;
@@ -173,6 +178,7 @@ slap_tool_init(
        int rc, i, dbnum;
        int mode = SLAP_TOOL_MODE;
        int truncatemode = 0;
+       int use_glue = 1;
 
 #ifdef CSRIMALLOC
        leakfilename = malloc( strlen( progname ) + STRLENOF( ".leak" ) + 1 );
@@ -185,11 +191,11 @@ slap_tool_init(
 
        switch( tool ) {
        case SLAPADD:
-               options = "b:cd:f:F:l:n:qtuvw";
+               options = "b:cd:f:F:gl:n:qtuvw";
                break;
 
        case SLAPCAT:
-               options = "a:b:cd:f:F:l:n:s:v";
+               options = "a:b:cd:f:F:gl:n:s:v";
                mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
                break;
 
@@ -209,12 +215,12 @@ slap_tool_init(
                break;
 
        case SLAPINDEX:
-               options = "b:cd:f:F:n:qv";
+               options = "b:cd:f:F:gn:qv";
                mode |= SLAP_TOOL_READMAIN;
                break;
 
        case SLAPACL:
-               options = "b:D:d:f:F:o:uU:v";
+               options = "b:D:d:f:F:o:uU:vX:";
                mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
                break;
 
@@ -254,6 +260,10 @@ slap_tool_init(
                        confdir = strdup( optarg );
                        break;
 
+               case 'g':       /* disable subordinate glue */
+                       use_glue = 0;
+                       break;
+
                case 'l':       /* LDIF file */
                        ldiffile = strdup( optarg );
                        break;
@@ -374,9 +384,10 @@ slap_tool_init(
        ldap_syslog = 0;
 
        if ( ldiffile == NULL ) {
-               ldiffp = tool == SLAPCAT ? stdout : stdin;
+               dummy.fp = tool == SLAPCAT ? stdout : stdin;
+               ldiffp = &dummy;
 
-       } else if ((ldiffp = fopen( ldiffile, tool == SLAPCAT ? "w" : "r" ))
+       } else if ((ldiffp = ldif_open( ldiffile, tool == SLAPCAT ? "w" : "r" ))
                == NULL )
        {
                perror( ldiffile );
@@ -387,41 +398,17 @@ slap_tool_init(
         * initialize stuff and figure out which backend we're dealing with
         */
 
-#ifdef SLAPD_MODULES
-       if ( module_init() != 0 ) {
-               fprintf( stderr, "%s: module_init failed!\n", progname );
-               exit( EXIT_FAILURE );
-       }
-#endif
-               
-       rc = slap_schema_init();
-
-       if ( rc != 0 ) {
-               fprintf( stderr, "%s: slap_schema_init failed!\n", progname );
-               exit( EXIT_FAILURE );
-       }
-
        rc = slap_init( mode, progname );
-
        if ( rc != 0 ) {
                fprintf( stderr, "%s: slap_init failed!\n", progname );
                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 );
-       }
-
        rc = read_config( conffile, confdir );
 
        if ( rc != 0 ) {
-               fprintf( stderr, "%s: bad configuration file!\n", progname );
+               fprintf( stderr, "%s: bad configuration %s!\n",
+                       progname, confdir ? "directory" : "file" );
                exit( EXIT_FAILURE );
        }
 
@@ -442,6 +429,16 @@ slap_tool_init(
                break;
        }
 
+       if ( use_glue ) {
+               rc = glue_sub_attach();
+
+               if ( rc != 0 ) {
+                       fprintf( stderr,
+                               "%s: subordinate configuration error\n", progname );
+                       exit( EXIT_FAILURE );
+               }
+       }
+
        rc = slap_schema_check();
 
        if ( rc != 0 ) {
@@ -514,17 +511,22 @@ slap_tool_init(
                /* If the named base is a glue master, operate on the
                 * entire context
                 */
-               if (SLAP_GLUE_INSTANCE(be)) {
+               if ( SLAP_GLUE_INSTANCE( be ) ) {
                        nosubordinates = 1;
                }
 
        } else if ( dbnum == -1 ) {
+               /* no suffix and no dbnum specified, just default to
+                * the first available database
+                */
                if ( nbackends <= 0 ) {
                        fprintf( stderr, "No available databases\n" );
                        exit( EXIT_FAILURE );
                }
                LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
                        dbnum++;
+
+                       /* db #0 is cn=config, don't select it as a default */
                        if ( dbnum < 1 ) continue;
                
                        if ( SLAP_MONITOR(be))
@@ -546,19 +548,19 @@ slap_tool_init(
                        exit( EXIT_FAILURE );
                }
                
-               if ( nosubordinates == 0 && dbnum > 0 ) {
+               if ( nosubordinates == 0 && dbnum > 1 ) {
                        Debug( LDAP_DEBUG_ANY,
                                "The first database does not allow %s;"
                                " using the first available one (%d)\n",
-                               progname, dbnum + 1, 0 );
+                               progname, dbnum, 0 );
                }
 
        } 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",
-                       nbackends );
+                       "Must be in the range 0 to %d"
+                       " (number of configured databases)\n",
+                       nbackends-1 );
                exit( EXIT_FAILURE );
 
        } else {
@@ -574,8 +576,16 @@ startup:;
        mal_leaktrace(1);
 #endif
 
-       if ( !dryrun && slap_startup( be ) ) {
+       if ( conffile != NULL ) {
+               ch_free( conffile );
+       }
+
+       if ( ldiffile != NULL ) {
+               ch_free( ldiffile );
+       }
 
+       /* slapdn doesn't specify a backend to startup */
+       if ( !dryrun && tool != SLAPDN && slap_startup( be ) ) {
                switch ( tool ) {
                case SLAPTEST:
                        fprintf( stderr, "slap_startup failed "