Skip to content

Commit

Permalink
Using chownSync and chmodSync. Added try/catch block too (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesús Ángel authored and jesuslinares committed Jan 24, 2019
1 parent 223e54e commit b12152e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ All notable changes to this project will be documented in this file.
## [v3.8.1]

### Fixed
- Fixed improper error handling ([#296](https://github.com/wazuh/wazuh-api/pull/296))
- Fixed improper error handling ([#296](https://github.com/wazuh/wazuh-api/pull/296)).
- Fix bug setting file permissions when rotating API logs file ([#295](https://github.com/wazuh/wazuh-api/pull/295)).

## [v3.8.0]

Expand Down
36 changes: 23 additions & 13 deletions helpers/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,28 @@ var stream = rfs(generator, {
});

stream.on('rotated', function(filename) {
// rotation job completed with success producing given filename
// setting correct permissions for generated files
logger.log("Rotated: " + filename);
fs.chmod(filename, 0o640);
fs.chmod(path.dirname(filename), 0o750);
fs.chmod(path.dirname(path.dirname(filename)), 0o750);

// if the API is running as root, set the user of the created files to ossec
if (!config.drop_privileges) {
fs.chown(filename, ossec_uid, ossec_gid);
fs.chown(path.dirname(filename), ossec_uid, ossec_gid);
fs.chown(path.dirname(path.dirname(filename)), ossec_uid, ossec_gid);
fs.chown(absolute_path_log, ossec_uid, ossec_gid);
try {
// rotation job completed with success producing given filename
// setting correct permissions for generated files
logger.log("Rotated: " + filename);
fs.chmodSync(filename, 0o640);
fs.chmodSync(path.dirname(filename), 0o750);
fs.chmodSync(path.dirname(path.dirname(filename)), 0o750);

// if the API is running as root, set the user of the created files to ossec
if (!config.drop_privileges) {
fs.chownSync(filename, ossec_uid, ossec_gid);
fs.chownSync(path.dirname(filename), ossec_uid, ossec_gid);
fs.chownSync(path.dirname(path.dirname(filename)), ossec_uid, ossec_gid);
fs.chownSync(absolute_path_log, ossec_uid, ossec_gid);
}

// Prevents from crashing the service if the above instructions fail
} catch (error) {
try {
logger.error(error.message || error);
} catch (err) {
console.log(err.message || err)
}
}
});

0 comments on commit b12152e

Please sign in to comment.