Browse Source

Resolves: 158342
Summary: db backend path handling could be impoved to deal with "//", "..", etc.
Changes:
util.c:
modified rel2abspath so that if the given path contains "//", calls the
normalize function, and the normalize function eliminates the repeated
separators.
ldbm_config.c, ldbm_instance_config.c:
before setting the nsslapd-directory paths, pass them to rel2abspath to clean
up the paths.

Noriko Hosoi 19 years ago
parent
commit
0d0cc2374e

+ 5 - 3
ldap/servers/slapd/back-ldbm/ldbm_config.c

@@ -227,7 +227,8 @@ static int ldbm_config_directory_set(void *arg, void *value, char *errorbuf, int
 
     if (CONFIG_PHASE_RUNNING == phase) {
         slapi_ch_free((void **) &(li->li_new_directory));
-        li->li_new_directory = slapi_ch_strdup(val);
+        li->li_new_directory = rel2abspath(val); /* normalize the path;
+                                                    strdup'ed in rel2abspath */
         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")) {
@@ -294,8 +295,9 @@ done:
         }
         slapi_ch_free((void **) &(li->li_new_directory));
         slapi_ch_free((void **) &(li->li_directory));
-        li->li_new_directory = slapi_ch_strdup(val);
-        li->li_directory = slapi_ch_strdup(val);
+        li->li_new_directory = rel2abspath(val); /* normalize the path;
+                                                    strdup'ed in rel2abspath */
+        li->li_directory = rel2abspath(val);     /* ditto */
     }
 
     return retval;

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

@@ -189,15 +189,19 @@ ldbm_instance_config_instance_dir_set(void *arg, void *value, char *errorbuf, in
         {
             char sep = get_sep(dir);
             char *p = strrchr(dir, sep);
-            if (NULL == p)    /* never happens, tho */
+            if (NULL == p)    /* should not happens, tho */
             {
                 inst->inst_parent_dir_name = NULL;
-                inst->inst_dir_name = slapi_ch_strdup(dir);
+                inst->inst_dir_name = rel2abspath(dir); /* normalize dir;
+                                                           strdup'ed in 
+                                                           rel2abspath */
             }
             else
             {
                 *p = '\0';
-                inst->inst_parent_dir_name = slapi_ch_strdup(dir);
+                inst->inst_parent_dir_name = rel2abspath(dir); /* normalize dir;
+                                                                  strdup'ed in
+                                                                  rel2abspath */
                 inst->inst_dir_name = slapi_ch_strdup(p+1);
                 *p = sep;
             }

+ 9 - 6
ldap/servers/slapd/util.c

@@ -61,9 +61,11 @@
 
 #if defined( _WIN32 )
 #define _PSEP "\\"
+#define _PSEP2 "\\\\"
 #define _CSEP '\\'
 #else
 #define _PSEP "/"
+#define _PSEP2 "//"
 #define _CSEP '/'
 #endif
 
@@ -422,9 +424,9 @@ normalize_path(char *path)
         if (NULL == bnamep) {
             bnamep = dnamep;
         } else {
-           *bnamep = '\0';
-           bnamep++;
-       }
+            *bnamep = '\0';
+            bnamep++;
+        }
         if (0 != strcmp(bnamep, ".")) {
             *dp++ = slapi_ch_strdup(bnamep);    /* remove "/./" in the path */
         }
@@ -447,9 +449,10 @@ normalize_path(char *path)
             if (rdp > rdirs)
                 rdp--;
         }
-        if (*dp)
+        if (*dp && strlen(*dp) > 0)
             *rdp++ = slapi_ch_strdup(*dp);
     }
+    *rdp = NULL;
 
     clean_path(dirs);
     slapi_ch_free_string(&dname);
@@ -518,14 +521,14 @@ rel2abspath_ext( char *relpath, char *cwd )
             if ( abspath[ 0 ] != '\0' &&
                  abspath[ strlen( abspath ) - 1 ] != _CSEP )
             {
-                PL_strcatn( abspath, sizeof(abspath), "/" );
+                PL_strcatn( abspath, sizeof(abspath), _PSEP );
             }
             PL_strcatn( abspath, sizeof(abspath), relpath );
         }
     }
     retpath = slapi_ch_strdup(abspath);
     /* if there's no '.', no need to call normalize_path */
-    if (NULL != strchr(abspath, '.'))
+    if (NULL != strchr(abspath, '.') || NULL != strstr(abspath, _PSEP2))
     {
         char **norm_path = normalize_path(abspath);
         char **np, *rp;