Commit Graph

205 Commits

Author SHA1 Message Date
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
Lennart Poettering 849958d1ba tmpfiles: add new "C" line for copying files or directories 2014-06-10 23:02:40 +02:00
Lennart Poettering 13f8b8cbb4 bus-proxy: properly index policy by uid/gid when parsing 2014-06-10 17:56:52 +02:00
Lennart Poettering d6797c920e namespace: beef up read-only bind mount logic
Instead of blindly creating another bind mount for read-only mounts,
check if there's already one we can use, and if so, use it. Also,
recursively mark all submounts read-only too. Also, ignore autofs mounts
when remounting read-only unless they are already triggered.
2014-06-06 14:37:40 +02:00
Lennart Poettering 6d313367d9 namespace: when setting up an inaccessible mount point, unmounting everything below
This has the benefit of not triggering any autofs mount points
unnecessarily.
2014-06-05 21:35:35 +02:00
Kay Sievers c38dfac9ed shared: add touch_file() and let touch() always update timestamp 2014-05-24 07:21:11 +08:00
Lennart Poettering 878cd7e95c machined: add logic to query IP addresses of containers 2014-05-18 20:52:49 +09:00
Zbigniew Jędrzejewski-Szmek de0671ee7f Remove unnecessary casts in printfs
No functional change expected :)
2014-05-15 15:29:58 +02:00
Lennart Poettering 856a5a7d76 timesyncd: lookup name server via sd-resolve, support IPv6, react to SIGINT/SITERM 2014-05-05 23:53:17 +02:00
Lennart Poettering 6b01f1d391 delta: draw arrows with draw_special_char()
Let's unify generation of unicode chars at one place.

Also, don't add an extra space into chars we print, except for the tree
chars where this is really necessary.
2014-04-23 19:06:39 +02:00
Michael Olbrich c5220a940d systemctl: delete REBOOT_PARAM_FILE if no parameter is specified
And move it to sperate function.
2014-04-21 09:58:53 -04:00
Dave Reisner 370c860f74 implement a union to pad out file_handle
Cases where name_to_handle_at is used allocated the full struct to be
MAX_HANDLE_SZ, and assigned this size to handle_bytes. This is wrong
since handle_bytes should describe the length of the flexible array
member and not the whole struct.

Define a union type which includes sufficient padding to allow
assignment of MAX_HANDLE_SZ to be correct.
2014-04-21 09:52:08 -04:00
Zbigniew Jędrzejewski-Szmek ca2d378414 Unify GREEDY_REALLOC and GREEDY_REALLOC_T
greedy_realloc() and greedy_realloc0() now store the allocated
size as the count, not bytes.

Replace GREEDY_REALLOC uses with GREEDY_REALLOC_T everywhere,
and then rename GREEDY_REALLOC_T to GREEDY_REALLOC. It is just
too error-prone to have two slightly different macros which do the
same thing.
2014-04-12 10:20:55 -04:00
Lennart Poettering 3d94f76c99 util: replace close_pipe() with new safe_close_pair()
safe_close_pair() is more like safe_close(), except that it handles
pairs of fds, and doesn't make and misleading allusion, as it works
similarly well for socketpairs() as for pipe()s...
2014-03-24 03:22:44 +01:00
Lennart Poettering 03e334a1c7 util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed,
and returns -1 unconditionally. This makes it easy to write lines like
this:

        fd = safe_close(fd);

Which will close an fd if it is open, and reset the fd variable
correctly.

By making use of this new scheme we can drop a > 200 lines of code that
was required to test for non-negative fds or to reset the closed fd
variable afterwards.
2014-03-18 19:31:34 +01:00
Zbigniew Jędrzejewski-Szmek 8fe90522fb timedated: use builtins for integer log and exp 2014-03-14 21:44:20 -04:00
Lennart Poettering 29bfbcd675 util: add hexdump() call to create pretty hexdumps of data
This is very useful when debugging sd-bus to look at messages.
2014-03-14 21:17:14 +01:00
Michael Marineau 4cf7ea556a shared: add root argument to search_and_fopen
This adds the same root argument to search_and_fopen that
conf_files_list already has. Tools that use those two functions as a
pair can now be easily modified to load configuration files from an
alternate root filesystem tree.
2014-03-14 09:31:34 -04:00
Josh Triplett 01f83c1c76 util: Make in_charset a static inline in util.h
With in_charset now reduced to a one-liner (plus asserts), make it a
static inline.
2014-03-12 17:02:09 +01:00
Harald Hoyer f39d4a08e7 systemctl: for switch-root check, if we switch to a systemd init
If "systemctl switch-root" is called with a specific "INIT" or
/proc/cmdline contains "init=", then systemd would not serialize
itsself.

Let systemctl check, if the new init is in the standard systemd
installation path and if so, clear the INIT parameter,
to let systemd serialize itsself.
2014-03-11 04:45:33 +01:00
Harald Hoyer 9d9951a460 util: add files_same() helper function
files_same() returns
     1, if the files are the same
     0, if the files have different inode/dev numbers
 errno, for any stat error
2014-03-11 04:34:06 +01:00
Lennart Poettering 6db615c17e fstab-generator: merge /proc/cmdline parsing loops into one 2014-03-07 02:40:24 +01:00
Lennart Poettering 059cb3858a util: move more intellegince into parse_proc_cmdline()
Already split variable assignments before invoking the callback. And
drop "rd." settings if we are not in an initrd.
2014-03-06 18:48:22 +01:00
Lennart Poettering aa62a8936f util: add timeout to generator execution 2014-03-06 04:00:42 +01:00
Lennart Poettering 1c231f5648 logind: make $XDG_RUNTIME_DIR a per-user tmpfs
This way each user allocates from his own pool, with its own size limit.

This puts the size limit by default to 10% of the physical RAM size but
makes it configurable in logind.conf.
2014-03-04 20:02:50 +01:00
David Herrmann a1937e679f login: fix pos-array allocation
GREEDY_REALLOC takes a pointer to the real size, not the array-width as
argument. Therefore, our array is currently way to small to keep the seat
positions.

Introduce GREEDY_REALLOC0_T() as typed version of GREEDY_REALLOC and store
the array-width instead of array-size.
2014-02-25 12:22:31 +01:00
Lennart Poettering 5556b5fe41 core: clean up some confusing regarding SI decimal and IEC binary suffixes for sizes
According to Wikipedia it is customary to specify hardware metrics and
transfer speeds to the basis 1000 (SI decimal), while software metrics
and physical volatile memory (RAM) sizes to the basis 1024 (IEC binary).
So far we specified everything in IEC, let's fix that and be more
true to what's otherwise customary. Since we don't want to parse "Mi"
instead of "M" we document each time what the context used is.
2014-02-23 03:19:04 +01:00
Lennart Poettering ac45f971a1 core: add Personality= option for units to set the personality for spawned processes 2014-02-19 03:27:03 +01:00
Lennart Poettering 6afc95b736 nspawn: add new --personality= switch to make it easier to run 32bit containers on a 64bit host 2014-02-18 23:37:27 +01:00
Lennart Poettering 9f5650aecb util: generalize code that checks whether PIDs are alive or unwaited for 2014-02-18 02:51:47 +01:00
Lennart Poettering b6e2f3293d core: fixate show_status earlier, so that we actually print the welcome message
Previously, we'd fixed show_state only after printing the welcome
message which had the effect that the welcome message was almost always
suppressed.
2014-02-17 16:17:08 +01:00
Zbigniew Jędrzejewski-Szmek 141a79f491 Extract looping over /proc/cmdline into a shared function
In cryptsetup-generator automatic cleanup had to be replaced
with manual cleanup, and the code gets a bit longer. But existing
code had the issue that it returned negative values from main(),
which was wrong, so should be reworked anyway.
2014-02-17 02:26:22 -05:00
Zbigniew Jędrzejewski-Szmek 93b5eaec70 Fix prototype of get_process_state 2014-02-14 23:15:42 -05:00
Yuxuan Shui e10c9985bb core: fix detection of dead processes
Commit 5ba6985b moves the UNIT_VTABLE(u)->sigchld_event before systemd
actually reaps the zombie. Which leads to service_load_pid_file accepting
zombie as a valid pid.

This fixes timeouts like:
[ 2746.602243] systemd[1]: chronyd.service stop-sigterm timed out. Killing.
[ 2836.852545] systemd[1]: chronyd.service still around after SIGKILL. Ignoring.
[ 2927.102187] systemd[1]: chronyd.service stop-final-sigterm timed out. Killing.
[ 3017.352560] systemd[1]: chronyd.service still around after final SIGKILL. Entering failed mode.
2014-02-14 20:47:52 -05:00
Lennart Poettering c50e4f95d8 util: drop parse_user_at_host() since its unused now 2014-02-11 17:16:07 +01:00
Lennart Poettering fdb9161cd3 conf-parser: warn when we open configuration files with weird access bits 2014-02-03 19:59:18 +01:00
Lennart Poettering ec417ccc27 util: add u32ctz() call for determining ctz of uint32_t 2014-01-30 16:47:18 +01:00
Lennart Poettering b89446bb33 util: introduce new dev_urandom() call that is like random_bytes() but doesn't fall back to PRNG 2014-01-28 13:07:28 +01:00
Zbigniew Jędrzejewski-Szmek 65b3903ff5 journal: guarantee async-signal-safety in sd_journald_sendv
signal(7) provides a list of functions which may be called from a
signal handler. Other functions, which only call those functions and
don't access global memory and are reentrant are also safe.
sd_j_sendv was mostly OK, but would call mkostemp and writev in a
fallback path, which are unsafe.

Being able to call sd_j_sendv in a async-signal-safe way is important
because it allows it be used in signal handlers.

Safety is achieved by replacing mkostemp with open(O_TMPFILE) and an
open-coded writev replacement which uses write. Unfortunately,
O_TMPFILE is only available on kernels >= 3.11. When O_TMPFILE is
unavailable, an open-coded mkostemp is used.

https://bugzilla.gnome.org/show_bug.cgi?id=722889
2014-01-27 23:17:02 -05:00
Zbigniew Jędrzejewski-Szmek 8e33886ec5 Replace mkostemp+unlink with open(O_TMPFILE)
This will only work on Linux >= 3.11, and probably not on all
filesystems. Fallback code is provided.
2014-01-27 23:17:02 -05:00
Tom Gundersen 2c3d81d4a7 DEFINE_STRING_TABLE_LOOKUP: return _INVALID_* rather than assert on NULL string 2014-01-22 17:56:49 +01:00
Simon Peeters bf85c24daa shared: util.c: unify split and split_quoted 2014-01-05 09:16:15 -05:00
Simon Peeters b68fa010f7 shared: procfs_file_alloca: handle pid==0
when pid is set to 0 use /proc/self
2014-01-05 00:59:13 -05:00
Zbigniew Jędrzejewski-Szmek ccd06097c7 Use format patterns for usec_t, pid_t, nsec_t, usec_t
It is nicer to predefine patterns using configure time check instead of
using casts everywhere.

Since we do not need to use any flags, include "%" in the format instead
of excluding it like PRI* macros.
2014-01-02 19:45:47 -05:00
Zbigniew Jędrzejewski-Szmek e3e0314b56 systemctl: allow globbing in commands which take multiple unit names 2013-12-26 13:24:36 -05:00
Lennart Poettering 693eb9a2d4 bus: rename message "serial" to "cookie"
Even if the lower-leveld dbus1 protocol calls it "serial", let's expose
the word "cookie" for this instead, as this is what kdbus uses and since
it doesn't imply monotonicity the same way "serial" does.
2013-12-25 18:04:04 +01:00
Lennart Poettering eff0527098 util: unify SO_PEERCRED/SO_PEERSEC invocations
Introduce new call getpeercred() which internally just uses SO_PEERCRED
but checks if the returned data is actually useful due to namespace
quirks.
2013-12-24 15:53:04 +01:00
Lennart Poettering 9bf3b53533 shared: switch our hash table implementation over to SipHash
SipHash appears to be the new gold standard for hashing smaller strings
for hashtables these days, so let's make use of it.
2013-12-22 21:12:25 +01:00
Florian Weimer 4ff4ebb1fb util: remove union dirent_storage 2013-12-21 18:35:55 -05:00
Lennart Poettering bf108e5541 service: watch main pid even in final states
In some circumstances, for example when start-up times out we
immediately jump into the final state, at which point we still should
try to watch the main pid so that the SIGCHLD allows us to quickly
move into dead state.
2013-12-18 18:21:27 +01:00