Commit Graph

162 Commits

Author SHA1 Message Date
Jörg Thalheim d7aa78c32f meson: add option to skip installing to $sysconfdir
This is useful for development where overwriting files out side
the configured prefix will affect the host as well as stateless
systems such as NixOS that don't let packages install to /etc but handle
configuration on their own.

Alternative to https://github.com/systemd/systemd/pull/17501

tested with:

$ mkdir inst build && cd build
$ meson \
  -Dcreate-log-dirs=false \
  -Dsysvrcnd-path=$(realpath ../inst)/etc/rc.d \
  -Dsysvinit-path=$(realpath ../inst)/etc/init.d \
  -Drootprefix=$(realpath ../inst) \
  -Dinstall-sysconfdir=false \
  --prefix=$(realpath ../inst) ..
$ ninja install
2020-11-12 11:21:46 +01:00
Zbigniew Jędrzejewski-Szmek 44ee03d111 tree-wide: unsetenv cannot fail
... when called with a valid environment variable name. This means that
any time we call it with a fixed string, it is guaranteed to return 0.
(Also when the variable is not present in the environment block.)
2020-11-10 15:52:32 +01:00
Lennart Poettering df80c98cde
Merge pull request #17549 from yuwata/tiny-fixes
tiny fixes
2020-11-09 16:04:01 +01:00
Yu Watanabe 755b35b1aa home: fix copy-and-paste mistake
Fixes #17542.
2020-11-09 14:00:16 +09:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Zbigniew Jędrzejewski-Szmek e61f999755
Merge pull request #17472 from keszybz/spdx-license-headers
More SPDX license headers
2020-10-29 19:05:05 +01:00
Zbigniew Jędrzejewski-Szmek 4368277c74 tree-wide: use the usual SPDX header for our own files 2020-10-29 10:47:20 +01:00
Zbigniew Jędrzejewski-Szmek f1b823596f journal,homectl: unify implementations of libqrencode loading and fss key printing
We had two of each: both homectl and journalctl had the whole dlopen()
wrapper, and journalctl had two implementations (slightly different) of the
code to print the fss:// pattern.

print_qrcode() now returns -EOPNOTSUPP when compiled with qrcode support. Both
callers ignore the return value, so this changes nothing.

No functional change.
2020-10-27 18:33:29 +01:00
Lennart Poettering 66032ef489 macro: introduce POINTER_MAX as define for (void*) -1
Just add a safer, prettier way to write (void*) -1, that doesn't rely on
two's complement, but uses the correct underlying C constructs.
2020-10-22 08:33:20 +09:00
Chandradeep Dey 842067e675 homed: remove PAM_USER_UNKNOWN test in pam_sm_acct_mgmt
Why this change
---------------
Assumption - PAM's auth stack is properly configured.

Currently account pam_systemd_home.so returns PAM_SUCCESS for non
systemd-homed users, and a variety of return values (including
PAM_SUCCESS) for homed users.

account pam_unix returns PAM_AUTHINFO_UNAVAIL for systemd-homed
users, and a variety of return values (including PAM_AUTHINFO_UNAVAIL)
for normal users.

No possible combination in the pam stack can let us preserve the
various return values of the modules. For example, the configuration
mentioned in the manpage causes account pam_unix to never be reached
since pam_systemd_home just returns a success for ordinary users. Users
with expired passwords are allowed to log in because a check cannot be
made.

More configuration examples and why they don't work are mentioned
in #16906 and the downstream discussion linked there.

After this change
-----------------
account pam_unix will continue to return wrong value for homed users.
But we can skip the module conditionally using the return value from
account pam_systemd_home. We can already do this with the auth and
password modules.
2020-10-21 16:47:10 +02:00
Zbigniew Jędrzejewski-Szmek ab4a88eb92 sd-bus: add custom return code when $XDG_RUNTIME_DIR is not set
We would return ENOENT, which is extremely confusing. Strace is not helpful because
no *file* is actually missing. So let's add some logs at debug level and also use
a custom return code. Let all user-facing utilities print a custom error message
in that case.
2020-10-14 18:28:30 +02:00
Frantisek Sumsal d7a0f1f4f9 tree-wide: assorted coccinelle fixes 2020-10-09 15:02:23 +02:00
Lennart Poettering d1f6e01e47 homed: explicitly deactivate all home directories on shutdown
Let's explicitly deactivate all home dirs on shutdown, in order to
properly synchronizing unmounting and avoiding blocking devices.

Previously, we'd rely on automatic deactivation when home directories
become unused. However, that scheme is asynchronous, and ongoing
deactviations might conflicts with attempts to unmount /home. Let's fix
that by providing an explicit service systemd-homed-activate.service
whose only job is to have a ExecStop= line that explicitly deactivates
all home directories on shutdown. This service can the be ordered after
home.mount and similar, ensuring that we'll first deactivate all homes
before deactivating /home itself during shutdown.

This is kept separate from systemd-homed.service so that it is possible
to restart systemd-homed.service without deactivating all home
directories.

Fixes: #16842
2020-09-30 14:37:52 +02:00
Lennart Poettering 30f5d10421 mount-util: rework umount_verbose() to take log level and flags arg
Let's make umount_verbose() more like mount_verbose_xyz(), i.e. take log
level and flags param. In particular the latter matters, since we
typically don't actually want to follow symlinks when unmounting.
2020-09-23 18:57:36 +02:00
Lennart Poettering 511a8cfe30 mount-util: switch most mount_verbose() code over to not follow symlinks 2020-09-23 18:57:36 +02:00
Lennart Poettering a512e330ce homed: in images that lack mkfs.btrfs automatically fall back to ext4
It's better to tweak suboptimal defaults than to just fail with
compiled-in defaults.
2020-09-21 18:02:35 +02:00
Lennart Poettering f2ba663ea5 homed: show actual file system in messages about file systems 2020-09-21 18:02:35 +02:00
Lennart Poettering 3e0b54867e user-record: don't refuse login when last pw change time is in the future
The RTC is like just off, it's a weird system state, let's continue
without requiring pw change.
2020-09-21 18:02:35 +02:00
Lennart Poettering 61a29a020c homed: ignore ratelimiting counters when timestamp is from future
This likely indicates that the system clock is simply wrong, hence allow
access in this case.

Fixes: #15917
2020-09-21 18:02:35 +02:00
Lennart Poettering 51a95db6dc homed: don't block logins into accounts with future change time
This might happen if the system clock is wrong, and we should allow
access in this case (though certainly log about it).
2020-09-21 18:02:31 +02:00
Lennart Poettering f9d525ae55 homed: make clean that --storage=directory --image-path=/dev/some-block-device is not supported
The directory backend needs a file system path, and not a raw block
device. That's only supported for the LUKS2 backend.

Let's make this clearer in the man page and also generate a better error
message if attempted anyway.

Fixes: #17068
2020-09-18 22:35:36 +02:00
Lennart Poettering 9796a9fbad homed: make sure our worker processes finish before we exit
When exiting, let's explicitly wait for our worker processes to finish
first. That's useful if unmounting of /home/ is scheduled to happen
right after homed is down, as we then can be sure that the home
directories are properly unmounted and detached by the time homed is
fully terminated (otherwise it might happen that our worker gets killed
by the service manager, thus leaving the home directory and its backing
devices up/left for auto-clean which might be async).

Likely fixes #16842
2020-09-18 22:35:36 +02:00
Lennart Poettering cc9886bc20 homed: make it easier to run multiple instances of homed
When debugging homed while being logged into a user account manged by
homed it is a good idea to be able to run a second copy of homed. In
order to not collide with its AF_UNIX socket and bus name use, let's add
a new env var $SYSTEMD_HOME_DEBUG_SUFFIX, when set the busnames/socket
names are suffixed by it. When setting this while debugging one can
invoke an additional copy without interfering with the host one.
2020-09-18 22:35:36 +02:00
Lennart Poettering 79a6b4cc55 homed-bus: add missing spdx header 2020-09-18 22:35:36 +02:00
Lennart Poettering 3f440b13b7
Merge pull request #16981 from keszybz/use-crypt_ra
Use crypt_ra to allocate scratch area for password hashing
2020-09-18 19:46:08 +02:00
Zbigniew Jędrzejewski-Szmek 2ae297fe0d Move test_password_{one,many} to libcrypt-util.c
They are only used under src/home/, but I want to add tests in test-libcrypt-util.c.
And the functions are almost trivial, so I think it is OK to move them to shared.
2020-09-15 11:52:30 +02:00
Zbigniew Jędrzejewski-Szmek 0e98d17e77 Add a helper function that does make_salt+crypt_r
No functional change.
2020-09-15 09:30:56 +02:00
Frantisek Sumsal 890ea05ac2 home: return SYNTHETIC_ERRNO() when appropriate 2020-09-14 16:16:59 +02:00
Frantisek Sumsal 69e3234db7 tree-wide: fix typos found by codespell
Reported by Fossies.org
2020-09-14 15:32:37 +02:00
Yu Watanabe 144fb165fd homed: downgrade log level 2020-09-10 15:21:43 +09:00
Zbigniew Jędrzejewski-Szmek 90e74a66e6 tree-wide: define iterator inside of the macro 2020-09-08 12:14:05 +02:00
Lennart Poettering 86e443de2f
Merge pull request #16915 from poettering/cryptsetup-dlopen
pid1,repart,growfs: make libcryptsetup a dlopen() style dep
2020-09-03 14:57:29 +02:00
Gibeom Gwon 3d3d6e10da homed: remember the secret even when the for_state is FIXATING_FOR_ACQUIRE
Remember the secret if the for_state is FIXATING_FOR_ACTIVATION or
FIXATING_FOR_ACQUIRE. This fixes login failures when logging in
to an unfixated user.
2020-09-02 16:54:23 +02:00
Lennart Poettering 1e2f32305c shared: rename crypt-util.c → cryptsetup-util.c
"crypt-util.c" is such a generic name, let's avoid that, in particular
as libc's/libcrypt's crypt() function is so generically named too that
one might thing this is about that. Let's hence be more precise, and
make clear that this is about cryptsetup, and nothing else.

We already had cryptsetup-util.[ch] in src/cryptsetup/ doing keyfile
management. To avoid the needless confusion, let's rename that file to
cryptsetup-keyfile.[ch].
2020-09-02 15:00:32 +02:00
Florian Klink 43269733ef homed: fix log message to honor real homework path
This seems to be overridable by setting the SYSTEMD_HOMEWORK_PATH env
variable, but the error message always printed the SYSTEMD_HOMEWORK_PATH
constant.
2020-08-30 17:04:01 +02:00
Lennart Poettering 9be99f81a7 homed: report a home directory as "dirty" if image file has dirty flag 2020-08-25 18:18:56 +02:00
Lennart Poettering 565ac8b1c8 homed: mark LUKS loopback file as "dirty" via xattr when in use
Let's track the "dirty" state of a home directory backed by a LUKS
volume by setting a new xattr "home.home-dirty" on the backing file
whenever it is in use.

This allows us to later user this information to show a home directory
as "dirty". This is useful because we trim/allocate on log-out, and
if we don't do that a home directory will be larger than necessary. This
fact is something we should communicate to the admin.

The idea is that when an admin sees a user with a "dirty" home directory
they can ask them to log in, to clean up the dirty state, and thus trim
everything again.
2020-08-25 18:18:46 +02:00
Lennart Poettering 80c41552a8 homectl: teach homectl to generate recovery keys 2020-08-25 18:14:55 +02:00
Lennart Poettering 87d7893cfb homed: support recovery keys
For discussion around this see: https://pagure.io/fedora-workstation/issue/82

Recovery keys for homed are very similar to regular passwords, except
that they are exclusively generated by the computer, and not chosen by
the user. The idea is that they are printed or otherwise stored
externally and not what users type in every day.

Taking inspiration from Windows and MacOS this uses 256bit keys. We
format them in 64 yubikey modhex characters, in groups of 8 chars
separated by dashes.

Why yubikey modhex? modhex only uses characters that are are located at
the same place in western keyboard designs. This should reduce the
chance for incorrect inputs for a major chunk of our users, though
certainly not all. This is particular relevant during early boot and
recovery situations, where there's a good chance the keyboard mapping is
not correctly set up.
2020-08-25 18:14:55 +02:00
Lennart Poettering aecbc87df4 home: add helper to process/normalize modhex64 recovery keys 2020-08-25 18:14:55 +02:00
Zbigniew Jędrzejewski-Szmek 3b9d671754
Merge pull request #16676 from poettering/repart-mkfs
repart: add new settings Format=, CopyFiles=, Encrypt= and teach --size= a new value "auto"
2020-08-25 12:19:46 +02:00
Lennart Poettering c95f9a2351 shared: introduce mkfs-util.c/.h
Let's move the "mkfs" code from homed there, plus other related code.

This way we can easily reuse it from other places.
2020-08-24 21:59:49 +02:00
Zbigniew Jędrzejewski-Szmek 73d3ac8e24 various: treat BUS_ERROR_NO_SUCH_UNIT the same as SD_BUS_ERROR_SERVICE_UNKNOWN
We return BUS_ERROR_NO_SUCH_UNIT a.k.a. org.freedesktop.systemd1.NoSuchUnit
in various places. In #16813:
Aug 22 06:14:48 core sudo[2769199]: pam_systemd_home(sudo:account): Failed to query user record: Unit dbus-org.freedesktop.home1.service not found.
Aug 22 06:14:48 core dbus-daemon[5311]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.home1.service': Unit dbus-org.freedesktop.home1.service not found.
Aug 22 06:14:48 core dbus-daemon[5311]: [system] Activating via systemd: service name='org.freedesktop.home1' unit='dbus-org.freedesktop.home1.service' requested by ':1.6564' (uid=0 pid=2769199 comm="sudo su ")

This particular error comes from bus_unit_validate_load_state() in pid1:
  case UNIT_NOT_FOUND:
       return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not found.", u->id);

It seems possible that we should return a different error, but it doesn't really
matter: if we change pid1 to return a different error, we still need to handle
BUS_ERROR_NO_SUCH_UNIT as in this patch to handle pid1 with current code.
2020-08-24 19:48:26 +02:00
Lennart Poettering caf6bd166f homed: default to "btrfs" as fs type in the LUKS backend
Apparently both Fedora and suse default to btrfs now, it should hence be
good enough for us too.

This enables a bunch of really nice things for us, most importanly we
can resize home directories freely (i.e. both grow *and* shrink) while
online. It also allows us to add nice subvolume based home directory
snapshotting later on.

Also, whenever we mention the three supported types, alaways mention
them in alphabetical order, which is also our new order of preference.
2020-08-19 15:46:07 +02:00
Lennart Poettering 1b13600948
Merge pull request #16771 from poettering/dyn-pwq
make libpwquality a dlopen() dependency + use it in systemd-firstboot, too
2020-08-19 15:40:41 +02:00
Lennart Poettering 679badd7ba home: make libpwquality dep a runtime dlopen() one
Also, let's move the glue for this to src/shared/ so that we later can
reuse this in sysemd-firstboot.

Given that libpwquality is a more a leaf dependency, let's make it
runtime optional, so that downstream distros can downgrade their package
deps from Required to Recommended.
2020-08-19 10:03:24 +02:00
Lennart Poettering 64dc138d1e homework: downgrade chattr failure log message
NOCOW is a btrfs-only thing hence don't log louder than necessary if we
don't have it.
2020-08-18 12:41:31 +02:00
Lennart Poettering df14bda2b5 homework: explicitly close cryptsetup context, to not keep loopback device busy
The cryptsetup context pins the loop device even after deactivation.
Let's explicitly release the context to make sure the subsequent
loopback device detaching works cleanly.
2020-08-18 12:41:26 +02:00
Lennart Poettering 6d7b47eb3e homework: correct error passed into log message 2020-08-18 12:41:22 +02:00
Lennart Poettering a2a8a509cd homework: sync everything to disk before we rename LUKS loopback file into place
This how this works on Linux: when atomically creating a file we need to
fully populate it under a temporary name and then when we are fully
done, sync it and the directory it is contained in, before renaming it
to the final name.
2020-08-18 12:41:18 +02:00