]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapcommon.c
Must use txns everywhere, otherwise it will deadlock
[openldap] / servers / slapd / slapcommon.c
index 0ce9fc9e3b657e29de8cf2aaa8d0e749ff99ea22..05f331a6f67eced51a68e51475e21d9027a56c26 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2007 The OpenLDAP Foundation.
+ * Copyright 1998-2009 The OpenLDAP Foundation.
  * Portions Copyright 1998-2003 Kurt D. Zeilenga.
  * Portions Copyright 2003 IBM Corporation.
  * All rights reserved.
@@ -88,7 +88,7 @@ usage( int tool, const char *progname )
                break;
 
        case SLAPINDEX:
-               options = " [-c]\n\t[-g] [-n databasenumber | -b suffix] [attr ...] [-q]\n";
+               options = " [-c]\n\t[-g] [-n databasenumber | -b suffix] [attr ...] [-q] [-t]\n";
                break;
 
        case SLAPTEST:
@@ -218,7 +218,7 @@ slap_tool_init(
        char *subtree = NULL;
        char *ldiffile  = NULL;
        char **debug_unknowns = NULL;
-       int rc, i, dbnum;
+       int rc, i;
        int mode = SLAP_TOOL_MODE;
        int truncatemode = 0;
        int use_glue = 1;
@@ -241,7 +241,7 @@ slap_tool_init(
 
        switch( tool ) {
        case SLAPADD:
-               options = "b:cd:f:F:gj:l:n:o:qstuvw";
+               options = "b:cd:f:F:gj:l:n:o:qsS:uvw";
                break;
 
        case SLAPCAT:
@@ -265,7 +265,7 @@ slap_tool_init(
                break;
 
        case SLAPINDEX:
-               options = "b:cd:f:F:gn:o:qv";
+               options = "b:cd:f:F:gn:o:qtv";
                mode |= SLAP_TOOL_READMAIN;
                break;
 
@@ -353,7 +353,7 @@ slap_tool_init(
                        break;
 
                case 'n':       /* which config file db to index */
-                       if ( lutil_atoi( &dbnum, optarg ) ) {
+                       if ( lutil_atoi( &dbnum, optarg ) || dbnum < 0 ) {
                                usage( tool, progname );
                        }
                        break;
@@ -384,6 +384,14 @@ slap_tool_init(
                        realm = optarg;
                        break;
 
+               case 'S':
+                       if ( lutil_atou( &csnsid, optarg )
+                               || csnsid > SLAP_SYNC_SID_MAX )
+                       {
+                               usage( tool, progname );
+                       }
+                       break;
+
                case 's':       /* dump subtree */
                        if ( tool == SLAPADD )
                                mode |= SLAP_TOOL_NO_SCHEMA_CHECK;
@@ -556,7 +564,7 @@ slap_tool_init(
        }
 
        if ( use_glue ) {
-               rc = glue_sub_attach();
+               rc = glue_sub_attach( 0 );
 
                if ( rc != 0 ) {
                        fprintf( stderr,
@@ -681,12 +689,12 @@ slap_tool_init(
                                progname, dbnum, 0 );
                }
 
-       } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
+       } else if ( dbnum >= nbackends ) {
                fprintf( stderr,
                        "Database number selected via -n is out of range\n"
                        "Must be in the range 0 to %d"
-                       " (number of configured databases)\n",
-                       nbackends-1 );
+                       " (the number of configured databases)\n",
+                       nbackends - 1 );
                exit( EXIT_FAILURE );
 
        } else {
@@ -697,6 +705,15 @@ slap_tool_init(
        }
 
 startup:;
+       if ( be ) {
+               BackendDB *bdtmp;
+
+               dbnum = 0;
+               LDAP_STAILQ_FOREACH( bdtmp, &backendDB, be_next ) {
+                       if ( bdtmp == be ) break;
+                       dbnum++;
+               }
+       }
 
 #ifdef CSRIMALLOC
        mal_leaktrace(1);
@@ -732,13 +749,16 @@ startup:;
        }
 }
 
-void slap_tool_destroy( void )
+int slap_tool_destroy( void )
 {
+       int rc = 0;
        if ( !dryrun ) {
                if ( need_shutdown ) {
-                       slap_shutdown( be );
+                       if ( slap_shutdown( be ))
+                               rc = EXIT_FAILURE;
                }
-               slap_destroy();
+               if ( slap_destroy())
+                       rc = EXIT_FAILURE;
        }
 #ifdef SLAPD_MODULES
        if ( slapMode == SLAP_SERVER_MODE ) {
@@ -760,4 +780,9 @@ void slap_tool_destroy( void )
        if ( !BER_BVISNULL( &authcDN ) ) {
                ch_free( authcDN.bv_val );
        }
+
+       if ( ldiffp && ldiffp != &dummy ) {
+               ldif_close( ldiffp );
+       }
+       return rc;
 }