]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/slapcommon.c
Don't reeval expression
[openldap] / servers / slapd / tools / slapcommon.c
index ffa14fa6e4253830cc9dac93bc0ce8d64bef0ba6..2004511a678686ba3d65a24c851042bde913aa5a 100644 (file)
@@ -1,6 +1,6 @@
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 /* slapcommon.c - common routine for the slap tools */
@@ -24,7 +24,8 @@ char  *conffile       = SLAPD_DEFAULT_CONFIGFILE;
 int            truncatemode = 0;
 int            verbose         = 0;
 int            continuemode = 0;
-int    nosubs          = 0;
+int            nosubordinates = 0;
+int            dryrun = 0;
 
 char   *ldiffile       = NULL;
 FILE   *ldiffp         = NULL;
@@ -97,7 +98,7 @@ slap_tool_init(
 
        switch( tool ) {
        case SLAPADD:
-               options = "b:cd:f:l:n:tv";
+               options = "b:cd:f:l:n:tuv";
                break;
 
        case SLAPINDEX:
@@ -148,6 +149,10 @@ slap_tool_init(
                        mode |= SLAP_TRUNCATE_MODE;
                        break;
 
+               case 'u':       /* dry run */
+                       dryrun++;
+                       break;
+
                case 'v':       /* turn on verbose */
                        verbose++;
                        break;
@@ -176,6 +181,13 @@ 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_init( mode, progname );
 
        if (rc != 0 ) {
@@ -183,14 +195,19 @@ slap_tool_init(
                exit( EXIT_FAILURE );
        }
 
-       rc = schema_init();
+       rc = slap_schema_init();
 
        if (rc != 0 ) {
                fprintf( stderr, "%s: slap_schema_init failed!\n", progname );
                exit( EXIT_FAILURE );
        }
 
-       read_config( conffile );
+       rc = read_config( conffile, 0 );
+
+       if ( rc != 0 ) {
+               fprintf( stderr, "%s: bad configuration file!\n", progname );
+               exit( EXIT_FAILURE );
+       }
 
        if ( !nbackends ) {
                fprintf( stderr, "No databases found in config file\n" );
@@ -204,7 +221,7 @@ slap_tool_init(
                exit( EXIT_FAILURE );
        }
 
-       rc = schema_prep();
+       rc = slap_schema_check();
 
        if (rc != 0 ) {
                fprintf( stderr, "%s: slap_schema_prep failed!\n", progname );
@@ -217,11 +234,11 @@ slap_tool_init(
                rc = dnNormalize( NULL, &base, &nbase );
                if( rc != LDAP_SUCCESS ) {
                        fprintf( stderr, "%s: slap_init invalid suffix (\"%s\")\n",
-                               progname, base );
+                               progname, base.bv_val );
                        exit( EXIT_FAILURE );
                }
 
-               be = select_backend( nbase->bv_val, 0, 0 );
+               be = select_backend( nbase, 0, 0 );
                ber_bvfree( nbase );
 
                if( be == NULL ) {
@@ -232,16 +249,16 @@ slap_tool_init(
                /* If the named base is a glue master, operate on the
                 * entire context
                 */
-               if (be->be_glueflags & SLAP_GLUE_INSTANCE)
-                       nosubs = 1;
+               if (be->be_flags & SLAP_BFLAG_GLUE_INSTANCE)
+                       nosubordinates = 1;
 
        } else if ( dbnum == -1 ) {
                be = &backends[dbnum=0];
                /* If just doing the first by default and it is a
                 * glue subordinate, find the master.
                 */
-               while (be->be_glueflags & SLAP_GLUE_SUBORDINATE) {
-                       nosubs = 1;
+               while (be->be_flags & SLAP_BFLAG_GLUE_SUBORDINATE) {
+                       nosubordinates = 1;
                        be++;
                }
 
@@ -268,6 +285,18 @@ void slap_tool_destroy( void )
 {
        slap_shutdown( be );
        slap_destroy();
+#ifdef SLAPD_MODULES
+       if ( slapMode == SLAP_SERVER_MODE ) {
+       /* always false. just pulls in necessary symbol references. */
+               lutil_uuidstr(NULL, 0);
+       }
+       module_kill();
+#endif
+       schema_destroy();
+#ifdef HAVE_TLS
+       ldap_pvt_tls_destroy();
+#endif
+       config_destroy();
 
 #ifdef CSRIMALLOC
        mal_dumpleaktrace( leakfile );