Skip to content

Commit

Permalink
[#477] Change permission config.ldif.startok to owner (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
vharseko authored Feb 6, 2025
1 parent b0f3e79 commit 26b29c6
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2014-2016 ForgeRock AS.
* Portions Copyright 2025 3A Systems,LLC
*/
package org.opends.server.config;

Expand All @@ -30,6 +31,8 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.attribute.PosixFilePermissions;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
Expand Down Expand Up @@ -758,6 +761,7 @@ public void writeSuccessfulStartupConfig()

// Copy the current config file to a temporary file.
File tempFile = new File(tempFilePath);

try (FileInputStream inputStream = new FileInputStream(configFile))
{
try (FileOutputStream outputStream = new FileOutputStream(tempFilePath, false))
Expand All @@ -775,6 +779,13 @@ public void writeSuccessfulStartupConfig()

outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
try {
Files.setPosixFilePermissions(tempFile.toPath(), PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-------")).value());
} catch (IOException e) {
logger.traceException(e);
logger.warn(ERR_STARTOK_CANNOT_WRITE, configFile, tempFilePath, getExceptionMessage(e));
} catch (UnsupportedOperationException e){}
}
catch (IOException e)
{
Expand Down

0 comments on commit 26b29c6

Please sign in to comment.