2018-09-28 10:11:11 +02:00
|
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2018 Endless Mobile, Inc.
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*
|
|
|
|
|
* Authors:
|
|
|
|
|
* - Philip Withnall <withnall@endlessm.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
#include <glib/gi18n-lib.h>
|
2018-11-26 15:48:45 +01:00
|
|
|
|
#include <gio/gdesktopappinfo.h>
|
2018-09-28 10:11:11 +02:00
|
|
|
|
#include <gio/gio.h>
|
2019-02-26 18:43:56 +01:00
|
|
|
|
#include <libmalcontent/app-filter.h>
|
2018-09-28 10:11:11 +02:00
|
|
|
|
|
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
G_DEFINE_QUARK (MctAppFilterError, mct_app_filter_error)
|
2018-09-28 10:11:11 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* MctAppFilterListType:
|
|
|
|
|
* @MCT_APP_FILTER_LIST_BLACKLIST: Any program in the list is not allowed to
|
2018-09-28 10:11:11 +02:00
|
|
|
|
* be run.
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* @MCT_APP_FILTER_LIST_WHITELIST: Any program not in the list is not allowed
|
2018-09-28 10:11:11 +02:00
|
|
|
|
* to be run.
|
|
|
|
|
*
|
|
|
|
|
* Different semantics for interpreting an application list.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*/
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MCT_APP_FILTER_LIST_BLACKLIST,
|
|
|
|
|
MCT_APP_FILTER_LIST_WHITELIST,
|
|
|
|
|
} MctAppFilterListType;
|
2018-09-28 10:11:11 +02:00
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
struct _MctAppFilter
|
2018-09-28 10:11:11 +02:00
|
|
|
|
{
|
|
|
|
|
gint ref_count;
|
|
|
|
|
|
|
|
|
|
uid_t user_id;
|
|
|
|
|
|
|
|
|
|
gchar **app_list; /* (owned) (array zero-terminated=1) */
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterListType app_list_type;
|
2018-10-09 12:24:25 +02:00
|
|
|
|
|
2018-10-12 05:47:16 +02:00
|
|
|
|
GVariant *oars_ratings; /* (type a{ss}) (owned non-floating) */
|
2018-11-29 22:09:57 +01:00
|
|
|
|
gboolean allow_user_installation;
|
2018-11-28 17:39:39 +01:00
|
|
|
|
gboolean allow_system_installation;
|
2018-09-28 10:11:11 +02:00
|
|
|
|
};
|
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
G_DEFINE_BOXED_TYPE (MctAppFilter, mct_app_filter,
|
|
|
|
|
mct_app_filter_ref, mct_app_filter_unref)
|
2018-09-28 10:11:11 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_ref:
|
|
|
|
|
* @filter: (transfer none): an #MctAppFilter
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*
|
|
|
|
|
* Increment the reference count of @filter, and return the same pointer to it.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): the same pointer as @filter
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*/
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilter *
|
|
|
|
|
mct_app_filter_ref (MctAppFilter *filter)
|
2018-09-28 10:11:11 +02:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (filter != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (filter->ref_count >= 1, NULL);
|
|
|
|
|
g_return_val_if_fail (filter->ref_count <= G_MAXINT - 1, NULL);
|
|
|
|
|
|
|
|
|
|
filter->ref_count++;
|
|
|
|
|
return filter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_unref:
|
|
|
|
|
* @filter: (transfer full): an #MctAppFilter
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*
|
|
|
|
|
* Decrement the reference count of @filter. If the reference count reaches
|
|
|
|
|
* zero, free the @filter and all its resources.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_unref (MctAppFilter *filter)
|
2018-09-28 10:11:11 +02:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (filter != NULL);
|
|
|
|
|
g_return_if_fail (filter->ref_count >= 1);
|
|
|
|
|
|
|
|
|
|
filter->ref_count--;
|
|
|
|
|
|
|
|
|
|
if (filter->ref_count <= 0)
|
|
|
|
|
{
|
|
|
|
|
g_strfreev (filter->app_list);
|
2018-10-09 12:24:25 +02:00
|
|
|
|
g_variant_unref (filter->oars_ratings);
|
2018-09-28 10:11:11 +02:00
|
|
|
|
g_free (filter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_get_user_id:
|
|
|
|
|
* @filter: an #MctAppFilter
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Get the user ID of the user this #MctAppFilter is for.
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: user ID of the relevant user
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*/
|
|
|
|
|
uid_t
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_get_user_id (MctAppFilter *filter)
|
2018-09-28 10:11:11 +02:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (filter != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->ref_count >= 1, FALSE);
|
|
|
|
|
|
|
|
|
|
return filter->user_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_is_path_allowed:
|
|
|
|
|
* @filter: an #MctAppFilter
|
2018-10-12 05:47:33 +02:00
|
|
|
|
* @path: (type filename): absolute path of a program to check
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*
|
|
|
|
|
* Check whether the program at @path is allowed to be run according to this
|
|
|
|
|
* app filter. @path will be canonicalised without doing any I/O.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the user this @filter corresponds to is allowed to run the
|
|
|
|
|
* program at @path according to the @filter policy; %FALSE otherwise
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_is_path_allowed (MctAppFilter *filter,
|
2018-09-28 10:11:11 +02:00
|
|
|
|
const gchar *path)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (filter != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->ref_count >= 1, FALSE);
|
|
|
|
|
g_return_val_if_fail (path != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (g_path_is_absolute (path), FALSE);
|
|
|
|
|
|
|
|
|
|
g_autofree gchar *canonical_path = g_canonicalize_filename (path, "/");
|
|
|
|
|
gboolean path_in_list = g_strv_contains ((const gchar * const *) filter->app_list,
|
|
|
|
|
canonical_path);
|
|
|
|
|
|
|
|
|
|
switch (filter->app_list_type)
|
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
case MCT_APP_FILTER_LIST_BLACKLIST:
|
2018-09-28 10:11:11 +02:00
|
|
|
|
return !path_in_list;
|
2019-02-26 18:43:56 +01:00
|
|
|
|
case MCT_APP_FILTER_LIST_WHITELIST:
|
2018-09-28 10:11:11 +02:00
|
|
|
|
return path_in_list;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 06:59:04 +02:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_is_flatpak_ref_allowed:
|
|
|
|
|
* @filter: an #MctAppFilter
|
2018-11-14 16:17:18 +01:00
|
|
|
|
* @app_ref: flatpak ref for the app, for example `app/org.gnome.Builder/x86_64/master`
|
2018-10-12 06:59:04 +02:00
|
|
|
|
*
|
|
|
|
|
* Check whether the flatpak app with the given @app_ref is allowed to be run
|
|
|
|
|
* according to this app filter.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the user this @filter corresponds to is allowed to run the
|
|
|
|
|
* flatpak called @app_ref according to the @filter policy; %FALSE otherwise
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-10-12 06:59:04 +02:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_is_flatpak_ref_allowed (MctAppFilter *filter,
|
2018-10-12 06:59:04 +02:00
|
|
|
|
const gchar *app_ref)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (filter != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->ref_count >= 1, FALSE);
|
|
|
|
|
g_return_val_if_fail (app_ref != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
gboolean ref_in_list = g_strv_contains ((const gchar * const *) filter->app_list,
|
|
|
|
|
app_ref);
|
|
|
|
|
|
|
|
|
|
switch (filter->app_list_type)
|
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
case MCT_APP_FILTER_LIST_BLACKLIST:
|
2018-10-12 06:59:04 +02:00
|
|
|
|
return !ref_in_list;
|
2019-02-26 18:43:56 +01:00
|
|
|
|
case MCT_APP_FILTER_LIST_WHITELIST:
|
2018-10-12 06:59:04 +02:00
|
|
|
|
return ref_in_list;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 16:17:18 +01:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_is_flatpak_app_allowed:
|
|
|
|
|
* @filter: an #MctAppFilter
|
2018-11-14 16:17:18 +01:00
|
|
|
|
* @app_id: flatpak ID for the app, for example `org.gnome.Builder`
|
|
|
|
|
*
|
|
|
|
|
* Check whether the flatpak app with the given @app_id is allowed to be run
|
|
|
|
|
* according to this app filter. This is a globbing match, matching @app_id
|
|
|
|
|
* against potentially multiple entries in the blacklist, as the blacklist
|
|
|
|
|
* contains flatpak refs (for example, `app/org.gnome.Builder/x86_64/master`)
|
|
|
|
|
* which contain architecture and branch information. App IDs (for example,
|
|
|
|
|
* `org.gnome.Builder`) do not contain architecture or branch information.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the user this @filter corresponds to is allowed to run the
|
|
|
|
|
* flatpak called @app_id according to the @filter policy; %FALSE otherwise
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-11-14 16:17:18 +01:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_is_flatpak_app_allowed (MctAppFilter *filter,
|
2018-11-14 16:17:18 +01:00
|
|
|
|
const gchar *app_id)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (filter != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->ref_count >= 1, FALSE);
|
|
|
|
|
g_return_val_if_fail (app_id != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
gsize app_id_len = strlen (app_id);
|
|
|
|
|
|
|
|
|
|
gboolean id_in_list = FALSE;
|
|
|
|
|
for (gsize i = 0; filter->app_list[i] != NULL; i++)
|
|
|
|
|
{
|
|
|
|
|
/* Avoid using flatpak_ref_parse() to avoid a dependency on libflatpak
|
|
|
|
|
* just for that one function. */
|
|
|
|
|
if (g_str_has_prefix (filter->app_list[i], "app/") &&
|
|
|
|
|
strncmp (filter->app_list[i] + strlen ("app/"), app_id, app_id_len) == 0 &&
|
|
|
|
|
filter->app_list[i][strlen ("app/") + app_id_len] == '/')
|
|
|
|
|
{
|
|
|
|
|
id_in_list = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (filter->app_list_type)
|
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
case MCT_APP_FILTER_LIST_BLACKLIST:
|
2018-11-14 16:17:18 +01:00
|
|
|
|
return !id_in_list;
|
2019-02-26 18:43:56 +01:00
|
|
|
|
case MCT_APP_FILTER_LIST_WHITELIST:
|
2018-11-14 16:17:18 +01:00
|
|
|
|
return id_in_list;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-26 15:48:45 +01:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_is_appinfo_allowed:
|
|
|
|
|
* @filter: an #MctAppFilter
|
2018-11-26 15:48:45 +01:00
|
|
|
|
* @app_info: (transfer none): application information
|
|
|
|
|
*
|
|
|
|
|
* Check whether the app with the given @app_info is allowed to be run
|
|
|
|
|
* according to this app filter. This matches on multiple keys potentially
|
|
|
|
|
* present in the #GAppInfo, including the path of the executable.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the user this @filter corresponds to is allowed to run the
|
|
|
|
|
* app represented by @app_info according to the @filter policy; %FALSE
|
|
|
|
|
* otherwise
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-11-26 15:48:45 +01:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_is_appinfo_allowed (MctAppFilter *filter,
|
2018-11-26 15:48:45 +01:00
|
|
|
|
GAppInfo *app_info)
|
|
|
|
|
{
|
|
|
|
|
g_autofree gchar *abs_path = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (filter != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->ref_count >= 1, FALSE);
|
|
|
|
|
g_return_val_if_fail (G_IS_APP_INFO (app_info), FALSE);
|
|
|
|
|
|
|
|
|
|
abs_path = g_find_program_in_path (g_app_info_get_executable (app_info));
|
|
|
|
|
|
|
|
|
|
if (abs_path != NULL &&
|
2019-02-26 18:43:56 +01:00
|
|
|
|
!mct_app_filter_is_path_allowed (filter, abs_path))
|
2018-11-26 15:48:45 +01:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (G_IS_DESKTOP_APP_INFO (app_info))
|
|
|
|
|
{
|
|
|
|
|
g_autofree gchar *flatpak_app = NULL;
|
|
|
|
|
g_autofree gchar *old_flatpak_apps_str = NULL;
|
|
|
|
|
|
|
|
|
|
/* This gives `org.gnome.Builder`. */
|
|
|
|
|
flatpak_app = g_desktop_app_info_get_string (G_DESKTOP_APP_INFO (app_info), "X-Flatpak");
|
|
|
|
|
if (flatpak_app != NULL)
|
|
|
|
|
flatpak_app = g_strstrip (flatpak_app);
|
|
|
|
|
|
|
|
|
|
if (flatpak_app != NULL &&
|
2019-02-26 18:43:56 +01:00
|
|
|
|
!mct_app_filter_is_flatpak_app_allowed (filter, flatpak_app))
|
2018-11-26 15:48:45 +01:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* FIXME: This could do with the g_desktop_app_info_get_string_list() API
|
|
|
|
|
* from GLib 2.60. Gives `gimp.desktop;org.gimp.Gimp.desktop;`. */
|
|
|
|
|
old_flatpak_apps_str = g_desktop_app_info_get_string (G_DESKTOP_APP_INFO (app_info), "X-Flatpak-RenamedFrom");
|
|
|
|
|
if (old_flatpak_apps_str != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_auto(GStrv) old_flatpak_apps = g_strsplit (old_flatpak_apps_str, ";", -1);
|
|
|
|
|
|
|
|
|
|
for (gsize i = 0; old_flatpak_apps[i] != NULL; i++)
|
|
|
|
|
{
|
2018-12-12 14:36:17 +01:00
|
|
|
|
gchar *old_flatpak_app = g_strstrip (old_flatpak_apps[i]);
|
2018-11-26 15:48:45 +01:00
|
|
|
|
|
|
|
|
|
if (g_str_has_suffix (old_flatpak_app, ".desktop"))
|
|
|
|
|
old_flatpak_app[strlen (old_flatpak_app) - strlen (".desktop")] = '\0';
|
|
|
|
|
old_flatpak_app = g_strstrip (old_flatpak_app);
|
|
|
|
|
|
|
|
|
|
if (*old_flatpak_app != '\0' &&
|
2019-02-26 18:43:56 +01:00
|
|
|
|
!mct_app_filter_is_flatpak_app_allowed (filter, old_flatpak_app))
|
2018-11-26 15:48:45 +01:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-08 18:20:11 +01:00
|
|
|
|
static gint
|
|
|
|
|
strcmp_cb (gconstpointer a,
|
|
|
|
|
gconstpointer b)
|
|
|
|
|
{
|
|
|
|
|
const gchar *str_a = *((const gchar * const *) a);
|
|
|
|
|
const gchar *str_b = *((const gchar * const *) b);
|
|
|
|
|
|
|
|
|
|
return g_strcmp0 (str_a, str_b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_get_oars_sections:
|
|
|
|
|
* @filter: an #MctAppFilter
|
2018-11-08 18:20:11 +01:00
|
|
|
|
*
|
|
|
|
|
* List the OARS sections present in this app filter. The sections are returned
|
|
|
|
|
* in lexicographic order. A section will be listed even if its stored value is
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* %MCT_APP_FILTER_OARS_VALUE_UNKNOWN. The returned list may be empty.
|
2018-11-08 18:20:11 +01:00
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer container) (array zero-terminated=1): %NULL-terminated
|
|
|
|
|
* array of OARS sections
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-11-08 18:20:11 +01:00
|
|
|
|
*/
|
|
|
|
|
const gchar **
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_get_oars_sections (MctAppFilter *filter)
|
2018-11-08 18:20:11 +01:00
|
|
|
|
{
|
|
|
|
|
g_autoptr(GPtrArray) sections = g_ptr_array_new_with_free_func (NULL);
|
|
|
|
|
GVariantIter iter;
|
|
|
|
|
const gchar *oars_section;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (filter != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (filter->ref_count >= 1, NULL);
|
|
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, filter->oars_ratings);
|
|
|
|
|
|
|
|
|
|
while (g_variant_iter_loop (&iter, "{&s&s}", &oars_section, NULL))
|
|
|
|
|
g_ptr_array_add (sections, (gpointer) oars_section);
|
|
|
|
|
|
|
|
|
|
/* Sort alphabetically for easier comparisons later. */
|
|
|
|
|
g_ptr_array_sort (sections, strcmp_cb);
|
|
|
|
|
|
|
|
|
|
g_ptr_array_add (sections, NULL); /* NULL terminator */
|
|
|
|
|
|
|
|
|
|
return (const gchar **) g_ptr_array_free (g_steal_pointer (§ions), FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-09 12:24:25 +02:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_get_oars_value:
|
|
|
|
|
* @filter: an #MctAppFilter
|
2018-10-09 12:24:25 +02:00
|
|
|
|
* @oars_section: name of the OARS section to get the value from
|
|
|
|
|
*
|
|
|
|
|
* Get the value assigned to the given @oars_section in the OARS filter stored
|
|
|
|
|
* within @filter. If that section has no value explicitly defined,
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* %MCT_APP_FILTER_OARS_VALUE_UNKNOWN is returned.
|
2018-10-09 12:24:25 +02:00
|
|
|
|
*
|
|
|
|
|
* This value is the most intense value allowed for apps to have in this
|
|
|
|
|
* section, inclusive. Any app with a more intense value for this section must
|
|
|
|
|
* be hidden from the user whose @filter this is.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* This does not factor in mct_app_filter_is_system_installation_allowed().
|
2018-11-13 12:30:19 +01:00
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Returns: an #MctAppFilterOarsValue
|
|
|
|
|
* Since: 0.2.0
|
2018-10-09 12:24:25 +02:00
|
|
|
|
*/
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterOarsValue
|
|
|
|
|
mct_app_filter_get_oars_value (MctAppFilter *filter,
|
2018-10-09 12:24:25 +02:00
|
|
|
|
const gchar *oars_section)
|
|
|
|
|
{
|
|
|
|
|
const gchar *value_str;
|
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
g_return_val_if_fail (filter != NULL, MCT_APP_FILTER_OARS_VALUE_UNKNOWN);
|
2018-10-09 12:24:25 +02:00
|
|
|
|
g_return_val_if_fail (filter->ref_count >= 1,
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MCT_APP_FILTER_OARS_VALUE_UNKNOWN);
|
2018-10-09 12:24:25 +02:00
|
|
|
|
g_return_val_if_fail (oars_section != NULL && *oars_section != '\0',
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MCT_APP_FILTER_OARS_VALUE_UNKNOWN);
|
2018-10-09 12:24:25 +02:00
|
|
|
|
|
|
|
|
|
if (!g_variant_lookup (filter->oars_ratings, oars_section, "&s", &value_str))
|
2019-02-26 18:43:56 +01:00
|
|
|
|
return MCT_APP_FILTER_OARS_VALUE_UNKNOWN;
|
2018-10-09 12:24:25 +02:00
|
|
|
|
|
|
|
|
|
if (g_str_equal (value_str, "none"))
|
2019-02-26 18:43:56 +01:00
|
|
|
|
return MCT_APP_FILTER_OARS_VALUE_NONE;
|
2018-10-09 12:24:25 +02:00
|
|
|
|
else if (g_str_equal (value_str, "mild"))
|
2019-02-26 18:43:56 +01:00
|
|
|
|
return MCT_APP_FILTER_OARS_VALUE_MILD;
|
2018-10-09 12:24:25 +02:00
|
|
|
|
else if (g_str_equal (value_str, "moderate"))
|
2019-02-26 18:43:56 +01:00
|
|
|
|
return MCT_APP_FILTER_OARS_VALUE_MODERATE;
|
2018-10-09 12:24:25 +02:00
|
|
|
|
else if (g_str_equal (value_str, "intense"))
|
2019-02-26 18:43:56 +01:00
|
|
|
|
return MCT_APP_FILTER_OARS_VALUE_INTENSE;
|
2018-10-09 12:24:25 +02:00
|
|
|
|
else
|
2019-02-26 18:43:56 +01:00
|
|
|
|
return MCT_APP_FILTER_OARS_VALUE_UNKNOWN;
|
2018-10-09 12:24:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-29 22:09:57 +01:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_is_user_installation_allowed:
|
|
|
|
|
* @filter: an #MctAppFilter
|
2018-11-29 22:09:57 +01:00
|
|
|
|
*
|
|
|
|
|
* Get whether the user is allowed to install to their flatpak user repository.
|
|
|
|
|
* This should be queried in addition to the OARS values
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* (mct_app_filter_get_oars_value()) — if it returns %FALSE, the OARS values
|
2018-11-29 22:09:57 +01:00
|
|
|
|
* should be ignored and app installation should be unconditionally disallowed.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if app installation is allowed to the user repository for
|
|
|
|
|
* this user; %FALSE if it is unconditionally disallowed for this user
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-11-29 22:09:57 +01:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_is_user_installation_allowed (MctAppFilter *filter)
|
2018-11-29 22:09:57 +01:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (filter != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->ref_count >= 1, FALSE);
|
|
|
|
|
|
|
|
|
|
return filter->allow_user_installation;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 12:30:19 +01:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_is_system_installation_allowed:
|
|
|
|
|
* @filter: an #MctAppFilter
|
2018-11-13 12:30:19 +01:00
|
|
|
|
*
|
2018-11-28 17:39:39 +01:00
|
|
|
|
* Get whether the user is allowed to install to the flatpak system repository.
|
|
|
|
|
* This should be queried in addition to the OARS values
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* (mct_app_filter_get_oars_value()) — if it returns %FALSE, the OARS values
|
2018-11-28 17:39:39 +01:00
|
|
|
|
* should be ignored and app installation should be unconditionally disallowed.
|
2018-11-13 12:30:19 +01:00
|
|
|
|
*
|
2018-11-28 17:39:39 +01:00
|
|
|
|
* Returns: %TRUE if app installation is allowed to the system repository for
|
|
|
|
|
* this user; %FALSE if it is unconditionally disallowed for this user
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-11-13 12:30:19 +01:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_is_system_installation_allowed (MctAppFilter *filter)
|
2018-11-13 12:30:19 +01:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (filter != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->ref_count >= 1, FALSE);
|
|
|
|
|
|
2018-11-28 17:39:39 +01:00
|
|
|
|
return filter->allow_system_installation;
|
2018-11-13 12:30:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 05:47:59 +02:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* _mct_app_filter_build_app_filter_variant:
|
|
|
|
|
* @filter: an #MctAppFilter
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
|
|
|
|
* Build a #GVariant which contains the app filter from @filter, in the format
|
|
|
|
|
* used for storing it in AccountsService.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer floating): a new, floating #GVariant containing the app
|
|
|
|
|
* filter
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*/
|
|
|
|
|
static GVariant *
|
2019-02-26 18:43:56 +01:00
|
|
|
|
_mct_app_filter_build_app_filter_variant (MctAppFilter *filter)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
{
|
|
|
|
|
g_auto(GVariantBuilder) builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("(bas)"));
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (filter != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (filter->ref_count >= 1, NULL);
|
|
|
|
|
|
|
|
|
|
g_variant_builder_add (&builder, "b",
|
2019-02-26 18:43:56 +01:00
|
|
|
|
(filter->app_list_type == MCT_APP_FILTER_LIST_WHITELIST));
|
2018-10-12 05:47:59 +02:00
|
|
|
|
g_variant_builder_open (&builder, G_VARIANT_TYPE ("as"));
|
|
|
|
|
|
|
|
|
|
for (gsize i = 0; filter->app_list[i] != NULL; i++)
|
|
|
|
|
g_variant_builder_add (&builder, "s", filter->app_list[i]);
|
|
|
|
|
|
|
|
|
|
g_variant_builder_close (&builder);
|
|
|
|
|
|
|
|
|
|
return g_variant_builder_end (&builder);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-09 12:24:25 +02:00
|
|
|
|
/* Check if @error is a D-Bus remote error matching @expected_error_name. */
|
2018-09-28 10:11:11 +02:00
|
|
|
|
static gboolean
|
|
|
|
|
bus_remote_error_matches (const GError *error,
|
|
|
|
|
const gchar *expected_error_name)
|
|
|
|
|
{
|
|
|
|
|
g_autofree gchar *error_name = NULL;
|
|
|
|
|
|
|
|
|
|
if (!g_dbus_error_is_remote_error (error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
error_name = g_dbus_error_get_remote_error (error);
|
|
|
|
|
|
|
|
|
|
return g_str_equal (error_name, expected_error_name);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
/* Convert a #GDBusError into a #MctAppFilter error. */
|
2018-09-28 10:11:11 +02:00
|
|
|
|
static GError *
|
|
|
|
|
bus_error_to_app_filter_error (const GError *bus_error,
|
|
|
|
|
uid_t user_id)
|
|
|
|
|
{
|
|
|
|
|
if (g_error_matches (bus_error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED) ||
|
|
|
|
|
bus_remote_error_matches (bus_error, "org.freedesktop.Accounts.Error.PermissionDenied"))
|
2019-02-26 18:43:56 +01:00
|
|
|
|
return g_error_new (MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_PERMISSION_DENIED,
|
2018-09-28 10:11:11 +02:00
|
|
|
|
_("Not allowed to query app filter data for user %u"),
|
2018-12-19 17:59:04 +01:00
|
|
|
|
(guint) user_id);
|
2018-12-11 17:50:47 +01:00
|
|
|
|
else if (g_error_matches (bus_error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD) ||
|
|
|
|
|
bus_remote_error_matches (bus_error, "org.freedesktop.Accounts.Error.Failed"))
|
2019-02-26 18:43:56 +01:00
|
|
|
|
return g_error_new (MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_INVALID_USER,
|
2018-12-19 17:59:04 +01:00
|
|
|
|
_("User %u does not exist"), (guint) user_id);
|
2018-09-28 10:11:11 +02:00
|
|
|
|
else
|
|
|
|
|
return g_error_copy (bus_error);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-02 10:17:56 +01:00
|
|
|
|
/* Find the object path for the given @user_id on the accountsservice D-Bus
|
|
|
|
|
* interface, by calling its FindUserById() method. This is a synchronous,
|
|
|
|
|
* blocking function. */
|
|
|
|
|
static gchar *
|
|
|
|
|
accounts_find_user_by_id (GDBusConnection *connection,
|
|
|
|
|
uid_t user_id,
|
|
|
|
|
gboolean allow_interactive_authorization,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
g_autofree gchar *object_path = NULL;
|
|
|
|
|
g_autoptr(GVariant) result_variant = NULL;
|
|
|
|
|
g_autoptr(GError) local_error = NULL;
|
|
|
|
|
|
|
|
|
|
result_variant =
|
|
|
|
|
g_dbus_connection_call_sync (connection,
|
|
|
|
|
"org.freedesktop.Accounts",
|
|
|
|
|
"/org/freedesktop/Accounts",
|
|
|
|
|
"org.freedesktop.Accounts",
|
|
|
|
|
"FindUserById",
|
2018-12-19 17:59:04 +01:00
|
|
|
|
g_variant_new ("(x)", (gint64) user_id),
|
2018-11-02 10:17:56 +01:00
|
|
|
|
G_VARIANT_TYPE ("(o)"),
|
|
|
|
|
allow_interactive_authorization
|
|
|
|
|
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
|
|
|
|
|
: G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1, /* timeout, ms */
|
|
|
|
|
cancellable,
|
|
|
|
|
&local_error);
|
|
|
|
|
if (local_error != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_autoptr(GError) app_filter_error = bus_error_to_app_filter_error (local_error,
|
|
|
|
|
user_id);
|
|
|
|
|
g_propagate_error (error, g_steal_pointer (&app_filter_error));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_variant_get (result_variant, "(o)", &object_path);
|
|
|
|
|
|
|
|
|
|
return g_steal_pointer (&object_path);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-31 12:01:44 +01:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_get_app_filter:
|
2018-10-31 12:01:44 +01:00
|
|
|
|
* @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()
|
2019-03-19 17:55:11 +01:00
|
|
|
|
* @flags: flags to affect the behaviour of the call
|
2018-10-31 12:01:44 +01:00
|
|
|
|
* @cancellable: (nullable): a #GCancellable, or %NULL
|
|
|
|
|
* @error: return location for a #GError, or %NULL
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Synchronous version of mct_get_app_filter_async().
|
2018-10-31 12:01:44 +01:00
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): app filter for the queried user
|
2019-03-19 17:55:11 +01:00
|
|
|
|
* Since: 0.3.0
|
2018-10-31 12:01:44 +01:00
|
|
|
|
*/
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilter *
|
2019-03-19 17:55:11 +01:00
|
|
|
|
mct_get_app_filter (GDBusConnection *connection,
|
|
|
|
|
uid_t user_id,
|
|
|
|
|
MctGetAppFilterFlags flags,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GError **error)
|
2018-10-31 12:01:44 +01:00
|
|
|
|
{
|
|
|
|
|
g_autofree gchar *object_path = NULL;
|
|
|
|
|
g_autoptr(GVariant) result_variant = NULL;
|
|
|
|
|
g_autoptr(GVariant) properties = NULL;
|
|
|
|
|
g_autoptr(GError) local_error = NULL;
|
2019-02-26 18:43:56 +01:00
|
|
|
|
g_autoptr(MctAppFilter) app_filter = NULL;
|
2018-10-31 12:01:44 +01:00
|
|
|
|
gboolean is_whitelist;
|
|
|
|
|
g_auto(GStrv) app_list = NULL;
|
|
|
|
|
const gchar *content_rating_kind;
|
|
|
|
|
g_autoptr(GVariant) oars_variant = NULL;
|
|
|
|
|
g_autoptr(GHashTable) oars_map = NULL;
|
2018-11-29 22:09:57 +01:00
|
|
|
|
gboolean allow_user_installation;
|
2018-11-28 17:39:39 +01:00
|
|
|
|
gboolean allow_system_installation;
|
2018-10-31 12:01:44 +01:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (connection == NULL || G_IS_DBUS_CONNECTION (connection), NULL);
|
|
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (connection == NULL)
|
|
|
|
|
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
|
|
|
|
|
if (connection == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2018-11-02 10:17:56 +01:00
|
|
|
|
object_path = accounts_find_user_by_id (connection, user_id,
|
2019-03-19 17:55:11 +01:00
|
|
|
|
(flags & MCT_GET_APP_FILTER_FLAGS_INTERACTIVE),
|
2018-11-02 10:17:56 +01:00
|
|
|
|
cancellable, error);
|
|
|
|
|
if (object_path == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2018-10-31 12:01:44 +01:00
|
|
|
|
result_variant =
|
|
|
|
|
g_dbus_connection_call_sync (connection,
|
|
|
|
|
"org.freedesktop.Accounts",
|
|
|
|
|
object_path,
|
|
|
|
|
"org.freedesktop.DBus.Properties",
|
|
|
|
|
"GetAll",
|
|
|
|
|
g_variant_new ("(s)", "com.endlessm.ParentalControls.AppFilter"),
|
|
|
|
|
G_VARIANT_TYPE ("(a{sv})"),
|
2019-03-19 17:55:11 +01:00
|
|
|
|
(flags & MCT_GET_APP_FILTER_FLAGS_INTERACTIVE)
|
2018-10-31 12:01:44 +01:00
|
|
|
|
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
|
|
|
|
|
: G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1, /* timeout, ms */
|
|
|
|
|
cancellable,
|
|
|
|
|
&local_error);
|
|
|
|
|
if (local_error != NULL)
|
|
|
|
|
{
|
2019-04-24 11:50:48 +02:00
|
|
|
|
g_autoptr(GError) app_filter_error = NULL;
|
|
|
|
|
|
|
|
|
|
if (g_error_matches (local_error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS))
|
|
|
|
|
{
|
|
|
|
|
/* o.fd.D.GetAll() will return InvalidArgs errors if
|
|
|
|
|
* accountsservice doesn’t have the com.endlessm.ParentalControls.AppFilter
|
|
|
|
|
* extension interface installed. */
|
|
|
|
|
app_filter_error = g_error_new_literal (MCT_APP_FILTER_ERROR,
|
|
|
|
|
MCT_APP_FILTER_ERROR_DISABLED,
|
|
|
|
|
_("App filtering is globally disabled"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
app_filter_error = bus_error_to_app_filter_error (local_error,
|
|
|
|
|
user_id);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-31 12:01:44 +01:00
|
|
|
|
g_propagate_error (error, g_steal_pointer (&app_filter_error));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Extract the properties we care about. They may be silently omitted from the
|
|
|
|
|
* results if we don’t have permission to access them. */
|
|
|
|
|
properties = g_variant_get_child_value (result_variant, 0);
|
2018-12-12 14:43:39 +01:00
|
|
|
|
if (!g_variant_lookup (properties, "AppFilter", "(b^as)",
|
2018-10-31 12:01:44 +01:00
|
|
|
|
&is_whitelist, &app_list))
|
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
g_set_error (error, MCT_APP_FILTER_ERROR,
|
|
|
|
|
MCT_APP_FILTER_ERROR_PERMISSION_DENIED,
|
2018-10-31 12:01:44 +01:00
|
|
|
|
_("Not allowed to query app filter data for user %u"),
|
2018-12-19 17:59:04 +01:00
|
|
|
|
(guint) user_id);
|
2018-10-31 12:01:44 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-12 14:43:39 +01:00
|
|
|
|
if (!g_variant_lookup (properties, "OarsFilter", "(&s@a{ss})",
|
2018-10-31 12:01:44 +01:00
|
|
|
|
&content_rating_kind, &oars_variant))
|
|
|
|
|
{
|
|
|
|
|
/* Default value. */
|
|
|
|
|
content_rating_kind = "oars-1.1";
|
2018-12-14 15:26:15 +01:00
|
|
|
|
oars_variant = g_variant_new ("a{ss}", NULL);
|
2018-10-31 12:01:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check that the OARS filter is in a format we support. Currently, that’s
|
|
|
|
|
* only oars-1.0 and oars-1.1. */
|
|
|
|
|
if (!g_str_equal (content_rating_kind, "oars-1.0") &&
|
|
|
|
|
!g_str_equal (content_rating_kind, "oars-1.1"))
|
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
g_set_error (error, MCT_APP_FILTER_ERROR,
|
|
|
|
|
MCT_APP_FILTER_ERROR_INVALID_DATA,
|
2018-10-31 12:01:44 +01:00
|
|
|
|
_("OARS filter for user %u has an unrecognized kind ‘%s’"),
|
2018-12-19 17:59:04 +01:00
|
|
|
|
(guint) user_id, content_rating_kind);
|
2018-10-31 12:01:44 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-12 14:43:39 +01:00
|
|
|
|
if (!g_variant_lookup (properties, "AllowUserInstallation", "b",
|
2018-11-29 22:09:57 +01:00
|
|
|
|
&allow_user_installation))
|
|
|
|
|
{
|
|
|
|
|
/* Default value. */
|
|
|
|
|
allow_user_installation = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-12 14:43:39 +01:00
|
|
|
|
if (!g_variant_lookup (properties, "AllowSystemInstallation", "b",
|
2018-11-28 17:39:39 +01:00
|
|
|
|
&allow_system_installation))
|
2018-11-13 12:30:19 +01:00
|
|
|
|
{
|
|
|
|
|
/* Default value. */
|
2018-11-28 17:39:39 +01:00
|
|
|
|
allow_system_installation = FALSE;
|
2018-11-13 12:30:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
/* Success. Create an #MctAppFilter object to contain the results. */
|
|
|
|
|
app_filter = g_new0 (MctAppFilter, 1);
|
2018-10-31 12:01:44 +01:00
|
|
|
|
app_filter->ref_count = 1;
|
|
|
|
|
app_filter->user_id = user_id;
|
|
|
|
|
app_filter->app_list = g_steal_pointer (&app_list);
|
|
|
|
|
app_filter->app_list_type =
|
2019-02-26 18:43:56 +01:00
|
|
|
|
is_whitelist ? MCT_APP_FILTER_LIST_WHITELIST : MCT_APP_FILTER_LIST_BLACKLIST;
|
2018-10-31 12:01:44 +01:00
|
|
|
|
app_filter->oars_ratings = g_steal_pointer (&oars_variant);
|
2018-11-29 22:09:57 +01:00
|
|
|
|
app_filter->allow_user_installation = allow_user_installation;
|
2018-11-28 17:39:39 +01:00
|
|
|
|
app_filter->allow_system_installation = allow_system_installation;
|
2018-10-31 12:01:44 +01:00
|
|
|
|
|
|
|
|
|
return g_steal_pointer (&app_filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void get_app_filter_thread_cb (GTask *task,
|
|
|
|
|
gpointer source_object,
|
|
|
|
|
gpointer task_data,
|
|
|
|
|
GCancellable *cancellable);
|
2018-09-28 10:11:11 +02:00
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2018-10-31 12:01:44 +01:00
|
|
|
|
GDBusConnection *connection; /* (nullable) (owned) */
|
2018-09-28 10:11:11 +02:00
|
|
|
|
uid_t user_id;
|
2019-03-19 17:55:11 +01:00
|
|
|
|
MctGetAppFilterFlags flags;
|
2018-09-28 10:11:11 +02:00
|
|
|
|
} GetAppFilterData;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_app_filter_data_free (GetAppFilterData *data)
|
|
|
|
|
{
|
2018-10-31 12:01:44 +01:00
|
|
|
|
g_clear_object (&data->connection);
|
2018-09-28 10:11:11 +02:00
|
|
|
|
g_free (data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GetAppFilterData, get_app_filter_data_free)
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_get_app_filter_async:
|
2018-09-28 10:11:11 +02:00
|
|
|
|
* @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()
|
2019-03-19 17:55:11 +01:00
|
|
|
|
* @flags: flags to affect the behaviour of the call
|
2018-09-28 10:11:11 +02:00
|
|
|
|
* @cancellable: (nullable): a #GCancellable, or %NULL
|
2018-10-31 12:01:16 +01:00
|
|
|
|
* @callback: a #GAsyncReadyCallback
|
2018-09-28 10:11:11 +02:00
|
|
|
|
* @user_data: user data to pass to @callback
|
|
|
|
|
*
|
|
|
|
|
* Asynchronously get a snapshot of the app filter settings for the given
|
|
|
|
|
* @user_id.
|
|
|
|
|
*
|
|
|
|
|
* @connection should be a connection to the system bus, where accounts-service
|
|
|
|
|
* runs. It’s provided mostly for testing purposes, or to allow an existing
|
|
|
|
|
* connection to be re-used. Pass %NULL to use the default connection.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* On failure, an #MctAppFilterError, a #GDBusError or a #GIOError will be
|
2018-09-28 10:11:11 +02:00
|
|
|
|
* returned.
|
|
|
|
|
*
|
2019-03-19 17:55:11 +01:00
|
|
|
|
* Since: 0.3.0
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_get_app_filter_async (GDBusConnection *connection,
|
2018-09-28 10:11:11 +02:00
|
|
|
|
uid_t user_id,
|
2019-03-19 17:55:11 +01:00
|
|
|
|
MctGetAppFilterFlags flags,
|
2018-09-28 10:11:11 +02:00
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
g_autoptr(GTask) task = NULL;
|
|
|
|
|
g_autoptr(GetAppFilterData) data = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (connection == NULL || G_IS_DBUS_CONNECTION (connection));
|
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
|
|
task = g_task_new (NULL, cancellable, callback, user_data);
|
2019-02-26 18:43:56 +01:00
|
|
|
|
g_task_set_source_tag (task, mct_get_app_filter_async);
|
2018-09-28 10:11:11 +02:00
|
|
|
|
|
|
|
|
|
data = g_new0 (GetAppFilterData, 1);
|
2018-10-31 12:01:44 +01:00
|
|
|
|
data->connection = (connection != NULL) ? g_object_ref (connection) : NULL;
|
2018-09-28 10:11:11 +02:00
|
|
|
|
data->user_id = user_id;
|
2019-03-19 17:55:11 +01:00
|
|
|
|
data->flags = flags;
|
2018-09-28 10:11:11 +02:00
|
|
|
|
g_task_set_task_data (task, g_steal_pointer (&data),
|
|
|
|
|
(GDestroyNotify) get_app_filter_data_free);
|
|
|
|
|
|
2018-10-31 12:01:44 +01:00
|
|
|
|
g_task_run_in_thread (task, get_app_filter_thread_cb);
|
2018-09-28 10:11:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2018-10-31 12:01:44 +01:00
|
|
|
|
get_app_filter_thread_cb (GTask *task,
|
|
|
|
|
gpointer source_object,
|
|
|
|
|
gpointer task_data,
|
|
|
|
|
GCancellable *cancellable)
|
2018-09-28 10:11:11 +02:00
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
g_autoptr(MctAppFilter) filter = NULL;
|
2018-10-31 12:01:44 +01:00
|
|
|
|
GetAppFilterData *data = task_data;
|
2018-09-28 10:11:11 +02:00
|
|
|
|
g_autoptr(GError) local_error = NULL;
|
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
filter = mct_get_app_filter (data->connection, data->user_id,
|
2019-03-19 17:55:11 +01:00
|
|
|
|
data->flags,
|
2018-10-31 12:01:44 +01:00
|
|
|
|
cancellable, &local_error);
|
2018-09-28 10:11:11 +02:00
|
|
|
|
|
|
|
|
|
if (local_error != NULL)
|
|
|
|
|
g_task_return_error (task, g_steal_pointer (&local_error));
|
|
|
|
|
else
|
2018-10-31 12:01:44 +01:00
|
|
|
|
g_task_return_pointer (task, g_steal_pointer (&filter),
|
2019-02-26 18:43:56 +01:00
|
|
|
|
(GDestroyNotify) mct_app_filter_unref);
|
2018-09-28 10:11:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_get_app_filter_finish:
|
2018-09-28 10:11:11 +02:00
|
|
|
|
* @result: a #GAsyncResult
|
|
|
|
|
* @error: return location for a #GError, or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Finish an asynchronous operation to get the app filter for a user, started
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* with mct_get_app_filter_async().
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): app filter for the queried user
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-09-28 10:11:11 +02:00
|
|
|
|
*/
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilter *
|
|
|
|
|
mct_get_app_filter_finish (GAsyncResult *result,
|
2018-09-28 10:11:11 +02:00
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (g_task_is_valid (result, NULL), NULL);
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
|
|
return g_task_propagate_pointer (G_TASK (result), error);
|
|
|
|
|
}
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
2018-10-31 12:01:44 +01:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_set_app_filter:
|
2018-10-31 12:01:44 +01:00
|
|
|
|
* @connection: (nullable): a #GDBusConnection to the system bus, or %NULL to
|
|
|
|
|
* 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
|
2019-03-19 17:55:11 +01:00
|
|
|
|
* @flags: flags to affect the behaviour of the call
|
2018-10-31 12:01:44 +01:00
|
|
|
|
* @cancellable: (nullable): a #GCancellable, or %NULL
|
|
|
|
|
* @error: return location for a #GError, or %NULL
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Synchronous version of mct_set_app_filter_async().
|
2018-10-31 12:01:44 +01:00
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success, %FALSE otherwise
|
2019-03-19 17:55:11 +01:00
|
|
|
|
* Since: 0.3.0
|
2018-10-31 12:01:44 +01:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2019-03-19 17:55:11 +01:00
|
|
|
|
mct_set_app_filter (GDBusConnection *connection,
|
|
|
|
|
uid_t user_id,
|
|
|
|
|
MctAppFilter *app_filter,
|
|
|
|
|
MctSetAppFilterFlags flags,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GError **error)
|
2018-10-31 12:01:44 +01:00
|
|
|
|
{
|
|
|
|
|
g_autofree gchar *object_path = NULL;
|
|
|
|
|
g_autoptr(GVariant) app_filter_variant = NULL;
|
|
|
|
|
g_autoptr(GVariant) oars_filter_variant = NULL;
|
2018-11-29 22:09:57 +01:00
|
|
|
|
g_autoptr(GVariant) allow_user_installation_variant = NULL;
|
2018-11-28 17:39:39 +01:00
|
|
|
|
g_autoptr(GVariant) allow_system_installation_variant = NULL;
|
2018-10-31 12:01:44 +01:00
|
|
|
|
g_autoptr(GVariant) app_filter_result_variant = NULL;
|
|
|
|
|
g_autoptr(GVariant) oars_filter_result_variant = NULL;
|
2018-11-29 22:09:57 +01:00
|
|
|
|
g_autoptr(GVariant) allow_user_installation_result_variant = NULL;
|
2018-11-28 17:39:39 +01:00
|
|
|
|
g_autoptr(GVariant) allow_system_installation_result_variant = NULL;
|
2018-10-31 12:01:44 +01:00
|
|
|
|
g_autoptr(GError) local_error = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (connection == NULL || G_IS_DBUS_CONNECTION (connection), FALSE);
|
|
|
|
|
g_return_val_if_fail (app_filter != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (app_filter->ref_count >= 1, FALSE);
|
|
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
if (connection == NULL)
|
|
|
|
|
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
|
|
|
|
|
if (connection == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2018-11-02 10:17:56 +01:00
|
|
|
|
object_path = accounts_find_user_by_id (connection, user_id,
|
2019-03-19 17:55:11 +01:00
|
|
|
|
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE),
|
2018-11-02 10:17:56 +01:00
|
|
|
|
cancellable, error);
|
|
|
|
|
if (object_path == NULL)
|
|
|
|
|
return FALSE;
|
2018-10-31 12:01:44 +01:00
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
app_filter_variant = _mct_app_filter_build_app_filter_variant (app_filter);
|
2018-10-31 12:01:44 +01:00
|
|
|
|
oars_filter_variant = g_variant_new ("(s@a{ss})", "oars-1.1",
|
|
|
|
|
app_filter->oars_ratings);
|
2018-11-29 22:09:57 +01:00
|
|
|
|
allow_user_installation_variant = g_variant_new_boolean (app_filter->allow_user_installation);
|
2018-11-28 17:39:39 +01:00
|
|
|
|
allow_system_installation_variant = g_variant_new_boolean (app_filter->allow_system_installation);
|
2018-10-31 12:01:44 +01:00
|
|
|
|
|
|
|
|
|
app_filter_result_variant =
|
|
|
|
|
g_dbus_connection_call_sync (connection,
|
|
|
|
|
"org.freedesktop.Accounts",
|
|
|
|
|
object_path,
|
|
|
|
|
"org.freedesktop.DBus.Properties",
|
|
|
|
|
"Set",
|
|
|
|
|
g_variant_new ("(ssv)",
|
|
|
|
|
"com.endlessm.ParentalControls.AppFilter",
|
2018-12-12 14:43:39 +01:00
|
|
|
|
"AppFilter",
|
2018-10-31 12:01:44 +01:00
|
|
|
|
g_steal_pointer (&app_filter_variant)),
|
|
|
|
|
G_VARIANT_TYPE ("()"),
|
2019-03-19 17:55:11 +01:00
|
|
|
|
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE)
|
2018-10-31 12:01:44 +01:00
|
|
|
|
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
|
|
|
|
|
: G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1, /* timeout, ms */
|
|
|
|
|
cancellable,
|
|
|
|
|
&local_error);
|
|
|
|
|
if (local_error != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_propagate_error (error, bus_error_to_app_filter_error (local_error, user_id));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oars_filter_result_variant =
|
|
|
|
|
g_dbus_connection_call_sync (connection,
|
|
|
|
|
"org.freedesktop.Accounts",
|
|
|
|
|
object_path,
|
|
|
|
|
"org.freedesktop.DBus.Properties",
|
|
|
|
|
"Set",
|
|
|
|
|
g_variant_new ("(ssv)",
|
|
|
|
|
"com.endlessm.ParentalControls.AppFilter",
|
2018-12-12 14:43:39 +01:00
|
|
|
|
"OarsFilter",
|
2018-10-31 12:01:44 +01:00
|
|
|
|
g_steal_pointer (&oars_filter_variant)),
|
|
|
|
|
G_VARIANT_TYPE ("()"),
|
2019-03-19 17:55:11 +01:00
|
|
|
|
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE)
|
2018-10-31 12:01:44 +01:00
|
|
|
|
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
|
|
|
|
|
: G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1, /* timeout, ms */
|
|
|
|
|
cancellable,
|
|
|
|
|
&local_error);
|
|
|
|
|
if (local_error != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_propagate_error (error, bus_error_to_app_filter_error (local_error, user_id));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-29 22:09:57 +01:00
|
|
|
|
allow_user_installation_result_variant =
|
|
|
|
|
g_dbus_connection_call_sync (connection,
|
|
|
|
|
"org.freedesktop.Accounts",
|
|
|
|
|
object_path,
|
|
|
|
|
"org.freedesktop.DBus.Properties",
|
|
|
|
|
"Set",
|
|
|
|
|
g_variant_new ("(ssv)",
|
|
|
|
|
"com.endlessm.ParentalControls.AppFilter",
|
2018-12-12 14:43:39 +01:00
|
|
|
|
"AllowUserInstallation",
|
2018-11-29 22:09:57 +01:00
|
|
|
|
g_steal_pointer (&allow_user_installation_variant)),
|
|
|
|
|
G_VARIANT_TYPE ("()"),
|
2019-03-19 17:55:11 +01:00
|
|
|
|
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE)
|
2018-11-29 22:09:57 +01:00
|
|
|
|
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
|
|
|
|
|
: G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1, /* timeout, ms */
|
|
|
|
|
cancellable,
|
|
|
|
|
&local_error);
|
|
|
|
|
if (local_error != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_propagate_error (error, bus_error_to_app_filter_error (local_error, user_id));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-28 17:39:39 +01:00
|
|
|
|
allow_system_installation_result_variant =
|
2018-11-13 12:30:19 +01:00
|
|
|
|
g_dbus_connection_call_sync (connection,
|
|
|
|
|
"org.freedesktop.Accounts",
|
|
|
|
|
object_path,
|
|
|
|
|
"org.freedesktop.DBus.Properties",
|
|
|
|
|
"Set",
|
|
|
|
|
g_variant_new ("(ssv)",
|
|
|
|
|
"com.endlessm.ParentalControls.AppFilter",
|
2018-12-12 14:43:39 +01:00
|
|
|
|
"AllowSystemInstallation",
|
2018-11-28 17:39:39 +01:00
|
|
|
|
g_steal_pointer (&allow_system_installation_variant)),
|
2018-11-13 12:30:19 +01:00
|
|
|
|
G_VARIANT_TYPE ("()"),
|
2019-03-19 17:55:11 +01:00
|
|
|
|
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE)
|
2018-11-13 12:30:19 +01:00
|
|
|
|
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
|
|
|
|
|
: G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1, /* timeout, ms */
|
|
|
|
|
cancellable,
|
|
|
|
|
&local_error);
|
|
|
|
|
if (local_error != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_propagate_error (error, bus_error_to_app_filter_error (local_error, user_id));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-31 12:01:44 +01:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void set_app_filter_thread_cb (GTask *task,
|
|
|
|
|
gpointer source_object,
|
|
|
|
|
gpointer task_data,
|
|
|
|
|
GCancellable *cancellable);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2018-10-31 12:01:44 +01:00
|
|
|
|
GDBusConnection *connection; /* (nullable) (owned) */
|
2018-10-12 05:47:59 +02:00
|
|
|
|
uid_t user_id;
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilter *app_filter; /* (owned) */
|
2019-03-19 17:55:11 +01:00
|
|
|
|
MctSetAppFilterFlags flags;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
} SetAppFilterData;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_app_filter_data_free (SetAppFilterData *data)
|
|
|
|
|
{
|
2018-10-31 12:01:44 +01:00
|
|
|
|
g_clear_object (&data->connection);
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_unref (data->app_filter);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
g_free (data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SetAppFilterData, set_app_filter_data_free)
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_set_app_filter_async:
|
2018-10-12 05:47:59 +02:00
|
|
|
|
* @connection: (nullable): a #GDBusConnection to the system bus, or %NULL to
|
|
|
|
|
* 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
|
2019-03-19 17:55:11 +01:00
|
|
|
|
* @flags: flags to affect the behaviour of the call
|
2018-10-12 05:47:59 +02:00
|
|
|
|
* @cancellable: (nullable): a #GCancellable, or %NULL
|
2018-10-31 12:01:16 +01:00
|
|
|
|
* @callback: a #GAsyncReadyCallback
|
2018-10-12 05:47:59 +02:00
|
|
|
|
* @user_data: user data to pass to @callback
|
|
|
|
|
*
|
|
|
|
|
* Asynchronously set the app filter settings for the given @user_id to the
|
|
|
|
|
* given @app_filter instance. This will set all fields of the app filter.
|
|
|
|
|
*
|
|
|
|
|
* @connection should be a connection to the system bus, where accounts-service
|
|
|
|
|
* runs. It’s provided mostly for testing purposes, or to allow an existing
|
|
|
|
|
* connection to be re-used. Pass %NULL to use the default connection.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* On failure, an #MctAppFilterError, a #GDBusError or a #GIOError will be
|
2018-10-12 05:47:59 +02:00
|
|
|
|
* returned. The user’s app filter settings will be left in an undefined state.
|
|
|
|
|
*
|
2019-03-19 17:55:11 +01:00
|
|
|
|
* Since: 0.3.0
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2019-03-19 17:55:11 +01:00
|
|
|
|
mct_set_app_filter_async (GDBusConnection *connection,
|
|
|
|
|
uid_t user_id,
|
|
|
|
|
MctAppFilter *app_filter,
|
|
|
|
|
MctSetAppFilterFlags flags,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
{
|
|
|
|
|
g_autoptr(GTask) task = NULL;
|
|
|
|
|
g_autoptr(SetAppFilterData) data = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (connection == NULL || G_IS_DBUS_CONNECTION (connection));
|
|
|
|
|
g_return_if_fail (app_filter != NULL);
|
|
|
|
|
g_return_if_fail (app_filter->ref_count >= 1);
|
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
|
|
task = g_task_new (NULL, cancellable, callback, user_data);
|
2019-02-26 18:43:56 +01:00
|
|
|
|
g_task_set_source_tag (task, mct_set_app_filter_async);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
data = g_new0 (SetAppFilterData, 1);
|
2018-12-12 14:36:53 +01:00
|
|
|
|
data->connection = (connection != NULL) ? g_object_ref (connection) : NULL;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
data->user_id = user_id;
|
2019-02-26 18:43:56 +01:00
|
|
|
|
data->app_filter = mct_app_filter_ref (app_filter);
|
2019-03-19 17:55:11 +01:00
|
|
|
|
data->flags = flags;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
g_task_set_task_data (task, g_steal_pointer (&data),
|
|
|
|
|
(GDestroyNotify) set_app_filter_data_free);
|
|
|
|
|
|
2018-10-31 12:01:44 +01:00
|
|
|
|
g_task_run_in_thread (task, set_app_filter_thread_cb);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2018-10-31 12:01:44 +01:00
|
|
|
|
set_app_filter_thread_cb (GTask *task,
|
|
|
|
|
gpointer source_object,
|
|
|
|
|
gpointer task_data,
|
|
|
|
|
GCancellable *cancellable)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
{
|
2018-10-31 12:01:44 +01:00
|
|
|
|
gboolean success;
|
|
|
|
|
SetAppFilterData *data = task_data;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
g_autoptr(GError) local_error = NULL;
|
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
success = mct_set_app_filter (data->connection, data->user_id,
|
2019-03-19 17:55:11 +01:00
|
|
|
|
data->app_filter, data->flags,
|
2018-10-31 12:01:44 +01:00
|
|
|
|
cancellable, &local_error);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
if (local_error != NULL)
|
|
|
|
|
g_task_return_error (task, g_steal_pointer (&local_error));
|
|
|
|
|
else
|
2018-10-31 12:01:44 +01:00
|
|
|
|
g_task_return_boolean (task, success);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_set_app_filter_finish:
|
2018-10-12 05:47:59 +02:00
|
|
|
|
* @result: a #GAsyncResult
|
|
|
|
|
* @error: return location for a #GError, or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Finish an asynchronous operation to set the app filter for a user, started
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* with mct_set_app_filter_async().
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success, %FALSE otherwise
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_set_app_filter_finish (GAsyncResult *result,
|
2018-10-12 05:47:59 +02:00
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (g_task_is_valid (result, NULL), FALSE);
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
return g_task_propagate_boolean (G_TASK (result), error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Actual implementation of #MctAppFilterBuilder.
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
|
|
|
|
* All members are %NULL if un-initialised, cleared, or ended.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
GPtrArray *paths_blacklist; /* (nullable) (owned) (element-type filename) */
|
2019-02-26 18:43:56 +01:00
|
|
|
|
GHashTable *oars; /* (nullable) (owned) (element-type utf8 MctAppFilterOarsValue) */
|
2018-11-29 22:09:57 +01:00
|
|
|
|
gboolean allow_user_installation;
|
2018-11-28 17:39:39 +01:00
|
|
|
|
gboolean allow_system_installation;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
/*< private >*/
|
|
|
|
|
gpointer padding[2];
|
2019-02-26 18:43:56 +01:00
|
|
|
|
} MctAppFilterBuilderReal;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
G_STATIC_ASSERT (sizeof (MctAppFilterBuilderReal) ==
|
|
|
|
|
sizeof (MctAppFilterBuilder));
|
|
|
|
|
G_STATIC_ASSERT (__alignof__ (MctAppFilterBuilderReal) ==
|
|
|
|
|
__alignof__ (MctAppFilterBuilder));
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
G_DEFINE_BOXED_TYPE (MctAppFilterBuilder, mct_app_filter_builder,
|
|
|
|
|
mct_app_filter_builder_copy, mct_app_filter_builder_free)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_builder_init:
|
|
|
|
|
* @builder: an uninitialised #MctAppFilterBuilder
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
|
|
|
|
* Initialise the given @builder so it can be used to construct a new
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* #MctAppFilter. @builder must have been allocated on the stack, and must not
|
2018-10-12 05:47:59 +02:00
|
|
|
|
* already be initialised.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Construct the #MctAppFilter by calling methods on @builder, followed by
|
|
|
|
|
* mct_app_filter_builder_end(). To abort construction, use
|
|
|
|
|
* mct_app_filter_builder_clear().
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_builder_init (MctAppFilterBuilder *builder)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterBuilder local_builder = MCT_APP_FILTER_BUILDER_INIT ();
|
|
|
|
|
MctAppFilterBuilderReal *_builder = (MctAppFilterBuilderReal *) builder;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (_builder != NULL);
|
|
|
|
|
g_return_if_fail (_builder->paths_blacklist == NULL);
|
|
|
|
|
g_return_if_fail (_builder->oars == NULL);
|
|
|
|
|
|
|
|
|
|
memcpy (builder, &local_builder, sizeof (local_builder));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_builder_clear:
|
|
|
|
|
* @builder: an #MctAppFilterBuilder
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
|
|
|
|
* Clear @builder, freeing any internal state in it. This will not free the
|
|
|
|
|
* top-level storage for @builder itself, which is assumed to be allocated on
|
|
|
|
|
* the stack.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* If called on an already-cleared #MctAppFilterBuilder, this function is
|
2018-10-12 05:47:59 +02:00
|
|
|
|
* idempotent.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_builder_clear (MctAppFilterBuilder *builder)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterBuilderReal *_builder = (MctAppFilterBuilderReal *) builder;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (_builder != NULL);
|
|
|
|
|
|
|
|
|
|
g_clear_pointer (&_builder->paths_blacklist, g_ptr_array_unref);
|
|
|
|
|
g_clear_pointer (&_builder->oars, g_hash_table_unref);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_builder_new:
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Construct a new #MctAppFilterBuilder on the heap. This is intended for
|
2018-10-12 05:47:59 +02:00
|
|
|
|
* language bindings. The returned builder must eventually be freed with
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_builder_free(), but can be cleared zero or more times with
|
|
|
|
|
* mct_app_filter_builder_clear() first.
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Returns: (transfer full): a new heap-allocated #MctAppFilterBuilder
|
|
|
|
|
* Since: 0.2.0
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*/
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterBuilder *
|
|
|
|
|
mct_app_filter_builder_new (void)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
g_autoptr(MctAppFilterBuilder) builder = NULL;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
builder = g_new0 (MctAppFilterBuilder, 1);
|
|
|
|
|
mct_app_filter_builder_init (builder);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
return g_steal_pointer (&builder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_builder_copy:
|
|
|
|
|
* @builder: an #MctAppFilterBuilder
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Copy the given @builder to a newly-allocated #MctAppFilterBuilder on the
|
2018-10-12 05:47:59 +02:00
|
|
|
|
* heap. This is safe to use with cleared, stack-allocated
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* #MctAppFilterBuilders.
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): a copy of @builder
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*/
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterBuilder *
|
|
|
|
|
mct_app_filter_builder_copy (MctAppFilterBuilder *builder)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterBuilderReal *_builder = (MctAppFilterBuilderReal *) builder;
|
|
|
|
|
g_autoptr(MctAppFilterBuilder) copy = NULL;
|
|
|
|
|
MctAppFilterBuilderReal *_copy;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (builder != NULL, NULL);
|
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
copy = mct_app_filter_builder_new ();
|
|
|
|
|
_copy = (MctAppFilterBuilderReal *) copy;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_builder_clear (copy);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
if (_builder->paths_blacklist != NULL)
|
|
|
|
|
_copy->paths_blacklist = g_ptr_array_ref (_builder->paths_blacklist);
|
|
|
|
|
if (_builder->oars != NULL)
|
|
|
|
|
_copy->oars = g_hash_table_ref (_builder->oars);
|
2018-11-29 22:09:57 +01:00
|
|
|
|
_copy->allow_user_installation = _builder->allow_user_installation;
|
2018-11-28 17:39:39 +01:00
|
|
|
|
_copy->allow_system_installation = _builder->allow_system_installation;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
return g_steal_pointer (©);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_builder_free:
|
|
|
|
|
* @builder: a heap-allocated #MctAppFilterBuilder
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Free an #MctAppFilterBuilder originally allocated using
|
|
|
|
|
* mct_app_filter_builder_new(). This must not be called on stack-allocated
|
|
|
|
|
* builders initialised using mct_app_filter_builder_init().
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_builder_free (MctAppFilterBuilder *builder)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (builder != NULL);
|
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_builder_clear (builder);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
g_free (builder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_builder_end:
|
|
|
|
|
* @builder: an initialised #MctAppFilterBuilder
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Finish constructing an #MctAppFilter with the given @builder, and return it.
|
|
|
|
|
* The #MctAppFilterBuilder will be cleared as if mct_app_filter_builder_clear()
|
2018-10-12 05:47:59 +02:00
|
|
|
|
* had been called.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Returns: (transfer full): a newly constructed #MctAppFilter
|
|
|
|
|
* Since: 0.2.0
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*/
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilter *
|
|
|
|
|
mct_app_filter_builder_end (MctAppFilterBuilder *builder)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterBuilderReal *_builder = (MctAppFilterBuilderReal *) builder;
|
|
|
|
|
g_autoptr(MctAppFilter) app_filter = NULL;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
g_auto(GVariantBuilder) oars_builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("a{ss}"));
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
gpointer key, value;
|
|
|
|
|
g_autoptr(GVariant) oars_variant = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (_builder != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (_builder->paths_blacklist != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (_builder->oars != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
/* Ensure the paths list is %NULL-terminated. */
|
|
|
|
|
g_ptr_array_add (_builder->paths_blacklist, NULL);
|
|
|
|
|
|
|
|
|
|
/* Build the OARS variant. */
|
|
|
|
|
g_hash_table_iter_init (&iter, _builder->oars);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
|
{
|
|
|
|
|
const gchar *oars_section = key;
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterOarsValue oars_value = GPOINTER_TO_INT (value);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
const gchar *oars_value_strs[] =
|
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
NULL, /* MCT_APP_FILTER_OARS_VALUE_UNKNOWN */
|
2018-10-12 05:47:59 +02:00
|
|
|
|
"none",
|
|
|
|
|
"mild",
|
|
|
|
|
"moderate",
|
|
|
|
|
"intense",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
g_assert ((int) oars_value >= 0 &&
|
|
|
|
|
(int) oars_value < (int) G_N_ELEMENTS (oars_value_strs));
|
|
|
|
|
|
|
|
|
|
if (oars_value_strs[oars_value] != NULL)
|
|
|
|
|
g_variant_builder_add (&oars_builder, "{ss}",
|
|
|
|
|
oars_section, oars_value_strs[oars_value]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oars_variant = g_variant_ref_sink (g_variant_builder_end (&oars_builder));
|
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
/* Build the #MctAppFilter. */
|
|
|
|
|
app_filter = g_new0 (MctAppFilter, 1);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
app_filter->ref_count = 1;
|
|
|
|
|
app_filter->user_id = -1;
|
|
|
|
|
app_filter->app_list = (gchar **) g_ptr_array_free (g_steal_pointer (&_builder->paths_blacklist), FALSE);
|
2019-02-26 18:43:56 +01:00
|
|
|
|
app_filter->app_list_type = MCT_APP_FILTER_LIST_BLACKLIST;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
app_filter->oars_ratings = g_steal_pointer (&oars_variant);
|
2018-11-29 22:09:57 +01:00
|
|
|
|
app_filter->allow_user_installation = _builder->allow_user_installation;
|
2018-11-28 17:39:39 +01:00
|
|
|
|
app_filter->allow_system_installation = _builder->allow_system_installation;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_builder_clear (builder);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
return g_steal_pointer (&app_filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_builder_blacklist_path:
|
|
|
|
|
* @builder: an initialised #MctAppFilterBuilder
|
2018-10-12 05:47:59 +02:00
|
|
|
|
* @path: (type filename): an absolute path to blacklist
|
|
|
|
|
*
|
|
|
|
|
* Add @path to the blacklist of app paths in the filter under construction. It
|
|
|
|
|
* will be canonicalised (without doing any I/O) before being added.
|
|
|
|
|
* The canonicalised @path will not be added again if it’s already been added.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_builder_blacklist_path (MctAppFilterBuilder *builder,
|
2018-10-12 05:47:59 +02:00
|
|
|
|
const gchar *path)
|
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterBuilderReal *_builder = (MctAppFilterBuilderReal *) builder;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (_builder != NULL);
|
|
|
|
|
g_return_if_fail (_builder->paths_blacklist != NULL);
|
|
|
|
|
g_return_if_fail (path != NULL);
|
|
|
|
|
g_return_if_fail (g_path_is_absolute (path));
|
|
|
|
|
|
|
|
|
|
g_autofree gchar *canonical_path = g_canonicalize_filename (path, "/");
|
|
|
|
|
|
|
|
|
|
if (!g_ptr_array_find_with_equal_func (_builder->paths_blacklist,
|
|
|
|
|
canonical_path, g_str_equal, NULL))
|
|
|
|
|
g_ptr_array_add (_builder->paths_blacklist, g_steal_pointer (&canonical_path));
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 06:59:04 +02:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_builder_blacklist_flatpak_ref:
|
|
|
|
|
* @builder: an initialised #MctAppFilterBuilder
|
2018-10-12 06:59:04 +02:00
|
|
|
|
* @app_ref: a flatpak app ref to blacklist
|
|
|
|
|
*
|
|
|
|
|
* Add @app_ref to the blacklist of flatpak refs in the filter under
|
|
|
|
|
* construction. The @app_ref will not be added again if it’s already been
|
|
|
|
|
* added.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-10-12 06:59:04 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_builder_blacklist_flatpak_ref (MctAppFilterBuilder *builder,
|
2018-10-12 06:59:04 +02:00
|
|
|
|
const gchar *app_ref)
|
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterBuilderReal *_builder = (MctAppFilterBuilderReal *) builder;
|
2018-10-12 06:59:04 +02:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (_builder != NULL);
|
|
|
|
|
g_return_if_fail (_builder->paths_blacklist != NULL);
|
|
|
|
|
g_return_if_fail (app_ref != NULL);
|
|
|
|
|
|
|
|
|
|
if (!g_ptr_array_find_with_equal_func (_builder->paths_blacklist,
|
|
|
|
|
app_ref, g_str_equal, NULL))
|
|
|
|
|
g_ptr_array_add (_builder->paths_blacklist, g_strdup (app_ref));
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 05:47:59 +02:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_builder_set_oars_value:
|
|
|
|
|
* @builder: an initialised #MctAppFilterBuilder
|
2018-10-12 05:47:59 +02:00
|
|
|
|
* @oars_section: name of the OARS section to set the value for
|
|
|
|
|
* @value: value to set for the @oars_section
|
|
|
|
|
*
|
|
|
|
|
* Set the OARS value for the given @oars_section, indicating the intensity of
|
|
|
|
|
* content covered by that section which the user is allowed to see (inclusive).
|
|
|
|
|
* Any apps which have more intense content in this section should not be usable
|
|
|
|
|
* by the user.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-10-12 05:47:59 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_builder_set_oars_value (MctAppFilterBuilder *builder,
|
2018-10-12 05:47:59 +02:00
|
|
|
|
const gchar *oars_section,
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterOarsValue value)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterBuilderReal *_builder = (MctAppFilterBuilderReal *) builder;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (_builder != NULL);
|
|
|
|
|
g_return_if_fail (_builder->oars != NULL);
|
|
|
|
|
g_return_if_fail (oars_section != NULL && *oars_section != '\0');
|
|
|
|
|
|
|
|
|
|
g_hash_table_insert (_builder->oars, g_strdup (oars_section),
|
|
|
|
|
GUINT_TO_POINTER (value));
|
|
|
|
|
}
|
2018-11-13 12:30:19 +01:00
|
|
|
|
|
2018-11-29 22:09:57 +01:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_builder_set_allow_user_installation:
|
|
|
|
|
* @builder: an initialised #MctAppFilterBuilder
|
2018-11-29 22:09:57 +01:00
|
|
|
|
* @allow_user_installation: %TRUE to allow app installation; %FALSE to
|
|
|
|
|
* unconditionally disallow it
|
|
|
|
|
*
|
|
|
|
|
* Set whether the user is allowed to install to their flatpak user repository.
|
|
|
|
|
* If this is %TRUE, app installation is still subject to the OARS values
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* (mct_app_filter_builder_set_oars_value()). If it is %FALSE, app installation
|
2018-11-29 22:09:57 +01:00
|
|
|
|
* is unconditionally disallowed for this user.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-11-29 22:09:57 +01:00
|
|
|
|
*/
|
|
|
|
|
void
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_builder_set_allow_user_installation (MctAppFilterBuilder *builder,
|
2018-11-29 22:09:57 +01:00
|
|
|
|
gboolean allow_user_installation)
|
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterBuilderReal *_builder = (MctAppFilterBuilderReal *) builder;
|
2018-11-29 22:09:57 +01:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (_builder != NULL);
|
|
|
|
|
|
|
|
|
|
_builder->allow_user_installation = allow_user_installation;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 12:30:19 +01:00
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* mct_app_filter_builder_set_allow_system_installation:
|
|
|
|
|
* @builder: an initialised #MctAppFilterBuilder
|
2018-11-28 17:39:39 +01:00
|
|
|
|
* @allow_system_installation: %TRUE to allow app installation; %FALSE to
|
2018-11-13 12:30:19 +01:00
|
|
|
|
* unconditionally disallow it
|
|
|
|
|
*
|
2018-11-28 17:39:39 +01:00
|
|
|
|
* Set whether the user is allowed to install to the flatpak system repository.
|
|
|
|
|
* If this is %TRUE, app installation is still subject to the OARS values
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* (mct_app_filter_builder_set_oars_value()). If it is %FALSE, app installation
|
2018-11-13 12:30:19 +01:00
|
|
|
|
* is unconditionally disallowed for this user.
|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
|
* Since: 0.2.0
|
2018-11-13 12:30:19 +01:00
|
|
|
|
*/
|
|
|
|
|
void
|
2019-02-26 18:43:56 +01:00
|
|
|
|
mct_app_filter_builder_set_allow_system_installation (MctAppFilterBuilder *builder,
|
2018-11-28 17:39:39 +01:00
|
|
|
|
gboolean allow_system_installation)
|
2018-11-13 12:30:19 +01:00
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
|
MctAppFilterBuilderReal *_builder = (MctAppFilterBuilderReal *) builder;
|
2018-11-13 12:30:19 +01:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (_builder != NULL);
|
|
|
|
|
|
2018-11-28 17:39:39 +01:00
|
|
|
|
_builder->allow_system_installation = allow_system_installation;
|
2018-11-13 12:30:19 +01:00
|
|
|
|
}
|