1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-08 14:22:09 +03:00

clang format apply

This commit is contained in:
Leonid Fedorov
2022-02-11 12:24:40 +00:00
parent 509f005be7
commit 7c808317dc
1367 changed files with 394342 additions and 413129 deletions

View File

@@ -25,12 +25,8 @@
using std::string;
using ByteVec = std::vector<uint8_t>;
struct option options[] =
{
{"help", no_argument, nullptr, 'h'},
{"user", required_argument, nullptr, 'u'},
{nullptr, 0, nullptr, 0 }
};
struct option options[] = {
{"help", no_argument, nullptr, 'h'}, {"user", required_argument, nullptr, 'u'}, {nullptr, 0, nullptr, 0}};
const string default_user = "mysql";
@@ -38,8 +34,8 @@ ByteVec generate_encryption_key();
void print_usage(const char* executable, const char* default_directory)
{
const char msg[] =
R"(usage: %s [-h|--help] [directory]
const char msg[] =
R"(usage: %s [-h|--help] [directory]
This utility generates a random AES encryption key and init vector and writes
them to disk. The data is written to the file '%s', in the specified
directory. The key and init vector are used by the utility 'cspasswd' to
@@ -51,75 +47,69 @@ configuration files.
-u, --user Designate the owner of the generated file (default: '%s')
directory : The directory where to store the file in (default: '%s')
)";
printf(msg, executable, SECRETS_FILENAME, default_user.c_str(), default_directory);
printf(msg, executable, SECRETS_FILENAME, default_user.c_str(), default_directory);
}
int main(int argc, char** argv)
{
const string default_directory = string(MCSDATADIR);
string username = default_user;
const string default_directory = string(MCSDATADIR);
string username = default_user;
int c;
while ((c = getopt_long(argc, argv, "hu:", options, nullptr)) != -1)
int c;
while ((c = getopt_long(argc, argv, "hu:", options, nullptr)) != -1)
{
switch (c)
{
switch (c)
{
case 'h':
print_usage(argv[0], default_directory.c_str());
return EXIT_SUCCESS;
case 'h': print_usage(argv[0], default_directory.c_str()); return EXIT_SUCCESS;
case 'u':
username = optarg;
break;
case 'u': username = optarg; break;
default:
print_usage(argv[0], default_directory.c_str());
return EXIT_FAILURE;
}
default: print_usage(argv[0], default_directory.c_str()); return EXIT_FAILURE;
}
}
string filepath = default_directory;
if (optind < argc)
{
filepath = argv[optind];
}
filepath.append("/").append(SECRETS_FILENAME);
string filepath = default_directory;
if (optind < argc)
{
filepath = argv[optind];
}
filepath.append("/").append(SECRETS_FILENAME);
// Check that the file doesn't exist.
errno = 0;
auto filepathc = filepath.c_str();
if (access(filepathc, F_OK) == 0)
{
printf("Secrets file '%s' already exists. Delete it before generating a new encryption key.\n",
filepathc);
return EXIT_FAILURE;
}
else if (errno != ENOENT)
{
printf("stat() for secrets file '%s' failed unexpectedly. Error %i, %s.\n",
filepathc, errno, strerror(errno));
return EXIT_FAILURE;
}
// Check that the file doesn't exist.
errno = 0;
auto filepathc = filepath.c_str();
if (access(filepathc, F_OK) == 0)
{
printf("Secrets file '%s' already exists. Delete it before generating a new encryption key.\n",
filepathc);
return EXIT_FAILURE;
}
else if (errno != ENOENT)
{
printf("stat() for secrets file '%s' failed unexpectedly. Error %i, %s.\n", filepathc, errno,
strerror(errno));
return EXIT_FAILURE;
}
int rval = EXIT_FAILURE;
auto new_key = generate_encryption_key();
if (!new_key.empty() && secrets_write_keys(new_key, filepath, username))
{
rval = EXIT_SUCCESS;
}
return rval;
int rval = EXIT_FAILURE;
auto new_key = generate_encryption_key();
if (!new_key.empty() && secrets_write_keys(new_key, filepath, username))
{
rval = EXIT_SUCCESS;
}
return rval;
}
ByteVec generate_encryption_key()
{
int keylen = EVP_CIPHER_key_length(secrets_cipher());
ByteVec key(keylen);
// Generate random bytes using OpenSSL.
if (RAND_bytes(key.data(), keylen) != 1)
{
auto errornum = ERR_get_error();
printf("OpenSSL RAND_bytes() failed. %s.\n", ERR_error_string(errornum, nullptr));
key.clear();
}
return key;
int keylen = EVP_CIPHER_key_length(secrets_cipher());
ByteVec key(keylen);
// Generate random bytes using OpenSSL.
if (RAND_bytes(key.data(), keylen) != 1)
{
auto errornum = ERR_get_error();
printf("OpenSSL RAND_bytes() failed. %s.\n", ERR_error_string(errornum, nullptr));
key.clear();
}
return key;
}