From 0e169b42657ce14ca8395081177b9b694db1884d Mon Sep 17 00:00:00 2001 From: Maksim Kita Date: Fri, 27 Aug 2021 13:46:59 +0300 Subject: [PATCH] Dictionaries small fixes --- src/Common/filesystemHelpers.h | 1 + src/Dictionaries/FileDictionarySource.cpp | 5 +++-- src/Dictionaries/LibraryDictionarySource.cpp | 7 ++++--- src/Dictionaries/registerCacheDictionaries.cpp | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Common/filesystemHelpers.h b/src/Common/filesystemHelpers.h index 71ef7844ef7..551b4ee0fc5 100644 --- a/src/Common/filesystemHelpers.h +++ b/src/Common/filesystemHelpers.h @@ -35,6 +35,7 @@ bool pathStartsWith(const std::filesystem::path & path, const std::filesystem::p /// Returns true if path starts with prefix path bool pathStartsWith(const String & path, const String & prefix_path); +/// Returns true if symlink starts with prefix path bool symlinkStartsWith(const String & path, const String & prefix_path); } diff --git a/src/Dictionaries/FileDictionarySource.cpp b/src/Dictionaries/FileDictionarySource.cpp index 54ce5e4a448..5a77dc02673 100644 --- a/src/Dictionaries/FileDictionarySource.cpp +++ b/src/Dictionaries/FileDictionarySource.cpp @@ -32,8 +32,9 @@ FileDictionarySource::FileDictionarySource( , sample_block{sample_block_} , context(context_) { - if (created_from_ddl && !pathStartsWith(filepath, context->getUserFilesPath())) - throw Exception(ErrorCodes::PATH_ACCESS_DENIED, "File path {} is not inside {}", filepath, context->getUserFilesPath()); + auto user_files_path = context->getUserFilesPath(); + if (created_from_ddl && !pathStartsWith(filepath, user_files_path)) + throw Exception(ErrorCodes::PATH_ACCESS_DENIED, "File path {} is not inside {}", filepath, user_files_path); } diff --git a/src/Dictionaries/LibraryDictionarySource.cpp b/src/Dictionaries/LibraryDictionarySource.cpp index 2a47d4c9172..74da196bc73 100644 --- a/src/Dictionaries/LibraryDictionarySource.cpp +++ b/src/Dictionaries/LibraryDictionarySource.cpp @@ -41,14 +41,15 @@ LibraryDictionarySource::LibraryDictionarySource( , sample_block{sample_block_} , context(Context::createCopy(context_)) { + auto dictionaries_lib_path = context->getDictionariesLibPath(); bool path_checked = false; if (fs::is_symlink(path)) - path_checked = symlinkStartsWith(path, context->getDictionariesLibPath()); + path_checked = symlinkStartsWith(path, dictionaries_lib_path); else - path_checked = pathStartsWith(path, context->getDictionariesLibPath()); + path_checked = pathStartsWith(path, dictionaries_lib_path); if (created_from_ddl && !path_checked) - throw Exception(ErrorCodes::PATH_ACCESS_DENIED, "File path {} is not inside {}", path, context->getDictionariesLibPath()); + throw Exception(ErrorCodes::PATH_ACCESS_DENIED, "File path {} is not inside {}", path, dictionaries_lib_path); if (!fs::exists(path)) throw Exception(ErrorCodes::FILE_DOESNT_EXIST, "LibraryDictionarySource: Can't load library {}: file doesn't exist", path); diff --git a/src/Dictionaries/registerCacheDictionaries.cpp b/src/Dictionaries/registerCacheDictionaries.cpp index 69197f992f0..88e01a31402 100644 --- a/src/Dictionaries/registerCacheDictionaries.cpp +++ b/src/Dictionaries/registerCacheDictionaries.cpp @@ -213,8 +213,9 @@ DictionaryPtr createCacheDictionaryLayout( else { auto storage_configuration = parseSSDCacheStorageConfiguration(config, full_name, layout_type, dictionary_layout_prefix, dict_lifetime); - if (created_from_ddl && !pathStartsWith(storage_configuration.file_path, global_context->getUserFilesPath())) - throw Exception(ErrorCodes::PATH_ACCESS_DENIED, "File path {} is not inside {}", storage_configuration.file_path, global_context->getUserFilesPath()); + auto user_files_path = global_context->getUserFilesPath(); + if (created_from_ddl && !pathStartsWith(storage_configuration.file_path, user_files_path)) + throw Exception(ErrorCodes::PATH_ACCESS_DENIED, "File path {} is not inside {}", storage_configuration.file_path, user_files_path); storage = std::make_shared>(storage_configuration); }