core: add @system special value to ConditionUser=
It allows checking if the user is a system user or a normal user
This commit is contained in:
@@ -154,6 +154,9 @@ static int condition_test_user(Condition *c) {
|
||||
if (r >= 0)
|
||||
return id == getuid() || id == geteuid();
|
||||
|
||||
if (streq("@system", c->parameter))
|
||||
return getuid() <= SYSTEM_UID_MAX || geteuid() <= SYSTEM_UID_MAX;
|
||||
|
||||
username = getusername_malloc();
|
||||
if (!username)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -385,6 +385,16 @@ static void test_condition_test_user(void) {
|
||||
log_info("ConditionUser=%s → %i", username, r);
|
||||
assert_se(r == 0);
|
||||
condition_free(condition);
|
||||
|
||||
condition = condition_new(CONDITION_USER, "@system", false, false);
|
||||
assert_se(condition);
|
||||
r = condition_test(condition);
|
||||
log_info("ConditionUser=@system → %i", r);
|
||||
if (geteuid() == 0)
|
||||
assert_se(r > 0);
|
||||
else
|
||||
assert_se(r == 0);
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
static void test_condition_test_group(void) {
|
||||
|
||||
Reference in New Issue
Block a user