mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
Merge pull request #6851 from keszybz/fix-masking-with-empty-files
Fix masking with empty files
This commit is contained in:
commit
06d92f88d3
@ -74,16 +74,21 @@ static int files_add(Hashmap *h, const char *suffix, const char *root, unsigned
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We only want executable regular files (or symlinks to them), or symlinks to /dev/null */
|
if (!null_or_empty(&st)) {
|
||||||
if (S_ISREG(st.st_mode)) {
|
/* A mask is a symlink to /dev/null or an empty file. It does not even
|
||||||
if ((st.st_mode & 0111) == 0) { /* not executable */
|
* have to be executable. Other entries must be regular executable files
|
||||||
log_debug("Ignoring %s/%s, as it is not marked executable.", dirpath, de->d_name);
|
* or symlinks to them. */
|
||||||
|
if (S_ISREG(st.st_mode)) {
|
||||||
|
if ((st.st_mode & 0111) == 0) { /* not executable */
|
||||||
|
log_debug("Ignoring %s/%s, as it is not marked executable.",
|
||||||
|
dirpath, de->d_name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log_debug("Ignoring %s/%s, as it is neither a regular file nor a mask.",
|
||||||
|
dirpath, de->d_name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (!null_or_empty(&st)) { /* /dev/null? */
|
|
||||||
log_debug("Ignoring %s/%s, as it is not a regular file (or symlink to /dev/null).", dirpath, de->d_name);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,10 +71,14 @@ static const gather_stdout_callback_t ignore_stdout[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void test_execute_directory(bool gather_stdout) {
|
static void test_execute_directory(bool gather_stdout) {
|
||||||
char template_lo[] = "/tmp/test-exec-util.XXXXXXX";
|
char template_lo[] = "/tmp/test-exec-util.lo.XXXXXXX";
|
||||||
char template_hi[] = "/tmp/test-exec-util.XXXXXXX";
|
char template_hi[] = "/tmp/test-exec-util.hi.XXXXXXX";
|
||||||
const char * dirs[] = {template_hi, template_lo, NULL};
|
const char * dirs[] = {template_hi, template_lo, NULL};
|
||||||
const char *name, *name2, *name3, *overridden, *override, *masked, *mask;
|
const char *name, *name2, *name3,
|
||||||
|
*overridden, *override,
|
||||||
|
*masked, *mask,
|
||||||
|
*masked2, *mask2, /* the mask is non-executable */
|
||||||
|
*masked2e, *mask2e; /* the mask is executable */
|
||||||
|
|
||||||
log_info("/* %s (%s) */", __func__, gather_stdout ? "gathering stdout" : "asynchronous");
|
log_info("/* %s (%s) */", __func__, gather_stdout ? "gathering stdout" : "asynchronous");
|
||||||
|
|
||||||
@ -88,6 +92,10 @@ static void test_execute_directory(bool gather_stdout) {
|
|||||||
override = strjoina(template_hi, "/overridden");
|
override = strjoina(template_hi, "/overridden");
|
||||||
masked = strjoina(template_lo, "/masked");
|
masked = strjoina(template_lo, "/masked");
|
||||||
mask = strjoina(template_hi, "/masked");
|
mask = strjoina(template_hi, "/masked");
|
||||||
|
masked2 = strjoina(template_lo, "/masked2");
|
||||||
|
mask2 = strjoina(template_hi, "/masked2");
|
||||||
|
masked2e = strjoina(template_lo, "/masked2e");
|
||||||
|
mask2e = strjoina(template_hi, "/masked2e");
|
||||||
|
|
||||||
assert_se(write_string_file(name,
|
assert_se(write_string_file(name,
|
||||||
"#!/bin/sh\necho 'Executing '$0\ntouch $(dirname $0)/it_works",
|
"#!/bin/sh\necho 'Executing '$0\ntouch $(dirname $0)/it_works",
|
||||||
@ -104,7 +112,15 @@ static void test_execute_directory(bool gather_stdout) {
|
|||||||
assert_se(write_string_file(masked,
|
assert_se(write_string_file(masked,
|
||||||
"#!/bin/sh\necho 'Executing '$0\ntouch $(dirname $0)/failed",
|
"#!/bin/sh\necho 'Executing '$0\ntouch $(dirname $0)/failed",
|
||||||
WRITE_STRING_FILE_CREATE) == 0);
|
WRITE_STRING_FILE_CREATE) == 0);
|
||||||
|
assert_se(write_string_file(masked2,
|
||||||
|
"#!/bin/sh\necho 'Executing '$0\ntouch $(dirname $0)/failed",
|
||||||
|
WRITE_STRING_FILE_CREATE) == 0);
|
||||||
|
assert_se(write_string_file(masked2e,
|
||||||
|
"#!/bin/sh\necho 'Executing '$0\ntouch $(dirname $0)/failed",
|
||||||
|
WRITE_STRING_FILE_CREATE) == 0);
|
||||||
assert_se(symlink("/dev/null", mask) == 0);
|
assert_se(symlink("/dev/null", mask) == 0);
|
||||||
|
assert_se(touch(mask2) == 0);
|
||||||
|
assert_se(touch(mask2e) == 0);
|
||||||
assert_se(touch(name3) >= 0);
|
assert_se(touch(name3) >= 0);
|
||||||
|
|
||||||
assert_se(chmod(name, 0755) == 0);
|
assert_se(chmod(name, 0755) == 0);
|
||||||
@ -112,6 +128,9 @@ static void test_execute_directory(bool gather_stdout) {
|
|||||||
assert_se(chmod(overridden, 0755) == 0);
|
assert_se(chmod(overridden, 0755) == 0);
|
||||||
assert_se(chmod(override, 0755) == 0);
|
assert_se(chmod(override, 0755) == 0);
|
||||||
assert_se(chmod(masked, 0755) == 0);
|
assert_se(chmod(masked, 0755) == 0);
|
||||||
|
assert_se(chmod(masked2, 0755) == 0);
|
||||||
|
assert_se(chmod(masked2e, 0755) == 0);
|
||||||
|
assert_se(chmod(mask2e, 0755) == 0);
|
||||||
|
|
||||||
if (gather_stdout)
|
if (gather_stdout)
|
||||||
execute_directories(dirs, DEFAULT_TIMEOUT_USEC, ignore_stdout, ignore_stdout_args, NULL);
|
execute_directories(dirs, DEFAULT_TIMEOUT_USEC, ignore_stdout, ignore_stdout_args, NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user