OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{SysCatalog.cpp} Namespace Reference

Functions

std::string hash_with_bcrypt (const std::string &pwd)
 
std::filesystem::path copy_catalog_if_read_only (std::filesystem::path base_data_path)
 

Function Documentation

std::filesystem::path anonymous_namespace{SysCatalog.cpp}::copy_catalog_if_read_only ( std::filesystem::path  base_data_path)

Definition at line 79 of file SysCatalog.cpp.

References CHECK_NE, gpu_enabled::copy(), g_read_only, logger::INFO, shared::kCatalogDirectoryName, shared::kDataDirectoryName, shared::kDefaultExportDirName, shared::kLockfilesDirectoryName, and LOG.

Referenced by Catalog_Namespace::SysCatalog::init().

79  {
80  std::filesystem::path catalog_base_data_path;
81 
82  // For a read-only server, make a temporary copy of the catalog directory.
83  // This catalog copy must take place before any other catalog accesses.
84  if (!g_read_only) {
85  // Catalog directory will be in the normal location.
86  catalog_base_data_path = base_data_path;
87  } else {
88  // Catalog directory will be in a temporary location.
89  catalog_base_data_path = base_data_path / "temporary";
90 
91  // Delete the temporary directory if it exists.
92  // The name "temporary" is hardcoded so nobody should object to its deletion!
93  CHECK_NE(catalog_base_data_path.string().find("temporary"), std::string::npos);
94  CHECK_NE(catalog_base_data_path, base_data_path);
95  if (std::filesystem::exists(catalog_base_data_path)) {
96  std::filesystem::remove_all(catalog_base_data_path);
97  }
98  std::filesystem::create_directories(catalog_base_data_path);
99 
100  // Make the temporary copy of the catalog.
101  const auto normal_catalog_path = base_data_path / shared::kCatalogDirectoryName;
102  const auto temporary_catalog_path =
103  catalog_base_data_path / shared::kCatalogDirectoryName;
104  LOG(INFO) << "copying catalog from " << normal_catalog_path << " to "
105  << temporary_catalog_path << " for read-only server";
106  std::filesystem::copy(normal_catalog_path,
107  temporary_catalog_path,
108  std::filesystem::copy_options::recursive);
109 
110  // Create a temporary empty directory structure similar to how initheavy would.
111  // Not expected to be used. Created just in case any code tries to access them.
112  try {
113  std::filesystem::create_directories(catalog_base_data_path /
115  } catch (...) {
116  }
117  try {
118  std::filesystem::create_directories(catalog_base_data_path /
120  } catch (...) {
121  }
122  try {
123  std::filesystem::create_directories(catalog_base_data_path /
125  } catch (...) {
126  }
127  try {
128  std::filesystem::create_directories(catalog_base_data_path /
131  } catch (...) {
132  }
133  try {
134  std::filesystem::create_directories(catalog_base_data_path /
137  } catch (...) {
138  }
139  }
140 
141  return catalog_base_data_path;
142 }
const std::string kDataDirectoryName
#define LOG(tag)
Definition: Logger.h:285
const std::string kDefaultExportDirName
DEVICE auto copy(ARGS &&...args)
Definition: gpu_enabled.h:51
#define CHECK_NE(x, y)
Definition: Logger.h:302
bool g_read_only
Definition: heavyai_locks.h:21
const std::string kCatalogDirectoryName
const std::string kLockfilesDirectoryName

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string anonymous_namespace{SysCatalog.cpp}::hash_with_bcrypt ( const std::string &  pwd)

Definition at line 71 of file SysCatalog.cpp.

References CHECK.

Referenced by Catalog_Namespace::SysCatalog::alterUser(), Catalog_Namespace::SysCatalog::createUser(), Catalog_Namespace::SysCatalog::initDB(), Catalog_Namespace::SysCatalog::updateBlankPasswordsToRandom(), Catalog_Namespace::SysCatalog::updatePasswordsToHashes(), and Catalog_Namespace::UserAlterations::wouldChange().

71  {
72  char salt[BCRYPT_HASHSIZE], hash[BCRYPT_HASHSIZE];
73  CHECK(bcrypt_gensalt(-1, salt) == 0);
74  CHECK(bcrypt_hashpw(pwd.c_str(), salt, hash) == 0);
75  return std::string(hash, BCRYPT_HASHSIZE);
76 }
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function: