]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
load-fragment: add user credential specifiers to user.conf
authorRonan Pigott <ronan@rjp.ie>
Tue, 28 Feb 2023 05:57:06 +0000 (22:57 -0700)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 10 Mar 2023 00:05:37 +0000 (00:05 +0000)
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.

man/systemd-system.conf.xml
src/core/load-fragment.c
src/core/main.c

index 554d0fbd451629e26e524bb8fcf4031cfa3ffd63..4860dab8417f888b3cb51824ce2e8b9086522334 100644 (file)
             <xi:include href="standard-specifiers.xml" xpointer="W"/>
             <xi:include href="standard-specifiers.xml" xpointer="T"/>
             <xi:include href="standard-specifiers.xml" xpointer="V"/>
+            <row>
+              <entry><literal>%h</literal></entry>
+              <entry>User home directory</entry>
+              <entry>This is the home directory of the <emphasis>user running the service manager instance</emphasis>.</entry>
+            </row>
+            <row>
+              <entry><literal>%u</literal></entry>
+              <entry>Username</entry>
+              <entry>This is the username of the <emphasis>user running the service manager instance</emphasis>.</entry>
+            </row>
+            <row>
+              <entry><literal>%U</literal></entry>
+              <entry>User id</entry>
+              <entry>This is the user id of the <emphasis>user running the service manager instance</emphasis>.</entry>
+            </row>
+            <row>
+              <entry><literal>%g</literal></entry>
+              <entry>Primary group</entry>
+              <entry>This is the primary group of the <emphasis>user running the service manager instance</emphasis>.</entry>
+            </row>
+            <row>
+              <entry><literal>%G</literal></entry>
+              <entry>Primary group id</entry>
+              <entry>This is the primary group id of the <emphasis>user running the service manager instance</emphasis>.</entry>
+            </row>
+            <row>
+              <entry><literal>%s</literal></entry>
+              <entry>User shell</entry>
+              <entry>This is the shell of the <emphasis>user running the service manager instance</emphasis>.</entry>
+            </row>
             <xi:include href="standard-specifiers.xml" xpointer="percent"/>
           </tbody>
         </tgroup>
index 0a36cee35cfeb8bab51cb105efda1e833a9a6ce6..c917f0976f3ed9f13b120c7031b584627b71e9cb 100644 (file)
@@ -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);
index 79eaa4e5d637808d8524ee050537d6664a30500c..7ebb447c03ad94f625e724426a1cbda208ecc099 100644 (file)
@@ -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                },