Commit Graph

92 Commits

Author SHA1 Message Date
Lennart Poettering 45c5fa253a pam_systemd: also print debug lines when ending a session 2020-05-12 11:10:30 +02:00
Lennart Poettering 3400bc866d pam_systemd: drop unused uid argument from export_legacy_dbus_address() 2020-05-12 11:10:27 +02:00
Zbigniew Jędrzejewski-Szmek 0328d672f3
Merge pull request #15651 from poettering/newlocale-check
check if locales are installed before using them
2020-05-08 11:31:34 +02:00
Vito Caputo 5d990cc571 login: switch to BusLocator-oriented helpers
Mechanical substitution reducing some verbosity
2020-05-07 08:46:43 -07:00
Lennart Poettering a00a78b84e tree-wide: port various bits over to locale_is_installed() 2020-05-07 17:24:22 +02:00
Zbigniew Jędrzejewski-Szmek f36a9d5909 tree-wide: use the return value from sockaddr_un_set_path()
It fully initializes the address structure, so no need for pre-initialization,
and also returns the length of the address, so no need to recalculate using
SOCKADDR_UN_LEN().

socklen_t is unsigned, so let's not use an int for it. (It doesn't matter, but
seems cleaner and more portable to not assume anything about the type.)
2020-03-02 15:55:44 +01:00
Topi Miettinen e21d90606a pam_systemd: resolve the tty of display via /sys instead of /dev
Rely on information provided by /proc/*/stat and /sys/dev/char for resolving
the controlling tty for the display server, instead of trying to access the
tty device in /dev (which may not be accessible for example due to
PrivateDevices=yes).
2020-01-29 16:06:48 +01:00
Lennart Poettering f9c1f4e193 pam-systemd: apply user record properties to session
This way any component providing us with JSON user record data can use
this for automatic resource management and other session properties.
2020-01-15 15:30:02 +01:00
Lennart Poettering 7bfbf6cc92 pam-systemd: normalize return values of append_session_xyz()
Let's propagate the PAM errors we got.
2020-01-15 15:29:59 +01:00
Lennart Poettering 9ab0d3ebe5 pam-systemd: port over to use a UserRecord structure
Later on this allows us to set various session properties from user
record.
2020-01-15 15:29:55 +01:00
Lennart Poettering 355c9966c2 pam-systemd: share bus connection with pam_systemd_home if we can
Let's use the pam-util.h provided helpers to acquire them.
2020-01-15 15:29:52 +01:00
Lennart Poettering d750dde2a6 pam-systemd: port to pam_bus_log_{create|parse}_error() and pam_log_oom() 2020-01-15 15:29:48 +01:00
Lennart Poettering fbcb630045 pam_systemd: prolong method call timeout when allocating session
Starting a session might involve starting the user@.service instance,
hence let's make the bus call timeout substantially longer.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=83828
2019-11-19 21:05:03 +01:00
Lennart Poettering dca81e2851 pam_systemd: add one more assert 2019-11-19 15:26:45 +01:00
Lennart Poettering 8d46418e93 pam_systemd: don't use PAM_SYSTEM_ERR for something that isn't precisely a system error
It's not really clear which PAM errors to use for which conditions, but
something called PAM_SYSTEM_ERR should probably not be used when the
error is not the result of some system call failure.
2019-11-19 15:26:45 +01:00
Lennart Poettering 1798f5afe3 pam-systemd: voidify pam_get_item() calls 2019-11-19 15:26:45 +01:00
Lennart Poettering 42e6680976 pam-systemd: remove duplicate error logging 2019-11-19 15:26:45 +01:00
Lennart Poettering d9608d40bc pam-systemd: include PAM error code in all our log messages where that makes sense 2019-11-19 11:53:15 +01:00
Zbigniew Jędrzejewski-Szmek a5f6f346d3
Merge pull request #13423 from pwithnall/12035-session-time-limits
Add `RuntimeMaxSec=` support to scope units (time-limited login sessions)
2019-10-28 14:57:00 +01:00
Philip Withnall adc09af234 pam_systemd: Forward systemd.runtime_max_sec setting to session scope
Allow earlier PAM modules to set `systemd.runtime_max_sec`. If they do,
parse it and set it as the `RuntimeMaxUSec=` property of the session
scope, to limit the maximum lifetime of the session. This could be
useful for time-limiting login sessions, for example.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #12035
2019-10-28 09:44:31 +01:00
Zbigniew Jędrzejewski-Szmek fdb3decaa7 util-lib: move some functions from basic/cgroup-util to shared/cgroup-setup
This way less stuff needs to be in basic. Initially, I wanted to move all the
parts of cgroup-utils.[ch] that depend on efivars.[ch] to shared, because
efivars.[ch] is in shared/. Later on, I decide to split efivars.[ch], so the
move done in this patch is not necessary anymore. Nevertheless, it is still
valid on its own. If at some point we want to expose libbasic, it is better to
to not have stuff that belong in libshared there.
2019-09-16 18:08:00 +02:00
Yu Watanabe 4bbccb02ea tree-wide: introduce strerror_safe() 2019-07-05 02:43:56 +09:00
Philip Withnall de5e9096e2 pam_systemd: Fix some option names in error messages
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-06-12 10:39:50 +01:00
Ben Boeckel 5238e95759 codespell: fix spelling errors 2019-04-29 16:47:18 +02:00
Lennart Poettering 83d4ab5533 pam-systemd: use secure_getenv() rather than getenv()
And explain why in a comment.
2019-04-08 10:24:03 +02:00
Zbigniew Jędrzejewski-Szmek ca78ad1de9 headers: remove unneeded includes from util.h
This means we need to include many more headers in various files that simply
included util.h before, but it seems cleaner to do it this way.
2019-03-27 11:53:12 +01:00
Lennart Poettering 47094ce067 util: move dbus specific definition into bus-internal.h
It shouldn't be defined globally, since it's pretty much an
implementation detail of DBus.
2019-03-14 13:25:51 +01:00
Lennart Poettering ecd5f1a9e0 util: move display_is_local() to pam_systemd.c, its only user
It's quite specific anyway, hence let's move this where it's used
2019-03-14 13:25:51 +01:00
Lennart Poettering c1642d7bf8
Merge pull request #11378 from keszybz/export-dbus-address-conditionally
Export dbus address conditionally
2019-01-17 18:36:01 +01:00
Zbigniew Jędrzejewski-Szmek 15ee6c204a Revert "pam_systemd: set $DBUS_SESSION_BUS_ADDRESS unconditionally"
This reverts commit 69bd76f2b9.

$DBUS_SESSION_BUS_ADDRESS is again set only if the socket exists.

Quoting https://github.com/systemd/systemd/pull/11327#issuecomment-452019027:
> [setting $DBUS_SESSION_BUS_ADDRESS unconditionally] makes pam_systemd
> incompatible with installations and distributions where dbus was not
> configured with --enable-user-session, and the session dbus-daemon is started
> by autolaunching or dbus-launch (as opposed to dbus.socket). I don't think
> that's wise: using autolaunching or dbus-launch, and disabling or not
> installing dbus.socket and dbus.service on the systemd user instance, is our
> compatibility story for people who still need a D-Bus session bus per X11
> session for whatever reason.
>
> For example, Debian can currently do either way, with a dbus-user-session
> package strongly recommended but not actually mandatory. dbus-user-session
> requires libpam-systemd; if pam_systemd now requires dbus.socket (which is in
> the dbus-user-session package), that's a circular dependency, which we
> normally try hard to avoid.

For systems that use dbus.socket this doesn't matter much, because the
user session is ordered after the user managaer, which pulls in dbus.socket
very early. For example, when logging over ssh:

sshd[20796]: pam_systemd(sshd:session): pam-systemd initializing
sshd[20796]: pam_systemd(sshd:session): Asking logind to create session: uid=1001 pid=20796 service=sshd type=tty class=user desktop= seat= vtnr=0 tty= display= remote=yes remote_user= remote_host=::1
sshd[20796]: pam_systemd(sshd:session): Session limits: memory_max=n/a tasks_max=n/a cpu_weight=n/a io_weight=n/a
systemd[1]: Created slice User Slice of UID 1001.
systemd[1]: Starting User Runtime Directory /run/user/1001...
systemd-logind[1210]: New session 3796 of user guest.
systemd[1]: Started User Runtime Directory /run/user/1001.
systemd[1]: Starting User Manager for UID 1001...
systemd[20805]: pam_systemd(systemd-user:session): pam-systemd initializing
systemd[20805]: Starting D-Bus User Message Bus Socket.
...
systemd[20805]: Reached target Sockets.
systemd[20805]: Reached target Basic System.
systemd[1]: Started User Manager for UID 1001.
systemd[1]: Started Session 3796 of user guest.
sshd[20796]: pam_systemd(sshd:session): Reply from logind: id=3796 object_path=/org/freedesktop/login1/session/_33796 runtime_path=/run/user/1001 session_fd=13 seat= vtnr=0 original_uid=1001
sshd[20796]: pam_unix(sshd:session): session opened for user guest by (uid=0)

Hence, everything in the ssh session is ordered after the user instance.
And in the user instance, services should be orderd after dbus.socket using
inter-unit dependencies. dbus.socket in turns does
systemctl --user set-environment DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus.

So there should be no race between starting of the dbus socket and our check
if it exists.

The alternative would be to set the "DBUS_SESSION_BUS_ADDRESS=unix:path=%s/bus;autolaunch:".
AFAICT, this would work as well. But I don't see any case where it actually works
better. Since this is an area with many compatiblity concerns, let's stick to
the previous setup which seems to work well.
2019-01-15 14:24:10 +01:00
Zbigniew Jędrzejewski-Szmek 055c08ef67 pam_systemd: do no allocate the path of fixed length 2019-01-15 14:24:10 +01:00
Zbigniew Jędrzejewski-Szmek c7e93c4d15 pam_systemd: reword message about not creating a session
The message is changed from
  Cannot create session: Already running in a session...
to
  Not creating session: Already running in a session...

This is more neutral and avoids suggesting a problem.

"Will not create session: ..." was suggested, but it sounds like the action
would have yet to be performed. I think Using present continuous is better.

Fixes #10822 (for good now, I hope).
2019-01-10 15:56:02 +01:00
Zbigniew Jędrzejewski-Szmek 69bd76f2b9 pam_systemd: set $DBUS_SESSION_BUS_ADDRESS unconditionally
There's very little lost if the variable is set for a socket that isn't
connectible, but a lot lost (races, ...) if it's not set but the socket exists.

Also, drop the FIXME note, since we don't plan to revert this revert any time
soon.
2019-01-06 17:37:00 +01:00
Zbigniew Jędrzejewski-Szmek 00efd4988b Revert "pam_systemd: drop setting DBUS_SESSION_BUS_ADDRESS"
This reverts commit 2b2b7228bf.

Fixes #11293.

Removing the environment variable causes problems, e.g. Xfce and Chromium and
... don't communicate with the running dbus instance. If they attempt to start their
own instance, things become even more confusing. Those packages could be fixed
one by one, but removing the variable right now is causing too many problems.
2019-01-04 11:19:10 +01:00
Lennart Poettering 2675747f3c pam_systemd: suppress LOG_DEBUG log messages if debugging is off
In the PAM module we need to suppress LOG_DEBUG messages manually, if
debug logging is not on, as PAM won't do this for us. We did this
correctly for most log messages already, but two were missing. Let's fix
those too.

Fixes: #10822
2018-11-19 14:03:34 +01:00
Yu Watanabe 8da2f9e807
Merge pull request #10412 from poettering/sockaddr-sun-path
various fixes related to struct sockaddr_un handling
2018-10-17 01:25:58 +09:00
Lennart Poettering 15a3e96f92 tree-wide: port various users over to sockaddr_un_set_path()
CID 1396140
CID 1396141
2018-10-15 19:40:51 +02:00
Lennart Poettering b921711248 logind: validate /run/user/1000 before we set it
Let's be safe than sorry, in particular as logind doesn't set it up
anymore, but user-runtime-dir@.service does, and logind doesn't really
track success of that.
2018-10-13 13:01:08 +02:00
David Tardon f369f47c26 be consistent about sun_path length
Most places use the whole buffer for name, without leaving extra space
for the trailing NUL.
2018-10-12 12:38:49 +02:00
Jürg Billeter da0da5eccf pam_systemd: support use in PID namespaces
Pass 0 as leader PID to CreateSession to let logind use the PID from the
D-Bus credentials. This allows use of pam_systemd in PID namespaces.
2018-09-10 19:04:21 +02:00
Zbigniew Jędrzejewski-Szmek cf6e28f3cb
Merge pull request #9484 from poettering/permille-everywhere
Permille everywhere
2018-07-26 10:13:56 +02:00
Lennart Poettering f806dfd345 tree-wide: increase granularity of percent specifications all over the place to permille
We so far had various placed we'd parse percentages with
parse_percent(). Let's make them use parse_permille() instead, which is
downward compatible (as it also parses percent values), and increases
the granularity a bit. Given that on the wire we usually normalize
relative specifications to something like UINT32_MAX anyway changing
from base-100 to base-1000 calculations can be done easily without
breaking compat.

This commit doesn't document this change in the man pages. While
allowing more precise specifcations permille is not as commonly
understood as perent I guess, hence let's keep this out of the docs for
now.
2018-07-25 16:14:45 +02:00
Lennart Poettering d487e2d68d pam_systemd: cast calls whose result we knowingly ignore to (void) 2018-07-25 16:09:33 +02:00
Lennart Poettering 36a4dbae4b pam_systemd: reduce append_session_cg_weight() indentation level a bit by moving to early exit 2018-07-25 16:09:33 +02:00
Lennart Poettering f7b8b5c4fb pam_systemd: move socket_from_display() from util.[ch] to pam_systemd.c
It's highly specific, kinda legacy (X11…) and only used at one place,
let's move this out of the common code, and into pam_systemd.c where it
is used.
2018-07-25 16:09:33 +02:00
Lennart Poettering e37e5ed32e pam_systemd: sort includes properly 2018-07-25 16:09:33 +02:00
Lennart Poettering b2f74f079d pam_systemd: always set XDG_SESSION_{CLASS|TYPE|DESKTOP}
We likely get the data from the env block, but we might also determine
it from elsewhere (such as PAM module parameters). Let's set the env
vars on the env block explicitly, so that they are available always, and
apps can rely on it.
2018-07-25 16:09:33 +02:00
Lennart Poettering d6baaa6978 pam_systemd: simplify code which with we set environment variables
Let's shorten things a bit by splitting out common code in a new
function.
2018-07-25 16:09:33 +02:00
Lennart Poettering 5fdfbbd505 pam_systemd: tiny coding style fix 2018-07-25 16:09:33 +02:00
Lennart Poettering f5cb2820fd pam_systemd: also make $XDG_SESSION_DESKTOP configurable via PAM module command line
Let's make this symmetric with XDG_SESSION_CLASS and XDG_SESSION_TYPE,
so that PAM stacks can configure this easily without involving env vars,
in case there are PAM session managers which only support a single
desktop anyway.
2018-07-25 16:09:33 +02:00