Commit Graph

138 Commits

Author SHA1 Message Date
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +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 a4fd6cd3f5 tty-ask-pw-agent: properly propagate error 2020-08-26 23:10:50 +02:00
Lennart Poettering 66bff73b4f tty-ask-pw-agent: the message string might not be set 2020-08-26 23:10:05 +02:00
Lennart Poettering 4c4a018cab tty-ask-pw-agent: make sure "--list" works correctly
Fixes: #16836
2020-08-26 23:02:13 +02:00
Lennart Poettering dad28bffd6 tree-wide: check POLLNVAL everywhere
poll() sets POLLNVAL inside of the poll structures if an invalid fd is
passed. So far we generally didn't check for that, thus not taking
notice of the error. Given that this specific kind of error is generally
indication of a programming error, and given that our code is embedded
into our projects via NSS or because people link against our library,
let's explicitly check for this and convert it to EBADF.

(I ran into a busy loop because of this missing check when some of my
test code accidentally closed an fd it shouldn't close, so this is a
real thing)
2020-06-10 08:57:31 +02:00
Lennart Poettering 4f9ff96a55 conf-parser: return mtime in config_parse() and friends
This is a follow-up for 9f83091e3c.

Instead of reading the mtime off the configuration files after reading,
let's do so before reading, but with the fd we read the data from. This
is not only cleaner (as it allows us to save one stat()), but also has
the benefit that we'll detect changes that happen while we read the
files.

This also reworks unit file drop-ins to use the common code for
determining drop-in mtime, instead of reading system clock for that.
2020-06-02 19:32:20 +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
Yu Watanabe 021cdf8330 tree-wide: drop signal.h when signal-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe 92133d2878 tree-wide: drop socket.h when socket-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe 455fa9610c tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
Zbigniew Jędrzejewski-Szmek 7d895205ef tty-ask-password: fix dead code path
Coverity was complaining that watch==1 always at this point.
CID #1405882.

Use structured initialization while at it.
2019-10-21 21:12:42 +02:00
Franck Bui 6b2faba764 tty-ask-pwd-agent: move ask_password_plymouth() in ask-password-api.c 2019-10-05 08:08:24 +02:00
Franck Bui 87c4444ac9 tty-ask-pwd-agent: small cleanup in process_one_password_file()
Split the part dealing which asks for password on tty in a dedicated function
making process_one_password_file() hopefully easier to read.

No functional changes.
2019-10-05 08:08:24 +02:00
Franck Bui 825721eb8d tty-ask-pwd-agent: add a FIXME 2019-10-05 08:08:24 +02:00
Franck Bui 1322757061 tty-ask-pwd-agent: share the same init code for --query and --watch
Previously we would have skipped the init code which consists in setting the
signal handling up and the wall tty block thingie.
2019-10-05 08:08:24 +02:00
Franck Bui 998c6da8ca tty-ask-pwd-agent: treat SIGINT as a request to exit immediately
Unlike SIGTERM, SIGINT is now treated as a request to exit as soon as
possible. IOW, if SIGINT is received, the agent wont process all remaining
passwords before exiting.

This allows a more comprehensive behavior when C-c is pressed and when the
agent is spawned by systemctl.

Before that patch, pressing C-c killed systemctl but left the agent waiting
for a password since SIGINT was blocked. The result was pretty clumsy.
2019-10-05 08:08:24 +02:00
Franck Bui d325f2443e tty-ask-pwd-agent: give the possiblity to skip a password prompt
If multiple passwords are waiting the agent will prompt for each of them. Give
the possiblity to the user to skip some of them by pressing 'C-d'.
2019-10-05 08:08:24 +02:00
Franck Bui 1503bcb12e tty-ask-pwd-agent: minor simplification by using FOREACH_DIRENT instead of FOREACH_DIRENT_ALL 2019-10-05 08:08:24 +02:00
Franck Bui 27c3112dcb fs-util: introduce inotify_add_watch_and_warn() helper
The default message for ENOSPC is very misleading: it says that the disk is
filled, but in fact the inotify watch limit is the problem.

So let's introduce and use a wrapper that simply calls inotify_add_watch(2) and
which fixes the error message up in case ENOSPC is returned.
2019-10-05 08:08:20 +02:00
Franck Bui 5461cdebfa tty-ask-pwd-agent: rename watch_passwords() and show_passwords()
Those names were a bit confusing both functions process password files the
former relies one the later and waits for new files.

Also show_passwords() was not only used to list password files/requests but
also to query the user.

No functional changes.
2019-10-04 08:10:20 +02:00
Franck Bui 85c221eb98 tty-ask-pwd-agent: simplify handling of --wall a bit
"wall" was always NULL when passed to parse_password() so let's simplify this
part a bit.

The effective changes are small but wall_tty_match() needed to be moved so it's
still visible from parse_password().

No functional changes.
2019-09-17 09:54:02 +02:00
Franck Bui 65943cc350 tty-ask-pwd-agent: fix message forwarded to wall(1)
Commit a1c111c2d1 wrongly replaced '!' with ':' when the message is
forwarded to wall(1).

Indeed in this case we are not requesting the user for providing a password but
instead we are simply displaying a message to suggest starting
tty-ask-password-agent for providing the password.
2019-09-16 22:08:26 +02:00
Zbigniew Jędrzejewski-Szmek 23d5dd1687 shared/exit-status: use Bitmap instead of Sets
I opted to embed the Bitmap structure directly in the ExitStatusSet.
This means that memory usage is a bit higher for units which don't define
this setting:

Service changes:
        /* size: 2720, cachelines: 43, members: 73 */
        /* sum members: 2680, holes: 9, sum holes: 39 */
        /* sum bitfield members: 7 bits, bit holes: 1, sum bit holes: 1 bits */
        /* last cacheline: 32 bytes */

        /* size: 2816, cachelines: 44, members: 73 */
        /* sum members: 2776, holes: 9, sum holes: 39 */
        /* sum bitfield members: 7 bits, bit holes: 1, sum bit holes: 1 bits */

But this way the code is simpler and we do less pointer chasing.
2019-07-29 15:54:53 +02:00
Lennart Poettering b910cc72c0 tree-wide: get rid of strappend()
It's a special case of strjoin(), so no need to keep both. In particular
as typing strjoin() is even shoert than strappend().
2019-07-12 14:31:12 +09:00
Zbigniew Jędrzejewski-Szmek e693a93235 Use _cleanup(free_and_erasep) where appropriate
Replaces #12959.
2019-07-10 11:39:03 +02:00
Yu Watanabe 6e79d2b5a4 ask-passwd: slightly optimize handling arguments
It is not necessary to copy arguments for each console.
2019-04-04 08:07:03 +02:00
Lennart Poettering 65e5d6934e tty-ask-pw-agent: use right array
No point in copying the array if we are not going to use the copy.

Prompted by: https://github.com/systemd/systemd/pull/12183#issuecomment-479591781
2019-04-04 12:33:25 +09:00
Lennart Poettering 189b03779e tty-ask-password: re-break comment 2019-04-02 10:19:23 +02:00
Lennart Poettering d850296466 tty-ask-password: simplify signal handler installation 2019-04-02 10:19:22 +02:00
Lennart Poettering 7452917740 tty-ask-password: no need to initialize something already NUL initialized to NUL 2019-04-02 10:19:22 +02:00
Lennart Poettering 4bec7f09f8 tty-ask-password: drop redundant local variable 2019-04-02 10:19:22 +02:00
Lennart Poettering ed179fd710 tty-ask-password: copy argv[] before forking child
Another fix in style of bd169c2be0.

Let's also avoid strjoina() in a loop (i.e. stack allocation). While in
this specific caseone could get away with it (since we'd immediately
afterwards leave the loop) it's still ugly, and every static checker
would be totally within its rights to complain.

Also, let's simplify things by not relying on argc, since it's redundant
anyway, and it's nicer to just treat things as NULL terminated strv
array.

Fixes: #12180
2019-04-02 10:19:17 +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 e56f9ffe51 util: split out plymouth related stuff 2019-03-14 13:25:51 +01:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +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
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 5e332028f2 util-lib: move main() definition macros to its own header file
This way, we can extend the macro a bit with stuff pulled in from other
headers without this affecting everything which pulls in macro.h, which
is one of our most basic headers.

This is just refactoring, no change in behaviour, in prepartion for
later changes.
2018-11-19 21:14:34 +01:00
Zbigniew Jędrzejewski-Szmek 0420d20dd2 tty-ask-password-agent: define main through macro 2018-11-17 09:13:35 +01:00
Jan Synacek 1432d2dbdf ask-password: improve log message when inotify limit is reached
When inotify_add_watch() fails because of the inotify limit, errno is
set to ENOSPC and then gets shown to users as "No space left on device".
That is very confusing and requires in-depth knowledge of the C library.
Therefore, show user-friendly message when inotify limit is reached.

Fixes #6030.
2018-11-07 15:48:43 +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
Lennart Poettering 87f5446311 string-util: introduce explicit_zero_safe()
The only real difference is that this wrapper can deal with NULL
pointer arguments, but only if the length is also zero.

CID 1396277
2018-10-24 21:00:15 +02: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
Marko Myllynen a1c111c2d1 More polite passphrase prompt
Instead of

Please enter passphrase for disk <disk-name>!

use

Please enter passphrase for disk <disk-name>:

which is more polite and matches Plymouth convention.
2018-10-09 16:26:03 +02: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
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +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