summaryrefslogtreecommitdiff
path: root/src/libsystemd
AgeCommit message (Collapse)Author
2015-07-16sd-bus: fix invalid stack access on test-bus-marshalDavid Herrmann
Make sure we actually parse "unsigned long long" if we encode a uint64_t. Otherwise, we will get random data from the stack.
2015-07-16sd-bus: fix gvariant structure encodingDavid Herrmann
In gvariant, all fixed-size objects need to be sized a multiple of their alignment. If a structure has only fixed-size members, it is required to be fixed size itself. If you imagine a structure like (ty), you have an 8-byte member followed by an 1-byte member. Hence, the overall inner-size is 9. The alignment of the object is 8, though. Therefore, the specs mandates final padding after fixed-size structures, to make sure it's sized a multiple of its alignment (=> 16). On the gvariant decoder side, we already account for this in bus_gvariant_get_size(), as we apply overall padding to the size of the structure. Therefore, our decoder correctly skips such final padding when parsing fixed-size structure. On the gvariant encoder side, however, we don't account for this final padding. This patch fixes the structure and dict-entry encoders to properly place such padding at the end of non-uniform fixed-size structures. The problem can be easily seen by running: $ busctl --user monitor and $ busctl call --user org.freedesktop.systemd1 / org.foobar foobar "(ty)" 777 8 The monitor will fail to parse the message and print an error. With this patch applied, everything works fine again. This patch also adds a bunch of test-cases to force non-uniform structures with non-pre-aligned positions. Thanks to Jan Alexander Steffens <jan.steffens@gmail.com> for spotting this and narrowing it down to non-uniform gvariant structures. Fixes #597.
2015-07-15sd-bus: fix object tree to be deeper than 2 levelsDavid Herrmann
So right now our object-tree is limited to 2 levels at most ('/' and '/foo/...../bar'). We never link any intermediate levels, even though that was clearly the plan. Fix the bus_node_allocate() helper to actually link all intermediate nodes, too, not just the root node. This fixes a simple inverse ptr-diff bug. The downside of this fix is that we clearly never tested (nor used) the object tree in any way. The only reason that the introspection works is that our enumerators shortcut the object tree. Lets see whether that code actually works.. Thanks to: Nathaniel McCallum <nathaniel@themccallums.org> ..for reporting this. See #524 for an actual example code.
2015-07-15sd-device: never return NULL+0David Herrmann
It is highly confusing if a getter function returns 0, but the value is set to NULL. This, right now, triggers assertions as code relies on the returned values to be non-NULL. Like with sd-bus-creds and friends, return 0 only if a value is actually available. Discussed with Tom, and actually fixes real bugs as in #512.
2015-07-14Merge commit 'refs/pull/436/head' of https://github.com/systemd/systemdDavid Herrmann
This merges: sd-netlink: respect attribute type flags ..fixing a conflict due to a typo fix.
2015-07-12basic: util - fix errorhandling in unhexmem()Tom Gundersen
We were ignoring failures from unhexchar, which meant that invalid hex characters were being turned into garbage rather than the string rejected. Fix this by making unhexmem return an error code, also change the API slightly, to return the size of the returned memory, reflecting the fact that the memory is a binary blob,and not a string. For convenience, still append a trailing NULL byte to the returned memory (not included in the returned size), allowing callers to treat it as a string without doing a second copy.
2015-07-09nss-mymachines: map userns users of containers to real user namesLennart Poettering
Given a container "foo", that maps user id $UID to container user, using user namespaces, this NSS module extenstion will now map the $UID to a name "vu-foo-$TUID" for the translated UID $UID. Similar, userns groups are mapped to "vg-foo-$TGID" for translated GIDs of $GID. This simple change should make userns users more discoverable. Also, given that many tools like "adduser" check NSS before allocating a UID, should lower the chance of UID range conflicts between tools.
2015-07-09Merge pull request #532 from dvdhrm/bus-managed-rootLennart Poettering
sd-bus: include queried path in GetManagedObjects
2015-07-09sd-bus: include queried path in GetManagedObjectsDavid Herrmann
If GetManagedObjects is called on /foo/bar, then it should also include the object /foo/bar, if it exists. Right now, we only include objects underneath /foo/bar/. This follows the behavior of existing dbus implementations. Obsoletes #527 and fixes #525. Reported by: Nathaniel McCallum
2015-07-09sd-bus: sd_bus_slot_get_description() should return const stringsDavid Herrmann
All other *_get_description() functions use 'const char**', so make sure sd_bus_slot_get_description() does the same. This changes API, but ABI stays stable. I think this is fine, but I wouldn't mind bumping SONAME. Reported in #528.
2015-07-07logind: fail on CreateSession if already in sessionDavid Herrmann
Right now, if you're already in a session and call CreateSession, we return information about the current session of yours. This is highy confusing and a nasty hack. Avoid that, and instead return a commonly known error, so the caller can detect that. This has the side-effect, that we no longer override XDG_VTNR and XDG_SEAT in pam_systemd, if you're already in a session. But this sounds like the right thing to do, anyway.
2015-07-07Remove repeated 'the'sZbigniew Jędrzejewski-Szmek
2015-07-06sd-bus: support matching on destination namesDavid Herrmann
Right now, we never install destination matches on kdbus as the kernel did not support MATCH rules on those. With the introduction of KDBUS_ITEM_DST_ID we can now match on destination IDs, so add explicit support for those. This requires a recent kdbus module to work. However, there seems to be no user-space that uses "Destination=''" matches, yet, so old kdbus modules still work fine (we couldn't find any real user). This is needed to match on unicast signals in bus-proxy. A followup will add support for this.
2015-07-06treewide: fix typosTorstein Husebø
2015-07-04Merge pull request #485 from poettering/sd-bus-flush-close-unrefDavid Herrmann
sd-bus: introduce new sd_bus_flush_close_unref() call
2015-07-04busctl: flush stdout after dumping dataDavid Herrmann
Running `busctl monitor` currently buffers data for several seconds / kilobytes before writing stdout. This is highly confusing if you dump in a file, ^C busctl and then end up with a file with data of the last few _seconds_ missing. Fix this by explicitly flushing after each signal.
2015-07-03sd-bus: introduce new sd_bus_flush_close_unref() callLennart Poettering
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-02sd-bus: don't leak kdbus notificationsDavid Herrmann
When we get notifications from the kernel, we always turn them into synthetic dbus1 messages. This means, we do *not* consume the kdbus message, and as such have to free the offset. Right now, the translation-helpers told the caller that they consumed the message, which is wrong. Fix this by explicitly releasing all kernel messages that are translated.
2015-06-30sd-netlink: respect attribute type flagsTom Gundersen
Though currently unused by us, netlink attribute types support embedding flags to indicate if the type is encoded in network byte-order and if it is a nested attribute. Read out these flags when parsing the message. We will now swap the byteorder in case it is non-native when reading out integers (though this is not needed by any of the types we currently support). We do not enforce the NESTED flag, as the kernel gets this wrong in many cases.
2015-06-28sd-netlink: message - remove unused next_rta_offset fieldTom Gundersen
This was a left-over from before we supported containers.
2015-06-28netlink: rework containersTom Gundersen
Instead of representing containers as several arrays, make a new netlink_container struct and keep one array of these structs. We also introduce netlink_attribute structs that in the future will hold meta-information about each atribute.
2015-06-28sd-netlink: make a couple of helper functions staticTom Gundersen
Also rename from rtnl_* to netlink_*.
2015-06-28sd-netlink: mark union containers as nestedTom Gundersen
This was an oversight, they are no different from regular containers in this respect.
2015-06-24sd-netlink: don't export internal type-system detailsDavid Herrmann
The kernel bonding layer allows passing an array of ARP IP targets as bond-configuration. Due to the weird implementation of arrays in netlink (which we haven't figure out a generic way to support, yet), we usually hard-code the supported array-sizes. However, this should not be exported from sd-netlink. Instead, make sure the caller just uses it's current hack of enumerating the types, and the sd-netlink core will have it's own list of supported array-sizes (to be removed in future extensions, btw!). If either does not match, we will just return a normal error. Note that we provide 2 constants for ARP_IP_TARGETS_MAX now. However, both have very different reasons: - the constant in netdev-bond.c is used to warn the user that the given number of targets might not be supported by the kernel (even though the kernel might increase that number at _any_ time) - the constant in sd-netlink is solely used due to us missing a proper array implementation. Once that's supported in the type-system, it can be removed without notice Last but not least, this patch turns the log_error() into a log_warning(). Given that the previous condition was off-by-one, anyway, it never hit at the right time. Thus, it was probably of no real use.
2015-06-24sd-netlink: don't treat NULL as root type-systemDavid Herrmann
Explicitly export the root type-system to the type-system callers. This avoids treating NULL as root, which for one really looks backwards (NULL is usually a leaf, not root), and secondly prevents us from properly debugging calling into non-nested types. Also rename the root to "type_system_root". Once we support more than rtnl, well will have to revisit that, anyway.
2015-06-24sd-netlink: don't treat type_system->count==0 as invalidDavid Herrmann
Empty type-systems are just fine. Avoid the nasty hack in union-type-systems that treat empty type-systems as invalid. Instead check for the actual types-array and make sure it's non-NULL (which is even true for empty type-systems, due to "empty_types" array).
2015-06-24sd-netlink: make sure the root-level type is nestedDavid Herrmann
In sd-netlink-message, we always guarantee that the currently selected type-system is non-NULL. Otherwise, we would be unable to parse any types in the current container level. Hence, this assertion must be true: message->container_type_system[m->n_containers] != NULL During message_new() we currently do not verify that this assertion is true. Instead, we blindly access nl_type->type_system and use it (which might be NULL for basic types and unions). Fix this, by explicitly checking that the root-level type is nested. Note that this is *not* a strict requirement of netlink, but it's a strict requirement for all message types we currently support. Furthermore, all the callers of message_new() already verify that only supported types are passed, therefore, this is a pure cosmetic check. However, it might be needed on the future, so make sure we don't trap into this once we change the type-system.
2015-06-24sd-netlink: drop NETLINK_TYPE_METADavid Herrmann
The NETLINK_TYPE_META pseudo-type is actually equivalent to an empty nested type. Drop it and define an empty type-system instead. This also has the nice side-effect that m->container_type_system[0] is never NULL (which has really nasty side-effects if you try to read attributes).
2015-06-24sd-netlink: turn 'max' into 'count' to support empty type-systemsDavid Herrmann
Right now we store the maximum type-ID of a type-system. This prevents us from creating empty type-systems. Store the "count" instead, which should be treated as max+1. Note that type_system_union_protocol_get_type_system() currently has a nasty hack to treat empty type-systems as invalid. This might need some modification later on as well.
2015-06-24sd-netlink: avoid casting size_t into intDavid Herrmann
size_t is usually 64bit and int 32bit on a 64bit machine. This probably does not matter for netlink message sizes, but nevertheless, avoid hard-coding it anywhere.
2015-06-24sd-netlink: make NLTypeSystem internalDavid Herrmann
Same as NLType, move NLTypeSystem into netlink-types.c and hide it from the outside. Provide an accessor function for the 'max' field that is used to allocate suitable array sizes. Note that this will probably be removed later on, anyway. Once we support bigger type-systems, it just seems impractical to allocate such big arrays for each container entry. An RBTree would probably do just fine.
2015-06-24sd-netlink: make NLType internalDavid Herrmann
If we extend NLType to support arrays and further extended types, we really want to avoid hard-coding the type-layout outside of netlink-types.c. We already avoid accessing nl_type->type_system outside of netlink-types.c, extend this to also avoid accessing any other fields. Provide accessor functions for nl_type->type and nl_type->size and then move NLType away from the type-system header. With this in place, follow-up patches can safely turn "type_system" and "type_system_union" into a real "union { }", and then add another type for arrays.
2015-06-24sd-netlink: don't access type->type_system[_union] directlyDavid Herrmann
Make sure we never access type->type_system or type->type_system_union directly. This is an implementation detail of the type-system and we should always use the accessors. Right now, they only exist for 2-level accesses (type-system to type-system). This patch introduces the 1-level accessors (type to type-system) and makes use of it. This patch makes sure the proper assertions are in place, so we never accidentally access sub-type-systems for non-nested/union types. Note that this places hard-asserts on the accessors. This should be fine, as we expect callers to only access sub type-systems if they *know* they're dealing with nested types.
2015-06-24sd-netlink: rename NLA_ to NETLINK_TYPE_David Herrmann
The NLA_ names are used to name real datatypes we extract out of netlink messages. The kernel has an internal enum with the same names (NLA_foobar), which is *NOT* binary compatible to our types. Furthermore, we support a different set of types than the kernel (as we try to treat some kernel peculiarities as our own types to simplify the API). Rename NLA_ to NETLINK_TYPE_ to make clear that this is our own set of types.
2015-06-23build-sys: add all source files and no built files to the tar ballKay Sievers
This fully synchronizes the content of a "make dist" and a "git archive" tar ball. http://lists.freedesktop.org/archives/systemd-devel/2015-June/033214.html
2015-06-21export sd_bus_object_added() / _removed()Geert Jansen
Fixes #306.
2015-06-17bus: fix installing DRIVER matches on kdbusDavid Herrmann
In kdbus we still have to support org.freedesktop.DBus matches even though there is no real bus driver. The reason is that bus-control.c turns NameOwnerChanged matches into proper kdbus matches. If we drop DRIVER matches early, we will never match on name-changes for kdbus. Two ways to fix this: 1) Install DRIVER matches on kdbus (which is the simple way our and which is what this patch does). 2) Properly fix the scope-detection to let NameOwnerChanged matches through (or better: block anything with Member!=NameOwnerChanged).
2015-06-17turn kdbus support into a runtime optionKay Sievers
./configure --enable/disable-kdbus can be used to set the default behavior regarding kdbus. If no kdbus kernel support is available, dbus-dameon will be used. With --enable-kdbus, the kernel command line option "kdbus=0" can be used to disable kdbus. With --disable-kdbus, the kernel command line option "kdbus=1" is required to enable kdbus support.
2015-06-17libsystemd: remove list of symbols to export only in the futureKay Sievers
2015-06-17Merge pull request #246 from smcv/xpg-not-xdgLennart Poettering
Stop talking about the "XDG" version of basename()
2015-06-17Stop talking about the "XDG" version of basename()Simon McVittie
XDG refers to X Desktop Group, a former name for freedesktop.org. This group is responsible for specifications like basedirs, .desktop files and icon naming, but as far as I know, it has never tried to redefine basename(). I think these references were meant to say XPG (X/Open Portability Guide), a precursor of POSIX. POSIX is better-known and less easily confused with XDG, and is how the basename(3) man page describes the libgen.h version of basename(). The other version of basename() is glibc-specific and is described in basename(3) as "the GNU version"; specifically mention that version, to disambiguate.
2015-06-17Merge pull request #244 from poettering/sdbus-suppress-localDavid Herrmann
sd-bus: suppress installing local bus matches server side
2015-06-17sd-bus: suppress installing local bus matches server sideLennart Poettering
Matches that can only match against messages from the org.freedesktop.DBus.Local service (or the local interfaces or path) should never be installed server side, suppress them hence. Similar, on kdbus matches that can only match driver messages shouldn't be passed to the kernel.
2015-06-17Merge pull request #239 from dvdhrm/event-assertLennart Poettering
sd-event: make errors on EPOLL_CTL_DEL pseudo-fatal
2015-06-17sd-event: make errors on EPOLL_CTL_DEL pseudo-fatalDavid Herrmann
If we call EPOLL_CTL_DEL, we *REALLY* expect the file-descriptor to be present in that given epoll-set. We actually track such state via our s->io.registered flag, so it better be true. Make sure if that's not true, we treat it similar to assert_return() (ie., print a loud warning).
2015-06-17build-sys: hide magic section variables from exported symbolsKay Sievers
https://github.com/systemd/systemd/issues/234
2015-06-16Merge pull request #197 from dvdhrm/hashmapMichal Schmidt
hashmap: fix iterators to not skip entries
2015-06-16sd-bus: use proper cleanup macroUmut Tezduyar Lindskog
2015-06-15everywhere: port everything to sigprocmask_many() and friendsLennart Poettering
This ports a lot of manual code over to sigprocmask_many() and friends. Also, we now consistly check for sigprocmask() failures with assert_se(), since the call cannot realistically fail unless there's a programming error. Also encloses a few sd_event_add_signal() calls with (void) when we ignore the return values for it knowingly.
2015-06-14hashmap: fix iterators to not skip entriesDavid Herrmann
Currently, the HASHMAP iterators stop at the first NULL entry in a hashmap. This is non-obvious and breaks users like sd-device, which legitimately store NULL values in a hashmap. Fix all the iterators by taking a pointer to the value storage, instead of returning it. The iterators now return a boolean that tells whether the end of the list was reached. Current users of HASHMAP_FOREACH() are *NOT* changed to explicitly check for NULL. If it turns out, there were users that inserted NULL into hashmaps, but didn't properly check for it during iteration, then we really want to find those and fix them.