Include Utility::SetFileOwnership() inside FS transactions

to make them even more atomic.
This commit is contained in:
Alexander A. Klimov 2023-01-27 11:51:11 +01:00
parent d22fdf2a7a
commit fd93feaec7
2 changed files with 10 additions and 6 deletions

View File

@ -524,15 +524,17 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
if (!ticket.IsEmpty()) {
String ticketPath = ApiListener::GetCertsDir() + "/ticket";
AtomicFile af (ticketPath, 0600);
AtomicFile::Write(ticketPath, 0600, ticket);
if (!Utility::SetFileOwnership(ticketPath, user, group)) {
if (!Utility::SetFileOwnership(af.GetTempFilename(), user, group)) {
Log(LogWarning, "cli")
<< "Cannot set ownership for user '" << user
<< "' group '" << group
<< "' on file '" << ticketPath << "'. Verify it yourself!";
}
af << ticket;
af.Commit();
}
/* If no parent connection was made, the user must supply the ca.crt before restarting Icinga 2.*/

View File

@ -553,15 +553,17 @@ wizard_global_zone_loop_start:
if (!ticket.IsEmpty()) {
String ticketPath = ApiListener::GetCertsDir() + "/ticket";
AtomicFile af (ticketPath, 0600);
AtomicFile::Write(ticketPath, 0600, ticket);
if (!Utility::SetFileOwnership(ticketPath, user, group)) {
if (!Utility::SetFileOwnership(af.GetTempFilename(), user, group)) {
Log(LogWarning, "cli")
<< "Cannot set ownership for user '" << user
<< "' group '" << group
<< "' on file '" << ticketPath << "'. Verify it yourself!";
}
af << ticket;
af.Commit();
}
/* If no parent connection was made, the user must supply the ca.crt before restarting Icinga 2.*/