Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/awelzel/57-relax-mkdir-ope…
Browse files Browse the repository at this point in the history
…n-permissions'

* origin/topic/awelzel/57-relax-mkdir-open-permissions:
  zeek-archiver: Respect umask setting
  • Loading branch information
awelzel committed Sep 3, 2024
2 parents 8a66cd6 + 8e02215 commit e850412
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=$(ls -ld $(archive_date_dir) | cut -d ' ' -f 1)
file_perms=$(ls -l $(archive_date_dir)/${log_out}.gz | cut -d ' ' -f 1)

test "${dir_perms}" == "drwxrwxr-x" || exit 1
test "${file_perms}" == "-rw-rw-r--" || 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=$(ls -ld $(archive_date_dir) | cut -d ' ' -f 1)
file_perms=$(ls -l $(archive_date_dir)/${log_out}.gz | cut -d ' ' -f 1)

test "${dir_perms}" == "drwx------" || exit 1
test "${file_perms}" == "-rw-------" || 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 e850412

Please sign in to comment.