From: Ronan Pigott Date: Tue, 28 Feb 2023 05:57:06 +0000 (-0700) Subject: load-fragment: add user credential specifiers to user.conf X-Git-Tag: v254-rc1~1076 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b40688d1830abc6f59b1f1f67eccd757c23eb09;p=thirdparty%2Fsystemd.git load-fragment: add user credential specifiers to user.conf This enables the ManagerEnvironment= settings in the user's user.conf to reference some user data like $HOME for the purpose of setting environment variables derived from these values. --- diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml index 554d0fbd451..4860dab8417 100644 --- a/man/systemd-system.conf.xml +++ b/man/systemd-system.conf.xml @@ -604,6 +604,36 @@ + + %h + User home directory + This is the home directory of the user running the service manager instance. + + + %u + Username + This is the username of the user running the service manager instance. + + + %U + User id + This is the user id of the user running the service manager instance. + + + %g + Primary group + This is the primary group of the user running the service manager instance. + + + %G + Primary group id + This is the primary group id of the user running the service manager instance. + + + %s + User shell + This is the shell of the user running the service manager instance. + diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 0a36cee35cf..c917f0976f3 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -2744,6 +2744,16 @@ int config_parse_environ( return 0; } + bool is_system = ltype; + + const Specifier table[] = { + COMMON_SYSTEM_SPECIFIERS, + COMMON_TMP_SPECIFIERS, + COMMON_CREDS_SPECIFIERS(is_system ? LOOKUP_SCOPE_SYSTEM : LOOKUP_SCOPE_USER), + { 'h', specifier_user_home, NULL }, + { 's', specifier_user_shell, NULL }, + }; + for (const char *p = rvalue;; ) { _cleanup_free_ char *word = NULL, *resolved = NULL; @@ -2761,7 +2771,7 @@ int config_parse_environ( if (u) r = unit_env_printf(u, word, &resolved); else - r = specifier_printf(word, sc_arg_max(), system_and_tmp_specifier_table, NULL, NULL, &resolved); + r = specifier_printf(word, sc_arg_max(), table, NULL, NULL, &resolved); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve specifiers in %s, ignoring: %m", word); diff --git a/src/core/main.c b/src/core/main.c index 79eaa4e5d63..7ebb447c03a 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -664,8 +664,8 @@ static int parse_config_file(void) { { "Manager", "DefaultStartLimitInterval", config_parse_sec, 0, &arg_default_start_limit_interval }, /* obsolete alias */ { "Manager", "DefaultStartLimitIntervalSec", config_parse_sec, 0, &arg_default_start_limit_interval }, { "Manager", "DefaultStartLimitBurst", config_parse_unsigned, 0, &arg_default_start_limit_burst }, - { "Manager", "DefaultEnvironment", config_parse_environ, 0, &arg_default_environment }, - { "Manager", "ManagerEnvironment", config_parse_environ, 0, &arg_manager_environment }, + { "Manager", "DefaultEnvironment", config_parse_environ, arg_system, &arg_default_environment }, + { "Manager", "ManagerEnvironment", config_parse_environ, arg_system, &arg_manager_environment }, { "Manager", "DefaultLimitCPU", config_parse_rlimit, RLIMIT_CPU, arg_default_rlimit }, { "Manager", "DefaultLimitFSIZE", config_parse_rlimit, RLIMIT_FSIZE, arg_default_rlimit }, { "Manager", "DefaultLimitDATA", config_parse_rlimit, RLIMIT_DATA, arg_default_rlimit },