sysusers: allow admin/runtime overrides to command-line config
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 31 Jan 2018 14:37:02 +0000 (15:37 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 2 Feb 2018 09:40:22 +0000 (10:40 +0100)
commitd16a1c1bb69e5f36e0eb41ed86670224d2e5ecda
tree133af561f08f9ad213d538674a8865129319153e
parent6e888894fc043a023731129ae4eb8ae5633e9f97
sysusers: allow admin/runtime overrides to command-line config

When used in a package installation script, we want to invoke systemd-sysusers
before that package is installed (so it can contain files owned by the newly
created user), so the configuration to use is specified on the command
line. This should be a copy of the configuration that will be installed as
/usr/lib/sysusers.d/package.conf. We still want to obey any overrides in
/etc/sysusers.d or /run/sysusers.d in the usual fashion. Otherwise, we'd get a
different result when systemd-sysusers is run with a copy of the new config on
the command line and when systemd-sysusers is run at boot after package
instalation. In the second case any files in /etc or /run have higher priority,
so the same should happen when the configuration is given on the command line.
More generally, we want the behaviour in this special case to be as close to
the case where the file is finally on disk as possible, so we have to read all
configuration files, since they all might contain overrides and additional
configuration that matters. Even files that have lower priority might specify
additional groups for the user we are creating. Thus, we need to read all
configuration, but insert our new configuration somewhere with the right
priority.

If --target=/path/to/file.conf is given on the command line, we gather the list
of files, and pretend that the command-line config is read from
/path/to/file.conf (doesn't matter if the file on disk actually exists or
not). All package scripts should use this option to obtain consistent and
idempotent behaviour.

The corner case when --target= is specified and there are no positional
arguments is disallowed.

v1:
- version with --config-name=
v2:
- disallow --config-name= and no positional args
v3:
- remove --config-name=
v4:
- add --target= and rework the code completely
v5:
- fix argcounting bug and add example in man page
v6:
- rename --target to --replace
man/systemd-sysusers.xml
src/basic/conf-files.c
src/basic/conf-files.h
src/sysusers/sysusers.c