Commit graph

147 commits

Author SHA1 Message Date
Lennart Poettering 7a8867abfa user-util: rework how we validate user names
This reworks the user validation infrastructure. There are now two
modes. In regular mode we are strict and test against a strict set of
valid chars. And in "relaxed" mode we just filter out some really
obvious, dangerous stuff. i.e. strict is whitelisting what is OK, but
"relaxed" is blacklisting what is really not OK.

The idea is that we use strict mode whenver we allocate a new user
(i.e. in sysusers.d or homed), while "relaxed" mode is when we process
users registered elsewhere, (i.e. userdb, logind, …)

The requirements on user name validity vary wildly. SSSD thinks its fine
to embedd "@" for example, while the suggested NAME_REGEX field on
Debian does not even allow uppercase chars…

This effectively liberaralizes a lot what we expect from usernames.

The code that warns about questionnable user names is now optional and
only used at places such as unit file parsing, so that it doesn't show
up on every userdb query, but only when processing configuration files
that know better.

Fixes: #15149 #15090
2020-04-08 17:11:20 +02:00
Zbigniew Jędrzejewski-Szmek 1fb5a5edc7 sysusers: do not require /proc to be mounted
We're operating on known paths in root-owned directories here, so the detour
through toctou-safe methods that require /proc to be mounted is not necessary.
Should fix https://bugzilla.redhat.com/show_bug.cgi?id=1807768.
2020-03-03 12:29:57 +01:00
Zbigniew Jędrzejewski-Szmek 08c7c3216b sysusers: many different errnos to express one condition
See https://bugzilla.redhat.com/show_bug.cgi?id=1807768. It turns
out that sysusers cannot query if the group exists:
Failed to check if group dnsmasq already exists: No such process
...
Failed to check if group systemd-timesync already exists: No such process

When the same command is executed later, the issue does not occur. Not sure why
the behaviour in the initial transaction is different. But let's accept all
errors that the man pages list. We check if the user/group exists before creating
anyway, so this seems pretty safe.
2020-03-03 11:56:25 +01:00
David Michael 649916d356 sysusers: support creating users with a specific primary group
This extends the "uid:gid" syntax for "u" lines so that a group
name can be given instead of a GID.  This requires that the group
is either queued for creation by sysusers, or it is already defined
on the system.

Closes #14340
2020-02-02 16:53:22 +01:00
Zbigniew Jędrzejewski-Szmek 12c829376a Revert "sysusers: properly mark generated accounts as locked"
This reverts the gist of commit 636e72bce6.
The comment and the tiny cleanup are left alone.

We shouldn't lock the accounts because people actually need to use them, and
if they are locked, various tools will refuse.
See https://github.com/systemd/systemd/pull/13277#issuecomment-529964578
and follow-up comments.
2019-10-22 17:59:11 +09:00
Lennart Poettering 636e72bce6 sysusers: properly mark generated accounts as locked
Previously, we'd only set the shell to /usr/bin/nologin and lock the
password for system users. Let's go one step further and also lock the
whole account.

This is a paranoid safety precaution, since neither disabling the shell
like this nor disabling the password is sufficient to lock an account,
since remote shell tools generally allow passing different shells, and
logins into ftp or similar protocols don't know the shell concept anyway.
Moreover, in times of ssh authentication by password is just one
option of authentication among many.

Takes inspiration from the recommendations in usermod(8)'s -L switch:

    "Note: if you wish to lock the account (not only access with a
    password), you should also set the EXPIRE_DATE to 1."
2019-08-14 18:19:56 +02:00
Zbigniew Jędrzejewski-Szmek a505166845
Merge pull request #13096 from keszybz/unit-loading
Preparatory work for the unit loading rework
2019-07-19 21:47:10 +02:00
Zbigniew Jędrzejewski-Szmek cde7910993 sysusers,strv: export the hash ops to map char* → strv
Also make string_strv_hashmap_put return 0 only if the entry already existed.
2019-07-19 16:49:41 +02:00
Michael Biebl 6db904625d meson: make nologin path build time configurable
Some distros install nologin as /usr/sbin/nologin, others as
/sbin/nologin.
Since we can't really on merged-usr everywhere (where the path wouldn't
matter), make the path build time configurable via -Dnologin-path=.

Closes #13028
2019-07-18 12:46:35 +02:00
Zbigniew Jędrzejewski-Szmek 4ec8514142 Rename EXTRACT_QUOTES to EXTRACT_UNQUOTE
Whenever I see EXTRACT_QUOTES, I'm always confused whether it means to
leave the quotes in or to take them out. Let's say "unquote", like we
say "cunescape".
2019-06-28 11:35:05 +02:00
Lennart Poettering e7b88b7bc1 tree-wide: introduce empty_or_dash() helper
At quite a few places we check isempty() || streq(…, "-"), let's add a
helper to simplify that, and replace that by a single function call.
2019-04-08 12:03:33 +02:00
Zbigniew Jędrzejewski-Szmek 330d1defdb sysusers: use return_error_errno() where possible 2019-04-07 22:00:11 +02:00
Zbigniew Jędrzejewski-Szmek 71fb15888b sysusers: add missing initalizer
I assume that this is the error causing the invalid free in
https://bugzilla.redhat.com/show_bug.cgi?id=1670679.
2019-04-07 21:49:08 +02:00
Lennart Poettering 6990fb6bc6 tree-wide: (void)ify a few unlink() and rmdir()
Let's be helpful to static analyzers which care about whether we
knowingly ignore return values. We do in these cases, since they are
usually part of error paths.
2019-03-27 18:09:56 +01:00
Lennart Poettering 76b31bbb24
Merge pull request #10920 from yuwata/hashmap-destructor
hashmap: make hashmap_free() call destructors of key or value
2018-12-03 17:59:44 +01:00
Lennart Poettering e4de72876e util-lib: split out all temporary file related calls into tmpfiles-util.c
This splits out a bunch of functions from fileio.c that have to do with
temporary files. Simply to make the header files a bit shorter, and to
group things more nicely.

No code changes, just some rearranging of source files.
2018-12-02 13:22:29 +01:00
Lennart Poettering ee228be10c util-lib: don't include fileio.h from fileio-label.h
There's no reason for doing that, hence simply don't.
2018-12-02 13:22:29 +01:00
Yu Watanabe 71da167373 sysusers: define main through macro
This also fixes possible memleak when uid/gid or user/group name
in database are conflicted.
2018-12-02 12:18:54 +01:00
Yu Watanabe f030d36cd0 sysusers: use fgetgrent_sane() 2018-12-02 12:18:54 +01:00
Yu Watanabe dd2fd972b7 sysusers: use ordered_hashmap_steal_first_key_and_value() 2018-11-23 06:22:30 +09: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
Zbigniew Jędrzejewski-Szmek 0221d68a13 basic/pager: convert the pager options to a flags argument
Pretty much everything uses just the first argument, and this doesn't make this
common pattern more complicated, but makes it simpler to pass multiple options.
2018-11-14 16:25:11 +01:00
Lennart Poettering 050ca29963 sysusers: FOREACH_LINE excorcism 2018-10-18 16:23:45 +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
Zbigniew Jędrzejewski-Szmek b0450864f1
Merge pull request #9274 from poettering/comment-header-cleanup
drop "this file is part of systemd" and lennart's copyright from header
2018-06-14 11:26:50 +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
Yu Watanabe c039af2388 sysusers: use fchmod_and_chown() 2018-06-14 12:03:49 +09:00
Lennart Poettering dcd5c891cb binfmt,sysctl,sysuers,tmpfiles: add auto-paging for --cat-config commands
The output of these commands is really long, and already enriched with
color. Let's add auto-paging to make this easier to digest.
2018-06-13 14:20:03 +02:00
Yu Watanabe 858d36c1ec path-util: introduce path_simplify()
The function is similar to path_kill_slashes() but also removes
initial './', trailing '/.', and '/./' in the path.
When the second argument of path_simplify() is false, then it
behaves as the same as path_kill_slashes(). Hence, this also
replaces path_kill_slashes() with path_simplify().
2018-06-03 23:39:26 +09:00
Yu Watanabe b8bed70068 sysusers: support specifier expansion for GECOS and home directory fields 2018-05-31 17:36:22 +09:00
Lennart Poettering b294e5943f core: introduce specifiers for /tmp and /var/tmp
This corresponds nicely with the specifiers we already pass for
/var/lib, /var/cache, /run and so on.

This is particular useful to update the test-path service files to
operate without guessable files, thus allowing multiple parallel
test-path invocations to pass without issues (the idea is to set $TMPDIR
early on in the test to some private directory, and then only use the
new %T or %V specifier to refer to it).
2018-05-29 11:39:15 +02:00
Yu Watanabe 5ed29cab4a sysusers: drop an unused variable
Follow-up for ec0327d69c.
2018-05-15 14:04:43 +02:00
Zbigniew Jędrzejewski-Szmek a826d4f7d0 Eliminate config_dirs vars which hold a static strv 2018-05-07 18:17:36 +02:00
Zbigniew Jędrzejewski-Szmek ec0327d69c sysusers: add --cat-config 2018-04-27 10:06:24 +02:00
Zbigniew Jędrzejewski-Szmek 340ac01986 sysusers: use uniform order for variables
Follow-up for 43e948eea6.
2018-04-20 15:56:52 +02:00
Zbigniew Jędrzejewski-Szmek d18b57f7fd
Merge pull request #8754 from poettering/sysusers-fix
two minor memleak fixes for sysusers, fixing #8718
2018-04-19 19:39:48 +02:00
Lennart Poettering 5d13a15b1d tree-wide: drop spurious newlines (#8764)
Double newlines (i.e. one empty lines) are great to structure code. But
let's avoid triple newlines (i.e. two empty lines), quadruple newlines,
quintuple newlines, …, that's just spurious whitespace.

It's an easy way to drop 121 lines of code, and keeps the coding style
of our sources a bit tigther.
2018-04-19 12:13:23 +02:00
Lennart Poettering d9bcc5a6a2 sysusers: fix minor memory leak 2018-04-18 18:00:05 +02:00
Lennart Poettering c1a32819c2 sysusers: clarify that we knowingly ignore process_items() return values 2018-04-18 18:00:05 +02:00
Lennart Poettering 43e948eea6 sysusers: fix memory leak when /etc/passwd contains multiple identical lines
Fixes: #8718
2018-04-18 18:00:05 +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
Yu Watanabe 1cc6c93a95 tree-wide: use TAKE_PTR() and TAKE_FD() macros 2018-04-05 14:26:26 +09: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
Franck Bui 8c1b45aa9c sysusers: make sure to reset errno before calling fget*ent()
Due to the glibc interface we have to test errno in various places to detect if
an error occured after calling fget*ent() helpers.
2018-03-20 11:38:39 +01:00
Franck Bui 19ec7de2d6 sysusers: also add support for NIS entries in /etc/shadow
Commit 563dc6f8e2 added support for
/etc/{passwd,group} only but since nsswitch.conf(5) appears to document the NIS
entries also for shadow, let's support this case too.
2018-03-20 11:28:19 +01:00
Franck Bui 563dc6f8e2 sysusers: do not append entries after the NIS ones
The NIS-catchall entry switches from files to NIS lookup and never goes back,
so it must be the last entry in /etc/passwd (the other +/-{user,@netgroup}
entries don't have to be).

That's how the nss_compat mode for /etc/passwd (and /etc/group) traditionally
works.

It's age-old historic behaviour that the NIS entry must be the last one.  It
doesn't seem to be specified somewhere, but it worked like this since very
early SunOS when NIS was first included.

Fixes: #8467
2018-03-16 10:01:33 +01:00
Michael Vogt 1825c909ff sysusers: support u username -:300 style syntax (#8325)
This PR implements the first part of RFE #8046. I.e. this allows to
write:
```
u username -:300
```
Where the uid is chosen automatically but the gid is fixed.
2018-03-02 12:56:44 +01:00