MXS-3415: Export config with correct permissions
The created file is now created with the correct permissions: read and write permissions for the user and group.
This commit is contained in:
parent
c668da624b
commit
8765eb88fa
@ -1368,32 +1368,39 @@ bool export_config_file(const char* filename)
|
||||
contexts.push_back(ctx);
|
||||
}
|
||||
|
||||
std::ofstream file(filename);
|
||||
std::ostringstream ss;
|
||||
ss << "# Generated by MaxScale " << MAXSCALE_VERSION << '\n';
|
||||
ss << "# Documentation: https://mariadb.com/kb/en/mariadb-enterprise/maxscale/ \n\n";
|
||||
|
||||
if (file)
|
||||
for (CONFIG_CONTEXT* ctx : contexts)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
file << "# Generated by MaxScale " << MAXSCALE_VERSION << '\n';
|
||||
file << "# Documentation: https://mariadb.com/kb/en/mariadb-enterprise/maxscale/ \n\n";
|
||||
|
||||
for (auto it = contexts.rbegin(); it != contexts.rend(); it++)
|
||||
ss << '[' << ctx->m_name << "]\n";
|
||||
for (const auto& elem : ctx->m_parameters)
|
||||
{
|
||||
CONFIG_CONTEXT* ctx = *it;
|
||||
|
||||
file << '[' << ctx->m_name << "]\n";
|
||||
for (const auto& elem : ctx->m_parameters)
|
||||
{
|
||||
file << elem.first << '=' << elem.second << '\n';
|
||||
}
|
||||
file << '\n';
|
||||
ss << elem.first << '=' << elem.second << '\n';
|
||||
}
|
||||
ss << '\n';
|
||||
}
|
||||
|
||||
int fd = open(filename, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
|
||||
|
||||
if (fd != -1)
|
||||
{
|
||||
std::string payload = ss.str();
|
||||
|
||||
if (write(fd, payload.c_str(), payload.size()) == -1)
|
||||
{
|
||||
MXS_ERROR("Failed to write to file '%s': %d, %s",
|
||||
filename, errno, mxs_strerror(errno));
|
||||
rval = false;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("Failed to open configuration export file '%s': %d, %s",
|
||||
filename,
|
||||
errno,
|
||||
mxs_strerror(errno));
|
||||
filename, errno, mxs_strerror(errno));
|
||||
rval = false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user