core: imply SetLoginEnvironment= if PAMName= is set

This geneally makes sense as setting up a PAM session pretty much
defines what a login session is.

In context of #30547 this has the benefit that we can take benefit of
the SetLoginEnvironment= effect without having to set it explicitly,
thus retaining some compat of the uid0 client towards older systemd
service managers.
This commit is contained in:
Lennart Poettering
2023-12-21 10:14:21 +01:00
parent b993e7e72e
commit d1a5be82ef
4 changed files with 20 additions and 7 deletions
+9 -6
View File
@@ -703,12 +703,15 @@
<varlistentry>
<term><varname>SetLoginEnvironment=</varname></term>
<listitem><para>Takes a boolean parameter that controls whether to set <varname>$HOME</varname>,
<varname>$LOGNAME</varname>, and <varname>$SHELL</varname> environment variables. If unset, this is
controlled by whether <varname>User=</varname> is set. If true, they will always be set for system services,
i.e. even when the default user <literal>root</literal> is used. If false, the mentioned variables are not set
by systemd, no matter whether <varname>User=</varname> is used or not. This option normally has no effect
on user services, since these variables are typically inherited from user manager's own environment anyway.</para>
<listitem><para>Takes a boolean parameter that controls whether to set the <varname>$HOME</varname>,
<varname>$LOGNAME</varname>, and <varname>$SHELL</varname> environment variables. If not set, this
defaults to true if <varname>User=</varname>, <varname>DynamicUser=</varname> or
<varname>PAMName=</varname> are set, false otherwise. If set to true, the variables will always be
set for system services, i.e. even when the default user <literal>root</literal> is used. If set to
false, the mentioned variables are not set by the service manager, no matter whether
<varname>User=</varname>, <varname>DynamicUser=</varname>, or <varname>PAMName=</varname> are used or
not. This option normally has no effect on services of the per-user service manager, since in that
case these variables are typically inherited from user manager's own environment anyway.</para>
<xi:include href="version-info.xml" xpointer="v255"/></listitem>
</varlistentry>
+1 -1
View File
@@ -1883,7 +1883,7 @@ static int build_environment(
"Failed to determine user credentials for root: %m");
}
bool set_user_login_env = c->set_login_environment >= 0 ? c->set_login_environment : (c->user || c->dynamic_user);
bool set_user_login_env = exec_context_get_set_login_environment(c);
if (username) {
x = strjoin("USER=", username);
+9
View File
@@ -1661,6 +1661,15 @@ uint64_t exec_context_get_timer_slack_nsec(const ExecContext *c) {
return (uint64_t) MAX(r, 0);
}
bool exec_context_get_set_login_environment(const ExecContext *c) {
assert(c);
if (c->set_login_environment >= 0)
return c->set_login_environment;
return c->user || c->dynamic_user || c->pam_name;
}
char** exec_context_get_syscall_filter(const ExecContext *c) {
_cleanup_strv_free_ char **l = NULL;
+1
View File
@@ -527,6 +527,7 @@ int exec_context_get_nice(const ExecContext *c);
int exec_context_get_cpu_sched_policy(const ExecContext *c);
int exec_context_get_cpu_sched_priority(const ExecContext *c);
uint64_t exec_context_get_timer_slack_nsec(const ExecContext *c);
bool exec_context_get_set_login_environment(const ExecContext *c);
char** exec_context_get_syscall_filter(const ExecContext *c);
char** exec_context_get_syscall_archs(const ExecContext *c);
char** exec_context_get_syscall_log(const ExecContext *c);