Merge branch 'gdbus-call-interactive' into 'main'

gdbus: Add --interactive option to `gdbus call`

See merge request GNOME/glib!2329
This commit is contained in:
Sebastian Dröge 2021-11-22 13:58:46 +00:00
commit 6d8045ddb4
2 changed files with 11 additions and 2 deletions

View File

@ -71,6 +71,7 @@
<arg choice="plain">--method <replaceable>org.project.InterfaceName.MethodName</replaceable></arg> <arg choice="plain">--method <replaceable>org.project.InterfaceName.MethodName</replaceable></arg>
<group> <group>
<arg choice="plain">--timeout <replaceable>seconds</replaceable></arg> <arg choice="plain">--timeout <replaceable>seconds</replaceable></arg>
<arg choice="plain">--interactive</arg>
</group> </group>
<arg choice="plain">ARG1</arg> <arg choice="plain">ARG1</arg>
<arg choice="plain" rep="repeat">ARG2</arg> <arg choice="plain" rep="repeat">ARG2</arg>

View File

@ -887,6 +887,7 @@ static gchar *opt_call_dest = NULL;
static gchar *opt_call_object_path = NULL; static gchar *opt_call_object_path = NULL;
static gchar *opt_call_method = NULL; static gchar *opt_call_method = NULL;
static gint opt_call_timeout = -1; static gint opt_call_timeout = -1;
static gboolean opt_call_interactive = FALSE;
static const GOptionEntry call_entries[] = static const GOptionEntry call_entries[] =
{ {
@ -894,6 +895,7 @@ static const GOptionEntry call_entries[] =
{ "object-path", 'o', 0, G_OPTION_ARG_STRING, &opt_call_object_path, N_("Object path to invoke method on"), NULL}, { "object-path", 'o', 0, G_OPTION_ARG_STRING, &opt_call_object_path, N_("Object path to invoke method on"), NULL},
{ "method", 'm', 0, G_OPTION_ARG_STRING, &opt_call_method, N_("Method and interface name"), NULL}, { "method", 'm', 0, G_OPTION_ARG_STRING, &opt_call_method, N_("Method and interface name"), NULL},
{ "timeout", 't', 0, G_OPTION_ARG_INT, &opt_call_timeout, N_("Timeout in seconds"), NULL}, { "timeout", 't', 0, G_OPTION_ARG_INT, &opt_call_timeout, N_("Timeout in seconds"), NULL},
{ "interactive", 'i', 0, G_OPTION_ARG_NONE, &opt_call_interactive, N_("Allow interactive authorization"), NULL},
G_OPTION_ENTRY_NULL G_OPTION_ENTRY_NULL
}; };
@ -925,6 +927,7 @@ handle_call (gint *argc,
gboolean skip_dashes; gboolean skip_dashes;
guint parm; guint parm;
guint n; guint n;
GDBusCallFlags flags;
ret = FALSE; ret = FALSE;
c = NULL; c = NULL;
@ -1204,6 +1207,11 @@ handle_call (gint *argc,
if (parameters != NULL) if (parameters != NULL)
parameters = g_variant_ref_sink (parameters); parameters = g_variant_ref_sink (parameters);
flags = G_DBUS_CALL_FLAGS_NONE;
if (opt_call_interactive)
flags |= G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION;
#ifdef G_OS_UNIX #ifdef G_OS_UNIX
result = g_dbus_connection_call_with_unix_fd_list_sync (c, result = g_dbus_connection_call_with_unix_fd_list_sync (c,
opt_call_dest, opt_call_dest,
@ -1212,7 +1220,7 @@ handle_call (gint *argc,
method_name, method_name,
parameters, parameters,
NULL, NULL,
G_DBUS_CALL_FLAGS_NONE, flags,
opt_call_timeout > 0 ? opt_call_timeout * 1000 : opt_call_timeout, opt_call_timeout > 0 ? opt_call_timeout * 1000 : opt_call_timeout,
fd_list, fd_list,
NULL, NULL,
@ -1226,7 +1234,7 @@ handle_call (gint *argc,
method_name, method_name,
parameters, parameters,
NULL, NULL,
G_DBUS_CALL_FLAGS_NONE, flags,
opt_call_timeout > 0 ? opt_call_timeout * 1000 : opt_call_timeout, opt_call_timeout > 0 ? opt_call_timeout * 1000 : opt_call_timeout,
NULL, NULL,
&error); &error);