Merge pull request #28249 from kitaisreal/dictionaries-small-fixes

Dictionaries small fixes
This commit is contained in:
Maksim Kita 2021-08-27 17:01:31 +03:00 committed by GitHub
commit 308fb6112d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 7 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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<SSDCacheDictionaryStorage<dictionary_key_type>>(storage_configuration);
}