Skip to content

Commit

Permalink
Merge branch 'polkit-ref-count'
Browse files Browse the repository at this point in the history
  • Loading branch information
keszybz committed Feb 5, 2020
2 parents 239bf94 + bc130b6 commit ea0d0ed
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 62 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ Features:

* the a-posteriori stopping of units bound to units that disappeared logic
should be reworked: there should be a queue of units, and we should only
enqeue stop jobs from a defer event that processes queue instead of
enqueue stop jobs from a defer event that processes queue instead of
right-away when we find a unit that is bound to one that doesn't exist
anymore. (similar to how the stop-unneeded queue has been reworked the same
way)
Expand Down
1 change: 1 addition & 0 deletions man/rules/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ manpages = [
'sd_bus_open_user_with_description',
'sd_bus_open_with_description'],
''],
['sd_bus_enqueue_for_read', '3', [], ''],
['sd_bus_error',
'3',
['SD_BUS_ERROR_MAKE_CONST',
Expand Down
88 changes: 88 additions & 0 deletions man/sd_bus_enqueue_for_read.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version='1.0'?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<!-- SPDX-License-Identifier: LGPL-2.1+ -->

<refentry id="sd_bus_enqueue_for_read"
xmlns:xi="http://www.w3.org/2001/XInclude">

<refentryinfo>
<title>sd_bus_enqueue_for_read</title>
<productname>systemd</productname>
</refentryinfo>

<refmeta>
<refentrytitle>sd_bus_enqueue_for_read</refentrytitle>
<manvolnum>3</manvolnum>
</refmeta>

<refnamediv>
<refname>sd_bus_enqueue_for_read</refname>

<refpurpose>Re-enqueue a bus message on a bus connection, for reading.</refpurpose>
</refnamediv>

<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>

<funcprototype>
<funcdef>int <function>sd_bus_enqueue_for_read</function></funcdef>
<paramdef>sd_bus *<parameter>bus</parameter></paramdef>
<paramdef>sd_bus_message *<parameter>message</parameter></paramdef>
</funcprototype>

</funcsynopsis>
</refsynopsisdiv>

<refsect1>
<title>Description</title>

<para><function>sd_bus_enqueue_for_read()</function> may be used to re-enqueue an incoming bus message on
the local read queue, so that it is processed and dispatched locally again, similar to how an incoming
message from the peer is processed. Takes a bus connection object and the message to enqueue. A reference
is taken of the message and the caller's reference thus remains in possession of the caller. The message
is enqueued at the end of the queue, thus will be dispatched after all other already queued messages are
dispatched.</para>

<para>This call is primarily useful for dealing with incoming method calls that may be processed only
after an additional asynchronous operation completes. One example are PolicyKit authorization requests
that are determined to be necessary to authorize a newly incoming method call: when the PolicyKit response
is received the original method call may be re-enqueued to process it again, this time with the
authorization result known.</para>
</refsect1>

<refsect1>
<title>Return Value</title>

<para>On success, this function return 0 or a positive integer. On failure, it returns a negative errno-style
error code.</para>

<refsect2>
<title>Errors</title>

<para>Returned errors may indicate the following problems:</para>

<variablelist>
<varlistentry>
<term><constant>-ECHILD</constant></term>

<listitem><para>The bus connection has been created in a different process.</para></listitem>
</varlistentry>
</variablelist>
</refsect2>
</refsect1>

<xi:include href="libsystemd-pkgconfig.xml" />

<refsect1>
<title>See Also</title>

<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_send</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
</para>
</refsect1>

</refentry>
1 change: 1 addition & 0 deletions src/libsystemd/libsystemd.sym
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ global:

LIBSYSTEMD_245 {
global:
sd_bus_enqueue_for_read;
sd_bus_message_dump;
sd_bus_message_sensitive;
sd_event_add_child_pidfd;
Expand Down
24 changes: 24 additions & 0 deletions src/libsystemd/sd-bus/sd-bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -4207,3 +4207,27 @@ _public_ int sd_bus_get_close_on_exit(sd_bus *bus) {

return bus->close_on_exit;
}

_public_ int sd_bus_enqueue_for_read(sd_bus *bus, sd_bus_message *m) {
int r;

assert_return(bus, -EINVAL);
assert_return(bus = bus_resolve(bus), -ENOPKG);
assert_return(m, -EINVAL);
assert_return(m->sealed, -EINVAL);
assert_return(!bus_pid_changed(bus), -ECHILD);

if (!BUS_IS_OPEN(bus->state))
return -ENOTCONN;

/* Re-enqueue a message for reading. This is primarily useful for PolicyKit-style authentication,
* where we accept a message, then determine we need to interactively authenticate the user, and then
* we want to process the message again. */

r = bus_rqueue_make_room(bus);
if (r < 0)
return r;

bus->rqueue[bus->rqueue_size++] = bus_message_ref_queued(m, bus);
return 0;
}
Loading

1 comment on commit ea0d0ed

@ralittles
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came here from the National Vulnerabilities Database when searching for a resolution to CVE-2020-1712: https://nvd.nist.gov/vuln/detail/CVE-2020-1712

Please sign in to comment.