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:
@ -1368,32 +1368,39 @@ bool export_config_file(const char* filename)
|
|||||||
contexts.push_back(ctx);
|
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);
|
ss << '[' << ctx->m_name << "]\n";
|
||||||
file << "# Generated by MaxScale " << MAXSCALE_VERSION << '\n';
|
for (const auto& elem : ctx->m_parameters)
|
||||||
file << "# Documentation: https://mariadb.com/kb/en/mariadb-enterprise/maxscale/ \n\n";
|
|
||||||
|
|
||||||
for (auto it = contexts.rbegin(); it != contexts.rend(); it++)
|
|
||||||
{
|
{
|
||||||
CONFIG_CONTEXT* ctx = *it;
|
ss << elem.first << '=' << elem.second << '\n';
|
||||||
|
|
||||||
file << '[' << ctx->m_name << "]\n";
|
|
||||||
for (const auto& elem : ctx->m_parameters)
|
|
||||||
{
|
|
||||||
file << elem.first << '=' << elem.second << '\n';
|
|
||||||
}
|
|
||||||
file << '\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
|
else
|
||||||
{
|
{
|
||||||
MXS_ERROR("Failed to open configuration export file '%s': %d, %s",
|
MXS_ERROR("Failed to open configuration export file '%s': %d, %s",
|
||||||
filename,
|
filename, errno, mxs_strerror(errno));
|
||||||
errno,
|
|
||||||
mxs_strerror(errno));
|
|
||||||
rval = false;
|
rval = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user