Commit 719585f1 authored by David Zeuthen's avatar David Zeuthen

Pass caller and subject pid to authentication agent

The authentication agent can use information this to inform the user
about the UI application that triggered the authentication request (if
any).
Signed-off-by: default avatarDavid Zeuthen <davidz@redhat.com>
parent 8f3e92e8
......@@ -71,7 +71,9 @@ The themed icon describing the action or the empty string if no icon is set.
<term><literal>IN Dict&lt;String,String&gt; <parameter>details</parameter></literal>:</term>
<listitem>
<para>
Details about the authentication request. This is a dictionary of key/value pairs where both key and value are strings. These strings are translated into the locale passed when registering the authentication agent using <link linkend="eggdbus-method-org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent">RegisterAuthenticationAgent()</link>.
Details about the authentication request. This is a dictionary of key/value pairs where both key and value are strings. These strings are translated into the locale passed when registering the authentication agent using <link linkend="eggdbus-method-org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent">RegisterAuthenticationAgent().</link>.
Keys starting with <literal>polkit.</literal> are reserved for internal use and should never be displayed in the UI.
Known key/value-pairs include <literal>polkit.caller-pid</literal> (the process id of the mechanism making the authorization check) and <literal>polkit.subject-pid</literal> (the process id of the subject the check is for).
</para>
</listitem>
</varlistentry>
......
......@@ -1795,6 +1795,60 @@ get_localized_data_for_challenge (PolkitBackendInteractiveAuthority *authority,
g_object_unref (action_desc);
}
static void
add_pid (PolkitDetails *details,
PolkitSubject *subject,
const gchar *key)
{
gchar buf[32];
gint pid;
if (POLKIT_IS_UNIX_PROCESS (subject))
{
pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject));
}
else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
{
PolkitSubject *process;
GError *error;
error = NULL;
process = polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME (subject),
NULL,
&error);
if (process == NULL)
{
g_printerr ("Error getting process for system bus name `%s': %s\n",
polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject)),
error->message);
g_error_free (error);
goto out;
}
pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (process));
g_object_unref (process);
}
else if (POLKIT_IS_UNIX_SESSION (subject))
{
goto out;
}
else
{
gchar *s;
s = polkit_subject_to_string (subject);
g_printerr ("Don't know how to get pid from subject of type %s: %s\n",
g_type_name (G_TYPE_FROM_INSTANCE (subject)),
s);
g_free (s);
goto out;
}
g_snprintf (buf, sizeof (buf), "%d", pid);
polkit_details_insert (details, key, buf);
out:
;
}
static void
authentication_agent_initiate_challenge (AuthenticationAgent *agent,
PolkitSubject *subject,
......@@ -1866,6 +1920,9 @@ authentication_agent_initiate_challenge (AuthenticationAgent *agent,
agent->active_sessions = g_list_prepend (agent->active_sessions, session);
add_pid (localized_details, caller, "polkit.caller-pid");
add_pid (localized_details, subject, "polkit.subject-pid");
details_gvariant = polkit_details_to_gvariant (localized_details);
g_variant_ref_sink (details_gvariant);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment