Commit Graph

112 Commits

Author SHA1 Message Date
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
Yu Watanabe 545cdb90f3 tree-wide: use instead of #ifdef for HAVE_* 2018-06-29 11:40:15 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Lennart Poettering d58ad743f9 os-util: add helpers for finding /etc/os-release
Place this new helpers in a new source file os-util.[ch], and move the
existing and related call path_is_os_tree() to it as well.
2018-05-24 17:01:57 +02:00
Lennart Poettering 1a5a177eaf fileio: accept FILE* in addition to path in parse_env_file()
Most our other parsing functions do this, let's do this here too,
internally we accept that anyway. Also, the closely related
load_env_file() and load_env_file_pairs() also do this, so let's be
systematic.
2018-05-24 17:01:57 +02:00
Mike Gilbert 089fb8653f basic: add log_level argument to timezone_is_valid 2018-05-12 15:20:13 -04:00
Lennart Poettering da6053d0a7 tree-wide: be more careful with the type of array sizes
Previously we were a bit sloppy with the index and size types of arrays,
we'd regularly use unsigned. While I don't think this ever resulted in
real issues I think we should be more careful there and follow a
stricter regime: unless there's a strong reason not to use size_t for
array sizes and indexes, size_t it should be. Any allocations we do
ultimately will use size_t anyway, and converting forth and back between
unsigned and size_t will always be a source of problems.

Note that on 32bit machines "unsigned" and "size_t" are equivalent, and
on 64bit machines our arrays shouldn't grow that large anyway, and if
they do we have a problem, however that kind of overly large allocation
we have protections for usually, but for overflows we do not have that
so much, hence let's add it.

So yeah, it's a story of the current code being already "good enough",
but I think some extra type hygiene is better.

This patch tries to be comprehensive, but it probably isn't and I missed
a few cases. But I guess we can cover that later as we notice it. Among
smaller fixes, this changes:

1. strv_length()' return type becomes size_t

2. the unit file changes array size becomes size_t

3. DNS answer and query array sizes become size_t

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
2018-04-27 14:29:06 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Lennart Poettering ae2a15bc14 macro: introduce TAKE_PTR() macro
This macro will read a pointer of any type, return it, and set the
pointer to NULL. This is useful as an explicit concept of passing
ownership of a memory area between pointers.

This takes inspiration from Rust:

https://doc.rust-lang.org/std/option/enum.Option.html#method.take

and was suggested by Alan Jenkins (@sourcejedi).

It drops ~160 lines of code from our codebase, which makes me like it.
Also, I think it clarifies passing of ownership, and thus helps
readability a bit (at least for the initiated who know the new macro)
2018-03-22 20:21:42 +01:00
Franck Bui 100d5f6ee6 user-util: add new wrappers for reading/writing {passwd,shadow,gshadow} database files (#8521)
The API povided by the glibc is too error-prone as one has to deal directly
with errno in order to detect if errors occured.

Suggested by Zbigniew.
2018-03-21 15:26:02 +01:00
Lennart Poettering be6b0c2165 coccinelle: make use of DIV_ROUND_UP() wherever appropriate
Let's use our macros where we can
2018-03-20 20:59:02 +01:00
Lennart Poettering daa557208d tty-ask-password-agent: don't open terminal multiple times
We already have the terminal open, hence pass the fd we got to
ask_password_tty(), so that it doesn't have to reopen it a second time.

This is mostly an optimization, but it has the nice benefit of making us
independent from RLIMIT_NOFILE issues and so on, as we don't need to
allocate another fd needlessly.
2018-02-14 00:11:16 +01:00
Björn Esser 9f555bba67 firstboot: Include <crypt.h> for declaration of crypt() if needed (#7944)
Not every target system may provide a crypt() function in its stdlibc
and may use an external or replacement library, like libxcrypt, for
providing such functions.

See https://fedoraproject.org/wiki/Changes/Replace_glibc_libcrypt_with_libxcrypt.
2018-01-25 17:30:15 +03:00
Lennart Poettering dccca82b1a log: minimize includes in log.h
log.h really should only include the bare minimum of other headers, as
it is really pulled into pretty much everything else and already in
itself one of the most basic pieces of code we have.

Let's hence drop inclusion of:

1. sd-id128.h because it's entirely unneeded in current log.h
2. errno.h, dito.
3. sys/signalfd.h which we can replace by a simple struct forward
   declaration
4. process-util.h which was needed for getpid_cached() which we now hide
   in a funciton log_emergency_level() instead, which nicely abstracts
   the details away.
5. sys/socket.h which was needed for struct iovec, but a simple struct
   forward declaration suffices for that too.

Ultimately this actually makes our source tree larger (since users of
the functionality above must now include it themselves, log.h won't do
that for them), but I think it helps to untangle our web of includes a
tiny bit.

(Background: I'd like to isolate the generic bits of src/basic/ enough
so that we can do a git submodule import into casync for it)
2018-01-11 14:44:31 +01:00
Yu Watanabe a7353b4d14 firstboot: do not write vconsole.conf when arg_keymap is empty 2017-11-25 19:11:57 +09:00