]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/slapcommon.c
Added the suffix=<dn> parameter to replica config directive
[openldap] / servers / slapd / tools / slapcommon.c
index f2791a629d413a3b7f165a7e6c85ed171104823f..9c583c964d28902221c6a5c520ae6fdd6eefb466 100644 (file)
@@ -1,5 +1,6 @@
+/* $OpenLDAP$ */
 /*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 /* slapcommon.c - common routine for the slap tools */
@@ -22,10 +23,16 @@ char        *progname       = NULL;
 char   *conffile       = SLAPD_DEFAULT_CONFIGFILE;
 int            truncatemode = 0;
 int            verbose         = 0;
+int            continuemode = 0;
 
 char   *ldiffile       = NULL;
 FILE   *ldiffp         = NULL;
 
+#ifdef CSRIMALLOC
+       char *leakfilename;
+       FILE *leakfile;
+#endif
+
 Backend *be = NULL;
 
 static void
@@ -33,8 +40,8 @@ usage( int tool )
 {
        char *options = NULL;
        fprintf( stderr,
-               "usage: %s [-v] [-d debuglevel] [-f configfile]\n"
-                        "\t[-n databasenumber | -b suffix]", progname );
+               "usage: %s [-v] [-c] [-d debuglevel] [-f configfile]\n"
+                       "\t[-n databasenumber | -b suffix]", progname );
 
        switch( tool ) {
        case SLAPADD:
@@ -46,7 +53,7 @@ usage( int tool )
                break;
 
        case SLAPINDEX:
-               options = "\tattributetype\n";
+               options = "\n";
                break;
        }
 
@@ -78,21 +85,31 @@ slap_tool_init(
 
        progname = lutil_progname( name, argc, argv );
 
+#ifdef CSRIMALLOC
+       leakfilename = malloc( strlen( progname ) + sizeof(".leak") );
+       sprintf( leakfilename, "%s.leak", progname );
+       if( ( leakfile = fopen( leakfilename, "w" )) == NULL ) {
+               leakfile = stderr;
+       }
+       free( leakfilename );
+#endif
+
        switch( tool ) {
        case SLAPADD:
-               options = "b:d:f:l:n:tv";
+               options = "b:cd:f:l:n:tv";
                break;
 
        case SLAPINDEX:
-               options = "b:d:f:n:v";
+               options = "b:cd:f:n:v";
                break;
 
        case SLAPCAT:
-               options = "b:d:f:l:n:v";
+               options = "b:cd:f:l:n:v";
                break;
 
        default:
-               fprintf( stderr, "%s: unknown tool mode (%d)\n", tool );
+               fprintf( stderr, "%s: unknown tool mode (%d)\n",
+                        progname, tool );
                exit( EXIT_FAILURE );
        }
 
@@ -104,8 +121,12 @@ slap_tool_init(
                case 'b':
                        base = strdup( optarg );
 
+               case 'c':       /* enable continue mode */
+                       continuemode++;
+                       break;
+
                case 'd':       /* turn on debugging */
-                       ldap_debug = atoi( optarg );
+                       ldap_debug += atoi( optarg );
                        break;
 
                case 'f':       /* specify a conf file */
@@ -135,9 +156,7 @@ slap_tool_init(
                }
        }
 
-       if ( ( argc != optind + (tool == SLAPINDEX ? 1 : 0) )
-               || (dbnum >= 0 && base != NULL ) )
-       {
+       if ( ( argc != optind ) || (dbnum >= 0 && base != NULL ) ) {
                usage( tool );
        }
 
@@ -162,6 +181,13 @@ slap_tool_init(
                exit( EXIT_FAILURE );
        }
 
+       rc = schema_init();
+
+       if (rc != 0 ) {
+               fprintf( stderr, "%s: slap_schema_init failed!\n", progname );
+               exit( EXIT_FAILURE );
+       }
+
        read_config( conffile );
 
        if ( !nbackends ) {
@@ -169,16 +195,23 @@ slap_tool_init(
                exit( EXIT_FAILURE );
        }
 
+       rc = schema_prep();
+
+       if (rc != 0 ) {
+               fprintf( stderr, "%s: slap_schema_prep failed!\n", progname );
+               exit( EXIT_FAILURE );
+       }
+
        if( base != NULL ) {
                char *tbase = ch_strdup( base );
 
-               if( dn_normalize_case( tbase ) == NULL ) {
+               if( dn_normalize( tbase ) == NULL ) {
                        fprintf( stderr, "%s: slap_init invalid suffix (\"%s\")\n",
                                progname, base );
                        exit( EXIT_FAILURE );
                }
 
-               be = select_backend( tbase );
+               be = select_backend( tbase, 0 );
                free( tbase );
 
                if( be == NULL ) {
@@ -200,4 +233,20 @@ slap_tool_init(
        } else {
                be = &backends[dbnum];
        }
+
+#ifdef CSRIMALLOC
+       mal_leaktrace(1);
+#endif
+
+       slap_startup( be );
+}
+
+void slap_tool_destroy( void )
+{
+       slap_shutdown( be );
+       slap_destroy();
+
+#ifdef CSRIMALLOC
+       mal_dumpleaktrace( leakfile );
+#endif
 }