return FALSE;
}
+#ifdef LIBDBUSPOLICY
static GDBusMessage*
create_access_error_reply (GDBusMessage *message,
- GError *error)
+ const GQuark domain,
+ const gint code,
+ const gchar *format,
+ ...)
{
- GDBusMessage *error_reply;
+ gchar *error_text;
+ GError *access_error;
gchar *dbus_error_name;
- dbus_error_name = g_dbus_error_encode_gerror (error);
- error_reply = g_dbus_message_new_method_error (message, dbus_error_name, "%s", error->message);
+ GDBusMessage *error_reply;
+ va_list args;
+
+ va_start (args, format);
+ error_text = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ access_error = NULL;
+ g_set_error (&access_error, domain, code, "%s", error_text);
+ dbus_error_name = g_dbus_error_encode_gerror (access_error);
+ g_error_free (access_error);
+
+ error_reply = g_dbus_message_new_method_error (message, dbus_error_name, "%s", error_text);
g_free (dbus_error_name);
+ g_free (error_text);
return error_reply;
}
+#endif
+
+#ifdef LIBDBUSPOLICY
+static GDBusMessage*
+check_result_to_error_reply (GDBusMessage *message,
+ const gint check_result)
+{
+ switch (check_result)
+ {
+ case DBUSPOLICY_RESULT_DENY:
+ return create_access_error_reply (message, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED,
+ "Cannot send message - message rejected due to XML security policies");
+
+ case DBUSPOLICY_RESULT_DEST_NOT_AVAILABLE:
+ if (g_dbus_message_get_flags (message) & G_DBUS_MESSAGE_FLAGS_NO_AUTO_START)
+ return create_access_error_reply (message, G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER,
+ "Name \"%s\" does not exist", g_dbus_message_get_destination (message));
+ else
+ return create_access_error_reply (message, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN,
+ "Cannot send message - destination '%s' not known", g_dbus_message_get_destination (message));
+
+ case DBUSPOLICY_RESULT_KDBUS_ERROR:
+ return create_access_error_reply (message, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED,
+ "Cannot send message - message rejected due to internal libdbuspolicy error (kdbus)");
+
+ case DBUSPOLICY_RESULT_CYNARA_ERROR:
+ return create_access_error_reply (message, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED,
+ "Cannot send message - message rejected due to internal libdbuspolicy error (Cynara)");
+
+ default:
+ return create_access_error_reply (message, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED,
+ "Cannot send message - unknown libdbuspolicy error");
+ }
+}
+#endif
static void
send_error_message (GKDBusWorker *worker,
gsize header_size;
gsize msg_size;
- GDBusMessage *access_error_message;
-
g_return_val_if_fail (G_IS_KDBUS_WORKER (worker), FALSE);
send = NULL;
NULL, 0, 0);
if (check != DBUSPOLICY_RESULT_ALLOW)
{
- switch (check)
- {
- case DBUSPOLICY_RESULT_DENY:
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED,
- "Cannot send message - message rejected due to XML security policies");
- break;
-
- case DBUSPOLICY_RESULT_DEST_NOT_AVAILABLE:
- if (g_dbus_message_get_flags (message) & G_DBUS_MESSAGE_FLAGS_NO_AUTO_START)
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER,
- "Name \"%s\" does not exist", g_dbus_message_get_destination (message));
- else
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN,
- "Cannot send message - destination '%s' not known", g_dbus_message_get_destination (message));
- break;
-
- case DBUSPOLICY_RESULT_KDBUS_ERROR:
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED,
- "Cannot send message - message rejected due to internal libdbuspolicy error (kdbus)");
- break;
-
- case DBUSPOLICY_RESULT_CYNARA_ERROR:
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED,
- "Cannot send message - message rejected due to internal libdbuspolicy error (Cynara)");
- break;
-
- default:
- g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED,
- "Cannot send message - unknown libdbuspolicy error");
- break;
- }
-
-
- access_error_message = create_access_error_reply(message, *error);
- g_clear_error(error); /* we send back an error reply, so error must be NULL */
+ GDBusMessage *access_error_message;
+ access_error_message = check_result_to_error_reply (message, check);
result = TRUE;
if (out_reply != NULL)
{
}
else
{
- send_error_message(worker, access_error_message);
+ send_error_message (worker, access_error_message);
}
goto out;