Commit graph

100 commits

Author SHA1 Message Date
Lennart Poettering f4f15635ec util-lib: move a number of fs operations into fs-util.[ch] 2015-10-27 13:25:56 +01:00
Michael Chapman 403ed0e5c9 bus-util: support details in CheckAuthorization calls
Extra details for an action can be supplied when calling polkit's
CheckAuthorization method. Details are a list of key/value string pairs.
Custom policy can use these details when making authorization decisions.
2015-09-06 00:07:16 +10:00
Lennart Poettering 5c904ba5a5 time-util: add new get_timezone() call to get local timezone
Let's move the timedated-specific code to time-util.h and make it
generic.
2015-08-26 20:36:42 +02:00
Lennart Poettering 03976f7b4a sd-bus: introduce new sd_bus_flush_close_unref() call
sd_bus_flush_close_unref() is a call that simply combines sd_bus_flush()
(which writes all unwritten messages out) + sd_bus_close() (which
terminates the connection, releasing all unread messages) +
sd_bus_unref() (which frees the connection).

The combination of this call is used pretty frequently in systemd tools
right before exiting, and should also be relevant for most external
clients, and is hence useful to cover in a call of its own.

Previously the combination of the three calls was already done in the
_cleanup_bus_close_unref_ macro, but this was only available internally.

Also see #327
2015-07-03 19:49:03 +02:00
Cristian Rodríguez 6b71bab08d timedate: fix memory leak in timedated
$ /usr/lib/systemd/systemd-timedated (wait until auto-exit)

=================================================================
==396==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 928 byte(s) in 1 object(s) allocated from:
    #0 0x7f782f788db1 in __interceptor_calloc (/usr/lib64/libasan.so.2+0x96db1)
    #1 0x562a83ae60cf in bus_message_from_header src/libsystemd/sd-bus/bus-message.c:480
    #2 0x562a83ae6f5a in bus_message_from_malloc src/libsystemd/sd-bus/bus-message.c:576
    #3 0x562a83ad3cad in bus_socket_make_message src/libsystemd/sd-bus/bus-socket.c:915
    #4 0x562a83ad4cfc in bus_socket_read_message src/libsystemd/sd-bus/bus-socket.c:1051
    #5 0x562a83ab733f in bus_read_message src/libsystemd/sd-bus/sd-bus.c:1647
    #6 0x562a83ab98ea in sd_bus_call src/libsystemd/sd-bus/sd-bus.c:2038
    #7 0x562a83b1f46d in sd_bus_call_method src/libsystemd/sd-bus/bus-convenience.c:94
    #8 0x562a83aab3e1 in context_read_ntp src/timedate/timedated.c:192
    #9 0x562a83aae1af in main src/timedate/timedated.c:730
    #10 0x7f782eb238c4 in __libc_start_main (/lib64/libc.so.6+0x208c4)

Indirect leak of 77 byte(s) in 1 object(s) allocated from:
    #0 0x7f782f788f6a in realloc (/usr/lib64/libasan.so.2+0x96f6a)
    #1 0x562a83ad418a in bus_socket_read_message src/libsystemd/sd-bus/bus-socket.c:963
    #2 0x562a83ab733f in bus_read_message src/libsystemd/sd-bus/sd-bus.c:1647
    #3 0x562a83ab98ea in sd_bus_call src/libsystemd/sd-bus/sd-bus.c:2038
    #4 0x562a83b1f46d in sd_bus_call_method src/libsystemd/sd-bus/bus-convenience.c:94
    #5 0x562a83aab3e1 in context_read_ntp src/timedate/timedated.c:192
    #6 0x562a83aae1af in main src/timedate/timedated.c:730
    #7 0x7f782eb238c4 in __libc_start_main (/lib64/libc.so.6+0x208c4)

Indirect leak of 2 byte(s) in 1 object(s) allocated from:
    #0 0x7f782f75493f in strdup (/usr/lib64/libasan.so.2+0x6293f)
    #1 0x562a83b0229b in bus_message_parse_fields src/libsystemd/sd-bus/bus-message.c:5382
    #2 0x562a83ae7290 in bus_message_from_malloc src/libsystemd/sd-bus/bus-message.c:601
    #3 0x562a83ad3cad in bus_socket_make_message src/libsystemd/sd-bus/bus-socket.c:915
    #4 0x562a83ad4cfc in bus_socket_read_message src/libsystemd/sd-bus/bus-socket.c:1051
    #5 0x562a83ab733f in bus_read_message src/libsystemd/sd-bus/sd-bus.c:1647
    #6 0x562a83ab98ea in sd_bus_call src/libsystemd/sd-bus/sd-bus.c:2038
    #7 0x562a83b1f46d in sd_bus_call_method src/libsystemd/sd-bus/bus-convenience.c:94
    #8 0x562a83aab3e1 in context_read_ntp src/timedate/timedated.c:192
    #9 0x562a83aae1af in main src/timedate/timedated.c:730
    #10 0x7f782eb238c4 in __libc_start_main (/lib64/libc.so.6+0x208c4)

SUMMARY: AddressSanitizer: 1007 byte(s) leaked in 3 allocation(s).

This is due to missing  _cleanup_bus_message_unref_ in context_read_ntp()
2015-05-15 20:00:22 +02:00
Zbigniew Jędrzejewski-Szmek f2bf5007a9 timedated: remove unnecessary goto
Not needed since 99f861310d.
2015-05-06 00:44:52 -04:00
Lennart Poettering 190700621f sd-bus: drop bus parameter from message callback prototype
This should simplify the prototype a bit. The bus parameter is redundant
in most cases, and in the few where it matters it can be derived from
the message via sd_bus_message_get_bus().
2015-04-29 18:36:25 +02:00
Lennart Poettering 10a8700606 tree-wide: get rid of more strerror() calls 2015-04-21 18:05:44 +02:00
Zbigniew Jędrzejewski-Szmek 81b8439902 timedated: fix enable/disable reversal
Bug introduced in 984f1b1d1b. The state was flipped later,
but the enable/disable routine made use of the state to decide
what to do.

context_enable_ntp() and context_start_ntp() now get the desired
state directly, so the Context parameter can be removed.
2015-03-21 19:55:33 -04:00
Zbigniew Jędrzejewski-Szmek 192b98b8fe timedated: flip internal status after executing operation
timedated would set the internal status before calling out to systemd to do
the actual change. When the operation was refused because of a SELinux denial,
the state kept in timedated would get out of sync, and the second call from
timedatectl would appear to succeed.

https://bugzilla.redhat.com/show_bug.cgi?id=1014315
2015-03-21 17:40:57 -04:00
Zbigniew Jędrzejewski-Szmek dc75168823 Use space after a silencing (void)
We were using a space more often than not, and this way is
codified in CODING_STYLE.
2015-03-13 23:42:17 -04:00
David Herrmann 15411c0cb1 tree-wide: there is no ENOTSUP on linux
Replace ENOTSUP by EOPNOTSUPP as this is what linux actually uses.
2015-03-13 14:10:39 +01:00
Shawn Landden 6829cec4dc adjust for time spent in timedated even without dbus timestamp
it is trivial to fall back to our own timestamp

v2: use now()
v3: remove useless if ()
v4: add comment
2015-03-07 08:10:51 -05:00
Shawn Landden 2479df3094 timedated: when performing "SetTime" compensate for program lag
(David: fix up compile-failure and simplify code a bit)
2015-02-26 11:53:33 +01: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 c529695e7a logind: open up most bus calls for unpriviliged processes, using PolicyKit
Also, allow clients to alter their own objects without any further
priviliges. i.e. this allows clients to kill and lock their own sessions
without involving PK.
2015-02-18 12:55:25 +01:00
Lennart Poettering d7b8eec7dc tmpfiles: add new line type 'v' for creating btrfs subvolumes 2014-12-28 02:08:40 +01:00
Filipe Brandenburger 88c4911768 timedated: remove spurious include of <sys/capability.h>
It does not use any functions from libcap directly. The CAP_SYS_TIME constant
in use by this file comes from <linux/capability.h> imported through "missing.h".

Tested that "systemd-timedated" builds cleanly and works after this change.
2014-12-25 10:57:16 -05:00
Lennart Poettering 96aad8d15a sd-bus: move common errors src/shared/bus-errors.h → src/libsystemd/sd-bus/bus-common-errors.h
Stuff in src/shared/ should not use stuff from src/libsystemd/ really.
2014-12-10 19:07:48 +01:00
Lennart Poettering 5f86c1f4c4 sd-bus: rework ELF error mapping table magic
The ELF magic cannot work for consumers of our shard library, since they
are in a different module. Hence make all the ELF magic private, and
instead introduce a public function to register additional static
mapping table.
2014-12-08 14:55:22 +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 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
Lennart Poettering e2cc6eca73 log: fix order of log_unit_struct() to match other logging calls
Also, while we are at it, introduce some syntactic sugar for creating
ERRNO= and MESSAGE= structured logging fields.
2014-11-28 02:18:46 +01:00
Zbigniew Jędrzejewski-Szmek fedfcdee6f Make bus errno mappings non-static
__attribute__((used)) is not enough to force static variables to
be carried over to a compiled program from a library. Mappings defined
in libsystemd-shared.a were not visible in the compiled binaries.
To ensure that the mappings are present in the final binary, the
tables are made non-static and are given a real unique name by which
they can be referenced.

To use a mapping defined not in the local compilation unit (e.g. in
a library) a reference to the mapping table is added. This is done
by including a declaration in the header file.

Expected values in test-engine are fixed to reflect the new mappings.
2014-10-31 11:32:00 -04:00
Zbigniew Jędrzejewski-Szmek 7358dc029a Convert the rest to sd_bus_errnomap
I tried to preserve most errno values, but in some cases they were
inconsistent (different errno values for the same error name) or just
mismatched.
2014-10-30 20:38:28 -04:00
WaLyong Cho cc56fafeeb mac: rename apis with mac_{selinux/smack}_ prefix 2014-10-23 17:13:15 +02:00
Lennart Poettering f38857914a bus-util: simplify bus_verify_polkit_async() a bit
First, let's drop the "bus" argument, we can determine it from the
message anyway.

Secondly, determine the right callback/userdata pair automatically from
what is currently is being dispatched. This should simplify things a lot
for us, since it makes it unnecessary to pass pointers through the
original handlers through all functions when we process messages, which
might require authentication.
2014-08-18 17:49:53 +02:00
Lennart Poettering b5af2aca12 Merge commit 'b39a2770ba55637da80e2e389222c59dbea73507' 2014-08-15 20:25:10 +02:00
Lennart Poettering def9a7aa01 sd-bus: add API to check if a client has privileges
This is a generalization of the vtable privilege check we already have,
but exported, and hence useful when preparing for a polkit change.

This will deal with the complexity that on dbus1 one cannot trust the
capability field we retrieve via the bus, since it is read via
/proc/$$/stat (and thus might be out-of-date) rather than directly from
the message (like on kdbus) or bus connection (as for uid creds on
dbus1).

Also, port over all code to this new API.
2014-08-15 20:08:51 +02:00
Stef Walter 36e34057a2 sd-bus: Remove bus arg from bus_verify_polkit_async_registry_free()
It's unneccessary, not used, and complicates callers of the
function.
2014-08-15 14:07:07 +02:00
Lennart Poettering 249968612f bus: always explicitly close bus from main programs
Since b5eca3a205 we don't attempt to GC
busses anymore when unsent messages remain that keep their reference,
when they otherwise are not referenced anymore. This means that if we
explicitly want connections to go away, we need to close them.

With this change we will no do so explicitly wherver we connect to the
bus from a main program (and thus know when the bus connection should go
away), or when we create a private bus connection, that really should go
away after our use.

This fixes connection leaks in the NSS and PAM modules.
2014-08-04 16:25:24 +02:00
Kay Sievers b72ddf0f4f timedated: manage systemd-timesyncd directly instead of lists of alternatives
Alternative NTP implementations should add a:
  Conflicts=systemd-timesyncd.service
to take over the built-in NTP functionality of systemd.
2014-07-09 17:04:11 +02:00
Lennart Poettering 7568345034 shared: make timezone and locale enumeration and validation generic
This way we can reuse it other code thatn just localectl/localed +
timedatectl/timedated.
2014-07-07 15:25:55 +02:00
Kay Sievers 82d115d9ab timedated: refuse manual system time updates when automatic timesync is enabled 2014-05-24 10:45:44 +08:00
Kay Sievers 609896125c clock-util: clock_[sg]et_time() -> clock_[sg]et_hwclock() 2014-05-24 10:26:33 +08:00
Kay Sievers 24efb11245 shared: rename hwclock.[ch] to clock-util.[ch] 2014-05-24 07:56:20 +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 19befb2d5f sd-bus: introduce sd_bus_slot objects encapsulating callbacks or vtables attached to a bus connection
This makes callback behaviour more like sd-event or sd-resolve, and
creates proper object for unregistering callbacks.

Taking the refernce to the slot is optional. If not taken life time of
the slot will be bound to the underlying bus object (or in the case of
an async call until the reply has been recieved).
2014-05-15 01:15:30 +02:00
Jason St. John 07a062a793 timedate: fix numerous grammar errors in comments and output/debug messages 2014-03-24 20:49:34 +01:00
Miklos Vajna 6f285378aa core, libsystemd, systemd, timedate, udev: spelling fixes 2014-03-17 02:35:35 -04:00
Lennart Poettering 37224a5ff5 bus: fix exit-on-idle for driverd 2013-12-19 22:18:39 +01:00
Lennart Poettering 6203e07a83 event: rework sd-event exit logic
With this change a failing event source handler will not cause the
entire event loop to fail. Instead, we just disable the specific event
source, log a message at debug level and go on.

This also introduces a new concept of "exit code" which can be stored in
the event loop and is returned by sd_event_loop(). We also rename "quit"
to "exit" everywhere else.

Altogether this should make things more robus and keep errors local
while still providing a way to return event loop errors in a clear way.
2013-12-13 04:06:43 +01:00
Kay Sievers 5bb658a178 bus: remove explicit activator-specific flags, the kdbus supports it now 2013-12-12 20:27:23 +01:00
Kay Sievers d90bb66996 bus: add SD_BUS_NAME_REPLACE_EXISTING to all activatable services, fix one flags conversion 2013-12-12 06:41:23 +01:00
Lennart Poettering 29a07cdb4a bus: instead of exposing the dbus1 flags when acquiring a name use our own that are closer to kdbus
This turns around DO_NOT_QUEUE into QUEUE which implies a more useful
default. (And negative options are awful anyway.)
2013-12-12 05:55:58 +01:00
Lennart Poettering fe2b58a4ff timedated: make sure GetAll() succeeds in systems lacking /dev/rtc (such as containers) 2013-12-12 03:06:21 +01:00
Lennart Poettering cde93897cd event: hook up sd-event with the service watchdog logic
Adds a new call sd_event_set_watchdog() that can be used to hook up the
event loop with the watchdog supervision logic of systemd. If enabled
and $WATCHDOG_USEC is set the event loop will ping the invoking systemd
daemon right after coming back from epoll_wait() but not more often than
$WATCHDOG_USEC/4. The epoll_wait() will sleep no longer than
$WATCHDOG_USEC/4*3, to make sure the service manager is called in time.

This means that setting WatchdogSec= in a .service file and calling
sd_event_set_watchdog() in your daemon is enough to hook it up with the
watchdog logic.
2013-12-11 18:20:09 +01:00
Lennart Poettering adacb9575a bus: introduce "trusted" bus concept and encode access control in object vtables
Introduces a new concept of "trusted" vs. "untrusted" busses. For the
latter libsystemd-bus will automatically do per-method access control,
for the former all access is automatically granted. Per-method access
control is encoded in the vtables: by default all methods are only
accessible to privileged clients. If the SD_BUS_VTABLE_UNPRIVILEGED flag
is set for a method it is accessible to unprivileged clients too. By
default whether a client is privileged is determined via checking for
its CAP_SYS_ADMIN capability, but this can be altered via the
SD_BUS_VTABLE_CAPABILITY() macro that can be ORed into the flags field
of the method.

Writable properties are also subject to SD_BUS_VTABLE_UNPRIVILEGED and
SD_BUS_VTABLE_CAPABILITY() for controlling write access to them. Note
however that read access is unrestricted, as PropertiesChanged messages
might send out the values anyway as an unrestricted broadcast.

By default the system bus is set to "untrusted" and the user bus is
"trusted" since per-method access control on the latter is unnecessary.

On dbus1 busses we check the UID of the caller rather than the
configured capability since the capability cannot be determined without
race. On kdbus the capability is checked if possible from the attached
meta-data of a message and otherwise queried from the sending peer.

This also decorates the vtables of the various daemons we ship with
these flags.
2013-12-10 16:52:49 +00:00