Skip to content

Commit

Permalink
core/manager: don't propagate manager session env to children
Browse files Browse the repository at this point in the history
Follow-up for 4cb4e6c

Fixes systemd#31287
  • Loading branch information
YHNdnzj authored and Jerry Wu committed Apr 3, 2024
1 parent eb77293 commit 03b1b71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/core/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,14 +667,26 @@ int manager_default_environment(Manager *m) {
/* Import locale variables LC_*= from configuration */
(void) locale_setup(&m->transient_environment);
} else {
/* The user manager passes its own environment along to its children, except for $PATH. */
/* The user manager passes its own environment along to its children, except for $PATH and
* session envs. */

m->transient_environment = strv_copy(environ);
if (!m->transient_environment)
return log_oom();

r = strv_env_replace_strdup(&m->transient_environment, "PATH=" DEFAULT_USER_PATH);
if (r < 0)
return log_oom();

/* Envvars set for our 'manager' class session are private and should not be propagated
* to children. Also it's likely that the graphical session will set these on their own. */
strv_env_unset_many(m->transient_environment,
"XDG_SESSION_ID",
"XDG_SESSION_CLASS",
"XDG_SESSION_TYPE",
"XDG_SESSION_DESKTOP",
"XDG_SEAT",
"XDG_VTNR");
}

sanitize_environment(m->transient_environment);
Expand Down
3 changes: 3 additions & 0 deletions src/login/pam_systemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,9 @@ _public_ PAM_EXTERN int pam_sm_open_session(
"id=%s object_path=%s runtime_path=%s session_fd=%d seat=%s vtnr=%u original_uid=%u",
id, object_path, runtime_path, session_fd, seat, vtnr, original_uid);

/* Please update manager_default_environment() in core/manager.c accordingly if more session envvars
* shall be added. */

r = update_environment(handle, "XDG_SESSION_ID", id);
if (r != PAM_SUCCESS)
return r;
Expand Down

0 comments on commit 03b1b71

Please sign in to comment.