Skip to content

Commit

Permalink
zeek-archiver: Respect umask setting
Browse files Browse the repository at this point in the history
Rather than hard-coding 0700 and 0644, use 0777 and 0666 and assume
and rely on open() and mkdir() to pick up the environment's umask
value.

This may theoretically break someone relying on the strict permissions,
but I'd argue it's not worth a configuration option. And pointing them
at umask may be pragmatic enough.

Closes #57.
  • Loading branch information
awelzel committed Aug 27, 2024
1 parent 8a66cd6 commit 2a247ee
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions testing/zeek-archiver/umask.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# @TEST-DOC: Check file permissions with different umask settings.
# @TEST-EXEC: bash %INPUT

. "$SCRIPTS/zeek-archiver-common.sh"

umask 0002

log_in=test__2020-07-16-09-43-10__2020-07-16-09-43-10__.log
log_out=test.09:43:10-09:43:10.log

echo hello > "$(queue_dir)/${log_in}"
zeek-archiver -1 -v "$(queue_dir)" "$(archive_dir)"

dir_perms=$(stat -c "%a" $(archive_date_dir))
file_perms=$(stat -c "%a" $(archive_date_dir)/${log_out}.gz)

test "${dir_perms}" == "775" || exit 1
test "${file_perms}" == "664" || exit 1

# @TEST-START-NEXT

. "$SCRIPTS/zeek-archiver-common.sh"

umask 0077

log_in=test__2020-07-16-09-43-10__2020-07-16-09-43-10__.log
log_out=test.09:43:10-09:43:10.log

echo hello > "$(queue_dir)/${log_in}"
zeek-archiver -1 -v "$(queue_dir)" "$(archive_dir)"

dir_perms=$(stat -c "%a" $(archive_date_dir))
file_perms=$(stat -c "%a" $(archive_date_dir)/${log_out}.gz)

test "${dir_perms}" == "700" || exit 1
test "${file_perms}" == "600" || exit 1
4 changes: 2 additions & 2 deletions zeek-archiver/zeek-archiver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static void parse_options(int argc, char** argv)

static bool make_dir(const char* dir)
{
if ( mkdir(dir, 0700) == 0 )
if ( mkdir(dir, 0775) == 0 )
return true;

auto mkdir_errno = errno;
Expand Down Expand Up @@ -540,7 +540,7 @@ static int run_compress_cmd(const char* src_file, const char* dst_file)
if ( src_fd != STDIN_FILENO )
close(src_fd);

int dst_fd = open(dst_file, O_CREAT | O_TRUNC | O_WRONLY, 0644);
int dst_fd = open(dst_file, O_CREAT | O_TRUNC | O_WRONLY, 0664);

if ( dst_fd < 0 )
{
Expand Down

0 comments on commit 2a247ee

Please sign in to comment.