Sfoglia il codice sorgente

[208672] parameterizing the hardcoded paths (phase 2. db, log, lock, pid, cert, and instance dir)
1) introduced these 3 new config attributes:
nsslapd-lockdir, nsslapd-tmpdir, nsslapd-certdir,
and eliminated: nsslapd-instancedir.
2) replaced the hardcoded paths with the corresponding attribute value in the
server as well as in the create/remove instance codes.
3) moved snmp stats file to the nsslapd-tmpdir
4) moved the server instance dir to <prefix>/lib/<brand>-ds/slapd-<id>

Noriko Hosoi 19 anni fa
parent
commit
57e9577e0e
33 ha cambiato i file con 1236 aggiunte e 1196 eliminazioni
  1. 26 16
      ldap/admin/include/dsalib.h
  2. 1 2
      ldap/admin/lib/dsalib_conf.c
  3. 133 126
      ldap/admin/lib/dsalib_db.c
  4. 46 0
      ldap/admin/lib/dsalib_location.c
  5. 100 51
      ldap/admin/lib/dsalib_util.c
  6. 178 219
      ldap/admin/src/create_instance.c
  7. 2 2
      ldap/admin/src/create_instance.h
  8. 2 2
      ldap/admin/src/ds_remove.c
  9. 3 3
      ldap/admin/src/scripts/template-bak2db.pl
  10. 5 5
      ldap/admin/src/scripts/template-db2bak.pl
  11. 5 6
      ldap/admin/src/scripts/template-db2index.pl
  12. 6 5
      ldap/admin/src/scripts/template-db2ldif.pl
  13. 3 3
      ldap/admin/src/scripts/template-ldif2db.pl
  14. 2 2
      ldap/admin/src/scripts/template-ns-accountstatus.pl
  15. 2 2
      ldap/admin/src/scripts/template-ns-activate.pl
  16. 2 2
      ldap/admin/src/scripts/template-ns-inactivate.pl
  17. 1 3
      ldap/servers/plugins/http/http_impl.c
  18. 7 7
      ldap/servers/plugins/rever/des.c
  19. 0 1
      ldap/servers/slapd/auth.c
  20. 6 16
      ldap/servers/slapd/back-ldbm/archive.c
  21. 156 157
      ldap/servers/slapd/back-ldbm/ldbm_config.c
  22. 2 0
      ldap/servers/slapd/back-ldbm/ldbm_config.h
  23. 2 1
      ldap/servers/slapd/ch_malloc.c
  24. 14 37
      ldap/servers/slapd/config.c
  25. 116 81
      ldap/servers/slapd/libglobs.c
  26. 3 3
      ldap/servers/slapd/libslapd.def
  27. 5 4
      ldap/servers/slapd/log.c
  28. 2 9
      ldap/servers/slapd/main.c
  29. 318 334
      ldap/servers/slapd/protect_db.c
  30. 6 4
      ldap/servers/slapd/proto-slap.h
  31. 12 9
      ldap/servers/slapd/slap.h
  32. 30 34
      ldap/servers/slapd/snmp_collator.c
  33. 40 50
      ldap/servers/slapd/ssl.c

+ 26 - 16
ldap/admin/include/dsalib.h

@@ -47,21 +47,21 @@
 #endif
 
 /* error types */
-#define DS_FILE_ERROR 0
-#define DS_MEMORY_ERROR 1
-#define DS_SYSTEM_ERROR 2
-#define DS_INCORRECT_USAGE 3
-#define DS_ELEM_MISSING 4
+#define DS_FILE_ERROR              0
+#define DS_MEMORY_ERROR            1
+#define DS_SYSTEM_ERROR            2
+#define DS_INCORRECT_USAGE         3
+#define DS_ELEM_MISSING            4
 #define DS_REGISTRY_DATABASE_ERROR 5
-#define DS_NETWORK_ERROR 6
-#define DS_GENERAL_FAILURE 7
-#define DS_WARNING 8
+#define DS_NETWORK_ERROR           6
+#define DS_GENERAL_FAILURE         7
+#define DS_WARNING                 8
 
 /* The upper bound on error types */
-#define DS_MAX_ERROR 9
+#define DS_MAX_ERROR               9
 
 /* The default error type (in case something goes wrong */
-#define DS_DEFAULT_ERROR 3
+#define DS_DEFAULT_ERROR           3
 
 #ifndef BIG_LINE
 #define	BIG_LINE	1024
@@ -80,18 +80,27 @@
 #define CONTENT_NAME "content"
 #endif
 
+/* config file/path info */
+#define DS_CONFIG_DIR      "DS_CONFIG_DIR"
+#define DS_CONFIG_FILE     "dse.ldif"
+#define DS_ORIGCONFIG_FILE "dse_original.ldif"
+#define PIDFILE            "PIDFILE"
+
+#define DS_CONFIG_LOCKDIR  "nsslapd-lockdir:"
+#define DS_CONFIG_ERRLOG   "nsslapd-errorlog:"
+
 #ifdef XP_UNIX
 
-#define FILE_PATHSEP '/'
+#define FILE_PATHSEP  '/'
 #define FILE_PATHSEPP "/"
-#define FILE_PARENT "../"
+#define FILE_PARENT   "../"
 #define WSACleanup()
 
 #elif defined(XP_WIN32)
 
-#define FILE_PATHSEP '/'
+#define FILE_PATHSEP  '/'
 #define FILE_PATHSEPP "\\\\"
-#define FILE_PARENT "..\\"
+#define FILE_PARENT   "..\\"
 
 #endif /* XP_WIN32 */
 
@@ -303,7 +312,6 @@ extern DS_EXPORT_SYMBOL void ds_print_server_status(int isrunning);
 extern DS_EXPORT_SYMBOL int ds_get_file_size(char *fileName);
 extern DS_EXPORT_SYMBOL void ds_display_tail(char *fileName, int timeOut, 
     int startSeek, char *doneMsg, char *lastLine);
-extern DS_EXPORT_SYMBOL char **ds_get_ldif_files();
 extern DS_EXPORT_SYMBOL int ds_ldif2db_preserve(char *file);
 extern DS_EXPORT_SYMBOL int ds_ldif2db(char *file);
 extern DS_EXPORT_SYMBOL int ds_ldif2db_backend_subtree(char *file, char *backend, char *subtree);
@@ -322,6 +330,8 @@ extern DS_EXPORT_SYMBOL char *ds_get_config_dir();
 extern DS_EXPORT_SYMBOL void ds_set_config_dir(char *config_dir);
 extern DS_EXPORT_SYMBOL char *ds_get_run_dir();
 extern DS_EXPORT_SYMBOL void ds_set_run_dir(char *run_dir);
+extern DS_EXPORT_SYMBOL char *ds_get_bak_dir();
+extern DS_EXPORT_SYMBOL void ds_set_bak_dir(char *bak_dir);
 extern DS_EXPORT_SYMBOL char *ds_get_pwenc(char *passwd_hash, char *password);
 extern DS_EXPORT_SYMBOL int ds_check_config(int type);
 extern DS_EXPORT_SYMBOL int ds_check_pw(char *pwhash, char *pwclear);
@@ -415,7 +425,7 @@ extern DS_EXPORT_SYMBOL char* ds_become_original();
 
 extern DS_EXPORT_SYMBOL char* ds_makeshort(char *filepath);
 
-extern DS_EXPORT_SYMBOL int ds_search_file(char *filename, char *searchstring);
+extern DS_EXPORT_SYMBOL int ds_search_file(char *filename, char *searchstring, char **returnstring);
 
 /* Begin parsing a POST in a CGI context */
 extern DS_EXPORT_SYMBOL int ds_post_begin(FILE *input);

+ 1 - 2
ldap/admin/lib/dsalib_conf.c

@@ -51,7 +51,6 @@
 
 #include "nspr.h"
 
-#define CONF_FILE_NAME "dse.ldif"
 #define CONF_SUFFIX "cn=config"
 
 DS_EXPORT_SYMBOL char *
@@ -83,7 +82,7 @@ ds_get_config(int type)
         return(NULL);
     }
 
-    PR_snprintf(conffile, PATH_MAX, "%s/%s", configdir, CONF_FILE_NAME);
+    PR_snprintf(conffile, PATH_MAX, "%s/%s", configdir, DS_CONFIG_FILE);
 
     if ( !(sf = fopen(conffile, "r")) )  {
         ds_send_error("could not read config file.", 1);

+ 133 - 126
ldap/admin/lib/dsalib_db.c

@@ -64,35 +64,42 @@
 DS_EXPORT_SYMBOL char **
 ds_get_bak_dirs()
 {
-    char	format_str[PATH_MAX];
+    char    format_str[PATH_MAX];
     char    *root;
-    int		i = 0;
-    char	**bak_dirs = NULL;
+    int        i = 0;
+    char    **bak_dirs = NULL;
+    char    *bakdir = NULL;
 
     if ( (root = ds_get_install_root()) == NULL ) 
-	{
+    {
         ds_send_error("Cannot find server root directory.", 0);
         return(bak_dirs);
     }
 
-    PR_snprintf( format_str, PATH_MAX, "%s%cbak", root, FILE_SEP );
-	bak_dirs = ds_get_file_list( format_str );
-	if( bak_dirs )
-	{
-		while( bak_dirs[i] != NULL )
-		{
-			/* Prepend the filename with the install root */
-			char filename[PATH_MAX];
-			PR_snprintf( filename, PATH_MAX, "%s%cbak%c%s", root, FILE_SEP,
-					 FILE_SEP, bak_dirs[i] );
-			free( bak_dirs[i] );
-			bak_dirs[i] = strdup( filename );
+    if ( (bakdir = ds_get_bak_dir()) == NULL )
+    {
+        ds_send_error("Cannot find backup directory.", 0);
+        return(bak_dirs);
+    }
+
+    PR_snprintf( format_str, PATH_MAX, "%s", bakdir );
+    bak_dirs = ds_get_file_list( format_str );
+    if( bak_dirs )
+    {
+        while( bak_dirs[i] != NULL )
+        {
+            /* Prepend the filename with the install root */
+            char filename[PATH_MAX];
+            PR_snprintf( filename, PATH_MAX, "%s%c%s",
+                            bakdir, FILE_SEP, bak_dirs[i] );
+            free( bak_dirs[i] );
+            bak_dirs[i] = strdup( filename );
 #if defined( XP_WIN32 )
-			ds_dostounixpath( bak_dirs[i] );
+            ds_dostounixpath( bak_dirs[i] );
 #endif
-			i++;
-		}
-	}
+            i++;
+        }
+    }
 
     return(bak_dirs);
 }
@@ -113,7 +120,7 @@ ds_bak2db(char *file)
     int         error = -1;
     int         status;
     FILE        *sf = NULL;
-	struct stat	fstats;
+    struct stat    fstats;
 
     if ( file == NULL ) {
         return DS_NULL_PARAMETER;
@@ -126,8 +133,8 @@ ds_bak2db(char *file)
         return DS_NO_SERVER_ROOT;
     }
 
-    if ( file[strlen(file) - 1] == '\n' )	/* strip out returns */
-		file[strlen(file) - 1] = '\0';
+    if ( file[strlen(file) - 1] == '\n' )    /* strip out returns */
+        file[strlen(file) - 1] = '\0';
 
     if( stat( file, &fstats ) == -1 && errno == ENOENT ) {
         return DS_CANNOT_OPEN_BACKUP_FILE;
@@ -138,12 +145,12 @@ ds_bak2db(char *file)
     tmp_dir = ds_get_tmp_dir();
     PR_snprintf(statfile, PATH_MAX, "%s%cbak2db.%d", tmp_dir, FILE_SEP, (int)getpid());
     PR_snprintf(startup_line, BIG_LINE,
-			"%s%cbak2db "
-			"%s%s%s > "
-			"%s%s%s 2>&1",
-			root, FILE_SEP, 
-			ENQUOTE, file, ENQUOTE, 
-			ENQUOTE, statfile, ENQUOTE );
+            "%s%cbak2db "
+            "%s%s%s > "
+            "%s%s%s 2>&1",
+            root, FILE_SEP, 
+            ENQUOTE, file, ENQUOTE, 
+            ENQUOTE, statfile, ENQUOTE );
     alter_startup_line(startup_line);
     fflush(0);
     error = system(startup_line);
@@ -151,19 +158,19 @@ ds_bak2db(char *file)
     if ( error == -1 ) {
         return DS_CANNOT_EXEC;
     }
-	fflush(0);
+    fflush(0);
     if( !(sf = fopen(statfile, "r")) )  {
         return DS_CANNOT_OPEN_STAT_FILE;
     }
 
     while ( fgets(startup_line, BIG_LINE, sf) ) {
-		if ((strstr(startup_line, "- Restoring file")) || 
-			(strstr(startup_line, "- Checkpointing"))) {
-			ds_show_message(startup_line);
-		} else {
-			haderror = 1;
-			ds_send_error(startup_line, 0);
-		}
+        if ((strstr(startup_line, "- Restoring file")) || 
+            (strstr(startup_line, "- Checkpointing"))) {
+            ds_show_message(startup_line);
+        } else {
+            haderror = 1;
+            ds_send_error(startup_line, 0);
+        }
     }
 
     fclose(sf);
@@ -189,9 +196,9 @@ ds_db2bak(char *file)
     int         haderror = 0;
     int         error = -1;
     FILE        *sf = NULL;
-    int		lite = 0;
+    int        lite = 0;
 #ifdef XP_WIN32
-    time_t	ltime;
+    time_t    ltime;
 #endif
 
     if ( (root = ds_get_install_root()) == NULL ) {
@@ -201,29 +208,29 @@ ds_db2bak(char *file)
     if ( (file == NULL) || (strlen(file) == 0) )
         file = NULL;
 
-	tmp_dir = ds_get_tmp_dir();
+    tmp_dir = ds_get_tmp_dir();
     PR_snprintf(statfile, PATH_MAX, "%s%cdb2bak.%d", tmp_dir, FILE_SEP, (int)getpid());
-	
-					
+    
+                    
 #if defined( XP_WIN32 )
-	if( file == NULL )
-	{
-		file = malloc( BIG_LINE );
-
-		time( &ltime );
-		PR_snprintf( file, BIG_LINE, "%s", ctime( &ltime ) );
-		ds_timetofname( file );
-	}
-
-	/* Check if the directory exists or can be created */
-	if ( !ds_file_exists( file ) ) {
-		char *errmsg = ds_mkdir_p( file, NEWDIR_MODE );
-		if( errmsg != NULL ) {
-/*			ds_send_error(errmsg, 10);
+    if( file == NULL )
+    {
+        file = malloc( BIG_LINE );
+
+        time( &ltime );
+        PR_snprintf( file, BIG_LINE, "%s", ctime( &ltime ) );
+        ds_timetofname( file );
+    }
+
+    /* Check if the directory exists or can be created */
+    if ( !ds_file_exists( file ) ) {
+        char *errmsg = ds_mkdir_p( file, NEWDIR_MODE );
+        if( errmsg != NULL ) {
+/*            ds_send_error(errmsg, 10);
  */
-			return DS_CANNOT_CREATE_DIRECTORY;
-		}
-	}
+            return DS_CANNOT_CREATE_DIRECTORY;
+        }
+    }
 #endif
 
 /* DBDB: note on the following line. 
@@ -238,16 +245,16 @@ ds_db2bak(char *file)
 
 
     PR_snprintf(startup_line, sizeof(startup_line),
-			"%s%cdb2bak "
-			"%s%s%s > "
-			"%s%s%s 2>&1",
-			root, FILE_SEP,
-			ENQUOTE,
-			(file == NULL) ? "" : file,
-			ENQUOTE,
-			ENQUOTE, statfile, ENQUOTE);
-
-	PATH_FOR_PLATFORM( startup_line );
+            "%s%cdb2bak "
+            "%s%s%s > "
+            "%s%s%s 2>&1",
+            root, FILE_SEP,
+            ENQUOTE,
+            (file == NULL) ? "" : file,
+            ENQUOTE,
+            ENQUOTE, statfile, ENQUOTE);
+
+    PATH_FOR_PLATFORM( startup_line );
     alter_startup_line(startup_line);
     fflush(0);
     error = system(startup_line);
@@ -274,7 +281,7 @@ ds_db2bak(char *file)
     unlink(statfile);
 
     if ( lite && haderror )
-	return DS_HAS_TOBE_READONLY_MODE;
+    return DS_HAS_TOBE_READONLY_MODE;
 
     if ( haderror )
         return DS_UNKNOWN_ERROR;
@@ -284,52 +291,52 @@ ds_db2bak(char *file)
 static void
 process_and_report( char *line, int line_size, FILE *cmd )
 {
-	while(fgets(line, line_size, cmd))  {
-		/* Strip off line feeds */
-		int ind = strlen( line ) - 1;
-		while ( (ind >= 0) &&
-				((line[ind] == '\n') ||
-				 (line[ind] == '\r')) ) {
-			line[ind] = 0;
-			ind--;
-		}
-		if ( ind < 1 ) {
-			continue;
-		}
-		ds_send_status(line);
-	}
+    while(fgets(line, line_size, cmd))  {
+        /* Strip off line feeds */
+        int ind = strlen( line ) - 1;
+        while ( (ind >= 0) &&
+                ((line[ind] == '\n') ||
+                 (line[ind] == '\r')) ) {
+            line[ind] = 0;
+            ind--;
+        }
+        if ( ind < 1 ) {
+            continue;
+        }
+        ds_send_status(line);
+    }
 }
 
 static int exec_and_report( char *startup_line )
 {
-	FILE        *cmd = NULL;
+    FILE        *cmd = NULL;
     char        line[BIG_LINE];
     int         haderror = 0;
 
-	PATH_FOR_PLATFORM( startup_line );
+    PATH_FOR_PLATFORM( startup_line );
     alter_startup_line(startup_line);
 
-	/*
-	  fprintf( stdout, "Launching <%s>\n", startup_line );
-	*/
+    /*
+      fprintf( stdout, "Launching <%s>\n", startup_line );
+    */
 
     fflush(0);
-	cmd = popen(startup_line, "r");
-	if(!cmd) {
+    cmd = popen(startup_line, "r");
+    if(!cmd) {
         return DS_CANNOT_EXEC;
     }
-	process_and_report( line, sizeof(line), cmd );
-	pclose(cmd);
+    process_and_report( line, sizeof(line), cmd );
+    pclose(cmd);
 
     /*
     ** The VLV indexing code prints OK,
     ** if the index was successfully created.
     */
-	if (strcmp(line,"OK")==0) {
-		haderror = 0;
-	} else {
-		haderror = DS_UNKNOWN_ERROR;
-	}
+    if (strcmp(line,"OK")==0) {
+        haderror = 0;
+    } else {
+        haderror = DS_UNKNOWN_ERROR;
+    }
 
     return haderror;
 }
@@ -345,8 +352,8 @@ ds_vlvindex(char **backendList, char **vlvList)
     char        startup_line[BIG_LINE];
     char        *root;
     char        *instroot;
-	char		**vlvc = NULL;
-			
+    char        **vlvc = NULL;
+            
 
     root = ds_get_server_root();
     instroot = ds_get_install_root();
@@ -355,21 +362,21 @@ ds_vlvindex(char **backendList, char **vlvList)
     }
 
     PR_snprintf(startup_line, sizeof(startup_line), "%s/bin/slapd/server/%s db2index "
-			"-D %s%s/%s "
-			"-n %s ",
-			root, SLAPD_NAME,			
-			ENQUOTE, instroot, ENQUOTE,
-			backendList[0]);
-
-
-	/* Create vlv TAG */
-	vlvc=vlvList;
-	while( *vlvc != NULL ) {
-		PR_snprintf( startup_line, sizeof(startup_line), "%s -T %s%s%s", startup_line,"\"",*vlvc,"\"" );
-		vlvc++;
-	}	
+            "-D %s%s/%s "
+            "-n %s ",
+            root, SLAPD_NAME,            
+            ENQUOTE, instroot, ENQUOTE,
+            backendList[0]);
+
+
+    /* Create vlv TAG */
+    vlvc=vlvList;
+    while( *vlvc != NULL ) {
+        PR_snprintf( startup_line, sizeof(startup_line), "%s -T %s%s%s", startup_line,"\"",*vlvc,"\"" );
+        vlvc++;
+    }    
    
-	return exec_and_report( startup_line );
+    return exec_and_report( startup_line );
 }
 
 /*
@@ -391,17 +398,17 @@ ds_addindex(char **attrList, char *backendName)
         return DS_NO_SERVER_ROOT;
     }
 
-	PR_snprintf(startup_line, sizeof(startup_line), "%s/bin/slapd/server/%s db2index "
-			"-D %s%s%s "
-			"-n %s",
-			root, SLAPD_NAME,			
-			ENQUOTE, instroot, ENQUOTE,
-			backendName);
-
-	while( *attrList != NULL ) {
-		PR_snprintf( startup_line, sizeof(startup_line), "%s -t %s", startup_line, *attrList );
-		attrList++;
-	}
+    PR_snprintf(startup_line, sizeof(startup_line), "%s/bin/slapd/server/%s db2index "
+            "-D %s%s%s "
+            "-n %s",
+            root, SLAPD_NAME,            
+            ENQUOTE, instroot, ENQUOTE,
+            backendName);
+
+    while( *attrList != NULL ) {
+        PR_snprintf( startup_line, sizeof(startup_line), "%s -t %s", startup_line, *attrList );
+        attrList++;
+    }
 
-	return exec_and_report( startup_line );
+    return exec_and_report( startup_line );
 }

+ 46 - 0
ldap/admin/lib/dsalib_location.c

@@ -132,6 +132,52 @@ ds_set_run_dir(char *run_dir)
     putenv(env);
 }
 
+/*
+ * Returns the bakup dir of the server, where db backup files are put.
+ * Info is returned in a static area. The caller must copy it 
+ * for reuse if needed.
+ */
+DS_EXPORT_SYMBOL char *
+ds_get_bak_dir()
+{
+    return getenv("DS_BAK_DIR");
+}
+
+/*
+ * set bak_dir to environment variable DS_BAK_DIR
+ * to retrieve the value using ds_get_bak_dir later.
+ */
+DS_EXPORT_SYMBOL void
+ds_set_bak_dir(char *bak_dir)
+{
+    static char env[PATH_MAX];
+    PR_snprintf(env, sizeof(env), "DS_BAK_DIR=%s", bak_dir);
+    putenv(env);
+}
+
+/*
+ * Returns the tmp dir of the server, where tmp files are put.
+ * Info is returned in a static area. The caller must copy it 
+ * for reuse if needed.
+ */
+DS_EXPORT_SYMBOL char *
+ds_get_tmp_dir()
+{
+    return getenv("DS_TMP_DIR");
+}
+
+/*
+ * set bak_dir to environment variable DS_TMP_DIR
+ * to retrieve the value using ds_get_tmp_dir later.
+ */
+DS_EXPORT_SYMBOL void
+ds_set_tmp_dir(char *tmp_dir)
+{
+    static char env[PATH_MAX];
+    PR_snprintf(env, sizeof(env), "DS_TMP_DIR=%s", tmp_dir);
+    putenv(env);
+}
+
 /*
  * Returns the install location of the server under the admserv
  * directory.

+ 100 - 51
ldap/admin/lib/dsalib_util.c

@@ -307,51 +307,6 @@ ds_cp_file(char *sfile, char *dfile, int mode)
 #endif
 }
 
-/* Returns a directory path used for tmp files. */
-DS_EXPORT_SYMBOL char * 
-ds_get_tmp_dir()
-{
-#if defined( XP_WIN32 )
-	size_t ilen;
-	char pch;
-#endif
-	static char tmpdir[] = "/tmp";
-	static char tmp[256] = {0};
- 	char* instanceDir = ds_get_install_root();
- 	
-	if(instanceDir == NULL)
-	{
-		#if defined( XP_WIN32 )
-			ilen = sizeof(tmp);
-			GetTempPath( ilen, tmp );
-			tmp[ilen-1] = (char)0;
-			/* Remove trailing slash. */
-			ilen = strlen(tmp);
-			pch = tmp[ilen-1];
-			if( pch == '\\' || pch == '/' )
-				tmp[ilen-1] = '\0';
-			return tmp;
-		#else
-			return( tmpdir );
-		#endif
-	}
-	
-	PR_snprintf(tmp, sizeof(tmp), "%s/tmp",instanceDir);
-	
-#if defined( XP_WIN32 )
-	for(ilen=0;ilen < strlen(tmp); ilen++)
-	{
-		if(tmp[ilen]=='/')
-			tmp[ilen]='\\';
-	}
-#endif
-
-	if(!ds_file_exists(tmp))
-		ds_mkdir_p(tmp,00770);
-		
-	return ( tmp );
-}
-
 DS_EXPORT_SYMBOL void 
 ds_unixtodospath(char *szText)
 {
@@ -630,8 +585,10 @@ ds_makeshort( char * filepath )
 }
 
 /* returns 1 if string "searchstring" found in file "filename" */
+/* if found, returnstring is allocated and filled with the line */
+/* caller should release the memory */
 DS_EXPORT_SYMBOL int 
-ds_search_file(char *filename, char *searchstring)
+ds_search_file(char *filename, char *searchstring, char **returnstring)
 {
     struct stat finfo;
 	FILE * sf;
@@ -648,6 +605,10 @@ ds_search_file(char *filename, char *searchstring)
 
 	while ( fgets(big_line, BIG_LINE, sf) ) {
 		if( strstr( big_line, searchstring ) != NULL ) {
+			*returnstring = (char *)malloc(strlen(big_line) + 1);
+			if (NULL != *returnstring) {
+				strcpy(*returnstring, big_line);
+			}
 		    fclose(sf);
 			return 1;
 		}
@@ -864,8 +825,6 @@ ds_system_errmsg(void)
     return static_error;
 }
 
-/* get db path dir info from dse.ldif and remove it if it's not under path
-*/
 #ifndef MAXPATHLEN
 #define MAXPATHLEN  1024
 #endif
@@ -907,7 +866,7 @@ rm_db_dirs(char *fullpath, DS_RM_RF_ERR_FUNC ds_rm_rf_err_func, void *arg)
 
 	if (fp == NULL)
 	{
-		ds_rm_rf_err_func(fullpath, "opening dse.ldif", arg);
+		ds_rm_rf_err_func(fullpath, "opening the config file", arg);
 		return;
 	}
 
@@ -990,6 +949,43 @@ rm_db_dirs(char *fullpath, DS_RM_RF_ERR_FUNC ds_rm_rf_err_func, void *arg)
 	fclose(fp);
 }
 
+static char *
+get_dir_from_startslapd(char *loc, char *keyword)
+{
+	char *returnstr = NULL; 
+	char *ptr = NULL;
+	char *confdir = NULL;
+if (ds_search_file(loc, keyword, &returnstr) > 0 && returnstr) {
+		ptr = strchr(returnstr, '=');
+		if (NULL != ptr) {
+			confdir = strdup(++ptr);
+		}
+		free(returnstr);
+	}
+	return confdir;
+}
+
+static char *
+get_dir_from_config(char *config_dir, char *config_attr)
+{
+    char *configfile = NULL;
+	char *returnstr = NULL; 
+	char *ptr = NULL;
+	char *dir = NULL;
+	configfile = PR_smprintf("%s%c%s", config_dir, FILE_PATHSEP, DS_CONFIG_FILE);
+	if (configfile && ds_search_file(configfile, config_attr, &returnstr) > 0
+		&& returnstr) {
+		ptr = strchr(returnstr, ':');
+		if (NULL != ptr) {
+			while (' ' == *ptr || '\t' == *ptr) ptr++;
+			dir = strdup(ptr);
+		}
+		free(returnstr);
+		PR_smprintf_free(configfile);
+	}
+	return dir;
+}
+
 /* this function will recursively remove a directory hierarchy from the file
    system, like "rm -rf"
    In order to handle errors, the user supplies a callback function.  When an
@@ -1041,9 +1037,61 @@ internal_rm_rf(const char *path, DS_RM_RF_ERR_FUNC ds_rm_rf_err_func, void *arg)
 					break;
 				}
 			} else {
-				/* if dse.ldif, check db dir is under the instance dir or not */
-				if (0 == strcmp(dirent->name, "dse.ldif"))
+				/* FHS changes the directory structure.
+				 * Config dir is no longer in the instance dir.
+				 * The info should be found in start-slapd,
+				 * therefore get the path from the file here.
+				 */
+				if (0 == strcmp(dirent->name, "start-slapd")) {
+				    char *config_dir = ds_get_config_dir();
+					char *run_dir = ds_get_run_dir();
+					if (NULL == config_dir || '\0' == *config_dir) {
+						config_dir = get_dir_from_startslapd(fullpath, DS_CONFIG_DIR);
+					}
+					if (NULL == run_dir || '\0' == *run_dir) {
+						char *ptr = NULL;
+						run_dir = get_dir_from_startslapd(fullpath, PIDFILE);
+						ptr = strrchr(run_dir, FILE_PATHSEP);
+						if (NULL != ptr) {
+							*ptr = '\0';	/* equiv to dirname */
+						}
+					}
+					if (NULL != run_dir) {
+						internal_rm_rf(run_dir, ds_rm_rf_err_func, NULL);
+						free(run_dir);
+					}
+					if (NULL != config_dir) {
+						char *lock_dir = get_dir_from_config(config_dir, DS_CONFIG_LOCKDIR);
+						char *err_log = get_dir_from_config(config_dir, DS_CONFIG_ERRLOG);
+
+						if (NULL != lock_dir) {
+							internal_rm_rf(lock_dir, ds_rm_rf_err_func, NULL);
+							free(lock_dir);
+						}
+						if (NULL != err_log) {
+							char *ptr = strrchr(err_log, FILE_PATHSEP);
+							if (NULL != ptr) {
+								*ptr = '\0'; /* equiv to 'dirname' */
+								internal_rm_rf(err_log, ds_rm_rf_err_func, NULL);
+							}
+							free(err_log);
+						}
+						/* removing db dirs */
+						rm_db_dirs(config_dir, ds_rm_rf_err_func, arg);
+
+						/* removing config dir */
+						internal_rm_rf(config_dir, ds_rm_rf_err_func, NULL);
+					}
+				}
+				/* 
+				 * When the file is the config file, 
+				 * check if db dir is in the instance dir or not.
+				 * If db dir exists in the instance dir, it's an old structure.
+				 * Let's clean the old db here, as well.
+				 */
+				if (0 == strcmp(dirent->name, DS_CONFIG_FILE)) {
 					rm_db_dirs(fullpath, ds_rm_rf_err_func, arg);
+				}
 
 				if (PR_Delete(fullpath) != PR_SUCCESS) {
 					if (!ds_rm_rf_err_func(fullpath, "deleting file", arg)) {
@@ -1086,6 +1134,7 @@ default_err_func(const char *path, const char *op, void *arg)
 	return 1; /* just continue */	
 }
 
+/* dir: instance dir, e.g.,  "$NETSITE_ROOT/slapd-<id>" */
 DS_EXPORT_SYMBOL int
 ds_rm_rf(const char *dir, DS_RM_RF_ERR_FUNC ds_rm_rf_err_func, void *arg)
 {

File diff suppressed because it is too large
+ 178 - 219
ldap/admin/src/create_instance.c


+ 2 - 2
ldap/admin/src/create_instance.h

@@ -50,8 +50,6 @@ extern "C" {            /* Assume C declarations for C++ */
 #endif  /* __cplusplus */
 
 #define BRAND_DS        "fedora-ds"
-#define DS_CONFIG_DIR   "DS_CONFIG_DIR"
-#define DS_CONFIG_FILE  "dse.ldif"
 
 #ifdef XP_UNIX
 #define PRODUCT_NAME    "slapd"
@@ -131,6 +129,8 @@ typedef struct {
     char *db_dir;
     char *bak_dir;
     char *ldif_dir;
+    char *tmp_dir;
+    char *cert_dir;
     char *prefix;
 } server_config_s;
 

+ 2 - 2
ldap/admin/src/ds_remove.c

@@ -189,8 +189,8 @@ int main(int argc, char *argv[])
 	}
 
 	/*
- 	 * Get the server pathto delete.
-	 * serevrpath = /export/serevrs/dirserv/slapd-talac
+ 	 * Get the server path to delete.
+	 * serverpath = /<server_root>/slapd-<id>
 	 */
 	if (!(servername = ds_get_cgi_var("InstanceName")))
 		servername = ds_get_server_name();

+ 3 - 3
ldap/admin/src/scripts/template-bak2db.pl

@@ -55,7 +55,7 @@ $taskname = "";
 $archivedir = "";
 $dbtype = "ldbm database";
 $instance = "";
-$dsroot = "{{DS-ROOT}}";
+$prefix = "{{DS-ROOT}}";
 $mydsroot = "{{MY-DS-ROOT}}";
 $verbose = 0;
 $rootdn = "";
@@ -127,7 +127,7 @@ $nsdbtype = "nsDatabaseType: $dbtype\n";
 $entry = "${dn}${misc}${cn}${nsinstance}${nsarchivedir}${nsdbtype}";
 $vstr = "";
 if ($verbose != 0) { $vstr = "-v"; }
-chdir("$dsroot{{SEP}}shared{{SEP}}bin");
-open(FOO, "| $dsroot{{SEP}}shared{{SEP}}bin{{SEP}}ldapmodify $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
+chdir("$prefix{{SEP}}shared{{SEP}}bin");
+open(FOO, "| $prefix{{SEP}}shared{{SEP}}bin{{SEP}}ldapmodify $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
 print(FOO "$entry");
 close(FOO);

+ 5 - 5
ldap/admin/src/scripts/template-db2bak.pl

@@ -53,8 +53,8 @@ sub usage {
 $taskname = "";
 $archivedir = "";
 $dbtype = "ldbm database";
-$dsroot = "{{DS-ROOT}}";
-$mydsroot = "{{MY-DS-ROOT}}";
+$prefix = "{{DS-ROOT}}";
+$mybakdir = "{{BAK-DIR}}";
 $verbose = 0;
 $rootdn = "";
 $passwd = "";
@@ -105,7 +105,7 @@ if ( $rootdn eq "" || $passwd eq "") { &usage; exit(1); }
 $mn++; $yr += 1900;
 $taskname = "backup_${yr}_${mn}_${dy}_${h}_${m}_${s}";
 if ($archivedir eq "") {
-	$archivedir = "${mydsroot}{{SEP}}bak{{SEP}}${yr}_${mn}_${dy}_${h}_${m}_${s}";
+	$archivedir = "${bakdir}{{SEP}}bak{{SEP}}${yr}_${mn}_${dy}_${h}_${m}_${s}";
 }
 $dn = "dn: cn=$taskname, cn=backup, cn=tasks, cn=config\n";
 $misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
@@ -115,7 +115,7 @@ $nsdbtype = "nsDatabaseType: $dbtype\n";
 $entry = "${dn}${misc}${cn}${nsarchivedir}${nsdbtype}";
 $vstr = "";
 if ($verbose != 0) { $vstr = "-v"; }
-chdir("$dsroot{{SEP}}shared{{SEP}}bin");
-open(FOO, "| $dsroot{{SEP}}shared{{SEP}}bin{{SEP}}ldapmodify $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
+chdir("$prefix{{SEP}}shared{{SEP}}bin");
+open(FOO, "| $prefix{{SEP}}shared{{SEP}}bin{{SEP}}ldapmodify $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
 print(FOO "$entry");
 close(FOO);

+ 5 - 6
ldap/admin/src/scripts/template-db2index.pl

@@ -65,8 +65,7 @@ $attribute_arg = "";
 $vlvattribute_arg = "";
 $verbose = 0;
 
-$dsroot = "{{DS-ROOT}}";
-$mydsroot = "{{MY-DS-ROOT}}";
+$prefix = "{{DS-ROOT}}";
 
 $i = 0;
 while ($i <= $#ARGV) 
@@ -163,11 +162,11 @@ $attribute="";
 $indexes_list="";
 $vlvattribute="";
 $vlvindexes_list="";
-chdir("$dsroot{{SEP}}shared{{SEP}}bin");
+chdir("$prefix{{SEP}}shared{{SEP}}bin");
 if ( $attribute_arg eq "" && $vlvattribute_arg eq "" )
 {
     # Get the list of indexes from the entry
-    $indexes_list="$dsroot{{SEP}}shared{{SEP}}bin{{SEP}}ldapsearch $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -s one " .
+    $indexes_list="$prefix{{SEP}}shared{{SEP}}bin{{SEP}}ldapsearch $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -s one " .
     "-b \"cn=index,cn=\"$instance\", cn=ldbm database,cn=plugins,cn=config\" \"(&(objectclass=*)(nsSystemIndex=false))\" cn";
 
     # build the values of the attribute nsIndexAttribute
@@ -187,7 +186,7 @@ if ( $attribute_arg eq "" && $vlvattribute_arg eq "" )
     }
 
     # Get the list of indexes from the entry
-    $vlvindexes_list="$dsroot{{SEP}}shared{{SEP}}bin{{SEP}}ldapsearch $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -s sub -b \"cn=\"$instance\", cn=ldbm database,cn=plugins,cn=config\" \"objectclass=vlvIndex\" cn";
+    $vlvindexes_list="$prefix{{SEP}}shared{{SEP}}bin{{SEP}}ldapsearch $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -s sub -b \"cn=\"$instance\", cn=ldbm database,cn=plugins,cn=config\" \"objectclass=vlvIndex\" cn";
 
     # build the values of the attribute nsIndexVlvAttribute
     open(LDAP1, "$vlvindexes_list |");
@@ -220,6 +219,6 @@ $cn =  "cn: $taskname\n";
 $nsinstance = "nsInstance: ${instance}\n";
 
 $entry = "${dn}${misc}${cn}${nsinstance}${attribute}${vlvattribute}";
-open(FOO, "| $dsroot{{SEP}}shared{{SEP}}bin{{SEP}}ldapmodify $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
+open(FOO, "| $prefix{{SEP}}shared{{SEP}}bin{{SEP}}ldapmodify $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
 print(FOO "$entry");
 close(FOO);

+ 6 - 5
ldap/admin/src/scripts/template-db2ldif.pl

@@ -100,8 +100,9 @@ $printkey = 1;
 $taskname = "";
 $ldiffile = "";
 $doreplica = 0;
-$dsroot = "{{DS-ROOT}}";
-$mydsroot = "{{MY-DS-ROOT}}";
+$prefix = "{{DS-ROOT}}";
+$ldifdir = "{{LDIF-DIR}}";
+$servid = "{{SERV-ID}}";
 $verbose = 0;
 $rootdn = "";
 $passwd = "";
@@ -195,7 +196,7 @@ if (($instances[0] eq "" && $included[0] eq "") || $rootdn eq "" || $passwd eq "
 $mn++; $yr += 1900;
 $taskname = "export_${yr}_${mn}_${dy}_${h}_${m}_${s}";
 if ($ldiffile eq "") {
-	$ldiffile = "${mydsroot}{{SEP}}ldif{{SEP}}${yr}_${mn}_${dy}_${h}_${m}_${s}.ldif";
+	$ldiffile = "${ldifdir}{{SEP}}${servid}-${yr}_${mn}_${dy}_${h}_${m}_${s}.ldif";
 }
 $dn = "dn: cn=$taskname, cn=export, cn=tasks, cn=config\n";
 $misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
@@ -241,7 +242,7 @@ $nsldiffile = "nsFilename: ${ldiffile}\n";
 $entry = "${dn}${misc}${cn}${nsinstance}${nsincluded}${nsexcluded}${nsreplica}${nsnobase64}${nsnowrap}${nsnoversion}${nsnouniqueid}${nsuseid2entry}${nsonefile}${nsexportdecrypt}${nsprintkey}${nsldiffile}";
 $vstr = "";
 if ($verbose != 0) { $vstr = "-v"; }
-chdir("$dsroot{{SEP}}shared{{SEP}}bin");
-open(FOO, "| $dsroot{{SEP}}shared{{SEP}}bin{{SEP}}ldapmodify $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
+chdir("$prefix{{SEP}}shared{{SEP}}bin");
+open(FOO, "| $prefix{{SEP}}shared{{SEP}}bin{{SEP}}ldapmodify $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
 print(FOO "$entry");
 close(FOO);

+ 3 - 3
ldap/admin/src/scripts/template-ldif2db.pl

@@ -93,7 +93,7 @@ $mergechunksiz = 0;
 $genuniqid = "time";
 $uniqidname = "";
 $taskname = "";
-$dsroot = "{{DS-ROOT}}";
+$prefix = "{{DS-ROOT}}";
 $mydsroot = "{{MY-DS-ROOT}}";
 $verbose = 0;
 $rootdn = "";
@@ -219,7 +219,7 @@ if ($uniqidname ne "") { $nsuniqidname = "nsUniqueIdGeneratorNamespace: ${uniqid
 $entry = "${dn}${misc}${cn}${nsinstance}${nsincluded}${nsexcluded}${nsldiffiles}${nsnoattrindexes}${nsimportencrypt}${nsmergechunksiz}${nsgenuniqid}${nsuniqidname}";
 $vstr = "";
 if ($verbose != 0) { $vstr = "-v"; }
-chdir("$dsroot{{SEP}}shared{{SEP}}bin");
-open(FOO, "| $dsroot{{SEP}}shared{{SEP}}bin{{SEP}}ldapmodify $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
+chdir("$prefix{{SEP}}shared{{SEP}}bin");
+open(FOO, "| $prefix{{SEP}}shared{{SEP}}bin{{SEP}}ldapmodify $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
 print(FOO "$entry");
 close(FOO);

+ 2 - 2
ldap/admin/src/scripts/template-ns-accountstatus.pl

@@ -356,7 +356,7 @@ sub checkScope
 ###############################
 
 # Generated variable
-$dsroot="{{DS-ROOT}}";
+$prefix="{{DS-ROOT}}";
 
 # Determine which command we are running
 if ( $0 =~ /ns-inactivate(.pl)?$/ )
@@ -392,7 +392,7 @@ else
 
 debug("Running ** $cmd ** $operation\n");
 
-$dsbinroot="$dsroot{{SEP}}shared{{SEP}}bin";
+$dsbinroot="$prefix{{SEP}}shared{{SEP}}bin";
 $ldapsearch="$dsbinroot{{SEP}}ldapsearch -1";
 $ldapmodify="$dsbinroot{{SEP}}ldapmodify";
  

+ 2 - 2
ldap/admin/src/scripts/template-ns-activate.pl

@@ -356,7 +356,7 @@ sub checkScope
 ###############################
 
 # Generated variable
-$dsroot="{{DS-ROOT}}";
+$prefix="{{DS-ROOT}}";
 
 # Determine which command we are running
 if ( $0 =~ /ns-inactivate(.pl)?$/ )
@@ -392,7 +392,7 @@ else
 
 debug("Running ** $cmd ** $operation\n");
 
-$dsbinroot="$dsroot{{SEP}}shared{{SEP}}bin";
+$dsbinroot="$prefix{{SEP}}shared{{SEP}}bin";
 $ldapsearch="$dsbinroot{{SEP}}ldapsearch -1";
 $ldapmodify="$dsbinroot{{SEP}}ldapmodify";
  

+ 2 - 2
ldap/admin/src/scripts/template-ns-inactivate.pl

@@ -356,7 +356,7 @@ sub checkScope
 ###############################
 
 # Generated variable
-$dsroot="{{DS-ROOT}}";
+$prefix="{{DS-ROOT}}";
 
 # Determine which command we are running
 if ( $0 =~ /ns-inactivate(.pl)?$/ )
@@ -392,7 +392,7 @@ else
 
 debug("Running ** $cmd ** $operation\n");
 
-$dsbinroot="$dsroot{{SEP}}shared{{SEP}}bin";
+$dsbinroot="$prefix{{SEP}}shared{{SEP}}bin";
 $ldapsearch="$dsbinroot{{SEP}}ldapsearch -1";
 $ldapmodify="$dsbinroot{{SEP}}ldapmodify";
  

+ 1 - 3
ldap/servers/plugins/http/http_impl.c

@@ -326,7 +326,7 @@ static int doRequest(const char *url, httpheader **httpheaderArray, char *body,
 
 					NSS_Shutdown();
 					nssFlags &= (~NSS_INIT_READONLY);
-       				val = config_get_instancedir();
+       				val = config_get_certdir();
        				PL_strncpyz(certDir, val, sizeof(certDir));
 					defaultprefix = strrchr(certDir, '/');
 					if (!defaultprefix)
@@ -336,8 +336,6 @@ static int doRequest(const char *url, httpheader **httpheaderArray, char *body,
 					defaultprefix++;
 					PR_snprintf(certPref, 1024, "%s-",defaultprefix);
 					PL_strncpyz(keyPref, certPref, sizeof(keyPref));
-					*defaultprefix= '\0';
-					PR_snprintf(certDir, 1024, "%salias", certDir);
        				nssStatus = NSS_Initialize(certDir, certPref, keyPref, "secmod.db", nssFlags);
 					slapi_ch_free((void **)&val);
 		

+ 7 - 7
ldap/servers/plugins/rever/des.c

@@ -214,7 +214,7 @@ static SVRCOREError genKey(struct pk11ContextStore **out, const char *token, cha
 	CK_MECHANISM pbeMech;
 	CK_MECHANISM cryptoMech;
 
-	char *instancedir = NULL;
+	char *configdir = NULL;
 	char *iv = NULL;
 
 	store = (struct pk11ContextStore*)slapi_ch_malloc(sizeof(*store));
@@ -243,22 +243,22 @@ static SVRCOREError genKey(struct pk11ContextStore **out, const char *token, cha
 	/* Generate a unique id, used as salt for the key generation */
 	if ( path == NULL )
 	{
-		instancedir = config_get_instancedir();
-		if ( instancedir == NULL )
+		configdir = config_get_configdir();
+		if ( configdir == NULL )
 		{
 		  return (err = SVRCORE_System_Error);
 		}
 	}
 	else
 	{
-		instancedir = slapi_ch_strdup(path);
+		configdir = slapi_ch_strdup(path);
 	}
-	if ( slapi_uniqueIDGenerateFromNameString (&iv, NULL, instancedir, strlen(instancedir)) != UID_SUCCESS )
+	if ( slapi_uniqueIDGenerateFromNameString (&iv, NULL, configdir, strlen(configdir)) != UID_SUCCESS )
 	{
-	  slapi_ch_free((void**)&instancedir);
+	  slapi_ch_free((void**)&configdir);
 	  return (err = SVRCORE_System_Error);
 	}
-	slapi_ch_free((void**)&instancedir);
+	slapi_ch_free((void**)&configdir);
 
 	pwitem = (SECItem *) PORT_Alloc(sizeof(SECItem));
 	if (pwitem == NULL)

+ 0 - 1
ldap/servers/slapd/auth.c

@@ -271,7 +271,6 @@ slapu_value_free_len( LDAP* ld, struct berval **values )
 void
 client_auth_init ()
 {
-    char *instancedir;
     int err;
     if (client_auth_config_file == NULL) {
 	char *confdir = config_get_configdir();

+ 6 - 16
ldap/servers/slapd/back-ldbm/archive.c

@@ -42,9 +42,7 @@
 int ldbm_back_archive2ldbm( Slapi_PBlock *pb )
 {
     struct ldbminfo    *li;
-    char *instancedir = NULL;
-    char *orig_dir = NULL;
-    char *directory = NULL;
+    char *directory = NULL;    /* -a <directory> */
     char *backendname = NULL;
     int return_value = -1;
     int task_flags = 0;
@@ -53,19 +51,17 @@ int ldbm_back_archive2ldbm( Slapi_PBlock *pb )
     int is_old_to_new = 0;
 
     slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &li );
-    slapi_pblock_get( pb, SLAPI_SEQ_VAL, &orig_dir );
+    slapi_pblock_get( pb, SLAPI_SEQ_VAL, &directory );
     slapi_pblock_get( pb, SLAPI_BACKEND_INSTANCE_NAME, &backendname);
     slapi_pblock_get( pb, SLAPI_BACKEND_TASK, &task );
     slapi_pblock_get( pb, SLAPI_TASK_FLAGS, &task_flags );
     li->li_flags = run_from_cmdline = (task_flags & TASK_RUNNING_FROM_COMMANDLINE);
 
-    if ( !orig_dir || !*orig_dir ) {
+    if ( !directory || !*directory ) {
         LDAPDebug( LDAP_DEBUG_ANY, "archive2db: no archive name\n",
                    0, 0, 0 );
         return( -1 );
     }
-    instancedir = config_get_instancedir();
-    directory = rel2abspath_ext(orig_dir, instancedir);
 
     /* check the current idl format vs backup DB version */
     if (idl_get_idl_new())
@@ -248,17 +244,14 @@ int ldbm_back_archive2ldbm( Slapi_PBlock *pb )
         }
     }
 out:
-    slapi_ch_free_string(&directory);
     return return_value;
 }
 
 int ldbm_back_ldbm2archive( Slapi_PBlock *pb )
 {
     struct ldbminfo    *li;
-    char *orig_dir = NULL;
-    char *directory = NULL;
+    char *directory = NULL;   /* -a <directory> */
     char *dir_bak = NULL;
-    char *instancedir = NULL;
     int return_value = -1;
     int task_flags = 0;
     int run_from_cmdline = 0;
@@ -266,19 +259,17 @@ int ldbm_back_ldbm2archive( Slapi_PBlock *pb )
     struct stat sbuf;
 
     slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &li );
-    slapi_pblock_get( pb, SLAPI_SEQ_VAL, &orig_dir );
+    slapi_pblock_get( pb, SLAPI_SEQ_VAL, &directory );
     slapi_pblock_get( pb, SLAPI_TASK_FLAGS, &task_flags );
     li->li_flags = run_from_cmdline = (task_flags & TASK_RUNNING_FROM_COMMANDLINE);
 
     slapi_pblock_get( pb, SLAPI_BACKEND_TASK, &task );
 
-    if ( !orig_dir || !*orig_dir ) {
+    if ( !directory || !*directory ) {
         LDAPDebug( LDAP_DEBUG_ANY, "db2archive: no archive name\n",
                    0, 0, 0 );
         return( -1 );
     }
-    instancedir = config_get_instancedir();
-    directory = rel2abspath_ext(orig_dir, instancedir);
     if (stat(directory, &sbuf) == 0) {
         int baklen = strlen(directory) + 5; /* ".bak\0" */
         dir_bak = slapi_ch_malloc(baklen);
@@ -446,6 +437,5 @@ err:
     }
 out:
     slapi_ch_free_string(&dir_bak);
-    slapi_ch_free_string(&directory);
     return return_value;
 }

+ 156 - 157
ldap/servers/slapd/back-ldbm/ldbm_config.c

@@ -226,13 +226,10 @@ static int ldbm_config_directory_set(void *arg, void *value, char *errorbuf, int
         LDAPDebug(LDAP_DEBUG_ANY, "New db directory location will not take affect until the server is restarted\n", 0, 0, 0);
     } else {
         if (!strcmp(val, "get default")) {
-            /* Generate the default db directory name. The default db directory 
-             * should be the instance directory with a '/db' thrown on the end. 
-             * We need to read cn=config to get the instance dir. */
             /* We use this funky "get default" string for the caller to 
              * tell us that it has no idea what the db directory should
-             * be.  This code figures it out be reading cn=config. */
-            
+             * be.  This code figures it out be reading "cn=config,cn=ldbm
+             * database,cn=plugins,cn=config" entry. */
             Slapi_PBlock *search_pb;
             Slapi_Entry **entries = NULL;
             Slapi_Attr *attr = NULL;
@@ -241,30 +238,33 @@ static int ldbm_config_directory_set(void *arg, void *value, char *errorbuf, int
             int res;
 
             search_pb = slapi_pblock_new();
-            slapi_search_internal_set_pb(search_pb, "cn=config", LDAP_SCOPE_BASE, 
-                                         "objectclass=*", NULL, 0, NULL, NULL, li->li_identity, 0);
+            slapi_search_internal_set_pb(search_pb, CONFIG_LDBM_DN,
+                    LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, NULL, NULL,
+                    li->li_identity, 0);
             slapi_search_internal_pb(search_pb);
             slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &res);
 
             if (res != LDAP_SUCCESS) {
-                LDAPDebug(LDAP_DEBUG_ANY, "ERROR: ldbm plugin unable to read cn=config\n",
-                          0, 0, 0);
+                LDAPDebug(LDAP_DEBUG_ANY, 
+                          "ERROR: ldbm plugin unable to read %s\n",
+                          CONFIG_LDBM_DN, 0, 0);
                 goto done;
             }
 
             slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
             if (NULL == entries) {
-                LDAPDebug(LDAP_DEBUG_ANY, "ERROR: ldbm plugin unable to read cn=config\n",
-                          0, 0, 0);
+                LDAPDebug(LDAP_DEBUG_ANY,
+                          "ERROR: ldbm plugin unable to read %s\n",
+                          CONFIG_LDBM_DN, 0, 0);
                 res = LDAP_OPERATIONS_ERROR;
                 goto done;
             }
             
-            res = slapi_entry_attr_find(entries[0], "nsslapd-instancedir", &attr);
+            res = slapi_entry_attr_find(entries[0], "nsslapd-directory", &attr);
             if (res != 0 || attr == NULL) {
                 LDAPDebug(LDAP_DEBUG_ANY, 
-                          "ERROR: ldbm plugin unable to read attribute nsslapd-instancedir from cn=config\n",
-                          0, 0, 0);
+                          "ERROR: ldbm plugin unable to read attribute nsslapd-directory from %s\n",
+                          CONFIG_LDBM_DN, 0, 0);
                 res = LDAP_OPERATIONS_ERROR;
                 goto done;
             }
@@ -273,8 +273,8 @@ static int ldbm_config_directory_set(void *arg, void *value, char *errorbuf, int
                     || ( NULL == v )
                     || ( NULL == ( s = slapi_value_get_string( v )))) {
                 LDAPDebug(LDAP_DEBUG_ANY, 
-                          "ERROR: ldbm plugin unable to read attribute nsslapd-instancedir from cn=config\n",
-                          0, 0, 0);
+                          "ERROR: ldbm plugin unable to read attribute nsslapd-directory from %s\n",
+                          CONFIG_LDBM_DN, 0, 0);
                 res = LDAP_OPERATIONS_ERROR;
                 goto done;
             }
@@ -284,7 +284,7 @@ done:
             if (res != LDAP_SUCCESS) {
                 return res;
             }
-            PR_snprintf(tmpbuf, BUFSIZ, "%s/db", s );
+            PR_snprintf(tmpbuf, BUFSIZ, "%s", s);
             val = tmpbuf;
         }
         slapi_ch_free((void **) &(li->li_new_directory));
@@ -350,7 +350,7 @@ static int ldbm_config_maxpassbeforemerge_set(void *arg, void *value, char *erro
             val = 100;
         } 
         
-		li->li_maxpassbeforemerge = val;
+        li->li_maxpassbeforemerge = val;
     }
 
     return retval;
@@ -661,7 +661,7 @@ static int ldbm_config_db_trickle_percentage_set(void *arg, void *value, char *e
     
     if (val < 0 || val > 100) {
         PR_snprintf(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
-					"Error: Invalid value for %s (%d). Must be between 0 and 100\n", CONFIG_DB_TRICKLE_PERCENTAGE, val);
+                    "Error: Invalid value for %s (%d). Must be between 0 and 100\n", CONFIG_DB_TRICKLE_PERCENTAGE, val);
         LDAPDebug(LDAP_DEBUG_ANY, "%s", errorbuf, 0, 0);
             return LDAP_UNWILLING_TO_PERFORM;
     }
@@ -896,12 +896,12 @@ static void *ldbm_config_import_cache_autosize_get(void *arg)
 }
 
 static int ldbm_config_import_cache_autosize_set(void *arg, void *value, char *errorbuf,
-				   int phase, int apply)
+                   int phase, int apply)
 {
     struct ldbminfo *li = (struct ldbminfo *)arg;
 
     if (apply)
-	li->li_import_cache_autosize = (int)value;
+    li->li_import_cache_autosize = (int)value;
     return LDAP_SUCCESS;
 }
 
@@ -913,12 +913,12 @@ static void *ldbm_config_cache_autosize_get(void *arg)
 }
 
 static int ldbm_config_cache_autosize_set(void *arg, void *value, char *errorbuf,
-				   int phase, int apply)
+                   int phase, int apply)
 {
     struct ldbminfo *li = (struct ldbminfo *)arg;
 
     if (apply)
-	li->li_cache_autosize = (int)value;
+    li->li_cache_autosize = (int)value;
     return LDAP_SUCCESS;
 }
 
@@ -930,12 +930,12 @@ static void *ldbm_config_cache_autosize_split_get(void *arg)
 }
 
 static int ldbm_config_cache_autosize_split_set(void *arg, void *value, char *errorbuf,
-					 int phase, int apply)
+                     int phase, int apply)
 {
     struct ldbminfo *li = (struct ldbminfo *)arg;
 
     if (apply)
-	li->li_cache_autosize_split = (int)value;
+    li->li_cache_autosize_split = (int)value;
     return LDAP_SUCCESS;
 }
 
@@ -1090,7 +1090,7 @@ static void *ldbm_config_get_use_vlv_index(void *arg)
 
 static int
 ldbm_config_exclude_from_export_set( void *arg, void *value, char *errorbuf,
-		int phase, int apply)
+        int phase, int apply)
 {
     struct ldbminfo *li = (struct ldbminfo *)arg;
 
@@ -1114,12 +1114,12 @@ static void *
 ldbm_config_exclude_from_export_get( void *arg )
 {
     struct ldbminfo *li = (struct ldbminfo *)arg;
-    char	*p, *retstr = NULL;
-    size_t	len = 0;
+    char    *p, *retstr = NULL;
+    size_t    len = 0;
     
     if ( NULL != li->li_attrs_to_exclude_from_export &&
          NULL != li->li_attrs_to_exclude_from_export[0] ) {
-        int		i;
+        int        i;
         
         for ( i = 0; li->li_attrs_to_exclude_from_export[i] != NULL; ++i ) {
             len += strlen( li->li_attrs_to_exclude_from_export[i] ) + 1;
@@ -1171,59 +1171,59 @@ static int ldbm_config_db_tx_max_set(
  * Configuration array for ldbm and dblayer variables
  *----------------------------------------------------------------------*/
 static config_info ldbm_config[] = {
-	{CONFIG_LOOKTHROUGHLIMIT, CONFIG_TYPE_INT, "5000", &ldbm_config_lookthroughlimit_get, &ldbm_config_lookthroughlimit_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
-	{CONFIG_MODE, CONFIG_TYPE_INT_OCTAL, "0600", &ldbm_config_mode_get, &ldbm_config_mode_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
-	{CONFIG_IDLISTSCANLIMIT, CONFIG_TYPE_INT, "4000", &ldbm_config_allidsthreshold_get, &ldbm_config_allidsthreshold_set, CONFIG_FLAG_ALWAYS_SHOW},
-	{CONFIG_DIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_directory_get, &ldbm_config_directory_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
-	{CONFIG_DBCACHESIZE, CONFIG_TYPE_SIZE_T, "10000000", &ldbm_config_dbcachesize_get, &ldbm_config_dbcachesize_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
-	{CONFIG_DBNCACHE, CONFIG_TYPE_INT, "0", &ldbm_config_dbncache_get, &ldbm_config_dbncache_set, CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
-	{CONFIG_MAXPASSBEFOREMERGE, CONFIG_TYPE_INT, "100", &ldbm_config_maxpassbeforemerge_get, &ldbm_config_maxpassbeforemerge_set, 0},
-	
-	/* dblayer config attributes */
-	{CONFIG_DB_LOGDIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_db_logdirectory_get, &ldbm_config_db_logdirectory_set, CONFIG_FLAG_ALWAYS_SHOW},
-	{CONFIG_DB_DURABLE_TRANSACTIONS, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_durable_transactions_get, &ldbm_config_db_durable_transactions_set, CONFIG_FLAG_ALWAYS_SHOW},
-	{CONFIG_DB_CIRCULAR_LOGGING, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_circular_logging_get, &ldbm_config_db_circular_logging_set, 0},
-	{CONFIG_DB_TRANSACTION_LOGGING, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_transaction_logging_get, &ldbm_config_db_transaction_logging_set, CONFIG_FLAG_ALWAYS_SHOW},
-	{CONFIG_DB_CHECKPOINT_INTERVAL, CONFIG_TYPE_INT, "60", &ldbm_config_db_checkpoint_interval_get, &ldbm_config_db_checkpoint_interval_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
-	{CONFIG_DB_TRANSACTION_BATCH, CONFIG_TYPE_INT, "0", &dblayer_get_batch_transactions, &dblayer_set_batch_transactions, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
-	{CONFIG_DB_LOGBUF_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_logbuf_size_get, &ldbm_config_db_logbuf_size_set, CONFIG_FLAG_ALWAYS_SHOW},
-	{CONFIG_DB_PAGE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_page_size_get, &ldbm_config_db_page_size_set, 0},
-	{CONFIG_DB_INDEX_PAGE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_index_page_size_get, &ldbm_config_db_index_page_size_set, 0},
-	{CONFIG_DB_IDL_DIVISOR, CONFIG_TYPE_INT, "0", &ldbm_config_db_idl_divisor_get, &ldbm_config_db_idl_divisor_set, 0},
-	{CONFIG_DB_LOGFILE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_logfile_size_get, &ldbm_config_db_logfile_size_set, 0},
-	{CONFIG_DB_TRICKLE_PERCENTAGE, CONFIG_TYPE_INT, "5", &ldbm_config_db_trickle_percentage_get, &ldbm_config_db_trickle_percentage_set, 0},
-	{CONFIG_DB_SPIN_COUNT, CONFIG_TYPE_INT, "0", &ldbm_config_db_spin_count_get, &ldbm_config_db_spin_count_set, 0},
-	{CONFIG_DB_VERBOSE, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_verbose_get, &ldbm_config_db_verbose_set, 0},
-	{CONFIG_DB_DEBUG, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_debug_get, &ldbm_config_db_debug_set, 0},
-	{CONFIG_DB_NAMED_REGIONS, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_named_regions_get, &ldbm_config_db_named_regions_set, 0},
-	{CONFIG_DB_LOCK, CONFIG_TYPE_INT, "10000", &ldbm_config_db_lock_get, &ldbm_config_db_lock_set, 0},
-	{CONFIG_DB_PRIVATE_MEM, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_private_mem_get, &ldbm_config_db_private_mem_set, 0},
-	{CONFIG_DB_PRIVATE_IMPORT_MEM, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_private_import_mem_get, &ldbm_config_db_private_import_mem_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
-	{CONFIG_DB_SHM_KEY, CONFIG_TYPE_LONG, "389389", &ldbm_config_db_shm_key_get, &ldbm_config_db_shm_key_set, 0},
-	{CONFIG_DB_CACHE, CONFIG_TYPE_INT, "0", &ldbm_config_db_cache_get, &ldbm_config_db_cache_set, 0},
-	{CONFIG_DB_DEBUG_CHECKPOINTING, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_debug_checkpointing_get, &ldbm_config_db_debug_checkpointing_set, 0},
-	{CONFIG_DB_HOME_DIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_db_home_directory_get, &ldbm_config_db_home_directory_set, 0},
-	{CONFIG_IMPORT_CACHE_AUTOSIZE, CONFIG_TYPE_INT, "-1", &ldbm_config_import_cache_autosize_get, &ldbm_config_import_cache_autosize_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
-	{CONFIG_CACHE_AUTOSIZE, CONFIG_TYPE_INT, "0", &ldbm_config_cache_autosize_get, &ldbm_config_cache_autosize_set, 0},
-	{CONFIG_CACHE_AUTOSIZE_SPLIT, CONFIG_TYPE_INT, "50", &ldbm_config_cache_autosize_split_get, &ldbm_config_cache_autosize_split_set, 0},
-	{CONFIG_IMPORT_CACHESIZE, CONFIG_TYPE_SIZE_T, "20000000", &ldbm_config_import_cachesize_get, &ldbm_config_import_cachesize_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_LOOKTHROUGHLIMIT, CONFIG_TYPE_INT, "5000", &ldbm_config_lookthroughlimit_get, &ldbm_config_lookthroughlimit_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_MODE, CONFIG_TYPE_INT_OCTAL, "0600", &ldbm_config_mode_get, &ldbm_config_mode_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_IDLISTSCANLIMIT, CONFIG_TYPE_INT, "4000", &ldbm_config_allidsthreshold_get, &ldbm_config_allidsthreshold_set, CONFIG_FLAG_ALWAYS_SHOW},
+    {CONFIG_DIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_directory_get, &ldbm_config_directory_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_DBCACHESIZE, CONFIG_TYPE_SIZE_T, "10000000", &ldbm_config_dbcachesize_get, &ldbm_config_dbcachesize_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_DBNCACHE, CONFIG_TYPE_INT, "0", &ldbm_config_dbncache_get, &ldbm_config_dbncache_set, CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_MAXPASSBEFOREMERGE, CONFIG_TYPE_INT, "100", &ldbm_config_maxpassbeforemerge_get, &ldbm_config_maxpassbeforemerge_set, 0},
+    
+    /* dblayer config attributes */
+    {CONFIG_DB_LOGDIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_db_logdirectory_get, &ldbm_config_db_logdirectory_set, CONFIG_FLAG_ALWAYS_SHOW},
+    {CONFIG_DB_DURABLE_TRANSACTIONS, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_durable_transactions_get, &ldbm_config_db_durable_transactions_set, CONFIG_FLAG_ALWAYS_SHOW},
+    {CONFIG_DB_CIRCULAR_LOGGING, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_circular_logging_get, &ldbm_config_db_circular_logging_set, 0},
+    {CONFIG_DB_TRANSACTION_LOGGING, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_transaction_logging_get, &ldbm_config_db_transaction_logging_set, CONFIG_FLAG_ALWAYS_SHOW},
+    {CONFIG_DB_CHECKPOINT_INTERVAL, CONFIG_TYPE_INT, "60", &ldbm_config_db_checkpoint_interval_get, &ldbm_config_db_checkpoint_interval_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_DB_TRANSACTION_BATCH, CONFIG_TYPE_INT, "0", &dblayer_get_batch_transactions, &dblayer_set_batch_transactions, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_DB_LOGBUF_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_logbuf_size_get, &ldbm_config_db_logbuf_size_set, CONFIG_FLAG_ALWAYS_SHOW},
+    {CONFIG_DB_PAGE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_page_size_get, &ldbm_config_db_page_size_set, 0},
+    {CONFIG_DB_INDEX_PAGE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_index_page_size_get, &ldbm_config_db_index_page_size_set, 0},
+    {CONFIG_DB_IDL_DIVISOR, CONFIG_TYPE_INT, "0", &ldbm_config_db_idl_divisor_get, &ldbm_config_db_idl_divisor_set, 0},
+    {CONFIG_DB_LOGFILE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_logfile_size_get, &ldbm_config_db_logfile_size_set, 0},
+    {CONFIG_DB_TRICKLE_PERCENTAGE, CONFIG_TYPE_INT, "5", &ldbm_config_db_trickle_percentage_get, &ldbm_config_db_trickle_percentage_set, 0},
+    {CONFIG_DB_SPIN_COUNT, CONFIG_TYPE_INT, "0", &ldbm_config_db_spin_count_get, &ldbm_config_db_spin_count_set, 0},
+    {CONFIG_DB_VERBOSE, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_verbose_get, &ldbm_config_db_verbose_set, 0},
+    {CONFIG_DB_DEBUG, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_debug_get, &ldbm_config_db_debug_set, 0},
+    {CONFIG_DB_NAMED_REGIONS, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_named_regions_get, &ldbm_config_db_named_regions_set, 0},
+    {CONFIG_DB_LOCK, CONFIG_TYPE_INT, "10000", &ldbm_config_db_lock_get, &ldbm_config_db_lock_set, 0},
+    {CONFIG_DB_PRIVATE_MEM, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_private_mem_get, &ldbm_config_db_private_mem_set, 0},
+    {CONFIG_DB_PRIVATE_IMPORT_MEM, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_private_import_mem_get, &ldbm_config_db_private_import_mem_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_DB_SHM_KEY, CONFIG_TYPE_LONG, "389389", &ldbm_config_db_shm_key_get, &ldbm_config_db_shm_key_set, 0},
+    {CONFIG_DB_CACHE, CONFIG_TYPE_INT, "0", &ldbm_config_db_cache_get, &ldbm_config_db_cache_set, 0},
+    {CONFIG_DB_DEBUG_CHECKPOINTING, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_debug_checkpointing_get, &ldbm_config_db_debug_checkpointing_set, 0},
+    {CONFIG_DB_HOME_DIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_db_home_directory_get, &ldbm_config_db_home_directory_set, 0},
+    {CONFIG_IMPORT_CACHE_AUTOSIZE, CONFIG_TYPE_INT, "-1", &ldbm_config_import_cache_autosize_get, &ldbm_config_import_cache_autosize_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_CACHE_AUTOSIZE, CONFIG_TYPE_INT, "0", &ldbm_config_cache_autosize_get, &ldbm_config_cache_autosize_set, 0},
+    {CONFIG_CACHE_AUTOSIZE_SPLIT, CONFIG_TYPE_INT, "50", &ldbm_config_cache_autosize_split_get, &ldbm_config_cache_autosize_split_set, 0},
+    {CONFIG_IMPORT_CACHESIZE, CONFIG_TYPE_SIZE_T, "20000000", &ldbm_config_import_cachesize_get, &ldbm_config_import_cachesize_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
 #if defined(USE_NEW_IDL)
-	{CONFIG_IDL_SWITCH, CONFIG_TYPE_STRING, "new", &ldbm_config_idl_get_idl_new, &ldbm_config_idl_set_tune, CONFIG_FLAG_ALWAYS_SHOW},
+    {CONFIG_IDL_SWITCH, CONFIG_TYPE_STRING, "new", &ldbm_config_idl_get_idl_new, &ldbm_config_idl_set_tune, CONFIG_FLAG_ALWAYS_SHOW},
 #else
-	{CONFIG_IDL_SWITCH, CONFIG_TYPE_STRING, "old", &ldbm_config_idl_get_idl_new, &ldbm_config_idl_set_tune, CONFIG_FLAG_ALWAYS_SHOW},
+    {CONFIG_IDL_SWITCH, CONFIG_TYPE_STRING, "old", &ldbm_config_idl_get_idl_new, &ldbm_config_idl_set_tune, CONFIG_FLAG_ALWAYS_SHOW},
 #endif
-	{CONFIG_BYPASS_FILTER_TEST, CONFIG_TYPE_STRING, "on", &ldbm_config_get_bypass_filter_test, &ldbm_config_set_bypass_filter_test, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
-	{CONFIG_USE_VLV_INDEX, CONFIG_TYPE_ONOFF, "on", &ldbm_config_get_use_vlv_index, &ldbm_config_set_use_vlv_index, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
-	{CONFIG_DB_LOCKDOWN, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_lockdown_get, &ldbm_config_db_lockdown_set, 0},
-	{CONFIG_INDEX_BUFFER_SIZE, CONFIG_TYPE_INT, "0", &ldbm_config_index_buffer_size_get, &ldbm_config_index_buffer_size_set, 0},
-	{CONFIG_EXCLUDE_FROM_EXPORT, CONFIG_TYPE_STRING,
-			CONFIG_EXCLUDE_FROM_EXPORT_DEFAULT_VALUE,
-			&ldbm_config_exclude_from_export_get,
-			&ldbm_config_exclude_from_export_set, CONFIG_FLAG_ALWAYS_SHOW},
-	{CONFIG_DB_TX_MAX, CONFIG_TYPE_INT, "200", &ldbm_config_db_tx_max_get, &ldbm_config_db_tx_max_set, 0},
-	{CONFIG_SERIAL_LOCK, CONFIG_TYPE_ONOFF, "on", &ldbm_config_serial_lock_get, &ldbm_config_serial_lock_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
-	{CONFIG_USE_LEGACY_ERRORCODE, CONFIG_TYPE_ONOFF, "off", &ldbm_config_legacy_errcode_get, &ldbm_config_legacy_errcode_set, 0},
-	{NULL, 0, NULL, NULL, NULL, 0}
+    {CONFIG_BYPASS_FILTER_TEST, CONFIG_TYPE_STRING, "on", &ldbm_config_get_bypass_filter_test, &ldbm_config_set_bypass_filter_test, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_USE_VLV_INDEX, CONFIG_TYPE_ONOFF, "on", &ldbm_config_get_use_vlv_index, &ldbm_config_set_use_vlv_index, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_DB_LOCKDOWN, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_lockdown_get, &ldbm_config_db_lockdown_set, 0},
+    {CONFIG_INDEX_BUFFER_SIZE, CONFIG_TYPE_INT, "0", &ldbm_config_index_buffer_size_get, &ldbm_config_index_buffer_size_set, 0},
+    {CONFIG_EXCLUDE_FROM_EXPORT, CONFIG_TYPE_STRING,
+            CONFIG_EXCLUDE_FROM_EXPORT_DEFAULT_VALUE,
+            &ldbm_config_exclude_from_export_get,
+            &ldbm_config_exclude_from_export_set, CONFIG_FLAG_ALWAYS_SHOW},
+    {CONFIG_DB_TX_MAX, CONFIG_TYPE_INT, "200", &ldbm_config_db_tx_max_get, &ldbm_config_db_tx_max_set, 0},
+    {CONFIG_SERIAL_LOCK, CONFIG_TYPE_ONOFF, "on", &ldbm_config_serial_lock_get, &ldbm_config_serial_lock_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_USE_LEGACY_ERRORCODE, CONFIG_TYPE_ONOFF, "off", &ldbm_config_legacy_errcode_get, &ldbm_config_legacy_errcode_set, 0},
+    {NULL, 0, NULL, NULL, NULL, 0}
 };
 
 void ldbm_config_setup_default(struct ldbminfo *li) 
@@ -1279,7 +1279,7 @@ int ldbm_config_load_dse_info(struct ldbminfo *li)
      * there, then we process the config information it stores.
      */
     PR_snprintf(dn, BUFSIZ, "cn=config, cn=%s, cn=plugins, cn=config", 
-				li->li_plugin->plg_name);
+                li->li_plugin->plg_name);
     search_pb = slapi_pblock_new();
     slapi_search_internal_set_pb(search_pb, dn, LDAP_SCOPE_BASE, 
         "objectclass=*", NULL, 0, NULL, NULL, li->li_identity, 0);
@@ -1304,14 +1304,14 @@ int ldbm_config_load_dse_info(struct ldbminfo *li)
                       0, 0, 0);
             return 1;
         }
-        parse_ldbm_config_entry(li, entries[0], ldbm_config);	
+        parse_ldbm_config_entry(li, entries[0], ldbm_config);    
     }
 
     if (search_pb) {
         slapi_free_search_results_internal(search_pb);
         slapi_pblock_destroy(search_pb);
     }
-	
+    
     /* Find all the instance entries and create a Slapi_Backend and an
      * ldbm_instance for each */
     ldbm_config_read_instance_entries(li, li->li_plugin->plg_name);
@@ -1371,14 +1371,14 @@ int ldbm_config_load_dse_info(struct ldbminfo *li)
 void ldbm_config_get(void *arg, config_info *config, char *buf)
 {
     char *tmp_string;
-	size_t val = 0;
+    size_t val = 0;
     
     if (config == NULL) {
         buf[0] = '\0';
     }
     
     switch(config->config_type) {
-	case CONFIG_TYPE_INT:
+    case CONFIG_TYPE_INT:
             sprintf(buf, "%d", (int) config->config_get_fn(arg));
             break;
     case CONFIG_TYPE_INT_OCTAL:
@@ -1388,7 +1388,7 @@ void ldbm_config_get(void *arg, config_info *config, char *buf)
         sprintf(buf, "%ld", (long) config->config_get_fn(arg));
         break;
     case CONFIG_TYPE_SIZE_T:
-		val = (size_t) config->config_get_fn(arg);
+        val = (size_t) config->config_get_fn(arg);
         sprintf(buf, "%lu", val);
         break;
     case CONFIG_TYPE_STRING:
@@ -1475,17 +1475,17 @@ int ldbm_config_set(void *arg, char *attr_name, config_info *config_array, struc
     int int_val;
     long long_val;
     size_t sz_val;
-	PRInt64 llval;
-	int maxint = (int)(((unsigned int)~0)>>1);
-	int minint = ~maxint;
-	PRInt64 llmaxint;
-	PRInt64 llminint;
-	int err = 0;
-	char *str_val;
+    PRInt64 llval;
+    int maxint = (int)(((unsigned int)~0)>>1);
+    int minint = ~maxint;
+    PRInt64 llmaxint;
+    PRInt64 llminint;
+    int err = 0;
+    char *str_val;
     int retval = 0;
 
-	LL_I2L(llmaxint, maxint);
-	LL_I2L(llminint, minint);
+    LL_I2L(llmaxint, maxint);
+    LL_I2L(llminint, minint);
 
     config = get_config_info(config_array, attr_name);
     if (NULL == config) {
@@ -1505,7 +1505,7 @@ int ldbm_config_set(void *arg, char *attr_name, config_info *config_array, struc
     /* If the config phase is initialization or if bval is NULL, we will use
      * the default value for the attribute. */
     if (CONFIG_PHASE_INITIALIZATION == phase || NULL == bval) {
-		use_default = 1;
+        use_default = 1;
     } else {
         use_default = 0;
         
@@ -1518,33 +1518,33 @@ int ldbm_config_set(void *arg, char *attr_name, config_info *config_array, struc
     switch(config->config_type) {
     case CONFIG_TYPE_INT:
         if (use_default) {
-			str_val = config->config_default_value;
+            str_val = config->config_default_value;
         } else {
-			str_val = bval->bv_val;
+            str_val = bval->bv_val;
+        }
+        /* get the value as a 64 bit value */
+        llval = db_atoi(str_val, &err);
+        /* check for parsing error (e.g. not a number) */
+        if (err) {
+            PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
+                    str_val, attr_name);
+            LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
+            return LDAP_UNWILLING_TO_PERFORM;
+        /* check for overflow */
+        } else if (LL_CMP(llval, >, llmaxint)) {
+            PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is greater than the maximum %d\n",
+                    str_val, attr_name, maxint);
+            LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
+            return LDAP_UNWILLING_TO_PERFORM;
+        /* check for underflow */
+        } else if (LL_CMP(llval, <, llminint)) {
+            PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is less than the minimum %d\n",
+                    str_val, attr_name, minint);
+            LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
+            return LDAP_UNWILLING_TO_PERFORM;
         }
-		/* get the value as a 64 bit value */
-		llval = db_atoi(str_val, &err);
-		/* check for parsing error (e.g. not a number) */
-		if (err) {
-			PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
-					str_val, attr_name);
-			LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
-			return LDAP_UNWILLING_TO_PERFORM;
-		/* check for overflow */
-		} else if (LL_CMP(llval, >, llmaxint)) {
-			PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is greater than the maximum %d\n",
-					str_val, attr_name, maxint);
-			LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
-			return LDAP_UNWILLING_TO_PERFORM;
-		/* check for underflow */
-		} else if (LL_CMP(llval, <, llminint)) {
-			PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is less than the minimum %d\n",
-					str_val, attr_name, minint);
-			LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
-			return LDAP_UNWILLING_TO_PERFORM;
-		}
-		/* convert 64 bit value to 32 bit value */
-		LL_L2I(int_val, llval);
+        /* convert 64 bit value to 32 bit value */
+        LL_L2I(int_val, llval);
         retval = config->config_set_fn(arg, (void *) int_val, err_buf, phase, apply_mod);
         break;
     case CONFIG_TYPE_INT_OCTAL:
@@ -1553,37 +1553,37 @@ int ldbm_config_set(void *arg, char *attr_name, config_info *config_array, struc
         } else {
             int_val = (int) strtol((char *)bval->bv_val, NULL, 8);
         }
-		retval = config->config_set_fn(arg, (void *) int_val, err_buf, phase, apply_mod);
-		break;
+        retval = config->config_set_fn(arg, (void *) int_val, err_buf, phase, apply_mod);
+        break;
     case CONFIG_TYPE_LONG:
         if (use_default) {
-			str_val = config->config_default_value;
+            str_val = config->config_default_value;
         } else {
-			str_val = bval->bv_val;
+            str_val = bval->bv_val;
         }
-		/* get the value as a 64 bit value */
-		llval = db_atoi(str_val, &err);
-		/* check for parsing error (e.g. not a number) */
-		if (err) {
-			PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
-					str_val, attr_name);
-			LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
-			return LDAP_UNWILLING_TO_PERFORM;
-		/* check for overflow */
-		} else if (LL_CMP(llval, >, llmaxint)) {
-			PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is greater than the maximum %d\n",
-					str_val, attr_name, maxint);
-			LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
-			return LDAP_UNWILLING_TO_PERFORM;
-		/* check for underflow */
-		} else if (LL_CMP(llval, <, llminint)) {
-			PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is less than the minimum %d\n",
-					str_val, attr_name, minint);
-			LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
-			return LDAP_UNWILLING_TO_PERFORM;
-		}
-		/* convert 64 bit value to 32 bit value */
-		LL_L2I(long_val, llval);
+        /* get the value as a 64 bit value */
+        llval = db_atoi(str_val, &err);
+        /* check for parsing error (e.g. not a number) */
+        if (err) {
+            PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
+                    str_val, attr_name);
+            LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
+            return LDAP_UNWILLING_TO_PERFORM;
+        /* check for overflow */
+        } else if (LL_CMP(llval, >, llmaxint)) {
+            PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is greater than the maximum %d\n",
+                    str_val, attr_name, maxint);
+            LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
+            return LDAP_UNWILLING_TO_PERFORM;
+        /* check for underflow */
+        } else if (LL_CMP(llval, <, llminint)) {
+            PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is less than the minimum %d\n",
+                    str_val, attr_name, minint);
+            LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
+            return LDAP_UNWILLING_TO_PERFORM;
+        }
+        /* convert 64 bit value to 32 bit value */
+        LL_L2I(long_val, llval);
         retval = config->config_set_fn(arg, (void *) long_val, err_buf, phase, apply_mod);
         break;
     case CONFIG_TYPE_SIZE_T:
@@ -1615,7 +1615,7 @@ int ldbm_config_set(void *arg, char *attr_name, config_info *config_array, struc
         if (use_default) {
             retval = config->config_set_fn(arg, config->config_default_value, err_buf, phase, apply_mod);
         } else {
-			retval = config->config_set_fn(arg, bval->bv_val, err_buf, phase, apply_mod);
+            retval = config->config_set_fn(arg, bval->bv_val, err_buf, phase, apply_mod);
         }
         break;
     case CONFIG_TYPE_ONOFF:
@@ -1663,7 +1663,7 @@ static int parse_ldbm_config_entry(struct ldbminfo *li, Slapi_Entry *e, config_i
  * Returns:
  *   SLAPI_DSE_CALLBACK_ERROR on failure
  *   SLAPI_DSE_CALLBACK_OK on success
- */		
+ */        
 int ldbm_config_modify_entry_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, int *returncode, char *returntext, void *arg) 
 { 
     int i; 
@@ -1678,7 +1678,7 @@ int ldbm_config_modify_entry_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore
     PR_Lock(li->li_config_mutex);
         
     slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods ); 
-	
+    
     returntext[0] = '\0'; 
 
     /* 
@@ -1750,15 +1750,14 @@ void ldbm_config_internal_set(struct ldbminfo *li, char *attrname, char *value)
 void replace_ldbm_config_value(char *conftype, char *val, struct ldbminfo *li)
 {
     Slapi_PBlock pb;
-	Slapi_Mods smods;
+    Slapi_Mods smods;
 
     pblock_init(&pb);
-	slapi_mods_init(&smods, 1);
-	slapi_mods_add(&smods, LDAP_MOD_REPLACE, conftype, strlen(val), val);
-    slapi_modify_internal_set_pb(&pb, 
-        		   "cn=config,cn=ldbm database,cn=plugins,cn=config",
-        		   slapi_mods_get_ldapmods_byref(&smods),
-        		   NULL, NULL, li->li_identity, 0);
+    slapi_mods_init(&smods, 1);
+    slapi_mods_add(&smods, LDAP_MOD_REPLACE, conftype, strlen(val), val);
+    slapi_modify_internal_set_pb(&pb, CONFIG_LDBM_DN,
+                   slapi_mods_get_ldapmods_byref(&smods),
+                   NULL, NULL, li->li_identity, 0);
     slapi_modify_internal_pb(&pb);
     slapi_mods_done(&smods);
     pblock_done(&pb);

+ 2 - 0
ldap/servers/slapd/back-ldbm/ldbm_config.h

@@ -144,6 +144,8 @@ struct config_info {
 
 #define CONFIG_USE_LEGACY_ERRORCODE     "nsslapd-do-not-use-vlv-error"
 
+#define CONFIG_LDBM_DN "cn=config,cn=ldbm database,cn=plugins,cn=config"
+
 #define LDBM_INSTANCE_CONFIG_DONT_WRITE 1
 
 /* Some fuctions in ldbm_config.c used by ldbm_instance_config.c */

+ 2 - 1
ldap/servers/slapd/ch_malloc.c

@@ -624,11 +624,12 @@ BOOL InitialiseImageHelp()
 {
 	if (!SymInitialized)
 	{
+		/* OBSOLETE: we don't have this directory structure any longer */
 		/*
 		 * searchpath= <instancedir>\bin\slapd\server;<instancedir>\lib
 		 */
 		char *searchpath= NULL;
-		char *id= config_get_instancedir();
+		/* char *id= config_get_instancedir(); eliminated */
 		if(id!=NULL)
 		{
 			char *p= id;

+ 14 - 37
ldap/servers/slapd/config.c

@@ -160,7 +160,6 @@ slapd_bootstrap_config(const char *configdir)
 	char *buf = 0;
 	char *lastp = 0;
 	char *entrystr = 0;
-	char *instancedir = NULL;
 
 	if (NULL == configdir) {
 		slapi_log_error(SLAPI_LOG_FATAL,
@@ -261,29 +260,6 @@ slapd_bootstrap_config(const char *configdir)
 								entrystr, configfile, 0);
 					continue;
 				}
-
-				/* if instancedir is not set, set it first */
-				{
-					instancedir = config_get_instancedir();
-					if (NULL == instancedir) {
-						workpath[0] = '\0';
-						if (entry_has_attr_and_value(e,
-												CONFIG_INSTANCEDIR_ATTRIBUTE,
-												workpath, sizeof(workpath))) {
-							if (config_set_instancedir(
-											CONFIG_INSTANCEDIR_ATTRIBUTE,
-											workpath, errorbuf, CONFIG_APPLY)
-								!= LDAP_SUCCESS) {
-								LDAPDebug(LDAP_DEBUG_ANY, "%s: %s: %s\n",
-									configfile, CONFIG_INSTANCEDIR_ATTRIBUTE,
-									errorbuf);
-							}
-						}
-					} else {
-						slapi_ch_free((void **)&instancedir);
-					}
-				}
-
 				/* increase file descriptors */
 #if !defined(_WIN32) && !defined(AIX)
 				if (!maxdescriptors[0] &&
@@ -369,6 +345,19 @@ slapd_bootstrap_config(const char *configdir)
 					}
 				}
 
+				/* set the cert dir; needed in slapd_nss_init */
+				workpath[0] = '\0';
+				if (entry_has_attr_and_value(e, CONFIG_CERTDIR_ATTRIBUTE,
+						workpath, sizeof(workpath)))
+				{
+					if (config_set_certdir(CONFIG_CERTDIR_ATTRIBUTE,
+							workpath, errorbuf, CONFIG_APPLY) != LDAP_SUCCESS)
+					{
+						LDAPDebug(LDAP_DEBUG_ANY, "%s: %s: %s. \n", configfile,
+									  CONFIG_CERTDIR_ATTRIBUTE, errorbuf);
+					}
+				}
+
 				/* see if the entry is a child of the plugin base dn */
 				if (slapi_sdn_isparent(&plug_dn,
 									   slapi_entry_get_sdn_const(e)))
@@ -390,6 +379,7 @@ slapd_bootstrap_config(const char *configdir)
 						}
 					}
 				}
+
 				/* see if the entry is a grand child of the plugin base dn */
 				if (slapi_sdn_isgrandparent(&plug_dn,
 											slapi_entry_get_sdn_const(e)))
@@ -517,19 +507,6 @@ slapd_bootstrap_config(const char *configdir)
 				if (e)
 					slapi_entry_free(e);
 			}
-
-			/* 
-			 * check if the instance dir is set.
-			 */
-			if ( NULL == ( instancedir = config_get_instancedir() )) {
-				slapi_log_error(SLAPI_LOG_FATAL, "startup",
-								"Instance directory is not specifiled in the file %s. It is mandatory.\n",
-								configfile);
-				exit (1);
-			} else {
-				slapi_ch_free((void **)&instancedir);
-			}
-			
 			/* kexcoff: initialize rootpwstoragescheme and pw_storagescheme
 			 *			if not explicilty set in the config file
 			 */

+ 116 - 81
ldap/servers/slapd/libglobs.c

@@ -513,16 +513,22 @@ static struct config_get_and_set {
 		CONFIG_CONSTANT_STRING, NULL},
 	{CONFIG_HASH_FILTERS_ATTRIBUTE, config_set_hash_filters,
 		NULL, 0, NULL, CONFIG_ON_OFF, (ConfigGetFunc)config_get_hash_filters},
-	{CONFIG_INSTANCEDIR_ATTRIBUTE, config_set_instancedir,
-		NULL, 0,
-		(void**)&global_slapdFrontendConfig.instancedir, CONFIG_STRING, NULL},
 	/* parameterizing schema dir */
 	{CONFIG_SCHEMADIR_ATTRIBUTE, config_set_schemadir,
 		NULL, 0,
 		(void**)&global_slapdFrontendConfig.schemadir, CONFIG_STRING, NULL},
-	/* parameterizing ldif dir */
-	{CONFIG_LDIFDIR_ATTRIBUTE, config_set_ldifdir,
-		NULL, 0, NULL, CONFIG_STRING, NULL},
+	/* parameterizing lock dir */
+	{CONFIG_LOCKDIR_ATTRIBUTE, config_set_lockdir,
+		NULL, 0,
+		(void**)&global_slapdFrontendConfig.lockdir, CONFIG_STRING, config_get_lockdir},
+	/* parameterizing tmp dir */
+	{CONFIG_TMPDIR_ATTRIBUTE, config_set_tmpdir,
+		NULL, 0,
+		(void**)&global_slapdFrontendConfig.tmpdir, CONFIG_STRING, config_get_tmpdir},
+	/* parameterizing cert dir */
+	{CONFIG_CERTDIR_ATTRIBUTE, config_set_certdir,
+		NULL, 0,
+		(void**)&global_slapdFrontendConfig.certdir, CONFIG_STRING, config_get_certdir},
 	{CONFIG_REWRITE_RFC1274_ATTRIBUTE, config_set_rewrite_rfc1274,
 		NULL, 0,
 		(void**)&global_slapdFrontendConfig.rewrite_rfc1274, CONFIG_ON_OFF, NULL},
@@ -2325,44 +2331,6 @@ config_set_workingdir( const char *attrname, char *value, char *errorbuf, int ap
   return retVal;
 }
 
-int 
-config_set_instancedir( const char *attrname, char *value, char *errorbuf, int apply ) {
-  int retVal = LDAP_SUCCESS;
-  slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
-
-  if ( config_value_is_null( attrname, value, errorbuf, 0 )) {
-	return LDAP_OPERATIONS_ERROR;
-  }
-	
-  if ( PR_Access ( value, PR_ACCESS_READ_OK ) != 0 ) {
-	PR_snprintf ( errorbuf, SLAPI_DSE_RETURNTEXT_SIZE, "Directory \"%s\" is not accessible.", value );
-	retVal = LDAP_OPERATIONS_ERROR;
-	return retVal;
-  }
-
-  if ( apply) {
-	CFG_LOCK_WRITE(slapdFrontendConfig);
-	slapdFrontendConfig->instancedir = slapi_ch_strdup ( value );
-#ifdef _WIN32
-	dostounixpath(slapdFrontendConfig->instancedir);
-#endif /* _WIN32 */
-	CFG_UNLOCK_WRITE(slapdFrontendConfig);
-
-	/* Set the slapd type also */
-	config_set_slapd_type ();
-
-	/* Set the configdir if not set (it must be set since 7.2) */
-	if (!slapdFrontendConfig->configdir)
-	{
-		char newdir[MAXPATHLEN+1];
-		PR_snprintf ( newdir, sizeof(newdir), "%s/%s",
-				slapdFrontendConfig->instancedir, CONFIG_SUBDIR_NAME);
-		retVal = config_set_configdir(attrname, newdir, errorbuf, apply);
-	}
-  }
-  return retVal;
-}
-
 /* alias of encryption key and certificate files is now retrieved through */
 /* calls to psetFullCreate() and psetGetAttrSingleValue(). See ssl.c, */
 /* where this function is still used to set the global variable */
@@ -3715,19 +3683,6 @@ config_get_localuser() {
 }
 
 #endif /* _WIN32 */
-
-char *
-config_get_instancedir() {
-  slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
-  char *retVal;
-  
-  CFG_LOCK_READ(slapdFrontendConfig);
-  retVal = config_copy_strval( slapdFrontendConfig->instancedir );
-  CFG_UNLOCK_READ(slapdFrontendConfig);
-
-  return retVal;
-}
-
 /* alias of encryption key and certificate files is now retrieved through */
 /* calls to psetFullCreate() and psetGetAttrSingleValue(). See ssl.c, */
 /* where this function is still used to set the global variable */
@@ -4067,27 +4022,6 @@ config_is_slapd_lite ()
 	return ( SLAPD_FULL );
 }
 
-/* This function is called once at the startup time and no more */
-void
-config_set_slapd_type( )
-{
-	char	*root = NULL;
-	char	*s_root = NULL;
-  	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
-
-	CFG_LOCK_WRITE(slapdFrontendConfig);
-	if ( slapdFrontendConfig->instancedir )
-		s_root = root = slapi_ch_strdup ( slapdFrontendConfig->instancedir );
-
-	if ( (root = strrchr( root, '/' )) != NULL ) {
-		*root = '\0';
-        }
-	slapdFrontendConfig->slapd_type = 0;
-	slapdFrontendConfig->versionstring = SLAPD_VERSION_STR;
-	CFG_UNLOCK_WRITE(slapdFrontendConfig);
-	slapi_ch_free ( (void **) &s_root );
-}
-
 int
 config_set_maxbersize( const char *attrname, char *value, char *errorbuf, int apply )
 {
@@ -4263,11 +4197,112 @@ config_set_schemadir(const char *attrname, char *value, char *errorbuf, int appl
 	return retVal;
 }
 
+char *
+config_get_lockdir()
+{
+	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+	char *retVal;
+
+	CFG_LOCK_READ(slapdFrontendConfig);
+	retVal = config_copy_strval(slapdFrontendConfig->lockdir);
+	CFG_UNLOCK_READ(slapdFrontendConfig);
+
+	return retVal; 
+}
+
 int
-config_set_ldifdir(const char *attrname, char *value, char *errorbuf, int apply)
+config_set_lockdir(const char *attrname, char *value, char *errorbuf, int apply)
 {
-	/* noop */
-	return LDAP_SUCCESS;
+	int retVal = LDAP_SUCCESS;
+	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+  
+	if ( config_value_is_null( attrname, value, errorbuf, 0 )) {
+		return LDAP_OPERATIONS_ERROR;
+	}
+  
+	if (!apply) {
+		return retVal;
+	}
+
+	CFG_LOCK_WRITE(slapdFrontendConfig);
+	slapi_ch_free((void **)&slapdFrontendConfig->lockdir);
+
+	slapdFrontendConfig->lockdir = slapi_ch_strdup(value);
+  
+	CFG_UNLOCK_WRITE(slapdFrontendConfig);
+	return retVal;
+}
+
+char *
+config_get_tmpdir()
+{
+	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+	char *retVal;
+
+	CFG_LOCK_READ(slapdFrontendConfig);
+	retVal = config_copy_strval(slapdFrontendConfig->tmpdir);
+	CFG_UNLOCK_READ(slapdFrontendConfig);
+
+	return retVal; 
+}
+
+int
+config_set_tmpdir(const char *attrname, char *value, char *errorbuf, int apply)
+{
+	int retVal = LDAP_SUCCESS;
+	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+  
+	if ( config_value_is_null( attrname, value, errorbuf, 0 )) {
+		return LDAP_OPERATIONS_ERROR;
+	}
+  
+	if (!apply) {
+		return retVal;
+	}
+
+	CFG_LOCK_WRITE(slapdFrontendConfig);
+	slapi_ch_free((void **)&slapdFrontendConfig->tmpdir);
+
+	slapdFrontendConfig->tmpdir = slapi_ch_strdup(value);
+  
+	CFG_UNLOCK_WRITE(slapdFrontendConfig);
+	return retVal;
+}
+
+char *
+config_get_certdir()
+{
+	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+	char *retVal;
+
+	CFG_LOCK_READ(slapdFrontendConfig);
+	retVal = config_copy_strval(slapdFrontendConfig->certdir);
+	CFG_UNLOCK_READ(slapdFrontendConfig);
+
+	return retVal; 
+}
+
+int
+config_set_certdir(const char *attrname, char *value, char *errorbuf, int apply)
+{
+	int retVal = LDAP_SUCCESS;
+	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+  
+	if ( config_value_is_null( attrname, value, errorbuf, 0 )) {
+		return LDAP_OPERATIONS_ERROR;
+	}
+  
+	if (!apply) {
+		return retVal;
+	}
+
+	CFG_LOCK_WRITE(slapdFrontendConfig);
+	slapi_ch_free((void **)&slapdFrontendConfig->certdir);
+
+	slapdFrontendConfig->certdir = slapi_ch_strdup(value);
+  
+	CFG_UNLOCK_WRITE(slapdFrontendConfig);
+	return retVal;
 }
 
 char **

+ 3 - 3
ldap/servers/slapd/libslapd.def

@@ -473,7 +473,7 @@ EXPORTS
 	slapi_build_control @437
 	slapi_entry_get_ndn		@438
 	dse_unset_dont_ever_write_dse_files		@439
-	config_set_instancedir 	@440
+;	config_set_instancedir 	@440
 	config_set_encryptionalias 	@441
 	config_set_threadnumber 	@442
 	config_set_maxthreadsperconn 	@443
@@ -537,7 +537,7 @@ EXPORTS
     slapi_entry_set_sdn @501
     slapi_sdn_copy @502
 	config_set_basedn	@503
-	config_get_instancedir	@504
+;	config_get_instancedir	@504
 	config_get_encryptionalias	@505
 	config_get_threadnumber	@506
 	config_get_maxthreadsperconn	@507
@@ -570,7 +570,7 @@ EXPORTS
 	attr_set_deletion_csn @534
     slapi_mod_dump @535
 	config_is_slapd_lite		@536
-	config_set_slapd_type		@537
+;	config_set_slapd_type		@537
 	config_get_versionstring	@538
 	slapi_is_rootdse			@539
 	slapi_find_matching_paren		@540

+ 5 - 4
ldap/servers/slapd/log.c

@@ -225,7 +225,8 @@ void g_log_init(int log_enabled)
 {
 	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
 #if defined( XP_WIN32 )
-	char * instancedir = NULL;
+	/* char * instancedir = NULL; obsolete. */
+	/* To port to Windows, need to support FHS. */
 #endif
 
 	ts_time_lock = PR_NewLock();
@@ -234,7 +235,7 @@ void g_log_init(int log_enabled)
 
 #if defined( XP_WIN32 )
 	pszServerName = slapi_ch_malloc( MAX_SERVICE_NAME );
-	instancedir = config_get_instancedir();
+	/* instancedir = config_get_instancedir(); eliminated */
 	unixtodospath(instancedir);
 	if( !SlapdGetServerNameFromCmdline(pszServerName, instancedir, 1) )
 	{
@@ -1578,14 +1579,14 @@ log_write_title (LOGFD fp)
 		PR_snprintf(buff, bufflen, "\t%s:%d (%s)\n\n",
 				fe_cfg->localhost,
 				fe_cfg->security ? fe_cfg->secureport : fe_cfg->port,
-				fe_cfg->instancedir ? fe_cfg->instancedir : "");
+				fe_cfg->configdir ? fe_cfg->configdir : "");
 	}
 	else {
 		/* If fe_cfg->localhost is not set, ignore fe_cfg->port since
 		 * it is the default and might be misleading.
 		 */
 		PR_snprintf(buff, bufflen, "\t<host>:<port> (%s)\n\n",
-				fe_cfg->instancedir ? fe_cfg->instancedir : "");
+				fe_cfg->configdir ? fe_cfg->configdir : "");
 	}
 	LOG_WRITE_NOW(fp, buff, strlen(buff), 0);
 	slapi_ch_free((void **)&buildnum);

+ 2 - 9
ldap/servers/slapd/main.c

@@ -274,13 +274,7 @@ fix_ownership()
 	else {
 		return;
 	}
-
-	/* The instance directory needs to be owned by the local user */
-	if (slapdFrontendConfig->instancedir) {
-		slapd_chown_if_not_owner(slapdFrontendConfig->instancedir,
-								 pw->pw_uid, -1);
-	}
-	/* config directory */
+	/* config directory needs to be owned by the local user */
 	if (slapdFrontendConfig->configdir) {
 		chown_dir_files(slapdFrontendConfig->configdir, pw, PR_FALSE);
 	}
@@ -698,8 +692,7 @@ main( int argc, char **argv)
 
 	process_command_line(argc,argv,myname,&extraname);
 
-	if (!slapdFrontendConfig->instancedir &&
-		!slapdFrontendConfig->configdir) {
+	if (NULL == slapdFrontendConfig->configdir) {
 		usage( myname, extraname );
 		exit( 1 );
 	}

+ 318 - 334
ldap/servers/slapd/protect_db.c

@@ -44,7 +44,6 @@
 
 #ifndef _WIN32
 
-#define LOCK_DIR    "locks"
 #define LOCK_FILE   "lock"
 #define IMPORT_DIR  "imports"
 #define EXPORT_DIR  "exports"
@@ -87,8 +86,8 @@ grab_lockfile()
        gets called by an atexit function, and NSPR is long gone by then. */
 
     /* Get the name of the lockfile */
-    snprintf(lockfile, sizeof(lockfile), "%s/%s", slapdFrontendConfig->instancedir, LOCK_FILE);
-	lockfile[sizeof(lockfile)-1] = (char)0;
+    snprintf(lockfile, sizeof(lockfile), "%s/%s", slapdFrontendConfig->lockdir, LOCK_FILE);
+    lockfile[sizeof(lockfile)-1] = (char)0;
     /* Get our pid */
     pid = getpid();
 
@@ -96,7 +95,7 @@ grab_lockfile()
     if ((fd = open(lockfile, O_RDWR | O_CREAT | O_EXCL, 0664)) != -1) {
         /* We got the lock, write our pid to the file */
         write(fd, (void *) &pid, sizeof(pid_t));
-	close(fd);
+    close(fd);
         return 0;
     }
      
@@ -109,13 +108,13 @@ grab_lockfile()
 
     while(1) {
         /* Try to grab the lockfile NUM_TRIES times waiting WAIT_TIME milliseconds after each try */
-	t.tv_sec = 0;
-	t.tv_usec = WAIT_TIME * 1000;
+    t.tv_sec = 0;
+    t.tv_usec = WAIT_TIME * 1000;
         for(x = 0; x < NUM_TRIES; x++) {
             if ((fd = open(lockfile, O_RDWR | O_CREAT | O_EXCL)) != -1) {
                 /* Got the lock */
                 write(fd, (void *) &pid, sizeof(pid_t));
-		close(fd);
+        close(fd);
                 return 0;
             }
             select(0, NULL, NULL, NULL, &t);
@@ -123,7 +122,7 @@ grab_lockfile()
         
         /* We still haven't got the lockfile.  Find out who owns it and see if they are still up */
         if ((fd = open(lockfile,  O_RDONLY)) != -1) {
-			size_t nb_bytes=0;	
+            size_t nb_bytes=0;    
 
             nb_bytes = read(fd, (void *) &owning_pid, sizeof(pid_t));
             if ( (nb_bytes != (size_t)(sizeof(pid_t)) ) || (owning_pid == 0) || (kill(owning_pid, 0) != 0 && errno == ESRCH) ) {
@@ -158,8 +157,8 @@ release_lockfile()
 
     /* This function assumes that the caller owns the lock, it doesn't check to make sure! */
 
-    snprintf(lockfile, sizeof(lockfile), "%s/%s", slapdFrontendConfig->instancedir, LOCK_FILE);
-	lockfile[sizeof(lockfile)-1] = (char)0;
+    snprintf(lockfile, sizeof(lockfile), "%s/%s", slapdFrontendConfig->lockdir, LOCK_FILE);
+    lockfile[sizeof(lockfile)-1] = (char)0;
     unlink(lockfile);
 }
 
@@ -171,9 +170,9 @@ static int
 is_process_up(pid_t pid) 
 {
     if (kill(pid, 0) == -1 && errno == ESRCH) {
-	return 0;
+        return 0;
     } else {
-	return 1;
+        return 1;
     }
 }
 
@@ -189,24 +188,24 @@ make_sure_dir_exists(char *dir)
 
     /* Make sure it exists */
     if (PR_MkDir(dir, 0755) != PR_SUCCESS) {
-		PRErrorCode prerr = PR_GetError();
-		if (prerr != PR_FILE_EXISTS_ERROR) {
-			LDAPDebug(LDAP_DEBUG_ANY, FILE_CREATE_ERROR, dir, prerr, slapd_pr_strerror(prerr));
-			return 1;
-		}
+        PRErrorCode prerr = PR_GetError();
+        if (prerr != PR_FILE_EXISTS_ERROR) {
+            LDAPDebug(LDAP_DEBUG_ANY, FILE_CREATE_ERROR, dir, prerr, slapd_pr_strerror(prerr));
+            return 1;
+        }
     }
 
     /* Make sure it's owned by the correct user */
     if (slapdFrontendConfig->localuser != NULL) {
       if ( (pw = getpwnam(slapdFrontendConfig->localuser)) == NULL ) {
-	LDAPDebug(LDAP_DEBUG_ANY, GETPWNAM_WARNING, slapdFrontendConfig->localuser, errno, strerror(errno));
+        LDAPDebug(LDAP_DEBUG_ANY, GETPWNAM_WARNING, slapdFrontendConfig->localuser, errno, strerror(errno));
       } else {
-	if (chown(dir, pw->pw_uid, -1) == -1) {
-	    stat(dir, &stat_buffer);
-	    if (stat_buffer.st_uid != pw->pw_uid) {
-		LDAPDebug(LDAP_DEBUG_ANY, CHOWN_WARNING, dir, 0, 0);
-	    }
-	}
+        if (chown(dir, pw->pw_uid, -1) == -1) {
+            stat(dir, &stat_buffer);
+            if (stat_buffer.st_uid != pw->pw_uid) {
+                LDAPDebug(LDAP_DEBUG_ANY, CHOWN_WARNING, dir, 0, 0);
+            }
+        }
       } /* else */
     }
 
@@ -226,25 +225,25 @@ add_this_process_to(char *dir_name)
     slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
 
     snprintf(file_name, sizeof(file_name), "%s/%d", dir_name, getpid());
-	file_name[sizeof(file_name)-1] = (char)0;
+    file_name[sizeof(file_name)-1] = (char)0;
     
     if ((prfd = PR_Open(file_name, PR_RDWR | PR_CREATE_FILE, 0666)) == NULL) {
-	LDAPDebug(LDAP_DEBUG_ANY, FILE_CREATE_WARNING, file_name, 0, 0);
-	return;
+    LDAPDebug(LDAP_DEBUG_ANY, FILE_CREATE_WARNING, file_name, 0, 0);
+    return;
     }
     
     /* Make sure the owner is of the file is the user the server
      * runs as. */
     if (slapdFrontendConfig->localuser != NULL) {
       if ( (pw = getpwnam(slapdFrontendConfig->localuser)) == NULL ) {
-	LDAPDebug(LDAP_DEBUG_ANY, GETPWNAM_WARNING, slapdFrontendConfig->localuser, errno, strerror(errno));
+    LDAPDebug(LDAP_DEBUG_ANY, GETPWNAM_WARNING, slapdFrontendConfig->localuser, errno, strerror(errno));
       } else {
-	if (chown(file_name, pw->pw_uid, -1) == -1) {
-	    stat(file_name, &stat_buffer);
-	    if (stat_buffer.st_uid != pw->pw_uid) {
-		LDAPDebug(LDAP_DEBUG_ANY, CHOWN_WARNING, file_name, 0, 0);
-	    }
-	}
+        if (chown(file_name, pw->pw_uid, -1) == -1) {
+            stat(file_name, &stat_buffer);
+            if (stat_buffer.st_uid != pw->pw_uid) {
+                LDAPDebug(LDAP_DEBUG_ANY, CHOWN_WARNING, file_name, 0, 0);
+            }
+        }
       } /* else */
     }
     PR_Close(prfd);
@@ -269,22 +268,22 @@ sample_and_update(char *dir_name)
     char file_name[MAXPATHLEN];
 
     if ((dir = PR_OpenDir(dir_name)) == NULL) {
-	return 0;
+        return 0;
     }
 
     while((entry = PR_ReadDir(dir, PR_SKIP_BOTH)) != NULL) {
-	pid = (pid_t) strtol(entry->name, &endp, 0);
-	if (*endp != '\0') {
-	    /* not quite sure what this file was, but we 
-	     * didn't put it there */
-	    continue;
-	}
-	if (is_process_up(pid)) {
-	    result = (long) pid;
-	} else {
-	    PR_snprintf(file_name, MAXPATHLEN, "%s/%s", dir_name, entry->name);
-	    PR_Delete(file_name);
-	}
+        pid = (pid_t) strtol(entry->name, &endp, 0);
+        if (*endp != '\0') {
+            /* not quite sure what this file was, but we 
+             * didn't put it there */
+            continue;
+        }
+        if (is_process_up(pid)) {
+            result = (long) pid;
+        } else {
+            PR_snprintf(file_name, MAXPATHLEN, "%s/%s", dir_name, entry->name);
+            PR_Delete(file_name);
+        }
     }
     PR_CloseDir(dir);
     return result;
@@ -299,7 +298,6 @@ remove_and_update(char *dir_name)
 {
     /* since this is called from an atexit function, we can't use
      * NSPR. */
-
     DIR *dir;
     struct dirent *entry;
     pid_t pid;
@@ -311,30 +309,30 @@ remove_and_update(char *dir_name)
     our_pid = getpid();
 
     if ((dir = opendir(dir_name)) == NULL) {
-	return;
+        return;
     }
 
     while((entry = readdir(dir)) != NULL) {
-	
-	/* skip dot and dot-dot */
-	if (strcmp(entry->d_name, ".") == 0 ||
-	    strcmp(entry->d_name, "..") == 0)
-	    continue;
-
-	pid = (pid_t) strtol(entry->d_name, &endp, 0);
-	if (*endp != '\0') {
-	    /* not quite sure what this file was, but we 
-	     * didn't put it there */
-	    continue;
-	}	
-	if (!is_process_up(pid) || pid == our_pid) {
-	    PR_snprintf(file_name, MAXPATHLEN, "%s/%s", dir_name, entry->d_name);
-	    unlink(file_name);
-	}
+    
+        /* skip dot and dot-dot */
+        if (strcmp(entry->d_name, ".") == 0 ||
+            strcmp(entry->d_name, "..") == 0)
+            continue;
+
+        pid = (pid_t) strtol(entry->d_name, &endp, 0);
+        if (*endp != '\0') {
+            /* not quite sure what this file was, but we 
+             * didn't put it there */
+            continue;
+        }    
+        if (!is_process_up(pid) || pid == our_pid) {
+            PR_snprintf(file_name, sizeof(file_name), "%s/%s", dir_name, entry->d_name);
+            unlink(file_name);
+        }
     }
     closedir(dir);
 }
-	
+    
 
 
 /* Walks through all the pid directories and clears any stale 
@@ -343,31 +341,26 @@ remove_and_update(char *dir_name)
 void
 remove_slapd_process()
 {
-    char lock_dir[MAXPATHLEN];
     char import_dir[MAXPATHLEN];
     char export_dir[MAXPATHLEN];
     char server_dir[MAXPATHLEN];
     slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
 
-
     /* Create the name of the directories that hold the pids of the currently running 
      * ns-slapd processes */
-    snprintf(lock_dir, sizeof(lock_dir), "%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR);
-	lock_dir[sizeof(lock_dir)-1] = (char)0;
-    snprintf(import_dir, sizeof(import_dir), "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, IMPORT_DIR);
-	import_dir[sizeof(import_dir)-1] = (char)0;
-    snprintf(export_dir, sizeof(export_dir), "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, EXPORT_DIR);
-	export_dir[sizeof(export_dir)-1] = (char)0;
-    snprintf(server_dir, sizeof(server_dir), "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, SERVER_DIR);
-	server_dir[sizeof(server_dir)-1] = (char)0;
+    snprintf(import_dir, sizeof(import_dir), "%s/%s", slapdFrontendConfig->lockdir, IMPORT_DIR);
+    import_dir[sizeof(import_dir)-1] = (char)0;
+    snprintf(export_dir, sizeof(export_dir), "%s/%s", slapdFrontendConfig->lockdir, EXPORT_DIR);
+    export_dir[sizeof(export_dir)-1] = (char)0;
+    snprintf(server_dir, sizeof(server_dir), "%s/%s", slapdFrontendConfig->lockdir, SERVER_DIR);
+    server_dir[sizeof(server_dir)-1] = (char)0;
 
     /* Grab the lockfile */
     if (grab_lockfile() != 0) {
-	/* Unable to grab the lockfile */
-	return;
+        /* Unable to grab the lockfile */
+        return;
     }
 
-    
     remove_and_update(import_dir);
     remove_and_update(export_dir);
     remove_and_update(server_dir);
@@ -378,7 +371,6 @@ remove_slapd_process()
 int
 add_new_slapd_process(int exec_mode, int r_flag, int skip_flag)
 {
-    char lock_dir[MAXPATHLEN];
     char import_dir[MAXPATHLEN];
     char export_dir[MAXPATHLEN];
     char server_dir[MAXPATHLEN];
@@ -387,33 +379,31 @@ add_new_slapd_process(int exec_mode, int r_flag, int skip_flag)
     slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
 
     if (skip_flag) {
-	return 0;
+        return 0;
     }
 
     /* Create the name of the directories that hold the pids of the currently running 
      * ns-slapd processes */
-    snprintf(lock_dir, sizeof(lock_dir), "%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR);
-	lock_dir[sizeof(lock_dir)-1] = (char)0;
-    snprintf(import_dir, sizeof(import_dir), "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, IMPORT_DIR);
-	import_dir[sizeof(import_dir)-1] = (char)0;
-    snprintf(export_dir, sizeof(export_dir), "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, EXPORT_DIR);
-	export_dir[sizeof(export_dir)-1] = (char)0;
-    snprintf(server_dir, sizeof(server_dir), "%s/%s/%s", slapdFrontendConfig->instancedir, LOCK_DIR, SERVER_DIR);
-	server_dir[sizeof(server_dir)-1] = (char)0;
+    snprintf(import_dir, sizeof(import_dir), "%s/%s", slapdFrontendConfig->lockdir, IMPORT_DIR);
+    import_dir[sizeof(import_dir)-1] = (char)0;
+    snprintf(export_dir, sizeof(export_dir), "%s/%s", slapdFrontendConfig->lockdir, EXPORT_DIR);
+    export_dir[sizeof(export_dir)-1] = (char)0;
+    snprintf(server_dir, sizeof(server_dir), "%s/%s", slapdFrontendConfig->lockdir, SERVER_DIR);
+    server_dir[sizeof(server_dir)-1] = (char)0;
 
     /* Grab the lockfile */
     if (grab_lockfile() != 0) {
-	/* Unable to grab the lockfile */
-	return -1;
+        /* Unable to grab the lockfile */
+        return -1;
     }
 
     /* Make sure the directories exist */
-    if (make_sure_dir_exists(lock_dir) != 0 ||
-	make_sure_dir_exists(import_dir) != 0 ||
-	make_sure_dir_exists(export_dir) != 0 || 
-	make_sure_dir_exists(server_dir) != 0) {
-	release_lockfile();
-	return -1;
+    if (make_sure_dir_exists(slapdFrontendConfig->lockdir) != 0 ||
+        make_sure_dir_exists(import_dir) != 0 ||
+        make_sure_dir_exists(export_dir) != 0 || 
+        make_sure_dir_exists(server_dir) != 0) {
+        release_lockfile();
+        return -1;
     }
 
     /* Go through the directories and find out what's going on.  
@@ -424,62 +414,62 @@ add_new_slapd_process(int exec_mode, int r_flag, int skip_flag)
 
     switch (exec_mode) {
     case SLAPD_EXEMODE_SLAPD:
-	if (running) {
-	    result = -1;
-	    LDAPDebug(LDAP_DEBUG_ANY, NO_SERVER_DUE_TO_SERVER, running, 0, 0);
-	} else if (importing) {
-	    result = -1;
-	    LDAPDebug(LDAP_DEBUG_ANY, NO_SERVER_DUE_TO_IMPORT, importing, 0, 0);
-	} else {
-	    add_this_process_to(server_dir);
-	    result = 0;
-	}
-	break;
+    if (running) {
+        result = -1;
+        LDAPDebug(LDAP_DEBUG_ANY, NO_SERVER_DUE_TO_SERVER, running, 0, 0);
+    } else if (importing) {
+        result = -1;
+        LDAPDebug(LDAP_DEBUG_ANY, NO_SERVER_DUE_TO_IMPORT, importing, 0, 0);
+    } else {
+        add_this_process_to(server_dir);
+        result = 0;
+    }
+    break;
     case SLAPD_EXEMODE_DB2LDIF:
-	if (r_flag)  {
-	    /* When the -r flag is used in db2ldif we need to make sure 
-	     * we get a consistent snapshot of the server.  As a result
-	     * it needs to run by itself, so no other slapd process can
-	     * change the database while it is running. */
-	    if (running || importing) {
-		LDAPDebug(LDAP_DEBUG_ANY, NO_DB2LDIFR_DUE_TO_USE, 0, 0, 0);
-		result = -1;
-	    } else {
-		/* Even though this is really going to export code, we will 
-		 * but it in the importing dir so no other process can change 
-		 * things while we are doing ldif2db with the -r flag. */
-		 add_this_process_to(import_dir);
-		 result = 0;
-	    }
-	} else {
-	    if (importing) {
-		LDAPDebug(LDAP_DEBUG_ANY, NO_DB2LDIF_DUE_TO_IMPORT, importing, 0, 0);
-		result = -1;		
-	    } else {
-		add_this_process_to(export_dir);
-		result = 0;
-	    }
-	}
-	break;
+    if (r_flag)  {
+        /* When the -r flag is used in db2ldif we need to make sure 
+         * we get a consistent snapshot of the server.  As a result
+         * it needs to run by itself, so no other slapd process can
+         * change the database while it is running. */
+        if (running || importing) {
+            LDAPDebug(LDAP_DEBUG_ANY, NO_DB2LDIFR_DUE_TO_USE, 0, 0, 0);
+            result = -1;
+        } else {
+            /* Even though this is really going to export code, we will 
+             * but it in the importing dir so no other process can change 
+             * things while we are doing ldif2db with the -r flag. */
+             add_this_process_to(import_dir);
+             result = 0;
+        }
+    } else {
+        if (importing) {
+            LDAPDebug(LDAP_DEBUG_ANY, NO_DB2LDIF_DUE_TO_IMPORT, importing, 0, 0);
+            result = -1;        
+        } else {
+            add_this_process_to(export_dir);
+            result = 0;
+        }
+    }
+    break;
     case SLAPD_EXEMODE_DB2ARCHIVE:
-	if (importing) {
-	    LDAPDebug(LDAP_DEBUG_ANY, NO_DB2BAK_DUE_TO_IMPORT, importing, 0, 0);	    
-	    result = -1;
-	} else {
-	    add_this_process_to(export_dir);
-	    result = 0;
-	}
-	break;
+    if (importing) {
+        LDAPDebug(LDAP_DEBUG_ANY, NO_DB2BAK_DUE_TO_IMPORT, importing, 0, 0);        
+        result = -1;
+    } else {
+        add_this_process_to(export_dir);
+        result = 0;
+    }
+    break;
     case SLAPD_EXEMODE_ARCHIVE2DB:
     case SLAPD_EXEMODE_LDIF2DB:
-	if (running || importing || exporting) {
-	    LDAPDebug(LDAP_DEBUG_ANY, NO_IMPORT_DUE_TO_USE, 0, 0, 0);
-	    result = -1;
-	} else {
-	    add_this_process_to(import_dir);
-	    result = 0;
-	}
-	break;
+    if (running || importing || exporting) {
+        LDAPDebug(LDAP_DEBUG_ANY, NO_IMPORT_DUE_TO_USE, 0, 0, 0);
+        result = -1;
+    } else {
+        add_this_process_to(import_dir);
+        result = 0;
+    }
+    break;
     case SLAPD_EXEMODE_DB2INDEX:
         if (running || importing || exporting) {
             LDAPDebug(LDAP_DEBUG_ANY, NO_DB2INDEX_DUE_TO_USE, 0, 0, 0);
@@ -514,7 +504,7 @@ add_new_slapd_process(int exec_mode, int r_flag, int skip_flag)
     release_lockfile();
     
     if (result == 0) {
-	atexit(remove_slapd_process);
+        atexit(remove_slapd_process);
     }
 
     return result;
@@ -525,31 +515,26 @@ add_new_slapd_process(int exec_mode, int r_flag, int skip_flag)
 /* is_slapd_running()
  * returns 1 if slapd is running, 0 if not, -1 on error
  */
-   
-  
 int
 is_slapd_running() {
   char server_dir[MAXPATHLEN];
-  char lock_dir[MAXPATHLEN];
   slapdFrontendConfig_t *cfg = getFrontendConfig();
   int running = 0;
   
-  snprintf(lock_dir, sizeof(lock_dir), "%s/%s", cfg->instancedir, LOCK_DIR);
-  lock_dir[sizeof(lock_dir)-1] = (char)0;
-  snprintf( server_dir, sizeof(server_dir), "%s/%s/%s", cfg->instancedir, LOCK_DIR, SERVER_DIR);
+  snprintf(server_dir, sizeof(server_dir), "%s/%s", cfg->lockdir, SERVER_DIR);
   server_dir[sizeof(server_dir)-1] = (char)0;
   
   /* Grab the lockfile */
   if (grab_lockfile() != 0) {
-	/* Unable to grab the lockfile */
-	return -1;
+    /* Unable to grab the lockfile */
+    return -1;
   }
 
   /* Make sure the directories exist */
-  if (make_sure_dir_exists(lock_dir) != 0 ||
-	  make_sure_dir_exists(server_dir) != 0) {
-	release_lockfile();
-	return -1;
+  if (make_sure_dir_exists(cfg->lockdir) != 0 ||
+      make_sure_dir_exists(server_dir) != 0) {
+    release_lockfile();
+    return -1;
   }
   
   running = sample_and_update(server_dir);
@@ -557,7 +542,6 @@ is_slapd_running() {
   return running;
 }
 
- 
 #else /* _WIN32 */
 
 /* The NT version of this code */
@@ -568,11 +552,11 @@ is_slapd_running() {
 int
 mutex_exists( char *mutexName )
 {
-	if ( OpenMutex( SYNCHRONIZE, FALSE, mutexName ) == NULL ) {
-		return( 0 );
-	} else {
-		return( 1 );
-	}		
+    if ( OpenMutex( SYNCHRONIZE, FALSE, mutexName ) == NULL ) {
+        return( 0 );
+    } else {
+        return( 1 );
+    }        
 }
 
 /* is_slapd_running(): 
@@ -586,28 +570,28 @@ is_slapd_running() {
   int result = 0;
   slapdFrontendConfig_t *cfg = getFrontendConfig();
 
-  strncpy( mutexName, cfg->instancedir, MAXPATHLEN );
-  strncpy( serverMutexName, cfg->instancedir, MAXPATHLEN );
+  strncpy( mutexName, cfg->lockdir, MAXPATHLEN );
+  strncpy( serverMutexName, cfg->lockdir, MAXPATHLEN );
   mutexName[ MAXPATHLEN ] = '\0';
 
   serverMutexName[ MAXPATHLEN ] = '\0';
   strcat( serverMutexName, "/server" );
-	
+    
   return mutex_exists ( serverMutexName );
 }
 
 static void fix_mutex_name(char *name)
 {
-	/* On NT mutex names cannot contain the '\' character.
-	 * This functions replaces '\' with '/' in the supplied
-	 * name. */
-	int x;
-
-	for (x = 0; name[x] != '\0'; x++) {
-		if ('\\' == name[x]) {
-			name[x] = '/';
-		}
-	}
+    /* On NT mutex names cannot contain the '\' character.
+     * This functions replaces '\' with '/' in the supplied
+     * name. */
+    int x;
+
+    for (x = 0; name[x] != '\0'; x++) {
+        if ('\\' == name[x]) {
+            name[x] = '/';
+        }
+    }
 }
 
 /*
@@ -624,9 +608,9 @@ static HANDLE open_mutex = NULL;
 void
 remove_slapd_process()
 {
-	if (open_mutex) {
-		CloseHandle(open_mutex);
-	}
+    if (open_mutex) {
+        CloseHandle(open_mutex);
+    }
 }
 
 /* This function makes sure different instances of slapd don't
@@ -646,158 +630,158 @@ remove_slapd_process()
 int
 add_new_slapd_process(int exec_mode, int r_flag, int skip_flag)
 {
-	char mutexName[ MAXPATHLEN + 1 ];
-	char serverMutexName[ MAXPATHLEN + 1 ];
-	char importMutexName[ MAXPATHLEN + 1 ];
-	char exportMutexName[ MAXPATHLEN + 1 ];
-
-	HANDLE mutex;
-	SECURITY_ATTRIBUTES mutexAttributes;
-	PSECURITY_DESCRIPTOR pSD;
-	LPVOID lpMsgBuf;
-
-	int result = 0;
-
-	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
-
-	if (skip_flag) {
-	    return 0;
-	}
-
-	/* Create the names for the mutexes */
-	PL_strncpyz(mutexName, slapdFrontendConfig->instancedir, sizeof(mutexName));
-
-	/* Make sure the name of the mutex is legal. */
-	fix_mutex_name(mutexName);
-
-	PR_snprintf(serverMutexName, sizeof(serverMutexName), "%s/server", mutexName);
-	PR_snprintf(importMutexName, sizeof(importMutexName), "%s/import", mutexName);
-	PR_snprintf(exportMutexName, sizeof(exportMutexName), "%s/export", mutexName);
-	
-	/* Fill in the security crap for the mutex */
-	pSD = (PSECURITY_DESCRIPTOR)slapi_ch_malloc( sizeof( SECURITY_DESCRIPTOR ) );
-	InitializeSecurityDescriptor( pSD, SECURITY_DESCRIPTOR_REVISION );
-	SetSecurityDescriptorDacl( pSD, TRUE, NULL, FALSE );
-	mutexAttributes.nLength = sizeof( mutexAttributes );
-	mutexAttributes.lpSecurityDescriptor = pSD;
-	mutexAttributes.bInheritHandle = FALSE;
-	
-	/* Get a handle to the main mutex */
-	if ( ( mutex = CreateMutex( &mutexAttributes, FALSE, mutexName ) ) == NULL ) {
-		FormatMessage( 
-    		FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
-    		NULL,
-    		GetLastError(),
-    		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
-    		(LPTSTR) &lpMsgBuf,
-    		0,
-    		NULL 
-		);
-
-		LDAPDebug( LDAP_DEBUG_ANY, CREATE_MUTEX_ERROR, lpMsgBuf, 0, 0 );
-		LocalFree( lpMsgBuf );
-		exit( 1 );
-	}
-	
-	/* Lock the main mutex */
-	if ( WaitForSingleObject( mutex, INFINITE ) == WAIT_FAILED ) {
-		FormatMessage( 
-    		FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
-    		NULL,
-    		GetLastError(),
-    		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
-    		(LPTSTR) &lpMsgBuf,
-    		0,
-    		NULL 
-		);
-
-		LDAPDebug( LDAP_DEBUG_ANY, WAIT_ERROR, lpMsgBuf, 0, 0 );
-		LocalFree( lpMsgBuf );
-		exit( 1 );
-	}
-
-
-	switch (exec_mode) {
-		case SLAPD_EXEMODE_SLAPD:
-			if ( mutex_exists( serverMutexName ) ||
-				 mutex_exists( importMutexName ) )  {
-				LDAPDebug( LDAP_DEBUG_ANY, NO_SERVER_DUE_TO_USE, 0, 0, 0);
-				result = -1;
-			} else {
-				open_mutex = CreateMutex( &mutexAttributes, FALSE, serverMutexName );
-				result = 0;
-			}
-			break;
-		case SLAPD_EXEMODE_DB2LDIF:
-			if (r_flag)  {
-				/* When the -r flag is used in db2ldif we need to make sure 
-				 * we get a consistent snapshot of the server.  As a result
-				 * it needs to run by itself, so no other slapd process can
-				 * change the database while it is running. */
-				if ( mutex_exists( serverMutexName ) ||
-				 	mutex_exists( importMutexName ) ||
-				 	mutex_exists( exportMutexName ) ) {
-					LDAPDebug(LDAP_DEBUG_ANY, NO_DB2LDIFR_DUE_TO_USE, 0, 0, 0);
-					result = -1;
-				} else {
-					CreateMutex( &mutexAttributes, FALSE, exportMutexName );
-					result = 0;
-				}
-				break;
-			}
-		case SLAPD_EXEMODE_DB2ARCHIVE:
-			if ( mutex_exists( importMutexName ) )  {
-				LDAPDebug(LDAP_DEBUG_ANY, NO_EXPORT_DUE_TO_IMPORT, 0, 0, 0);
-				result = -1;
-			} else {
-				CreateMutex( &mutexAttributes, FALSE, exportMutexName );
-				result = 0;
-			}
-			break;
-		case SLAPD_EXEMODE_ARCHIVE2DB:
-		case SLAPD_EXEMODE_LDIF2DB:
-			if ( mutex_exists( serverMutexName ) ||
-				 mutex_exists( importMutexName ) ||
-				 mutex_exists( exportMutexName ) ) {
-			        LDAPDebug(LDAP_DEBUG_ANY, NO_IMPORT_DUE_TO_USE, 0, 0, 0);
-				result = -1;
-			} else {
-				CreateMutex( &mutexAttributes, FALSE, importMutexName );
-				result = 0;
-			}
-			break;
+    char mutexName[ MAXPATHLEN + 1 ];
+    char serverMutexName[ MAXPATHLEN + 1 ];
+    char importMutexName[ MAXPATHLEN + 1 ];
+    char exportMutexName[ MAXPATHLEN + 1 ];
+
+    HANDLE mutex;
+    SECURITY_ATTRIBUTES mutexAttributes;
+    PSECURITY_DESCRIPTOR pSD;
+    LPVOID lpMsgBuf;
+
+    int result = 0;
+
+    slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+
+    if (skip_flag) {
+        return 0;
+    }
+
+    /* Create the names for the mutexes */
+    PL_strncpyz(mutexName, slapdFrontendConfig->lockdir, sizeof(mutexName));
+
+    /* Make sure the name of the mutex is legal. */
+    fix_mutex_name(mutexName);
+
+    PR_snprintf(serverMutexName, sizeof(serverMutexName), "%s/server", mutexName);
+    PR_snprintf(importMutexName, sizeof(importMutexName), "%s/import", mutexName);
+    PR_snprintf(exportMutexName, sizeof(exportMutexName), "%s/export", mutexName);
+    
+    /* Fill in the security crap for the mutex */
+    pSD = (PSECURITY_DESCRIPTOR)slapi_ch_malloc( sizeof( SECURITY_DESCRIPTOR ) );
+    InitializeSecurityDescriptor( pSD, SECURITY_DESCRIPTOR_REVISION );
+    SetSecurityDescriptorDacl( pSD, TRUE, NULL, FALSE );
+    mutexAttributes.nLength = sizeof( mutexAttributes );
+    mutexAttributes.lpSecurityDescriptor = pSD;
+    mutexAttributes.bInheritHandle = FALSE;
+    
+    /* Get a handle to the main mutex */
+    if ( ( mutex = CreateMutex( &mutexAttributes, FALSE, mutexName ) ) == NULL ) {
+        FormatMessage( 
+            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+            NULL,
+            GetLastError(),
+            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
+            (LPTSTR) &lpMsgBuf,
+            0,
+            NULL 
+        );
+
+        LDAPDebug( LDAP_DEBUG_ANY, CREATE_MUTEX_ERROR, lpMsgBuf, 0, 0 );
+        LocalFree( lpMsgBuf );
+        exit( 1 );
+    }
+    
+    /* Lock the main mutex */
+    if ( WaitForSingleObject( mutex, INFINITE ) == WAIT_FAILED ) {
+        FormatMessage( 
+            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+            NULL,
+            GetLastError(),
+            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
+            (LPTSTR) &lpMsgBuf,
+            0,
+            NULL 
+        );
+
+        LDAPDebug( LDAP_DEBUG_ANY, WAIT_ERROR, lpMsgBuf, 0, 0 );
+        LocalFree( lpMsgBuf );
+        exit( 1 );
+    }
+
+
+    switch (exec_mode) {
+        case SLAPD_EXEMODE_SLAPD:
+            if ( mutex_exists( serverMutexName ) ||
+                 mutex_exists( importMutexName ) )  {
+                LDAPDebug( LDAP_DEBUG_ANY, NO_SERVER_DUE_TO_USE, 0, 0, 0);
+                result = -1;
+            } else {
+                open_mutex = CreateMutex( &mutexAttributes, FALSE, serverMutexName );
+                result = 0;
+            }
+            break;
+        case SLAPD_EXEMODE_DB2LDIF:
+            if (r_flag)  {
+                /* When the -r flag is used in db2ldif we need to make sure 
+                 * we get a consistent snapshot of the server.  As a result
+                 * it needs to run by itself, so no other slapd process can
+                 * change the database while it is running. */
+                if ( mutex_exists( serverMutexName ) ||
+                     mutex_exists( importMutexName ) ||
+                     mutex_exists( exportMutexName ) ) {
+                    LDAPDebug(LDAP_DEBUG_ANY, NO_DB2LDIFR_DUE_TO_USE, 0, 0, 0);
+                    result = -1;
+                } else {
+                    CreateMutex( &mutexAttributes, FALSE, exportMutexName );
+                    result = 0;
+                }
+                break;
+            }
+        case SLAPD_EXEMODE_DB2ARCHIVE:
+            if ( mutex_exists( importMutexName ) )  {
+                LDAPDebug(LDAP_DEBUG_ANY, NO_EXPORT_DUE_TO_IMPORT, 0, 0, 0);
+                result = -1;
+            } else {
+                CreateMutex( &mutexAttributes, FALSE, exportMutexName );
+                result = 0;
+            }
+            break;
+        case SLAPD_EXEMODE_ARCHIVE2DB:
+        case SLAPD_EXEMODE_LDIF2DB:
+            if ( mutex_exists( serverMutexName ) ||
+                 mutex_exists( importMutexName ) ||
+                 mutex_exists( exportMutexName ) ) {
+                    LDAPDebug(LDAP_DEBUG_ANY, NO_IMPORT_DUE_TO_USE, 0, 0, 0);
+                result = -1;
+            } else {
+                CreateMutex( &mutexAttributes, FALSE, importMutexName );
+                result = 0;
+            }
+            break;
 #if defined(UPGRADEDB)
-		case SLAPD_EXEMODE_UPGRADEDB:
-			if ( mutex_exists( serverMutexName ) ||
-				 mutex_exists( importMutexName ) ||
-				 mutex_exists( exportMutexName ) ) {
-			        LDAPDebug(LDAP_DEBUG_ANY, NO_UPGRADEDB_DUE_TO_USE, 0, 0, 0);
-				result = -1;
-			} else {
-				CreateMutex( &mutexAttributes, FALSE, importMutexName );
-				result = 0;
-			}
-			break;
+        case SLAPD_EXEMODE_UPGRADEDB:
+            if ( mutex_exists( serverMutexName ) ||
+                 mutex_exists( importMutexName ) ||
+                 mutex_exists( exportMutexName ) ) {
+                    LDAPDebug(LDAP_DEBUG_ANY, NO_UPGRADEDB_DUE_TO_USE, 0, 0, 0);
+                result = -1;
+            } else {
+                CreateMutex( &mutexAttributes, FALSE, importMutexName );
+                result = 0;
+            }
+            break;
 #endif
-		case SLAPD_EXEMODE_DBTEST:
-			if ( mutex_exists( serverMutexName ) ||
-				 mutex_exists( importMutexName ) ||
-				 mutex_exists( exportMutexName ) ) {
-			        LDAPDebug(LDAP_DEBUG_ANY, NO_DBTEST_DUE_TO_USE, 0, 0, 0);
-				result = -1;
-			} else {
-				CreateMutex( &mutexAttributes, FALSE, importMutexName );
-				result = 0;
-			}
-			break;
-	}
-	
-	/* release the main mutex */
-	ReleaseMutex( mutex );
-
-	slapi_ch_free((void**)&pSD );
-
-	return( result );
+        case SLAPD_EXEMODE_DBTEST:
+            if ( mutex_exists( serverMutexName ) ||
+                 mutex_exists( importMutexName ) ||
+                 mutex_exists( exportMutexName ) ) {
+                    LDAPDebug(LDAP_DEBUG_ANY, NO_DBTEST_DUE_TO_USE, 0, 0, 0);
+                result = -1;
+            } else {
+                CreateMutex( &mutexAttributes, FALSE, importMutexName );
+                result = 0;
+            }
+            break;
+    }
+    
+    /* release the main mutex */
+    ReleaseMutex( mutex );
+
+    slapi_ch_free((void**)&pSD );
+
+    return( result );
 }
 #endif /* _WIN32 */    
     

+ 6 - 4
ldap/servers/slapd/proto-slap.h

@@ -246,7 +246,6 @@ int config_set_rootdn( const char *attrname, char *value, char *errorbuf, int ap
 int config_set_rootpw( const char *attrname, char *value, char *errorbuf, int apply );
 int config_set_rootpwstoragescheme( const char *attrname, char *value, char *errorbuf, int apply );
 int config_set_workingdir( const char *attrname, char *value, char *errorbuf, int apply );
-int config_set_instancedir( const char *attrname, char *value, char *errorbuf, int apply );
 int config_set_encryptionalias( const char *attrname, char *value, char *errorbuf, int apply );
 int config_set_threadnumber( const char *attrname, char *value, char *errorbuf, int apply );
 int config_set_maxthreadsperconn( const char *attrname, char *value, char *errorbuf, int apply );
@@ -302,7 +301,9 @@ int config_set_enquote_sup_oc(const char *attrname,  char *value, char *errorbuf
 int config_set_basedn( const char *attrname, char *value, char *errorbuf, int apply );
 int config_set_configdir( const char *attrname, char *value, char *errorbuf, int apply );
 int config_set_schemadir( const char *attrname, char *value, char *errorbuf, int apply );
-int config_set_ldifdir( const char *attrname, char *value, char *errorbuf, int apply );
+int config_set_lockdir( const char *attrname, char *value, char *errorbuf, int apply );
+int config_set_tmpdir( const char *attrname, char *value, char *errorbuf, int apply );
+int config_set_certdir( const char *attrname, char *value, char *errorbuf, int apply );
 int config_set_attrname_exceptions( const char *attrname, char *value, char *errorbuf, int apply );
 int config_set_hash_filters( const char *attrname, char *value, char *errorbuf, int apply );
 int config_set_rewrite_rfc1274( const char *attrname, char *value, char *errorbuf, int apply );
@@ -366,7 +367,6 @@ char *config_get_rootpwstoragescheme();
 char *config_get_localuser();
 #endif /* _WIN32 */
 char *config_get_workingdir();
-char *config_get_instancedir();
 char *config_get_encryptionalias();
 int config_get_threadnumber();
 int config_get_maxthreadsperconn();
@@ -401,6 +401,9 @@ int config_get_enquote_sup_oc();
 char *config_get_basedn();
 char *config_get_configdir();
 char *config_get_schemadir();
+char *config_get_lockdir();
+char *config_get_tmpdir();
+char *config_get_certdir();
 char **config_get_errorlog_list();
 char **config_get_accesslog_list();
 char **config_get_auditlog_list();
@@ -966,7 +969,6 @@ int	  g_get_global_lastmod();
 struct snmp_vars_t * g_get_global_snmp_vars();
 void FrontendConfig_init();
 int g_get_slapd_security_on();
-void config_set_slapd_type ();
 char *config_get_versionstring();
 
 void libldap_init_debug_level(int *);

+ 12 - 9
ldap/servers/slapd/slap.h

@@ -1648,7 +1648,6 @@ typedef struct _slapdEntryPoints {
 #define CONFIG_SSL3CIPHERS_ATTRIBUTE "nsslapd-SSL3ciphers"
 #define CONFIG_ACCESSLOG_ATTRIBUTE "nsslapd-accesslog"
 #define CONFIG_ERRORLOG_ATTRIBUTE "nsslapd-errorlog"
-#define CONFIG_INSTANCEDIR_ATTRIBUTE "nsslapd-instancedir"
 #define CONFIG_SECUREPORT_ATTRIBUTE "nsslapd-securePort"
 #define CONFIG_SECURELISTENHOST_ATTRIBUTE "nsslapd-securelistenhost"
 #define CONFIG_THREADNUMBER_ATTRIBUTE "nsslapd-threadnumber"
@@ -1709,7 +1708,9 @@ typedef struct _slapdEntryPoints {
 
 #define CONFIG_CONFIG_ATTRIBUTE "nsslapd-config"
 #define CONFIG_SCHEMADIR_ATTRIBUTE "nsslapd-schemadir"
-#define CONFIG_LDIFDIR_ATTRIBUTE "nsslapd-ldifdir"
+#define CONFIG_LOCKDIR_ATTRIBUTE "nsslapd-lockdir"
+#define CONFIG_TMPDIR_ATTRIBUTE "nsslapd-tmpdir"
+#define CONFIG_CERTDIR_ATTRIBUTE "nsslapd-certdir"
 #define CONFIG_SSLCLIENTAUTH_ATTRIBUTE "nsslapd-SSLclientAuth"
 #define CONFIG_SSL_CHECK_HOSTNAME_ATTRIBUTE "nsslapd-ssl-check-hostname"
 #define CONFIG_HASH_FILTERS_ATTRIBUTE "nsslapd-hash-filters"
@@ -1794,7 +1795,6 @@ typedef struct _slapdFrontendConfig {
   char *encryptionalias;
   char *errorlog;
   char *listenhost;
-  char *instancedir;
 #ifndef _WIN32
   char *localuser;
 #endif /* _WIN32 */
@@ -1877,15 +1877,18 @@ typedef struct _slapdFrontendConfig {
   
   ber_len_t maxbersize; /* Maximum BER element size we'll accept */
   int max_filter_nest_level;/* deepest nested filter we will accept */
-  int enquote_sup_oc;  /* put single quotes around an oc's 
-						  superior oc in cn=schema */
+  int enquote_sup_oc;       /* put single quotes around an oc's 
+                               superior oc in cn=schema */
 
-  char *certmap_basedn;			/* Default Base DN for certmap */
+  char *certmap_basedn;	    /* Default Base DN for certmap */
 
   char *workingdir;	/* full path of directory before detach */
-  char *configdir; /* full path name of directory containing configuration files */
-  char *schemadir; /* full path name of directory containing schema files */
-  int attrname_exceptions; /* if true, allow questionable attribute names */
+  char *configdir;  /* full path name of directory containing configuration files */
+  char *schemadir;  /* full path name of directory containing schema files */
+  char *lockdir;    /* full path name of directory containing lock files */
+  char *tmpdir;     /* full path name of directory containing tmp files */
+  char *certdir;    /* full path name of directory containing cert files */
+  int attrname_exceptions;  /* if true, allow questionable attribute names */
   int rewrite_rfc1274;		/* return attrs for both v2 and v3 names */
   char *schemareplace;		/* see CONFIG_SCHEMAREPLACE_* #defines below */
 } slapdFrontendConfig_t;

+ 30 - 34
ldap/servers/slapd/snmp_collator.c

@@ -392,54 +392,50 @@ int snmp_collator_start()
 {
 
   int err;
-  char *instancedir = config_get_instancedir();
+  char *statspath = config_get_tmpdir();
+  char *lp = NULL;
 
-	/*
-	 * Get directory for our stats file
-	 */
+  /*
+   * Get directory for our stats file
+   */
+  if (NULL == statspath) {
+     statspath = slapi_ch_strdup("/tmp");
+  }
 
-  PR_snprintf(szStatsFile, sizeof(szStatsFile), "%s/logs/%s", instancedir, 
-		  AGT_STATS_FILE);
+  PR_snprintf(szStatsFile, sizeof(szStatsFile), "%s/%s",
+                                                statspath, AGT_STATS_FILE);
   tmpstatsfile = szStatsFile;
+  slapi_ch_free((void **) &statspath);
 
-  slapi_ch_free((void **) &instancedir);
-
-
-	  /* open the memory map */
-	  
-	  if ((err = agt_mopen_stats(tmpstatsfile, O_RDWR,  &hdl) != 0))
-	  {
-	      if (err != EEXIST)			/* Ignore if file already exists */
-	      {
-	          printf("Failed to open stats file (%s) (error %d).\n", 
-	                 AGT_STATS_FILE, err);
-           
-	          exit(1);
-	      }
-	  }
+  /* open the memory map */
+  if ((err = agt_mopen_stats(tmpstatsfile, O_RDWR,  &hdl) != 0))
+  {
+    if (err != EEXIST)      /* Ignore if file already exists */
+    {
+      printf("Failed to open stats file (%s) (error %d).\n", 
+                                         szStatsFile, err);
+      exit(1);
+    }
+  }
 
 /* read config entry for entity table data */
-	 
 
 /* point stats struct at mmap data */
-	stats = (struct agt_stats_t *) mmap_tbl [hdl].fp;
+  stats = (struct agt_stats_t *) mmap_tbl [hdl].fp;
 
 /* initialize stats data */
 
-	snmp_collator_init();
+  snmp_collator_init();
 /*
-*	now that memmap is open and things point the right way
-*    an atomic set or increment anywhere in slapd should set
-*	the snmp memmap vars correctly and be able to be polled by snmp
+*  now that memmap is open and things point the right way
+*  an atomic set or increment anywhere in slapd should set
+*  the snmp memmap vars correctly and be able to be polled by snmp
 */
 
-	/* Arrange to be called back periodically */
-	snmp_eq_ctx = slapi_eq_repeat(snmp_collator_update, NULL, (time_t)0,
-			SLAPD_SNMP_UPDATE_INTERVAL);
-
-
-return 0;
-
+  /* Arrange to be called back periodically */
+  snmp_eq_ctx = slapi_eq_repeat(snmp_collator_update, NULL, (time_t)0,
+                                SLAPD_SNMP_UPDATE_INTERVAL);
+  return 0;
 }
 
 

+ 40 - 50
ldap/servers/slapd/ssl.c

@@ -51,10 +51,7 @@
 #include <io.h>
 #endif
 
-#ifdef LINUX
 #include <sys/param.h>
-#endif
-
 #include <ssl.h>
 #include <nss.h>
 #include <key.h>
@@ -456,7 +453,7 @@ slapd_nss_init(int init_ssl, int config_available)
 	int len = 0;
     PRUint32 nssFlags = 0;
 	Slapi_Entry *ec = NULL;
-	char *instancedir;
+	char *certdir;
 
 	if (config_available) {
 		getConfigEntry( configDN, &ec );
@@ -469,9 +466,11 @@ slapd_nss_init(int init_ssl, int config_available)
 		ec = NULL;
 	}
 
-	instancedir = config_get_instancedir();
-	PL_strncpyz(path, instancedir, sizeof(path));
-	slapi_ch_free_string(&instancedir);
+	/* set in slapd_bootstrap_config,
+	   thus certdir is available even if config_available is false */
+	certdir = config_get_certdir();
+	PL_strncpyz(path, certdir, sizeof(path));
+	slapi_ch_free_string(&certdir);
 
 	/* make sure path does not end in the path separator character */
 	len = strlen(path);
@@ -479,14 +478,15 @@ slapd_nss_init(int init_ssl, int config_available)
 		path[len-1] = '\0';
 	}
 
-	/* get the server root from the path */
+	/* get the server instance dir name from path:
+	   <sysconfig>/BRAND_DS/slapd-<id> */
 	val = strrchr(path, '/');
 	if (!val) {
 		val = strrchr(path, '\\');
 	}
 	val++;
 
-	if(keyfn && certfn) {
+	if (keyfn && certfn) {
 		if (is_abspath(certfn)) {
 			warn_if_no_cert_file(certfn);
 			/* first, initialize path from the certfn */
@@ -553,7 +553,6 @@ slapd_nss_init(int init_ssl, int config_available)
 		}
 		PR_snprintf(certPref, sizeof(certPref), "%s-", val);
 		PL_strncpyz(keyPref, certPref, sizeof(keyPref));
-		PL_strncpyz(val, "alias/", sizeof(path)-(val-path));
 	}
 
 	slapi_ch_free((void **) &certfn);
@@ -581,10 +580,6 @@ slapd_nss_init(int init_ssl, int config_available)
     return rv;
 }
 
-
-
-
-
 /*
  * slapd_ssl_init() is called from main() if we plan to listen
  * on a secure port.
@@ -1004,12 +999,11 @@ int slapd_ssl_init2(PRFileDesc **fd, int startTLS)
 
     tmpDir = slapd_get_tmp_dir();
 
-    slapi_log_error(
-        SLAPI_LOG_TRACE,
-        "slapd_ssl_init2",
-         "tmp dir = %s\n", tmpDir);
+    slapi_log_error(SLAPI_LOG_TRACE,
+                    "slapd_ssl_init2", "tmp dir = %s\n", tmpDir);
 
     rv = SSL_ConfigServerSessionIDCache(0, stimeout, stimeout, tmpDir);
+	slapi_ch_free(&tmpDir);
     if (rv) {
       errorCode = PR_GetError();
       if (errorCode == ENOSPC) {
@@ -1448,12 +1442,11 @@ slapd_ssl_listener_is_initialized()
 	return _ssl_listener_initialized;
 }
 
-
+/* memory to store tmpdir is allocated and returned; caller should free it. */
 char* slapd_get_tmp_dir()
 {
-	static char tmpdir[] = "/tmp";
-	static char tmp[256];
-	char* instanceDir;
+	static char tmp[MAXPATHLEN];
+	char* tmpdir = NULL;;
 #if defined( XP_WIN32 )
 	unsigned ilen;
 	char pch;
@@ -1462,64 +1455,61 @@ char* slapd_get_tmp_dir()
 
 	tmp[0] = '\0';
 
-	if((instanceDir = config_get_instancedir()) == NULL)
+	if((tmpdir = config_get_tmpdir()) == NULL)
 	{
 		slapi_log_error(
 			 SLAPI_LOG_FATAL,
 			 "slapd_get_tmp_dir",
-			 "config_get_instancedir returns NULL Setting tmp dir to default\n");
+			 "config_get_tmpdir returns NULL Setting tmp dir to default\n");
 
 #if defined( XP_WIN32 )
-			ilen = sizeof(tmp);
-			GetTempPath( ilen, tmp );
-			tmp[ilen-1] = (char)0;
-			ilen = strlen(tmp);
-			/* Remove trailing slash. */
-			pch = tmp[ilen-1];
-			if( pch == '\\' || pch == '/' )
-				tmp[ilen-1] = '\0';
-			return tmp;
+		ilen = sizeof(tmp);
+		GetTempPath( ilen, tmp );
+		tmp[ilen-1] = (char)0;
+		ilen = strlen(tmp);
+		/* Remove trailing slash. */
+		pch = tmp[ilen-1];
+		if( pch == '\\' || pch == '/' )
+			tmp[ilen-1] = '\0';
 #else
-			return( tmpdir );
+		strcpy(tmp, "/tmp");
 #endif
+		return slapi_ch_strdup(tmp);
 	}
 
-	PR_snprintf(tmp,sizeof(tmp),"%s/tmp",instanceDir);
-	slapi_ch_free_string(&instanceDir);
-
 #if defined( XP_WIN32 )
-	for(ilen=0;ilen < strlen(tmp); ilen++)
 	{
-		if(tmp[ilen]=='/')
-			tmp[ilen]='\\';
+		char *ptr = NULL;
+		char *endptr = tmpdir + strlen(tmpdir);
+		for(ptr = tmpdir; ptr < endptr; ptr++)
+		{
+			if('/' == *ptr)
+				*ptr = '\\';
+		}
 	}
 #endif
 
-	if(stat(tmp,&ffinfo) == -1)
+	if(stat(tmpdir, &ffinfo) == -1)
 #if defined( XP_WIN32 )
-		if(CreateDirectory(tmp, NULL) == 0)
+		if(CreateDirectory(tmpdir, NULL) == 0)
 		{
 			slapi_log_error(
 			 SLAPI_LOG_FATAL,
 			 "slapd_get_tmp_dir",
 			 "CreateDirectory(%s, NULL) Error: %s\n",
-			 tmp, strerror(errno));	
-			return ( tmpdir );
+			 tmpdir, strerror(errno));	
 		}
 #else
-		if(mkdir(tmp, 00770) == -1)
+		if(mkdir(tmpdir, 00770) == -1)
 		{
 			slapi_log_error(
 			 SLAPI_LOG_FATAL,
 			 "slapd_get_tmp_dir",
 			 "mkdir(%s, 00770) Error: %s\n",
-			 tmp, strerror(errno));	
-			return ( tmpdir );
+			 tmpdir, strerror(errno));	
 		}
 #endif
-
-	return ( tmp );
-
+	return ( tmpdir );
 }
 
 #endif /* NET_SSL */

Some files were not shown because too many files changed in this diff