Commit Graph

47 Commits

Author SHA1 Message Date
Richard Maw 6868560773 util: change unquote_*_word to extract_*_word
It now takes a separators argument, which defaults to WHITESPACE if NULL
is passed.
2015-08-07 15:50:42 +00:00
Richard Maw 4b1c175351 Convert unquote_*_word users to expect isempty(p) after the last entry
This is so that, when called in a loop, unquote_first_word can
distinguish between reaching the end of a string because it has consumed
all the input before the end, and consuming all the input.

This is important because we later add a flag that allows

    char *in = "";
    char *out;
    unquote_first_word(&in, &out, flags);

To put "" in out, and set in = NULL, so the trailing empty string of the
input can be consumed, and mark that the input has been consumed.
2015-08-07 15:50:42 +00:00
David Herrmann 97b11eedff tree-wide: introduce mfree()
Pretty trivial helper which wraps free() but returns NULL, so we can
simplify this:
        free(foobar);
        foobar = NULL;
to this:
        foobar = mfree(foobar);
2015-07-31 19:56:38 +02:00
Daniel Mack 2fc09a9cdd tree-wide: use free_and_strdup()
Use free_and_strdup() where appropriate and replace equivalent,
open-coded versions.
2015-07-30 13:09:01 +02:00
Lennart Poettering 1d13f648d0 util: add generic calls for prefixing a root directory to a path
So far a number of utilities implemented their own calls for this, unify
them in prefix_root() and prefix_roota(). The former uses heap memory,
the latter allocates from the stack via alloca().

Port over most users of a --root= logic.
2015-05-13 17:42:10 +02:00
Ronny Chevalier 6482f6269c shared: add formats-util.h 2015-04-10 23:54:48 +02:00
Lennart Poettering 4034a06ddb util: rework word parsing and c unescaping code
When parsing words from input files, optionally automatically unescape
the passed strings, controllable via a new flags parameter.

Make use of this in tmpfiles, and port everything else over, too.

This improves parsing quite a bit, since we no longer have to process the
same string multiple times with different calls, where an earlier call
might corrupt the input for a later call.
2015-03-26 11:56:22 +01:00
Ivan Shapovalov c5abf22514 sysusers: do not reject users with already present /etc/shadow entries
This is needed to interoperate firstboot and sysusers. The former one is started
first, and it writes only /etc/shadow when it is told to set the root password.
It's better to relax checks here than to duplicate functionality in firstboot.
2015-03-07 13:09:36 -05:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Lennart Poettering 63c372cb9d util: rework strappenda(), and rename it strjoina()
After all it is now much more like strjoin() than strappend(). At the
same time, add support for NULL sentinels, even if they are normally not
necessary.
2015-02-03 02:05:59 +01:00
Lennart Poettering 8cb4ab0058 logind: unify how we cast between uid_t and pointers for hashmap keys 2015-01-09 18:35:36 +01:00
Lennart Poettering d7b8eec7dc tmpfiles: add new line type 'v' for creating btrfs subvolumes 2014-12-28 02:08:40 +01:00
Lennart Poettering 7430ec6ac0 copy: use btrfs reflinking only whe we know we copy full files 2014-12-12 17:30:25 +01:00
Lennart Poettering fed1e721fd treewide: introduce UID_INVALID (and friends) as macro for (uid_t) -1 2014-11-28 20:55:04 +01:00
Michal Schmidt 4a62c710b6 treewide: another round of simplifications
Using the same scripts as in f647962d64 "treewide: yet more log_*_errno
+ return simplifications".
2014-11-28 19:57:32 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Michal Schmidt 8d3d7072e6 treewide: a few more log_*_errno + return simplifications
The one in tmpfiles.c:create_item() even looks like it fixes a bug.
2014-11-28 19:17:24 +01:00
Michal Schmidt f647962d64 treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
 'local $/;
  local $_=<>;
  s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
  print;'
 $f
done

And a couple of manual whitespace fixups.
2014-11-28 18:56:16 +01:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +01:00
Josh Triplett 7f0a55d432 Introduce CONF_DIRS_NULSTR helper to define standard conf dirs
Several different systemd tools define a nulstr containing a standard
series of configuration file directories, in /etc, /run, /usr/local/lib,
/usr/lib, and (#ifdef HAVE_SPLIT_USR) /lib.  Factor that logic out into
a new helper macro, CONF_DIRS_NULSTR.
2014-11-26 19:11:37 -05:00
Lennart Poettering fff1949960 sysuser: simplify access mode syncing by introducing helper function for it 2014-11-11 18:12:40 +01:00
Lennart Poettering f06863bde5 sysusers: be nice and print a warning if futimens() fails
CID# 1251163
2014-11-07 16:36:14 +01:00
Colin Guthrie e3c72c21d6 sysusers: Preserve ownership and mode on /etc/passwd and friends
When running sysusers we would clobber file ownership and permissions
on the files /etc/passwd, /etc/group and /etc/[g]shadow.

This simply preserves the ownership and mode if existing files are
found.
2014-10-30 13:38:10 +00:00
WaLyong Cho cc56fafeeb mac: rename apis with mac_{selinux/smack}_ prefix 2014-10-23 17:13:15 +02:00
Philippe De Swert 56d21cdebc sysusers: Remove some gcc warnings about uninitialized variables
Gcc is spewing some warnings about uninitialized variables.
Let's get rid of the noise.
2014-09-18 18:32:18 +02:00
Michal Schmidt d5099efc47 hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in
struct Hashmap separately. The functions always comprise a pair.
Store a single pointer to struct hash_ops instead.

systemd keeps hundreds of hashmaps, so this saves a little bit of
memory.
2014-09-15 16:08:50 +02:00
Thomas Hindoe Paaboel Andersen c46409021f sysusers: initialize r
Needed for the stdin case where it could otherwise end up being used
uninitialized.
2014-08-19 23:27:44 +02:00
Lennart Poettering 8530dc4467 tmpfiles: add new 'r' line type to add UIDs/GIDs to the pool to allocate UIDs/GIDs from
This way we can guarantee a limited amount of compatibility with
login.defs, by generate an appopriate "r" line out of it, on package
installation.
2014-08-19 19:06:39 +02:00
Lennart Poettering 7629889c86 sysusers: add another column to sysusers files for the home directory 2014-08-19 16:47:52 +02:00
Lennart Poettering dfc87cbfe5 sysusers: optionally, read sysuers configuration from standard input 2014-08-19 02:14:32 +02:00
Lennart Poettering 9ab315ccf2 sysusers: also update /etc/shadow and /etc/gshadow when creating new system users
This should resolve problems with tools like "grpck" and suchlike.
2014-08-19 01:57:24 +02:00
Thomas Hindoe Paaboel Andersen 24fb7c1fa6 sysusers: isempty will never be < 0
looks like a typo from 	1b99214789
2014-08-04 23:28:02 +02:00
Zbigniew Jędrzejewski-Szmek 601185b43d Unify parse_argv style
getopt is usually good at printing out a nice error message when
commandline options are invalid. It distinguishes between an unknown
option and a known option with a missing arg. It is better to let it
do its job and not use opterr=0 unless we actually want to suppress
messages. So remove opterr=0 in the few places where it wasn't really
useful.

When an error in options is encountered, we should not print a lengthy
help() and overwhelm the user, when we know precisely what is wrong
with the commandline. In addition, since help() prints to stdout, it
should not be used except when requested with -h or --help.

Also, simplify things here and there.
2014-08-03 21:46:07 -04:00
Zbigniew Jędrzejewski-Szmek 9f1c19405a sysusers: fix selinux context of backup files
Also, fix fopen_temporary_label to set proper context. By chance,
all users so far used the same context, so the error didn't matter.

Also, check return value from label_init().

https://bugzilla.redhat.com/show_bug.cgi?id=1121806
2014-07-21 20:53:05 -04:00
Zbigniew Jędrzejewski-Szmek f7f628b5db Add function to open temp files in selinux mode 2014-07-13 21:11:07 -04:00
Colin Walters a334cbba72 sysusers: preserve label of /etc/{passwd, group}
These files are specially labeled on SELinux systems, and we need to
preserve that label.
2014-07-13 21:10:56 -04:00
Zbigniew Jędrzejewski-Szmek 938a560b76 sysusers: allow overrides in /etc and /run
An administrator might want to block a certain sysusers config file from
being executed, e.g. to block the creation of a certain user.

Only a relatively short description is added in the man page, since
overrides should be relatively rare.
2014-07-10 22:51:41 -04:00
Lennart Poettering 38c74dad1c sysusers: don't allow control characters in gecos fields 2014-07-09 19:22:13 +02:00
Lennart Poettering 932ad62b84 sysusers: don't allow user names longer than UT_NAMESIZE
As pointed out by Miloslav Trmač it might be a good idea to make sure
that usernames stay with in the utmp-defined limits.
2014-07-09 19:22:13 +02:00
Lennart Poettering 45035609fc firstboot: follow lock protocol when changing /etc/shadow 2014-07-07 18:57:09 +02:00
Ronny Chevalier bce415edca sysusers: fix uninitialized warning 2014-07-06 14:16:16 +02:00
Lennart Poettering a12b0cc34d sysusers: add new line type "m" to add users as members to groups 2014-07-03 19:54:46 +02:00
Lennart Poettering 93240d3aba coredump: never write more than the configured processing size limit to disk 2014-06-23 16:28:05 +02:00
Lennart Poettering b0284aba93 sysusers: always treat ENOENT as entry-not-found when doing NSS calls
For most NSS calls it is documented that they return NULL + errno=0 when
an entry is not found. However, in reality it appears to be common to
return NULL + errno=ENOENT, instead. Handle that correctly, and don't
consider ENOENT a systematic error.
2014-06-13 20:11:59 +02:00
Kay Sievers c1b6b04f0e sysusers: do not set todo to create a user when we only need a group 2014-06-13 03:28:54 +02:00
Lennart Poettering 1b99214789 sysusers: add minimal tool to reconstruct /etc/passwd and /etc/group from static files
systemd-sysusers is a tool to reconstruct /etc/passwd and /etc/group
from static definition files that take a lot of inspiration from
tmpfiles snippets. These snippets should carry information about system
users only. To make sure it is not misused for normal users these
snippets only allow configuring UID and gecos field for each user, but
do not allow configuration of the home directory or shell, which is
necessary for real login users.

The purpose of this tool is to enable state-less systems that can
populate /etc with the minimal files necessary, solely from static data
in /usr. systemd-sysuser is additive only, and will never override
existing users.

This tool will create these files directly, and not via some user
database abtsraction layer. This is appropriate as this tool is supposed
to run really early at boot, and is only useful for creating system
users, and system users cannot be stored in remote databases anyway.

The tool is also useful to be invoked from RPM scriptlets, instead of
useradd. This allows moving from imperative user descriptions in RPM to
declarative descriptions.

The UID/GID for a user/group to be created can either be chosen dynamic,
or fixed, or be read from the owner of a file in the file system, in
order to support reconstructing the correct IDs for files that shall be
owned by them.

This also adds a minimal user definition file, that should be
sufficient for most basic systems. Distributions are expected to patch
these files and augment the contents, for example with fixed UIDs for
the users where that's necessary.
2014-06-12 23:07:33 +02:00