From 67f181642e4ea1cff4a5c0a005f4c74a0f8c762a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 25 Sep 2014 13:29:50 +0100 Subject: [PATCH 2/2] Implement getter, setter for ALLOW_INTERACTIVE_AUTHORIZATION flag Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83449 --- dbus/dbus-message.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ dbus/dbus-message.h | 8 ++++++++ 2 files changed, 56 insertions(+) diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 974e8fa..01c2367 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -4876,6 +4876,54 @@ dbus_message_demarshal_bytes_needed(const char *buf, } } +/** + * Sets a flag indicating that the caller of the method is prepared + * to wait for interactive authorization to take place (for instance + * via Polkit) before the actual method is processed. + * + * The flag is #FALSE by default; that is, by default the other end is + * expected to make any authorization decisions non-interactively + * and promptly. It may use the error + * #DBUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED to signal that + * authorization failed, but could have succeeded if this flag had + * been used. + * + * For messages whose type is not #DBUS_MESSAGE_TYPE_METHOD_CALL, + * this flag is meaningless and should not be set. + * + * On the protocol level this toggles + * #DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION. + * + * @param message the message + * @param allow #TRUE if interactive authorization is acceptable + */ +void +dbus_message_set_allow_interactive_authorization (DBusMessage *message, + dbus_bool_t allow) +{ + _dbus_return_if_fail (message != NULL); + _dbus_return_if_fail (!message->locked); + + _dbus_header_toggle_flag (&message->header, + DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION, + allow); +} + +/** + * Returns whether the flag controlled by + * dbus_message_set_allow_interactive_authorization() has been set. + * + * @param message the message + */ +dbus_bool_t +dbus_message_get_allow_interactive_authorization (DBusMessage *message) +{ + _dbus_return_val_if_fail (message != NULL, FALSE); + + return _dbus_header_get_flag (&message->header, + DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION); +} + /** @} */ /* tests in dbus-message-util.c */ diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h index 4fd44da..baa7d7b 100644 --- a/dbus/dbus-message.h +++ b/dbus/dbus-message.h @@ -302,6 +302,14 @@ DBUS_EXPORT int dbus_message_demarshal_bytes_needed (const char *str, int len); +DBUS_EXPORT +void dbus_message_set_allow_interactive_authorization (DBusMessage *message, + dbus_bool_t allow); + +DBUS_EXPORT +dbus_bool_t dbus_message_get_allow_interactive_authorization ( + DBusMessage *message); + /** @} */ DBUS_END_DECLS -- 2.1.1