core: gracefully skip unknown policy designators in RootImagePolicy et al (#40060)
Usually we gracefully ignore unknown configuration parameters, so that
service files can be written by upstreams and used across a variegated
range of distributions with various versions of systemd, to avoid
forcing users to the minimum common denominator and only adding settings
that are supported by the oldest distro supported.
Image policies do not behave like this, and any unknown partition or
policy designator causes the whole unit to fail to parse and a hard
error.
Change it so that parsing RootImagePolicy and friends via unit file or
D-Bus logs but otherwise ignores unknown specifiers, like other options
do.
This allows us to add new specifiers in the future, and users to adopt
them immediately.
Follow-up for d452335aa4
This commit is contained in:
@@ -22,11 +22,11 @@ static void test_policy(const ImagePolicy *p, const char *name) {
|
||||
|
||||
printf("%s\n", ansi_normal());
|
||||
|
||||
assert_se(image_policy_from_string(as_string, &parsed) >= 0);
|
||||
assert_se(image_policy_from_string(as_string, /* graceful= */ false, &parsed) >= 0);
|
||||
assert_se(image_policy_equal(p, parsed));
|
||||
parsed = image_policy_free(parsed);
|
||||
|
||||
assert_se(image_policy_from_string(as_string_simplified, &parsed) >= 0);
|
||||
assert_se(image_policy_from_string(as_string_simplified, /* graceful= */ false, &parsed) >= 0);
|
||||
assert_se(image_policy_equivalent(p, parsed));
|
||||
parsed = image_policy_free(parsed);
|
||||
|
||||
@@ -55,14 +55,14 @@ static void test_policy(const ImagePolicy *p, const char *name) {
|
||||
static void test_policy_string(const char *t) {
|
||||
_cleanup_free_ ImagePolicy *parsed = NULL;
|
||||
|
||||
assert_se(image_policy_from_string(t, &parsed) >= 0);
|
||||
assert_se(image_policy_from_string(t, /* graceful= */ false, &parsed) >= 0);
|
||||
test_policy(parsed, t);
|
||||
}
|
||||
|
||||
static void test_policy_equiv(const char *s, bool (*func)(const ImagePolicy *p)) {
|
||||
_cleanup_(image_policy_freep) ImagePolicy *p = NULL;
|
||||
|
||||
assert_se(image_policy_from_string(s, &p) >= 0);
|
||||
assert_se(image_policy_from_string(s, /* graceful= */ false, &p) >= 0);
|
||||
|
||||
assert_se(func(p));
|
||||
assert_se(func == image_policy_equiv_ignore || !image_policy_equiv_ignore(p));
|
||||
@@ -106,15 +106,25 @@ TEST_RET(test_image_policy_to_string) {
|
||||
test_policy_equiv("=unused+absent", image_policy_equiv_ignore);
|
||||
test_policy_equiv("root=ignore:=ignore", image_policy_equiv_ignore);
|
||||
|
||||
assert_se(image_policy_from_string("pfft", NULL) == -EINVAL);
|
||||
assert_se(image_policy_from_string("öäüß", NULL) == -EINVAL);
|
||||
assert_se(image_policy_from_string(":", NULL) == -EINVAL);
|
||||
assert_se(image_policy_from_string("a=", NULL) == -EBADSLT);
|
||||
assert_se(image_policy_from_string("=a", NULL) == -EBADRQC);
|
||||
assert_se(image_policy_from_string("==", NULL) == -EBADRQC);
|
||||
assert_se(image_policy_from_string("root=verity:root=encrypted", NULL) == -ENOTUNIQ);
|
||||
assert_se(image_policy_from_string("root=grbl", NULL) == -EBADRQC);
|
||||
assert_se(image_policy_from_string("wowza=grbl", NULL) == -EBADSLT);
|
||||
assert_se(image_policy_from_string("pfft", /* graceful= */ false, NULL) == -EINVAL);
|
||||
assert_se(image_policy_from_string("öäüß", /* graceful= */ false, NULL) == -EINVAL);
|
||||
assert_se(image_policy_from_string(":", /* graceful= */ false, NULL) == -EINVAL);
|
||||
assert_se(image_policy_from_string("a=", /* graceful= */ false, NULL) == -EBADSLT);
|
||||
assert_se(image_policy_from_string("=a", /* graceful= */ false, NULL) == -EBADRQC);
|
||||
assert_se(image_policy_from_string("==", /* graceful= */ false, NULL) == -EBADRQC);
|
||||
assert_se(image_policy_from_string("root=verity:root=encrypted", /* graceful= */ false, NULL) == -ENOTUNIQ);
|
||||
assert_se(image_policy_from_string("root=grbl", /* graceful= */ false, NULL) == -EBADRQC);
|
||||
assert_se(image_policy_from_string("wowza=grbl", /* graceful= */ false, NULL) == -EBADSLT);
|
||||
|
||||
assert_se(image_policy_from_string("pfft", /* graceful= */ true, NULL) == -EINVAL);
|
||||
assert_se(image_policy_from_string("öäüß", /* graceful= */ true, NULL) == -EINVAL);
|
||||
assert_se(image_policy_from_string(":", /* graceful= */ true, NULL) == -EINVAL);
|
||||
assert_se(image_policy_from_string("a=", /* graceful= */ true, NULL) == 0);
|
||||
assert_se(image_policy_from_string("=a", /* graceful= */ true, NULL) == 0);
|
||||
assert_se(image_policy_from_string("==", /* graceful= */ true, NULL) == 0);
|
||||
assert_se(image_policy_from_string("root=verity:root=encrypted", /* graceful= */ true, NULL) == -ENOTUNIQ);
|
||||
assert_se(image_policy_from_string("root=grbl", /* graceful= */ true, NULL) == 0);
|
||||
assert_se(image_policy_from_string("wowza=grbl", /* graceful= */ true, NULL) == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -131,9 +141,9 @@ TEST(extend) {
|
||||
static void test_policy_intersect_one(const char *a, const char *b, const char *c) {
|
||||
_cleanup_(image_policy_freep) ImagePolicy *x = NULL, *y = NULL, *z = NULL, *t = NULL;
|
||||
|
||||
assert_se(image_policy_from_string(a, &x) >= 0);
|
||||
assert_se(image_policy_from_string(b, &y) >= 0);
|
||||
assert_se(image_policy_from_string(c, &z) >= 0);
|
||||
assert_se(image_policy_from_string(a, /* graceful= */ false, &x) >= 0);
|
||||
assert_se(image_policy_from_string(b, /* graceful= */ false, &y) >= 0);
|
||||
assert_se(image_policy_from_string(c, /* graceful= */ false, &z) >= 0);
|
||||
|
||||
assert_se(image_policy_intersect(x, y, &t) >= 0);
|
||||
|
||||
@@ -163,8 +173,8 @@ TEST(image_policy_intersect) {
|
||||
static void test_policy_ignore_designators_one(const char *a, const PartitionDesignator array[], size_t n, const char *b) {
|
||||
_cleanup_(image_policy_freep) ImagePolicy *x = NULL, *y = NULL, *t = NULL;
|
||||
|
||||
ASSERT_OK(image_policy_from_string(a, &x));
|
||||
ASSERT_OK(image_policy_from_string(b, &y));
|
||||
ASSERT_OK(image_policy_from_string(a, /* graceful= */ false, &x));
|
||||
ASSERT_OK(image_policy_from_string(b, /* graceful= */ false, &y));
|
||||
|
||||
_cleanup_free_ char *s1 = NULL, *s2 = NULL, *s3 = NULL;
|
||||
ASSERT_OK(image_policy_to_string(x, true, &s1));
|
||||
|
||||
Reference in New Issue
Block a user