shared/specifier: fix %u/%U/%g/%G when called as unprivileged user

We would resolve those specifiers to the calling user/group. This is mostly OK
when done in the manager, because the manager generally operates as root
in system mode, and a non-root in user mode. It would still be wrong if
called with --test though. But in systemctl, this would be generally wrong,
since we can call 'systemctl --system' as a normal user, either for testing
or even for actual operation with '--root=…'.

When operating in --global mode, %u/%U/%g/%G should return an error.

The information whether we're operating in system mode, user mode, or global
mode is passed as the data pointer to specifier_group_name(), specifier_user_name(),
specifier_group_id(), specifier_user_id(). We can't use userdata, because
it's already used for other things.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-03-29 16:17:56 +02:00
parent 4a84db4c0c
commit 172e9cc3ee
11 changed files with 150 additions and 99 deletions
+7 -2
View File
@@ -97,7 +97,12 @@ static int specifier_last_component(char specifier, const void *data, const char
return 0;
}
int install_name_printf(const UnitFileInstallInfo *i, const char *format, const char *root, char **ret) {
int install_name_printf(
UnitFileScope scope,
const UnitFileInstallInfo *i,
const char *format,
const char *root,
char **ret) {
/* This is similar to unit_name_printf() */
const Specifier table[] = {
@@ -109,7 +114,7 @@ int install_name_printf(const UnitFileInstallInfo *i, const char *format, const
COMMON_SYSTEM_SPECIFIERS,
COMMON_CREDS_SPECIFIERS,
COMMON_CREDS_SPECIFIERS(scope),
{}
};