Merge branch 'add-flags' into 'master'

lib: Change allow_interactive_authorization bool to flags

See merge request pwithnall/malcontent!6
This commit is contained in:
Philip Withnall 2019-03-19 17:09:30 +00:00
commit fb1d43428b
4 changed files with 120 additions and 66 deletions

View File

@ -563,20 +563,19 @@ accounts_find_user_by_id (GDBusConnection *connection,
* @connection: (nullable): a #GDBusConnection to the system bus, or %NULL to
* use the default
* @user_id: ID of the user to query, typically coming from getuid()
* @allow_interactive_authorization: %TRUE to allow interactive polkit
* authorization dialogues to be displayed during the call; %FALSE otherwise
* @flags: flags to affect the behaviour of the call
* @cancellable: (nullable): a #GCancellable, or %NULL
* @error: return location for a #GError, or %NULL
*
* Synchronous version of mct_get_app_filter_async().
*
* Returns: (transfer full): app filter for the queried user
* Since: 0.2.0
* Since: 0.3.0
*/
MctAppFilter *
mct_get_app_filter (GDBusConnection *connection,
uid_t user_id,
gboolean allow_interactive_authorization,
MctGetAppFilterFlags flags,
GCancellable *cancellable,
GError **error)
{
@ -603,7 +602,7 @@ mct_get_app_filter (GDBusConnection *connection,
return NULL;
object_path = accounts_find_user_by_id (connection, user_id,
allow_interactive_authorization,
(flags & MCT_GET_APP_FILTER_FLAGS_INTERACTIVE),
cancellable, error);
if (object_path == NULL)
return NULL;
@ -616,7 +615,7 @@ mct_get_app_filter (GDBusConnection *connection,
"GetAll",
g_variant_new ("(s)", "com.endlessm.ParentalControls.AppFilter"),
G_VARIANT_TYPE ("(a{sv})"),
allow_interactive_authorization
(flags & MCT_GET_APP_FILTER_FLAGS_INTERACTIVE)
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
: G_DBUS_CALL_FLAGS_NONE,
-1, /* timeout, ms */
@ -700,7 +699,7 @@ typedef struct
{
GDBusConnection *connection; /* (nullable) (owned) */
uid_t user_id;
gboolean allow_interactive_authorization;
MctGetAppFilterFlags flags;
} GetAppFilterData;
static void
@ -717,8 +716,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (GetAppFilterData, get_app_filter_data_free)
* @connection: (nullable): a #GDBusConnection to the system bus, or %NULL to
* use the default
* @user_id: ID of the user to query, typically coming from getuid()
* @allow_interactive_authorization: %TRUE to allow interactive polkit
* authorization dialogues to be displayed during the call; %FALSE otherwise
* @flags: flags to affect the behaviour of the call
* @cancellable: (nullable): a #GCancellable, or %NULL
* @callback: a #GAsyncReadyCallback
* @user_data: user data to pass to @callback
@ -733,12 +731,12 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (GetAppFilterData, get_app_filter_data_free)
* On failure, an #MctAppFilterError, a #GDBusError or a #GIOError will be
* returned.
*
* Since: 0.2.0
* Since: 0.3.0
*/
void
mct_get_app_filter_async (GDBusConnection *connection,
uid_t user_id,
gboolean allow_interactive_authorization,
MctGetAppFilterFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@ -755,7 +753,7 @@ mct_get_app_filter_async (GDBusConnection *connection,
data = g_new0 (GetAppFilterData, 1);
data->connection = (connection != NULL) ? g_object_ref (connection) : NULL;
data->user_id = user_id;
data->allow_interactive_authorization = allow_interactive_authorization;
data->flags = flags;
g_task_set_task_data (task, g_steal_pointer (&data),
(GDestroyNotify) get_app_filter_data_free);
@ -773,7 +771,7 @@ get_app_filter_thread_cb (GTask *task,
g_autoptr(GError) local_error = NULL;
filter = mct_get_app_filter (data->connection, data->user_id,
data->allow_interactive_authorization,
data->flags,
cancellable, &local_error);
if (local_error != NULL)
@ -810,21 +808,20 @@ mct_get_app_filter_finish (GAsyncResult *result,
* use the default
* @user_id: ID of the user to set the filter for, typically coming from getuid()
* @app_filter: (transfer none): the app filter to set for the user
* @allow_interactive_authorization: %TRUE to allow interactive polkit
* authorization dialogues to be displayed during the call; %FALSE otherwise
* @flags: flags to affect the behaviour of the call
* @cancellable: (nullable): a #GCancellable, or %NULL
* @error: return location for a #GError, or %NULL
*
* Synchronous version of mct_set_app_filter_async().
*
* Returns: %TRUE on success, %FALSE otherwise
* Since: 0.2.0
* Since: 0.3.0
*/
gboolean
mct_set_app_filter (GDBusConnection *connection,
uid_t user_id,
MctAppFilter *app_filter,
gboolean allow_interactive_authorization,
MctSetAppFilterFlags flags,
GCancellable *cancellable,
GError **error)
{
@ -851,7 +848,7 @@ mct_set_app_filter (GDBusConnection *connection,
return FALSE;
object_path = accounts_find_user_by_id (connection, user_id,
allow_interactive_authorization,
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE),
cancellable, error);
if (object_path == NULL)
return FALSE;
@ -873,7 +870,7 @@ mct_set_app_filter (GDBusConnection *connection,
"AppFilter",
g_steal_pointer (&app_filter_variant)),
G_VARIANT_TYPE ("()"),
allow_interactive_authorization
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE)
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
: G_DBUS_CALL_FLAGS_NONE,
-1, /* timeout, ms */
@ -896,7 +893,7 @@ mct_set_app_filter (GDBusConnection *connection,
"OarsFilter",
g_steal_pointer (&oars_filter_variant)),
G_VARIANT_TYPE ("()"),
allow_interactive_authorization
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE)
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
: G_DBUS_CALL_FLAGS_NONE,
-1, /* timeout, ms */
@ -919,7 +916,7 @@ mct_set_app_filter (GDBusConnection *connection,
"AllowUserInstallation",
g_steal_pointer (&allow_user_installation_variant)),
G_VARIANT_TYPE ("()"),
allow_interactive_authorization
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE)
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
: G_DBUS_CALL_FLAGS_NONE,
-1, /* timeout, ms */
@ -942,7 +939,7 @@ mct_set_app_filter (GDBusConnection *connection,
"AllowSystemInstallation",
g_steal_pointer (&allow_system_installation_variant)),
G_VARIANT_TYPE ("()"),
allow_interactive_authorization
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE)
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
: G_DBUS_CALL_FLAGS_NONE,
-1, /* timeout, ms */
@ -967,7 +964,7 @@ typedef struct
GDBusConnection *connection; /* (nullable) (owned) */
uid_t user_id;
MctAppFilter *app_filter; /* (owned) */
gboolean allow_interactive_authorization;
MctSetAppFilterFlags flags;
} SetAppFilterData;
static void
@ -986,8 +983,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (SetAppFilterData, set_app_filter_data_free)
* use the default
* @user_id: ID of the user to set the filter for, typically coming from getuid()
* @app_filter: (transfer none): the app filter to set for the user
* @allow_interactive_authorization: %TRUE to allow interactive polkit
* authorization dialogues to be displayed during the call; %FALSE otherwise
* @flags: flags to affect the behaviour of the call
* @cancellable: (nullable): a #GCancellable, or %NULL
* @callback: a #GAsyncReadyCallback
* @user_data: user data to pass to @callback
@ -1002,13 +998,13 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (SetAppFilterData, set_app_filter_data_free)
* On failure, an #MctAppFilterError, a #GDBusError or a #GIOError will be
* returned. The users app filter settings will be left in an undefined state.
*
* Since: 0.2.0
* Since: 0.3.0
*/
void
mct_set_app_filter_async (GDBusConnection *connection,
uid_t user_id,
MctAppFilter *app_filter,
gboolean allow_interactive_authorization,
MctSetAppFilterFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@ -1028,7 +1024,7 @@ mct_set_app_filter_async (GDBusConnection *connection,
data->connection = (connection != NULL) ? g_object_ref (connection) : NULL;
data->user_id = user_id;
data->app_filter = mct_app_filter_ref (app_filter);
data->allow_interactive_authorization = allow_interactive_authorization;
data->flags = flags;
g_task_set_task_data (task, g_steal_pointer (&data),
(GDestroyNotify) set_app_filter_data_free);
@ -1046,8 +1042,7 @@ set_app_filter_thread_cb (GTask *task,
g_autoptr(GError) local_error = NULL;
success = mct_set_app_filter (data->connection, data->user_id,
data->app_filter,
data->allow_interactive_authorization,
data->app_filter, data->flags,
cancellable, &local_error);
if (local_error != NULL)

View File

@ -76,6 +76,40 @@ typedef enum
MCT_APP_FILTER_OARS_VALUE_INTENSE,
} MctAppFilterOarsValue;
/**
* MctGetAppFilterFlags:
* @MCT_GET_APP_FILTER_FLAGS_NONE: No flags set.
* @MCT_GET_APP_FILTER_FLAGS_INTERACTIVE: Allow interactive polkit dialogs when
* requesting authorization.
*
* Flags to control the behaviour of mct_get_app_filter() and
* mct_get_app_filter_async().
*
* Since: 0.3.0
*/
typedef enum
{
MCT_GET_APP_FILTER_FLAGS_NONE = 0,
MCT_GET_APP_FILTER_FLAGS_INTERACTIVE,
} MctGetAppFilterFlags;
/**
* MctSetAppFilterFlags:
* @MCT_SET_APP_FILTER_FLAGS_NONE: No flags set.
* @MCT_SET_APP_FILTER_FLAGS_INTERACTIVE: Allow interactive polkit dialogs when
* requesting authorization.
*
* Flags to control the behaviour of mct_set_app_filter() and
* mct_set_app_filter_async().
*
* Since: 0.3.0
*/
typedef enum
{
MCT_SET_APP_FILTER_FLAGS_NONE = 0,
MCT_SET_APP_FILTER_FLAGS_INTERACTIVE,
} MctSetAppFilterFlags;
/**
* MctAppFilter:
*
@ -116,12 +150,12 @@ gboolean mct_app_filter_is_system_installation_allowed (MctAppFil
MctAppFilter *mct_get_app_filter (GDBusConnection *connection,
uid_t user_id,
gboolean allow_interactive_authorization,
MctGetAppFilterFlags flags,
GCancellable *cancellable,
GError **error);
void mct_get_app_filter_async (GDBusConnection *connection,
uid_t user_id,
gboolean allow_interactive_authorization,
MctGetAppFilterFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
@ -131,13 +165,13 @@ MctAppFilter *mct_get_app_filter_finish (GAsyncResult *result,
gboolean mct_set_app_filter (GDBusConnection *connection,
uid_t user_id,
MctAppFilter *app_filter,
gboolean allow_interactive_authorization,
MctSetAppFilterFlags flags,
GCancellable *cancellable,
GError **error);
void mct_set_app_filter_async (GDBusConnection *connection,
uid_t user_id,
MctAppFilter *app_filter,
gboolean allow_interactive_authorization,
MctSetAppFilterFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);

View File

@ -555,7 +555,8 @@ test_app_filter_bus_get (BusFixture *fixture,
mct_get_app_filter_async (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid,
FALSE, NULL, async_result_cb, &result);
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
async_result_cb, &result);
while (result == NULL)
g_main_context_iteration (NULL, TRUE);
@ -565,7 +566,8 @@ test_app_filter_bus_get (BusFixture *fixture,
{
app_filter = mct_get_app_filter (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid,
FALSE, NULL, &local_error);
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
&local_error);
}
g_assert_no_error (local_error);
@ -608,7 +610,8 @@ test_app_filter_bus_get_whitelist (BusFixture *fixture,
app_filter = mct_get_app_filter (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid,
FALSE, NULL, &local_error);
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
&local_error);
g_assert_no_error (local_error);
g_assert_nonnull (app_filter);
@ -658,7 +661,8 @@ test_app_filter_bus_get_all_oars_values (BusFixture *fixture,
app_filter = mct_get_app_filter (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid,
FALSE, NULL, &local_error);
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
&local_error);
g_assert_no_error (local_error);
g_assert_nonnull (app_filter);
@ -705,7 +709,8 @@ test_app_filter_bus_get_defaults (BusFixture *fixture,
app_filter = mct_get_app_filter (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid,
FALSE, NULL, &local_error);
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
&local_error);
g_assert_no_error (local_error);
g_assert_nonnull (app_filter);
@ -736,7 +741,8 @@ test_app_filter_bus_get_error_invalid_user (BusFixture *fixture,
mct_get_app_filter_async (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->missing_uid,
FALSE, NULL, async_result_cb, &result);
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
async_result_cb, &result);
/* Handle the FindUserById() call and claim the user doesnt exist. */
gint64 user_id;
@ -780,7 +786,8 @@ test_app_filter_bus_get_error_permission_denied (BusFixture *fixture,
mct_get_app_filter_async (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid,
FALSE, NULL, async_result_cb, &result);
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
async_result_cb, &result);
/* Handle the FindUserById() call. */
gint64 user_id;
@ -835,7 +842,8 @@ test_app_filter_bus_get_error_permission_denied_missing (BusFixture *fixture,
mct_get_app_filter_async (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid,
FALSE, NULL, async_result_cb, &result);
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
async_result_cb, &result);
/* Handle the FindUserById() call. */
gint64 user_id;
@ -888,7 +896,8 @@ test_app_filter_bus_get_error_unknown (BusFixture *fixture,
mct_get_app_filter_async (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid,
FALSE, NULL, async_result_cb, &result);
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
async_result_cb, &result);
/* Handle the FindUserById() call and return a bogus error. */
gint64 user_id;
@ -1068,7 +1077,8 @@ test_app_filter_bus_set (BusFixture *fixture,
mct_set_app_filter_async (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid, app_filter,
FALSE, NULL, async_result_cb, &result);
MCT_SET_APP_FILTER_FLAGS_NONE, NULL,
async_result_cb, &result);
while (result == NULL)
g_main_context_iteration (NULL, TRUE);
@ -1078,7 +1088,8 @@ test_app_filter_bus_set (BusFixture *fixture,
{
success = mct_set_app_filter (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid, app_filter,
FALSE, NULL, &local_error);
MCT_SET_APP_FILTER_FLAGS_NONE, NULL,
&local_error);
}
g_assert_no_error (local_error);
@ -1106,7 +1117,8 @@ test_app_filter_bus_set_error_invalid_user (BusFixture *fixture,
mct_set_app_filter_async (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->missing_uid, app_filter,
FALSE, NULL, async_result_cb, &result);
MCT_SET_APP_FILTER_FLAGS_NONE, NULL,
async_result_cb, &result);
/* Handle the FindUserById() call and claim the user doesnt exist. */
gint64 user_id;
@ -1160,7 +1172,8 @@ test_app_filter_bus_set_error_permission_denied (BusFixture *fixture,
success = mct_set_app_filter (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid, app_filter,
FALSE, NULL, &local_error);
MCT_SET_APP_FILTER_FLAGS_NONE, NULL,
&local_error);
g_assert_error (local_error,
MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_PERMISSION_DENIED);
@ -1197,7 +1210,8 @@ test_app_filter_bus_set_error_unknown (BusFixture *fixture,
success = mct_set_app_filter (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid, app_filter,
FALSE, NULL, &local_error);
MCT_SET_APP_FILTER_FLAGS_NONE, NULL,
&local_error);
g_assert_error (local_error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR);
g_assert_false (success);
@ -1239,7 +1253,8 @@ test_app_filter_bus_set_error_invalid_property (BusFixture *fixture,
success = mct_set_app_filter (gt_dbus_queue_get_client_connection (fixture->queue),
fixture->valid_uid, app_filter,
FALSE, NULL, &local_error);
MCT_SET_APP_FILTER_FLAGS_NONE, NULL,
&local_error);
g_assert_error (local_error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
g_assert_false (success);

View File

@ -37,9 +37,14 @@ def __get_app_filter(user_id, interactive):
If `interactive` is `True`, interactive polkit authorisation dialogues will
be allowed. An exception will be raised on failure."""
if interactive:
flags = Malcontent.GetAppFilterFlags.INTERACTIVE
else:
flags = Malcontent.GetAppFilterFlags.NONE
return Malcontent.get_app_filter(
connection=None, user_id=user_id,
allow_interactive_authorization=interactive, cancellable=None)
flags=flags, cancellable=None)
def __get_app_filter_or_error(user_id, interactive):
@ -58,9 +63,14 @@ def __set_app_filter(user_id, app_filter, interactive):
If `interactive` is `True`, interactive polkit authorisation dialogues will
be allowed. An exception will be raised on failure."""
if interactive:
flags = Malcontent.GetAppFilterFlags.INTERACTIVE
else:
flags = Malcontent.GetAppFilterFlags.NONE
Malcontent.set_app_filter(
connection=None, user_id=user_id, app_filter=app_filter,
allow_interactive_authorization=interactive, cancellable=None)
flags=flags, cancellable=None)
def __set_app_filter_or_error(user_id, app_filter, interactive):