Browse Source

Resolves: #174776
Summary: Multiple restores from a non-existant directory could wipe out database
Description: The given archive path was not normalized. Due to the trailing
slash '/', comparing with the db dir failed and wiped out the db dirs.
Applying the path normalization to the archive path.

Noriko Hosoi 18 năm trước cách đây
mục cha
commit
8736b7804e
1 tập tin đã thay đổi với 7 bổ sung3 xóa
  1. 7 3
      ldap/servers/slapd/back-ldbm/archive.c

+ 7 - 3
ldap/servers/slapd/back-ldbm/archive.c

@@ -47,7 +47,8 @@
 int ldbm_back_archive2ldbm( Slapi_PBlock *pb )
 {
     struct ldbminfo    *li;
-    char *directory = NULL;    /* -a <directory> */
+    char *rawdirectory = NULL;    /* -a <directory> */
+    char *directory = NULL;       /* normalized */
     char *backendname = NULL;
     int return_value = -1;
     int task_flags = 0;
@@ -56,18 +57,20 @@ 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, &directory );
+    slapi_pblock_get( pb, SLAPI_SEQ_VAL, &rawdirectory );
     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 ( !directory || !*directory ) {
+    if ( !rawdirectory || !*rawdirectory ) {
         LDAPDebug( LDAP_DEBUG_ANY, "archive2db: no archive name\n",
                    0, 0, 0 );
         return( -1 );
     }
 
+    directory = rel2abspath(rawdirectory);
+
     /* check the current idl format vs backup DB version */
     if (idl_get_idl_new())
     {
@@ -251,6 +254,7 @@ int ldbm_back_archive2ldbm( Slapi_PBlock *pb )
         }
     }
 out:
+    slapi_ch_free_string(&directory);
     return return_value;
 }