summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus
AgeCommit message (Collapse)Author
2015-09-07sd-bus: when connecting to a container AF_UNIX bus, return errorLennart Poettering
When forking of a child process for connecting to a container, pass the preicse connection error to the calling process. We already did this correctly for kdbus busses, let's do so for dbus1 busses, too.
2015-09-06Merge pull request #1162 from dvdhrm/bus-recursive-nodesLennart Poettering
sd-bus: make introspection data non-recursive
2015-09-05sd-bus: make introspection data non-recursiveDavid Herrmann
Currently, our introspection data looks like this: <node> <interface name="org.freedesktop.DBus.Peer"> ... </interface> <interface name="org.freedesktop.DBus.Introspectable"> ... </interface> <interface name="org.freedesktop.DBus.Properties"> ... </interface> <node name="org"/> <node name="org/freedesktop"/> <node name="org/freedesktop/login1"/> <node name="org/freedesktop/login1/user"/> <node name="org/freedesktop/login1/user/self"/> <node name="org/freedesktop/login1/user/_1000"/> <node name="org/freedesktop/login1/seat"/> <node name="org/freedesktop/login1/seat/self"/> <node name="org/freedesktop/login1/seat/seat0"/> <node name="org/freedesktop/login1/session"/> <node name="org/freedesktop/login1/session/self"/> <node name="org/freedesktop/login1/session/c1"/> </node> (ordered alphabetically for better visibility) This is grossly incorrect. The spec says that we're allowed to return non-directed children, however, it does not allow us to return data recursively in multiple parents. If we return "org", then we must not return anything else that starts with "org/". It is unclear, whether we can include child-nodes as a tree. Moreover, it is usually not what the caller wants. Hence, this patch changes sd-bus to never return introspection data recursively. Instead, only a single child-layer is returned. This patch relies on enumerators to never return hierarchies. If someone registers an enumerator via sd_bus_add_enumerator, they better register sub-enumerators if they support *TRUE* hierarchies. Each enumerator is treated as a single layer and not filtered. Enumerators are still allowed to return nested data. However, that data is still required to be a single hierarchy. For instance, returning "/org/foo" and "/com/bar" is fine, but including "/com" or "/org" in that dataset is not. This should be the default for enumerators and I see no reason to filter in sd-bus. Moreover, filtering that data-set would require to sort the strv by path and then do prefix-filtering. This is O(n log n), which would be fine, but still better to avoid. Fixes #664.
2015-09-05sd-bus: derive uid from cgroup if possibleDavid Herrmann
Whenever we run in a user context, sd_bus_{default_user,open_user}() and friends should always connect to the user-bus of the current context, instead of deriving the uid from getuid(). This allows us running programs via sudo/su, without the nasty side-effect of accidentally connecting to the root user-bus. This patch enforces the idea of making su/sudo *not* opening sessions by default. That is, all they do is raising privileges, but keeping everything set as before. You can still use su/sudo to open real sessions by requesting a login-session (or loading pam_systemd otherwise). However, in this case XDG_RUNTIME_DIR= will not be set (as usual in these cases), hence, you will not be able to connect to *any* user-bus. Long story short: With this patch applied, both: - ./busctl --user - sudo ./busctl --user ..will successfully connect to the user-bus of the local user. Fixes #390.
2015-09-05Merge pull request #1140 from poettering/sd-event-signalsDavid Herrmann
A variety of sd-event, sd-login and cgroup fixes
2015-09-04tests: Skip tests which need to access /sys/fs/cgroup if that is not availableMartin Pitt
Commit efdb023 ("core: unified cgroup hierarchy support") introduced a new error ENOEXEC in cg_unified() if /sys/fs/cgroup/ is not available. Adjust the "skip" checks in various tests accordingly. Add a corresponding "skip" check to test-bus-creds as well, as sd_bus_creds_new_from_pid() now calls cg_unified() as well. This re-fixes "make check" in build chroots without /sys/fs/cgroup. https://github.com/systemd/systemd/issues/1132
2015-09-04audit: audit calls should return ENODATA when process are not in an audit ↵Lennart Poettering
session ENODATA is how we usually indicate such "missing info" cases, so we should do this here, too.
2015-09-01sd-bus: when connecting to a container, don't fall back to host busLennart Poettering
We should never connect to the host bus as fallback if connecting to a container failed via one method. Otherwise connecting to a dbus1 container will always result in a connection to the host.
2015-09-01sd-bus: when connecting to a kdbus container bus pass error upLennart Poettering
We rely on the correct error used when opening the kdbus device node, hence let's make sure we pass it up from the namespaced child process to the process which actually wants to connect.
2015-08-30sd-bus: Fix incorrect cleanup attribute in bus_match_to_string()Cristian Rodríguez
Must be _cleanup_fclose_ not _cleanup_free_
2015-08-27Merge pull request #1055 from poettering/dhcp-updatesTom Gundersen
Various networkd and dhcp updates
2015-08-27sd-bus: do not connect to dbus-1 socket when kdbus is availableDavid Herrmann
We should not fall back to dbus-1 and connect to the proxy when kdbus returns an error that indicates that kdbus is running but just does not accept new connections because of quota limits or something similar. Based on a patch by Kay.
2015-08-27Revert "sd-bus: do not connect to dbus-1 socket when kdbus is available"David Herrmann
This reverts commit d4d00020d6ad855d65d31020fefa5003e1bb477f. The idea of the commit is broken and needs to be reworked. We really cannot reduce the bus-addresses to a single address. We always will have systemd with native clients and legacy clients at the same time, so we also need both addresses at the same time.
2015-08-27sd-bus: rename bloom-tag to arg0-hasDavid Herrmann
We use dashes in our bloom-tags. Make sure the newly introduced arg0has tag uses the same style. Note that the external dbus-tags don't use dashes, though. They are defined in the spec and we need to keep compatibility there.
2015-08-27Merge pull request #1036 from poettering/sd-bus-arg0hasDavid Herrmann
sd-bus: introduce new match type "arg0has=" for matching arrays of st…
2015-08-27Merge pull request #1024 from poettering/sd-bus-explicitDavid Herrmann
sd-bus: introduce new SD_BUS_VTABLE_PROPERTY_EXPLICIT flag
2015-08-27sd-bus: it's not a user error to query the error contained in a bus messageLennart Poettering
It's an OK way to check whether a message contains an erro, let's not consider this a loggable assertion event.
2015-08-25sd-bus: introduce new match type "arg0has=" for matching arrays of stringsLennart Poettering
Previously, sd-bus inofficially already supported bus matches that tested a string against an array of strings ("as"). This was done via an enhanced way to interpret "arg0=" matches. This is problematic however, since clients have no way to determine if their respective implementation understood strv matches or not, thus allowing invalid matches to be installed without a way to detect that. This patch changes the logic to only allow such matches with a new "arg0has=" syntax. This has the benefit that non-conforming implementations will return a parse error and a client application may thus efficiently detect support for the match type. Matches of this type are useful for "udev"-like systems that "tag" objects with a number of strings, and clients need to be able to match against any of these "tags". The name "has" takes inspiration from Python's ".has_key()" construct.
2015-08-25sd-bus: introduce new SD_BUS_VTABLE_PROPERTY_EXPLICIT flagLennart Poettering
This allows marking properties as "explicit". Properties marked like this are included in the introspection, but are avoided in GetAll() property queries, PropertiesChanged() signals and in in GetManaged() object manager calls and InterfacesAdded() signals. Expensive properties may be marked that way, and they will be retrievable when explicitly being requested, but never in "blanket" all-property queries and signals. This flag may be combined with the flags for "const" and "emit-validation" properties, but not with "emit-validation", as that is only useful for properties whose value shall be sent in "blanket" all-property signals. The "explicit" flag is also exposed in the introspection data via a new annotation.
2015-08-24util: make machine_name_is_valid() a macro and move it to hostname-util.hLennart Poettering
As it turns out machine_name_is_valid() does the exact same thing as hostname_is_valid() these days, as it just invoked that and checked the name length was < 64. However, hostname_is_valid() checks the length against HOST_NAME_MAX anyway (which is 64 on Linux), hence any additional check is redundant. We hence replace machine_name_is_valid() by a macro that simply maps it to hostname_is_valid() but sets the allow_trailing_dot parameter to false. We also move this this call to hostname-util.h, to the same place as the hostname_is_valid() declaration.
2015-08-24sd-bus: don't list activators as proper peersDavid Herrmann
If a connection passed KDBUS_HELLO_ACTIVATOR, it cannot do I/O on the bus. Hence, we should not treat it as proper peer. To actually query it, you have to explicitly ask for activators. This makes kdbus in-line with what dbus-daemon does.
2015-08-24Revert "sd-bus: include queried path in GetManagedObjects"David Herrmann
This reverts commit 92d16a53e385781a55d9231d9f8f89c1747ab0e4. As it turns out, this is not how ObjectManager is supposed to work. It is just a special behavior of BlueZ, but no-one else implements it this way. Revert the patch as discussed on github, and as such revert to the previous behavior (as described in the spec).
2015-08-17Merge pull request #977 from richardmaw-codethink/machinectl-userns-login-v2Lennart Poettering
Fix machinectl login with containers in user namespaces (v2)
2015-08-17Merge pull request #976 from elfring/Remove_unnecessary_checks2Lennart Poettering
Delete unnecessary checks before some function calls
2015-08-17namespace helpers: Allow entering a UID namespaceRichard Maw
To be able to use `systemd-run` or `machinectl login` on a container that is in a private user namespace, the sub-process must have entered the user namespace before connecting to the container's D-Bus, otherwise the UID and GID in the peer credentials are garbage. So we extend namespace_open and namespace_enter to support UID namespaces, and we enter the UID namespace in bus_container_connect_{socket,kernel}. namespace_open will degrade to a no-op if user namespaces are not enabled in the kernel. Special handling is required for the setns call in namespace_enter with a user namespace, since transitioning to your own namespace is forbidden, as it would result in re-entering your user namespace as root. Arguably it may be valid to check this at the call site, rather than inside namespace_enter, but it is less code to do it inside, and if the intention of calling namespace_enter is to *be* in the target namespace, rather than to transition to the target namespace, it is a reasonable approach. The check for whether the user namespace is the same must happen before entering namespaces, as we may not be able to access /proc during the intermediate transition stage. We can't instead attempt to enter the user namespace and then ignore the failure from it being the same namespace, since the error code is not distinct, and we can't compare namespaces while mid-transition.
2015-08-17Bug #944: Deletion of unnecessary checks before a few calls of systemd functionsMarkus Elfring
The following functions return immediately if a null pointer was passed. * calendar_spec_free * link_address_free * manager_free * sd_bus_unref * sd_journal_close * udev_monitor_unref * udev_unref It is therefore not needed that a function caller repeats a corresponding check. This issue was fixed by using the software Coccinelle 1.0.1.
2015-08-17Merge pull request #953 from poettering/ebadfDaniel Mack
tree-wide: generate EBADF when we get invalid fds
2015-08-17Bug #944: Replacement of a free() call by mfree()Markus Elfring
The function "mfree" should be called instead of "free" at a specific source code place.
2015-08-16sd-bus: always fill in sd_bus_error paramters, on errorLennart Poettering
Whenever one of our calls is invoked with a non-NULL, writable sd_bus_error parameter, let's fill in some valid error on failure. We previously only filled in remote errors, but never local errors, which is hard to handle by users. Hence, let's clean this up to always fill in the error. This introduces a new bus_assert_return() macro that works like assert_return() but optionally also initializes a bus_error struct. Fixes #224. Based on a patch by Umut Tezduyar.
2015-08-14tree-wide: generate EBADF when we get invalid fdsLennart Poettering
This is a follow-up to #907, and makes the same change for all our other public APIs.
2015-08-11 sd-bus: do not connect to dbus-1 socket when kdbus is availableKay Sievers
We should not fall back to dbus-1 and connect to the proxy when kdbus returns an error that indicates that kdbus is running but just does not accept new connections because of quota limits or something similar. Using is_kdbus_available() in libsystemd/ requires it to move from shared/ to libsystemd/. Based on a patch from David Herrmann: https://github.com/systemd/systemd/pull/886
2015-08-08Coverity #1299015reverendhomer
bus can never be NULL due to assert
2015-08-06sd-bus: ignore BLOOM_FILTER kdbus itemsLennart Poettering
The kernel nowadays sends these along, and that's OK, hence don't even debug log about it, but completely ignore it.
2015-08-06tree-wide: fix indentationThomas Hindoe Paaboel Andersen
2015-08-02sd-bus: cleanup bus_reset_parsed_address()Namhyung Kim
Both strv_free() and mfree() return NULL pointer after free.
2015-08-02sd-bus: use mfree() in bus_reset_queues()Namhyung Kim
Recently mfree() was introduced to reduce work of tedious free + reset pointers. Use it in bus_reset_queues() too.
2015-08-02sd-bus: cleanup bus_close_fds()Namhyung Kim
The safe_close() already checks the fd and returns -1.
2015-07-31Merge pull request #813 from dvdhrm/bus-clientLennart Poettering
busctl: make sure --address connects as bus-client
2015-07-31Merge pull request #814 from dvdhrm/mfreeDaniel Mack
tree-wide: introduce mfree()
2015-07-31busctl: make sure --address connects as bus-clientDavid Herrmann
There is really no reason to use `busctl` to connect to legacy private bus endpoints. Fix this and make sure `busctl --address=unix:path=/foo` works!
2015-07-31tree-wide: introduce mfree()David Herrmann
Pretty trivial helper which wraps free() but returns NULL, so we can simplify this: free(foobar); foobar = NULL; to this: foobar = mfree(foobar);
2015-08-01busctl: fix assertion failure on --size optionNamhyung Kim
Using --size option triggers an assert failure below because parse_size() requires the second argument, base, being either 1000 or 1024. As it's for a packet size, it'd be better using IEC binary suffix (base 1024) IMHO. $ busctl --size 2048 Assertion 'base == 1000 || base == 1024' failed at src/basic/util.c:2222, function parse_size(). Aborting. Aborted (core dumped)
2015-08-01busctl: add missing description of --size optionNamhyung Kim
The size option was to specify maximum captured patch length but was missing its description in the command line help. Add it.
2015-08-01busctl: add and use strcmp_ptr()Namhyung Kim
In member_compare_func(), it compares interface, type and name of members. But as it can contain NULL pointer, it needs to check them before calling strcmp(). So make it as a separate strcmp_ptr function (named after streq_ptr) so that it can be used by others. Also let streq_ptr() to use it in order to make the code simpler.
2015-07-31bus-proxy: fix NameAcquired and NameLost to be directedDavid Herrmann
The NameAcquired and NameLost signals are _directed_ signals. Make sure we properly set the destination correctly, and verify it in our proxy-test.
2015-07-30Merge pull request #787 from dvdhrm/bus-listDaniel Mack
sd-bus: fix parsing of KDBUS_CMD_LIST
2015-07-30sd-bus: fix parsing of KDBUS_CMD_LISTDavid Herrmann
We *must not* assume that an entry returned by KDBUS_CMD_LIST only carries a single KDBUS_ITEM_OWNED_NAME. Similarly, we already parse multiple such items for message-metadata, so make sure we support the same on KDBUS_CMD_LIST. By relying on the kernel to return all names separately, we limit the kernel API significantly. Stop this and let the kernel decide how to return its data.
2015-07-30tree-wide: use free_and_strdup()Daniel Mack
Use free_and_strdup() where appropriate and replace equivalent, open-coded versions.
2015-07-29tree-wide: port everything over to fflush_and_check()Lennart Poettering
Some places invoked fflush() directly with their own manual error checking, let's unify all that by using fflush_and_check(). This also unifies the general error paths of fflush()+rename() file writers.
2015-07-29sd-bus: fix encoding/decoding gvariant root containerDavid Herrmann
The gvariant root container contains a 'variant' at the end, which embeds the whole message body. This variant *must* contain a structure so we are compatible to dbus1. Otherwise, it could encode at most 1 type, instead of a full signature. Our gvariant message parser already parses the variant-content as a structure, so we're mostly good. However, it does *not* include the opening and closing parantheses, nor does it parse them. This patch fixes the decoder to verify a message contains the parantheses, and also make the encoder add those parantheses into the marshaled message.