chiark / gitweb /
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)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:58:48 +0000 (07:58 +0200)
commit89dd80deba5dc00e263f543287a66752caf4e55c
treedb33eb2aef1dce9a696e4ca1c43d70fd1e7fc69e
parent5cef9f46e2e33b6843310531dd7f283537c30465
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
src/basic/conf-files.c
src/basic/conf-files.h