Commit Graph

127 Commits

Author SHA1 Message Date
Lennart Poettering 79485fc27a firstboot: clean-up the copied hostname, not argv[] directly, as that's ugly 2020-12-15 18:00:02 +01:00
Lennart Poettering 52ef5dd798 hostname-util: flagsify hostname_is_valid(), drop machine_name_is_valid()
Let's clean up hostname_is_valid() a bit: let's turn the second boolean
argument into a more explanatory flags field, and add a flag that
accepts the special name ".host" as valid. This is useful for the
container logic, where the special hostname ".host" refers to the "root
container", i.e. the host system itself, and can be specified at various
places.

let's also get rid of machine_name_is_valid(). It was just an alias,
which is confusing and even more so now that we have the flags param.
2020-12-15 17:59:48 +01: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 0e98d17e77 Add a helper function that does make_salt+crypt_r
No functional change.
2020-09-15 09:30:56 +02:00
afg 67d5d9d5ce firstboot: don't create/modify passwd and shadow if not asked 2020-09-03 09:13:47 +02:00
afg ae0d36c161 firstboot: fill empty color if ansi_color unavailable from os-release 2020-09-02 08:10:47 +02:00
Lennart Poettering 7baf10a7be firstboot: hook up with libpwquality 2020-08-19 10:03:56 +02:00
Lennart Poettering ee72df1c7b firstboot: move --image= logic into common code
That way we can reuse it in tmpfiles/sysusers/journalctl and so on.
2020-08-11 22:26:48 +02:00
Lennart Poettering 6aa05ebdd8 firstboot: move --image= logic into common code
That way we can reuse it in tmpfiles/sysusers/journalctl and so on.
2020-08-05 20:34:58 +02:00
Luca Boccassi 18d7370587 service: add new RootImageOptions feature
Allows to specify mount options for RootImage.
In case of multi-partition images, the partition number can be prefixed
followed by colon. Eg:

RootImageOptions=1:ro,dev 2:nosuid nodev

In absence of a partition number, 0 is assumed.
2020-07-29 17:17:32 +01:00
Daan De Meyer f649325ba7 firstboot: Update help string with --root-shell options 2020-07-29 15:35:59 +02:00
Daan De Meyer 31363bd564 firstboot: Check if the given shell exists 2020-07-28 09:58:24 +02:00
Lennart Poettering b226422cd7 firstboot: don't create /etc/passwd with mode 000
It needs to be world readable (unlike /etc/shadow) when created anew.

This fixes systems that boot with "systemd-nspawn --volatile=yes", i.e.
come up with an entirely empty /etc/ and thus no existing /etc/passwd
file when firstboot runs.
2020-07-23 17:09:11 +02:00
Daan De Meyer 28900a1bfe firstboot: Add --root-shell option 2020-07-22 21:22:46 +01:00
Daan De Meyer c4a53ebf7a firstboot: Tighten up passwd/shadow handling
There are a lot of edge cases that the current implementation
doesn't handle, especially in cases where one of passwd/shadow
exists and the other doesn't exist. For example, if
--root-password is specified, we will write /etc/shadow but
won't add a root entry to /etc/passwd if there is none.

To fix some of these issues, we constrain systemd-firstboot to
only modify /etc/passwd and /etc/shadow if both do not exist
already (or --force) is specified. On top of that, we calculate
all necessary information for both passwd and shadow upfront so
we can take it all into account when writing the actual files.

If no root password options are given --force is specified or both
files do not exist, we lock the root account for security purposes.
2020-07-22 21:22:41 +01:00
Lennart Poettering a122502077 firstboot: add option to turn off welcome text display 2020-07-07 11:20:42 +02:00
Lennart Poettering 3ff9fa591e firstboot: add --image= switch
This is like --root=, but takes an image file path or device node path
and dissects the image directly, mounting it internally.
2020-07-07 11:20:42 +02:00
Daan De Meyer a5925354bb firstboot: Add --kernel-command-line option 2020-05-27 18:54:26 +02:00
Daan De Meyer 676339a191 firstboot: Add --root-password-hashed option 2020-05-27 18:54:26 +02:00
Daan De Meyer 4926ceaff3 firstboot: Add --delete-root-password option 2020-05-27 18:54:25 +02:00
Daan De Meyer b4909a3fd0 firstboot: Add --force option 2020-05-27 18:54:25 +02:00
Daan De Meyer 1fbc95d388 firstboot: Don't check twice if /etc/shadow exists 2020-05-27 18:54:25 +02: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 38b38500c6 tree-wide: use "hostname" spelling everywhere
It's not that I think that "hostname" is vastly superior to "host name". Quite
the opposite — the difference is small, and in some context the two-word version
does fit better. But in the tree, there are ~200 occurrences of the first, and
>1600 of the other, and consistent spelling is more important than any particular
spelling choice.
2020-04-21 16:58:04 +02:00
Zbigniew Jędrzejewski-Szmek 39e96f844a firstboot: add missing check
If we check length of 'a', we must do the same for 'b'.
2020-02-06 09:52:39 +01:00
Lennart Poettering 42f3b2f975 shared: split out crypt() specific helpers into its own .c/.h in src/shared/
This way we can use libxcrypt specific functionality such as
crypt_gensalt() and thus take benefit of the newer algorithms libxcrypt
implements. (Also adds support for a new env var $SYSTEMD_CRYPT_PREFIX
which may be used to select the hash algorithm to use for libxcrypt.)

Also, let's move the weird crypt.h inclusion into libcrypt.h so that
there's a single place for it.
2020-01-15 15:26:27 +01:00
Lennart Poettering 3619634ca5 firstboot: drop duplicate trailing whitespace from root pw question
Since ask_password() (and related calls) already append one char, we
ended up appending two. That's not pretty. Let's fix this, and do it
like in all other cases ask_password() (or an equivalent function) is
called.
2019-08-11 06:13:57 +09:00
Zbigniew Jędrzejewski-Szmek ecada8f25e firstboot: only list all options on demand
The user most likely knows the name of their locale/keymap/whatever,
and paging through multiple pages of output has little benefit.

The header that was printed before is now not printed anymore. But
now it's obvious from the context what we are printing, so we don't
need to print the header.
2019-07-17 12:07:19 +02:00
Zbigniew Jędrzejewski-Szmek bfbf5f7408 firstboot: use free_and_strdup, free_and_replace 2019-07-17 12:07:19 +02:00
Lennart Poettering 4aeadec7e6 firstboot: use color in welcome text 2019-07-13 11:07:51 +02:00
Lennart Poettering bdd7cd264a firstboot: suppress locale menu if there's nothing to choose from 2019-07-13 11:07:51 +02:00
Zbigniew Jędrzejewski-Szmek 9ae4ef49cd Remove string_free_erase 2019-07-10 13:48:55 +02:00
Zbigniew Jędrzejewski-Szmek 127c167cdb
Merge pull request #12390 from poettering/string-file-mkdir
fileio: add a WRITE_STRING_FILE_MKDIR_0755 flag to write_string_file() that creates parent directories if needed
2019-05-28 14:42:55 +02:00
Lennart Poettering e82e549fb2 tree-wide: make use of the new WRITE_STRING_FILE_MKDIR_0755 flag 2019-05-08 06:36:20 -04:00
Lennart Poettering 22e596d6d5 tree-wide: voidify a few calls 2019-05-08 06:36:20 -04:00
Lennart Poettering 3862043310 firstboot: port to make_salt()
Also, let's use crypt_r() over crypt(). Not because we actually use
threads, but because it's safer and more future proof in general.
2019-04-29 20:26:38 +02:00
Lennart Poettering 8a016c746e util-lib: when copying files make sure to apply some chattrs early, some late
Some chattrs only work sensible if you set them right after opening a
file for create (think: FS_NOCOW_FL). Others only work when they are
applied when the file is fully written (think: FS_IMMUTABLE_FL). Let's
take that into account when copying files and applying a chattr to them.
2019-03-28 18:43:04 +01:00
Lennart Poettering f05e1d0d9f util: split out kbd related stuff
This stuff is neither generic enough to be in def.h, nor really has much
to do with locale, hence give it its own .c/.h file pair.
2019-03-14 13:25:51 +01:00
Lennart Poettering 9a6f746fb6 locale-util: prefix special glyph enum values with SPECIAL_GLYPH_
This has been irritating me for quite a while: let's prefix these enum
values with a common prefix, like we do for almost all other enums.

No change in behaviour, just some renaming.
2018-12-14 08:22:54 +01:00
Lennart Poettering 686d13b9f2 util-lib: split out env file parsing code into env-file.c
It's quite complex, let's split this out.

No code changes, just some file rearranging.
2018-12-02 13:22:29 +01:00
Zbigniew Jędrzejewski-Szmek baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Zbigniew Jędrzejewski-Szmek 294bf0c34a Split out pretty-print.c and move pager.c and main-func.h to shared/
This is high-level functionality, and fits better in shared/ (which is for
our executables), than in basic/ (which is also for libraries).
2018-11-20 18:40:02 +01:00
Yu Watanabe 45f394187a firstboot: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Lennart Poettering 6bf3c61c57 log: introduce new helper call log_setup_service()
Let's reduce the common boilerplate and have a single setup function
used by all service code to setup logging.
2018-11-20 11:18:22 +01:00
Lennart Poettering 68534345b8 random-util: optionally enable blocking getrandom() behaviour
When generating the salt for the firstboot password logic, let's use
getrandom() blocking mode, and insist in the very best entropy.
2018-11-08 09:44:27 +01:00
Lennart Poettering 94d457e8d9 random-util: change high_quality_required bool parameter into a flags parameter
No change in behaviour, just some refactoring.
2018-11-08 09:44:27 +01:00
Lennart Poettering 3335dc2d75 random-util: rename acquire_random_bytes() → genuine_random_bytes()
It's more descriptive, since we also have a function random_bytes()
which sounds very similar.

Also rename pseudorandom_bytes() to pseudo_random_bytes(). This way the
two functions are nicely systematic, one returning genuine random bytes
and the other pseudo random ones.
2018-11-08 09:44:27 +01:00
Xiang Fan c7b7d74e81 ask-password: check keyring in ask_password_tty and ask_password_agent
A race condition happens when calling ask_password_auto() multiple times
to unlock several disks on boot and effectively no password caching is
utilized. This patch fixes it by polling the cache when waiting for
the password.
2018-10-31 18:26:58 +01:00
Yu Watanabe 0cab6f7db8 firstboot: include error cause in log message 2018-10-20 01:54:52 +09:00
Lennart Poettering 37ec0fdd34 tree-wide: add clickable man page link to all --help texts
This is a bit like the info link in most of GNU's --help texts, but we
don't do info but man pages, and we make them properly clickable on
terminal supporting that, because awesome.

I think it's generally advisable to link up our (brief) --help texts and
our (more comprehensive) man pages a bit, so this should be an easy and
straight-forward way to do it.
2018-08-20 11:33:04 +02:00