1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-08 08:58:27 +03:00

206 Commits

Author SHA1 Message Date
Dan Nicholson
b5448c16f8 firstboot: fix root params with creds and prompting disabled
Remove an early return that prevents --prompt-root-password or
--prompt-root-shell and systemd.firstboot=off using credentials. In that case,
arg_prompt_root_password and arg_prompt_root_shell will be false, but the
prompt helpers still need to be called to read the credentials. Furthermore, if
only the root shell has been set, don't overwrite the root password.

(cherry picked from commit 35bc4c34240afdd55e117b909f26fa9a5dc54f3b)
2024-08-15 14:04:41 +01:00
Dan Nicholson
847dd914d0 firstboot: handle missing root password entries
If /etc/passwd and/or /etc/shadow exist but don't have an existing root entry,
one needs to be added. Previously this only worked if the files didn't exist.

(cherry picked from commit 2319154a6bec7b8c42e901dfacaefe95bf4e3750)
2024-08-15 14:04:41 +01:00
Dan Nicholson
21d270d38f firstboot: create locked and empty root passwords consistently
Although locked and empty passwords in /etc/passwd are treated the same, in all
other cases the entry is configured to read the password from /etc/shadow.

(cherry picked from commit 5088de9daa156a095e79684c658f9035db971538)
2024-08-15 14:04:41 +01:00
Mike Yuan
2560dcbfe6 stat-util: generalize is_* and verify_* handling 2024-03-04 19:53:51 +00:00
Lennart Poettering
f4a63ce25f dissect-image: add flag for explicitly enabling userspace verity signature checking
let's make userspace verity signature checking optional. This adds a
dissection flag to enable the logic and patches through all our users to
enable it by default, thus effectively not changing anything from the
status quo ante. However, know we have a knob to turn this off in
certain scenarios.
2024-02-28 16:17:40 +01:00
Lennart Poettering
d08fd4c314 ask-password: rework how we pass request meta info when asking passwords
Rather than adding more and more parameters to ask_password_auto(), let's
pass a structure of the fields that often are constant anyway.

This way, callers can fill in what they need, and we take the filled
structure which we can pass around internally as one.

This is in particular preparation for adding one more field in one of
the next commits.
2024-02-20 16:50:00 +01:00
Eric Daigle
321a8c595e firstboot: validate keymap entry
As described in #30940, systemd-firstboot currently does not perform
any validation on keymap entry, allowing nonexistent keymaps to be
written to /etc/vconsole.conf. This commit adds validation checks
based on those already performed on locale entry, preventing invalid
keymaps from being set.

Closes #30940

m
2024-02-12 10:23:38 +01:00
Lennart Poettering
75673cd8ae user-util: add get{pw,gr}{uid,gid,name}_malloc() helpers
These are wrappers around getpwuid_r() and friends, and will allocate the
right-sized buffer for this call.

We so far had multiple implementations of a buffer allocation loop
around getpwuid_r() and friends, and they all suck in some way. Let's
clean this up and add a common implementation, and use it everywhere.

Also, be more careful with error numbers, in particular systematically
turn ENOENT into ENOSRCH (the former is what is returned if /etc/passwd
is absent, which we want to consider identical to user not existing,
which is ENOSRCH). We so far did this at some invocations, but not all.

There are some invocations of getpwuid() left in the codebase. We really
should fix those too, and have a single unified implementation of the
logic, but those are not as trivial to convert, so left for another
time.
2024-01-22 17:55:07 +01:00
Antonio Alvarez Feijoo
4f464e7419
firstboot: fix memory leak 2024-01-10 17:31:49 +01:00
Antonio Alvarez Feijoo
981644edc9
firstboot: fix typo and add missing option to help text 2024-01-10 17:29:56 +01:00
Yu Watanabe
b3a9d980f3 tree-wide: drop space between variable and an increment/decrement 2023-12-25 01:56:40 +09:00
Matteo Croce
e22ad53d5c dbus-wait-for-jobs: change 'quiet' flag to enum
Change the 'quiet' flag to `bus_wait_for_jobs()` to an enum, so we can
select with more granularity the type of information logged.
2023-12-19 04:52:41 -08:00
Lennart Poettering
0a9c4a1082 firstboot: adjust what systemd.firstboot=no on the kernel cmdline does
So far by setting systemd.firstboot=no simply short-cut the whole tool
and made it exit early. This is against what the docs say though: they
just claim the user isn't asked for questions anymore. Let's change
behaviour so that the code actually matches the docs, or more
specifically: if credentials are passed into firstboot, then honour
them, regardless of the kernel cmdline option.

After all, if we get explicit data passed in we should operate on it,
and then leave systemd.firstboot=no just affect the interactivity.

I think this was actually mostly a bug introduced because the credential
stuff was added after the kernel cmdline option, hence this just catches
up with the new addition.
2023-12-18 11:10:47 +01:00
Nick Rosbrook
cd3207491d firstboot: remove /etc/localtime on --reset
The --reset option is supposed to remove all files configured by
firstboot, but currently it does not remove /etc/localtime.
2023-12-08 10:57:23 +09:00
Lennart Poettering
5fee4ac0f4 firstboot: reset terminal settings right before asking a question
We are about to do interactivity on the terminal, hence let's ensure we
are in the TTY mode we expect to be in.
2023-11-22 13:27:53 +01:00
Yu Watanabe
0e7a7cd4e9 locale,firstboot: add headers to vconsole.conf
Closes #29717.
Replaces #29760.

Co-authored-by: cunshunxia <cunshunxia@tencent.com>
2023-10-31 17:15:21 +09:00
Yu Watanabe
f155cb6d75 env-util: make write_env_file() optionally take headers
This also makes write_env_file() and write_env_file_label() optionally
take dir_fd, and drop write_env_file_at().

Preparation for later commits.
2023-10-31 17:15:21 +09:00
Zbigniew Jędrzejewski-Szmek
bb44fd0734 various: use _NEG_ macros to reduce indentation
No functional change intended.
2023-08-16 12:52:56 +02:00
Yu Watanabe
3787934b54 proc-cmdline: make proc_cmdline_get_bool() take flags
All other command line parsers takes flags. Let's make
proc_cmdline_get_bool() also take flags. Though, currently,
no flag is set by the caller.
2023-08-09 17:46:41 +09:00
Yu Watanabe
df490fc79b meson: move declarations of fsck, firstboot, machine-id-setup, and remount-fs 2023-08-01 15:54:45 +09:00
Lennart Poettering
a93993584d bus-unit-util: add common code for reloading PID 1
We have this very similar code in various places, and it#s not entirely
obvious (since we want a prolonged timeout for the reload), hence unify
this at one place.
2023-07-10 16:39:16 +02:00
Egor Ignatov
d34b1823ca shared: add password quality check abstraction layer to support both pwquality and passwdqc
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2023-07-06 10:59:41 +00:00
Dmitry V. Levin
bc0ef0e2c0 pwquality: add old password argument to quality_check_password
This would allow to use quality_check_password() in
user_record_quality_check_password() which still uses
sym_pwquality_check() directly.
2023-07-06 10:59:41 +00:00
Dmitry V. Levin
7fc3f9c032 pwquality: fix quality_check_password return value
quality_check_password() used to return the same value 0 in two
different cases: when pwq_allocate_context() failed with a
ERRNO_IS_NOT_SUPPORTED() code, and when pwquality_check() rejected the
password.  As result, users of quality_check_password() used to report
password weakness also in case when the underlying library was not
available.

Fix this by changing quality_check_password() to forward the
ERRNO_IS_NOT_SUPPORTED() code to its callers, and change the callers
to handle this case gracefully.
2023-07-06 10:59:41 +00:00
Lennart Poettering
8914f7e8e4 man: make sure credentials properly show up in directives index 2023-07-04 22:56:59 +02:00
Antonio Alvarez Feijoo
c7c1edd680 firstboot: fix typo 2023-06-26 17:24:02 +02:00
Zbigniew Jędrzejewski-Szmek
8eb668b9ab firstboot: synchronously wait for systemd-vconsole-setup.service/restart job
Requested in https://github.com/systemd/systemd/pull/27755#pullrequestreview-1443489520.

I dropped the info message about the job being requested, because we get
fairly verbose logs from starting the unit, and the additional message isn't
useful.

In the unit, the ordering before systemd-vconsole-setup.service is dropped,
because now it needs to happen in parallel, while systemd-firstboot.service
is running. This means that we may potentially execute vconsole-setup twice,
but it's fairly quick, so this doesn't matter much.
2023-05-26 15:07:01 +02:00
Zbigniew Jędrzejewski-Szmek
d0c50d8dfa firstboot: reload manager after writing /etc/locale.conf
Requested in https://github.com/systemd/systemd/pull/27750#issuecomment-1559258861.
I didn't apply the locale configuration in firstboot itself, because
we don't have any localized messages, so that wouldn't change anything.
2023-05-23 17:38:43 +02:00
Zbigniew Jędrzejewski-Szmek
cea32691c3 firstboot: do vconsole setup after configuring keymap
Fixes #13466.
2023-05-23 17:38:43 +02:00
Zbigniew Jędrzejewski-Szmek
a777a59243 firstboot: process the root account after sysusers created it
We would create root account from sysusers or from firstboot, depending on
which one ran earlier. Since firstboot offers more options, in particular can
set the root password, we needed to order it earlier. This created an ugly
ordering requirement:

systemd-sysusers.service > systemd-firstboot.service > ... >
  systemd-remount-fs.service > systemd-tmpfiles-setup-dev.service >
  systemd-sysusers.service

We want sysusers.service to create basic users, so we can create nodes in dev,
so we can operate on block devices and such, so that we can resize and remount
things. But at the same time, systemd-firstboot.service can only work if it is
run early, before systemd-sysusers.service has created /etc/passwd. We can't
have it both ways: the units that want to have a fully writable root file
system cannot be ordered before units which are required to do file system
preparation.

Instead of trying to order firstboot very early, let's let it do its thing even
if it is started later. Instead of refusing to create to the root account if
/etc/passwd and /etc/shadow exist, actually check if the account is configured.
Now sysusers writes root account with password PASSWORD_UNPROVISIONED
("!unprovisioned"), and then firstboot checks for this, and will configure root
in this case.

This allows sysusers to be executed earlier (or accounts to be set up earlier
in another way).

This effectively reverts b825ab1a99b69956057c79838faaf7b44afee474.
2023-05-23 15:09:39 +02:00
Zbigniew Jędrzejewski-Szmek
fd6ee7ed42 firstboot: clarify that machine-id options are only offline, add missing docs
Let's flat out refuse to configure machine-id on a running system with
systemd-firstboot. It wouldn't work anyway, because by the time firstboot is
started, pid1 has created /etc/machine-id, possibly with "unitialized", so
firstboot wouldn't touch the file. (If --force is specified, it works. So
let's allow that in case people want to do crazy things.)

While at it, add missing descriptions of various things that were added over
time, and group descriptions of similar options together.
2023-05-23 12:39:34 +02:00
Lennart Poettering
a4b3e94236 dissect-image: port mount_image_privately_interactively() to use /run/systemd/mount-rootfs/ too
Let's use the same common directory as the unit logic uses.

This means we have less to clean up, and opens the door to eventually
allow unprivileged operation of the
mount_image_privately_interactively() logic.
2023-05-16 09:26:17 +02:00
Yu Watanabe
06e78680e3 image-policy: introduce parse_image_policy_argument() helper
Addresses
84be0c710d (r1060130312),
84be0c710d (r1067927293), and
84be0c710d (r1067926416).

Follow-up for 84be0c710d9d562f6d2cf986cc2a8ff4c98a138b.
2023-04-13 11:17:28 +02:00
Lennart Poettering
3af48a86d9
Merge pull request #25608 from poettering/dissect-moar
dissect: add dissection policies
2023-04-12 13:46:08 +02:00
Daan De Meyer
a0657479f5 firstboot: Use root directory file descriptor for everything
There were a few remaining cases where we used arg_root instead of
the root directory file descriptor. Let's port those over to use the
root directory file descriptor as well.
2023-04-11 15:22:08 +02:00
Lennart Poettering
84be0c710d tree-wide: hook up image dissection policy logic everywhere 2023-04-05 20:45:30 +02:00
Daan De Meyer
05eb2c60bd firstboot: Add --reset option
This can be used to prepare an image for firstboot by removing all
files that systemd knows about that contain machine specific
information.
2023-04-01 10:50:15 +02:00
Daan De Meyer
b39710cccf firstboot: Do not dereference symlinks
Let's always operate on paths without resolving the final component.
If the path is a symlink, it could point to a vendor default in /usr,
in which case we definitely do not want to modify the vendor defaults.
To avoid this from happening, we replace the symlink with our own file
instead of modifying the file the symlink points at.
2023-04-01 10:46:42 +02:00
Daan De Meyer
df00c5162f firstboot: Refactor should_configure() 2023-03-29 18:05:04 +02:00
Daan De Meyer
fe75d5bcfa firstboot: Check for errors returned by dir_fd_is_root() 2023-03-29 17:59:50 +02:00
Daan De Meyer
fe58566282 user-util: Rename ETC_PASSWD_LOCK_NAME to ETC_PASSWD_LOCK_FILENAME 2023-03-29 17:52:35 +02:00
Daan De Meyer
b352e545ab firstboot: Modernize path handling
Let's open a file descriptor to the root directory and perform all
path operations using that file descriptor. On top of that, let's
make sure we pin the directory containing the file we want to work
on and use atomic copies and writes everywhere we can..
2023-03-29 09:25:38 +02:00
Daan De Meyer
f461a28da7 chase-symlinks: Rename chase_symlinks() to chase()
Chasing symlinks is a core function that's used in a lot of places
so it deservers a less verbose names so let's rename it to chase()
and chaseat().

We also slightly change the pattern used for the chaseat() helpers
so we get chase_and_openat() and similar.
2023-03-24 13:43:51 +01:00
Daan De Meyer
7c2f5495e2 copy: Move chattr arguments to full function signatures
These are almost never used, so let's move them to the _full()
functions signatures.
2023-03-21 20:53:09 +01:00
Daan De Meyer
a133d2c366 dissect-image: Return mount point fd if requested 2023-02-17 14:58:55 +01:00
Zbigniew Jędrzejewski-Szmek
d173d5564f basic/user-util: create /etc from take_etc_passwd_lock
This allows sysusers to operate with --root that is an empty directory.
It may be useful to, for example, populate the user database before installing
anything else.

firstboot was already doing this, so drop the duplicated call there.
2023-02-01 11:38:35 +01:00
Lennart Poettering
02b7005e38 tree-wide: unify how we pick OS pretty name to display 2023-01-24 15:32:42 +01:00
Yu Watanabe
5bb1d7fbab tree-wide: use -EBADF more 2022-12-21 01:50:33 +09:00
Zbigniew Jędrzejewski-Szmek
d6b4d1c7c4 basic: move version() to build.h+c 2022-11-08 13:41:14 +01:00
Luca Boccassi
4c4a73ce06 firstboot: fix segfault when --locale-messages= is passed without --locale=
\#0  __strcmp_evex () at ../sysdeps/x86_64/multiarch/strcmp-evex.S:295
No locals.
\#1  0x0000557444eb172b in process_locale () at ../src/firstboot/firstboot.c:342
        etc_localeconf = 0x7ffd40217b80 "/root/root/etc/locale.conf"
        locales = {0x0, 0x0, 0x0}
        i = 0
        r = <optimized out>
        __PRETTY_FUNCTION__ = "process_locale"
        __func__ = "process_locale"
\#2  0x0000557444eaff93 in run (argv=0x7ffd40217d98, argc=3) at ../src/firstboot/firstboot.c:1401
        loop_device = 0x0
        unlink_dir = 0x0
        r = <optimized out>
        loop_device = <optimized out>
        unlink_dir = <optimized out>
        r = <optimized out>
        __func__ = <optimized out>
        __PRETTY_FUNCTION__ = <optimized out>
        enabled = <optimized out>
        _error = <optimized out>
        _level = <optimized out>
        _e = <optimized out>
        _level = <optimized out>
        _e = <optimized out>
\#3  main (argc=3, argv=0x7ffd40217d98) at ../src/firstboot/firstboot.c:1432
        r = <optimized out>
        __PRETTY_FUNCTION__ = "main"

Fixes https://github.com/systemd/systemd/issues/25249
2022-11-04 15:51:49 +09:00