Split out permission store from session helper

This is now available as org.freedesktop.impl.portal.PermissionStore
tingping/wmclass
Alexander Larsson 2016-05-09 14:07:22 +02:00
parent 605b3f4e09
commit 28b549156a
16 changed files with 270 additions and 109 deletions

2
.gitignore vendored
View File

@ -30,6 +30,7 @@ gtk-doc.make
flatpak
flatpak-session-helper
xdg-document-portal
xdg-permission-store
flatpak-builder
testdb
doc/*.1
@ -39,6 +40,7 @@ flatpak-dbus.[ch]
flatpak-systemd-dbus.[ch]
flatpak-resources.[ch]
flatpak-dbus-proxy
permission-store-dbus.[ch]
flatpak-system-helper
xdg-desktop-portal
*.service

View File

@ -74,6 +74,7 @@ include builder/Makefile.am.inc
include session-helper/Makefile.am.inc
include system-helper/Makefile.am.inc
include dbus-proxy/Makefile.am.inc
include permission-store/Makefile.am.inc
include document-portal/Makefile.am.inc
include tests/Makefile.am.inc

View File

@ -1,11 +1,13 @@
introspectiondir = $(datadir)/dbus-1/interfaces
introspection_DATA = \
data/org.freedesktop.impl.portal.PermissionStore.xml \
data/org.freedesktop.portal.Documents.xml \
data/org.freedesktop.Flatpak.xml \
$(NULL)
EXTRA_DIST += \
data/org.freedesktop.portal.Documents.xml \
data/org.freedesktop.impl.portal.PermissionStore.xml \
data/org.freedesktop.systemd1.xml \
data/org.freedesktop.Flatpak.xml \
$(NULL)

View File

@ -31,57 +31,6 @@
</method>
</interface>
<interface name='org.freedesktop.Flatpak.PermissionStore'>
<method name="Lookup">
<arg name='table' type='s' direction='in'/>
<arg name='id' type='s' direction='in'/>
<arg name='permissions' type='a{sas}' direction='out'/>
<arg name='data' type='v' direction='out'/>
</method>
<method name="Set">
<arg name='table' type='s' direction='in'/>
<arg name='create' type='b' direction='in'/>
<arg name='id' type='s' direction='in'/>
<arg name='app_permissions' type='a{sas}' direction='in'/>
<arg name='data' type='v' direction='in'/>
</method>
<method name="Delete">
<arg name='table' type='s' direction='in'/>
<arg name='id' type='s' direction='in'/>
</method>
<method name="SetValue">
<arg name='table' type='s' direction='in'/>
<arg name='create' type='b' direction='in'/>
<arg name='id' type='s' direction='in'/>
<arg name='data' type='v' direction='in'/>
</method>
<method name="SetPermission">
<arg name='table' type='s' direction='in'/>
<arg name='create' type='b' direction='in'/>
<arg name='id' type='s' direction='in'/>
<arg name='app' type='s' direction='in'/>
<arg name='permissions' type='as' direction='in'/>
</method>
<method name="List">
<arg name='table' type='s' direction='in'/>
<arg name='ids' type='as' direction='out'/>
</method>
<signal name="Changed">
<arg name='table' type='s' direction='out'/>
<arg name='id' type='s' direction='out'/>
<arg name='deleted' type='b' direction='out'/>
<arg name='data' type='v' direction='out'/>
<arg name='permissions' type='a{sas}' direction='out'/>
</signal>
</interface>
<interface name='org.freedesktop.Flatpak.SystemHelper'>
<method name="Deploy">
<arg type='ay' name='repo_path' direction='in'/>

View File

@ -0,0 +1,78 @@
<!DOCTYPE node PUBLIC
"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!--
Copyright (C) 2015 Red Hat, 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 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.
Author: Alexander Larsson <alexl@redhat.com>
-->
<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
<interface name='org.freedesktop.impl.portal.PermissionStore'>
<method name="Lookup">
<arg name='table' type='s' direction='in'/>
<arg name='id' type='s' direction='in'/>
<arg name='permissions' type='a{sas}' direction='out'/>
<arg name='data' type='v' direction='out'/>
</method>
<method name="Set">
<arg name='table' type='s' direction='in'/>
<arg name='create' type='b' direction='in'/>
<arg name='id' type='s' direction='in'/>
<arg name='app_permissions' type='a{sas}' direction='in'/>
<arg name='data' type='v' direction='in'/>
</method>
<method name="Delete">
<arg name='table' type='s' direction='in'/>
<arg name='id' type='s' direction='in'/>
</method>
<method name="SetValue">
<arg name='table' type='s' direction='in'/>
<arg name='create' type='b' direction='in'/>
<arg name='id' type='s' direction='in'/>
<arg name='data' type='v' direction='in'/>
</method>
<method name="SetPermission">
<arg name='table' type='s' direction='in'/>
<arg name='create' type='b' direction='in'/>
<arg name='id' type='s' direction='in'/>
<arg name='app' type='s' direction='in'/>
<arg name='permissions' type='as' direction='in'/>
</method>
<method name="List">
<arg name='table' type='s' direction='in'/>
<arg name='ids' type='as' direction='out'/>
</method>
<signal name="Changed">
<arg name='table' type='s' direction='out'/>
<arg name='id' type='s' direction='out'/>
<arg name='deleted' type='b' direction='out'/>
<arg name='data' type='v' direction='out'/>
<arg name='permissions' type='a{sas}' direction='out'/>
</signal>
</interface>
</node>

View File

@ -22,7 +22,8 @@ dbus_service_DATA += document-portal/org.freedesktop.portal.Documents.service
xdg_document_portal_SOURCES = \
document-portal/xdp-main.c \
document-portal/xdp-enums.h \
$(xdp_dbus_built_sources) \
$(xdp_dbus_built_sources) \
$(ps_dbus_built_sources) \
document-portal/xdp-util.h \
document-portal/xdp-util.c \
document-portal/xdp-fuse.h \

View File

@ -17,6 +17,7 @@
#include "flatpak-dbus.h"
#include "flatpak-utils.h"
#include "flatpak-portal-error.h"
#include "permission-store/permission-store-dbus.h"
#include "xdp-fuse.h"
#include <sys/eventfd.h>
@ -36,7 +37,7 @@ typedef struct
static GMainLoop *loop = NULL;
static FlatpakDb *db = NULL;
static FlatpakPermissionStore *permission_store;
static XdgPermissionStore *permission_store;
static int daemon_event_fd = -1;
static int final_exit_status = 0;
static dev_t fuse_dev = 0;
@ -89,14 +90,14 @@ do_set_permissions (FlatpakDbEntry *entry,
if (persist_entry (new_entry))
{
flatpak_permission_store_call_set_permission (permission_store,
TABLE_NAME,
FALSE,
doc_id,
app_id,
perms_s,
NULL,
NULL, NULL);
xdg_permission_store_call_set_permission (permission_store,
TABLE_NAME,
FALSE,
doc_id,
app_id,
perms_s,
NULL,
NULL, NULL);
}
}
@ -243,8 +244,8 @@ portal_delete (GDBusMethodInvocation *invocation,
flatpak_db_set_entry (db, id, NULL);
if (persist_entry (entry))
flatpak_permission_store_call_delete (permission_store, TABLE_NAME,
id, NULL, NULL, NULL);
xdg_permission_store_call_delete (permission_store, TABLE_NAME,
id, NULL, NULL, NULL);
}
/* All i/o is done now, so drop the lock so we can invalidate the fuse caches */
@ -303,13 +304,13 @@ do_create_doc (struct stat *parent_st_buf, const char *path, gboolean reuse_exis
if (persistent)
{
flatpak_permission_store_call_set (permission_store,
TABLE_NAME,
TRUE,
id,
g_variant_new_array (G_VARIANT_TYPE ("{sas}"), NULL, 0),
g_variant_new_variant (data),
NULL, NULL, NULL);
xdg_permission_store_call_set (permission_store,
TABLE_NAME,
TRUE,
id,
g_variant_new_array (G_VARIANT_TYPE ("{sas}"), NULL, 0),
g_variant_new_variant (data),
NULL, NULL, NULL);
}
return id;
@ -823,10 +824,10 @@ main (int argc,
do_exit (3);
}
permission_store = flatpak_permission_store_proxy_new_sync (session_bus, G_DBUS_PROXY_FLAGS_NONE,
"org.freedesktop.Flatpak",
"/org/freedesktop/Flatpak/PermissionStore",
NULL, &error);
permission_store = xdg_permission_store_proxy_new_sync (session_bus, G_DBUS_PROXY_FLAGS_NONE,
"org.freedesktop.impl.portal.PermissionStore",
"/org/freedesktop/impl/portal/PermissionStore",
NULL, &error);
if (permission_store == NULL)
{
g_print ("No permission store: %s\n", error->message);

View File

@ -0,0 +1,30 @@
libexec_PROGRAMS += \
xdg-permission-store \
$(NULL)
service_in_files += permission-store/xdg-permission-store.service.in
systemduserunit_DATA += permission-store/xdg-permission-store.service
service_in_files += permission-store/org.freedesktop.impl.portal.PermissionStore.service.in
dbus_service_DATA += permission-store/org.freedesktop.impl.portal.PermissionStore.service
ps_dbus_built_sources = permission-store/permission-store-dbus.c permission-store/permission-store-dbus.h
BUILT_SOURCES += $(ps_dbus_built_sources)
$(ps_dbus_built_sources) : data/org.freedesktop.impl.portal.PermissionStore.xml
$(AM_V_GEN) $(GDBUS_CODEGEN) \
--interface-prefix org.freedesktop.impl.portal. \
--c-namespace Xdg \
--generate-c-code $(builddir)/permission-store/permission-store-dbus \
$(srcdir)/data/org.freedesktop.impl.portal.PermissionStore.xml \
$(NULL)
xdg_permission_store_SOURCES = \
$(ps_dbus_built_sources) \
permission-store/permission-store.c \
permission-store/xdg-permission-store.c \
permission-store/xdg-permission-store.h \
$(NULL)
xdg_permission_store_LDADD = $(BASE_LIBS) libflatpak-common.la
xdg_permission_store_CFLAGS = $(BASE_CFLAGS) $(SOUP_CFLAGS) $(OSTREE_CFLAGS) $(GSYSTEM_CFLAGS)

View File

@ -0,0 +1,4 @@
[D-BUS Service]
Name=org.freedesktop.impl.portal.PermissionStore
Exec=@libexecdir@/xdg-permission-store
SystemdService=xdg-permission-store.service

View File

@ -0,0 +1,84 @@
/*
* Copyright © 2014 Red Hat, Inc
*
* This program 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 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, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Alexander Larsson <alexl@redhat.com>
*/
#include "config.h"
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include "permission-store-dbus.h"
#include "xdg-permission-store.h"
#include "flatpak-utils.h"
static void
on_bus_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
xdg_permission_store_start (connection);
}
static void
on_name_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
}
static void
on_name_lost (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
exit (1);
}
int
main (int argc,
char **argv)
{
guint owner_id;
GMainLoop *loop;
setlocale (LC_ALL, "");
g_setenv ("GIO_USE_VFS", "local", TRUE);
g_set_prgname (argv[0]);
flatpak_migrate_from_xdg_app ();
owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
"org.freedesktop.impl.portal.PermissionStore",
G_BUS_NAME_OWNER_FLAGS_NONE,
on_bus_acquired,
on_name_acquired,
on_name_lost,
NULL,
NULL);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
g_bus_unown_name (owner_id);
return 0;
}

View File

@ -24,7 +24,8 @@
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include "flatpak-permission-store.h"
#include "permission-store-dbus.h"
#include "xdg-permission-store.h"
#include "flatpak-db.h"
#include "flatpak-portal-error.h"
@ -144,7 +145,7 @@ ensure_writeout (Table *table,
}
static gboolean
handle_list (FlatpakPermissionStore *object,
handle_list (XdgPermissionStore *object,
GDBusMethodInvocation *invocation,
const gchar *table_name)
{
@ -158,7 +159,7 @@ handle_list (FlatpakPermissionStore *object,
ids = flatpak_db_list_ids (table->db);
flatpak_permission_store_complete_list (object, invocation, (const char * const *) ids);
xdg_permission_store_complete_list (object, invocation, (const char * const *) ids);
return TRUE;
}
@ -186,7 +187,7 @@ get_app_permissions (FlatpakDbEntry *entry)
}
static gboolean
handle_lookup (FlatpakPermissionStore *object,
handle_lookup (XdgPermissionStore *object,
GDBusMethodInvocation *invocation,
const gchar *table_name,
const gchar *id)
@ -213,15 +214,15 @@ handle_lookup (FlatpakPermissionStore *object,
data = flatpak_db_entry_get_data (entry);
permissions = get_app_permissions (entry);
flatpak_permission_store_complete_lookup (object, invocation,
permissions,
g_variant_new_variant (data));
xdg_permission_store_complete_lookup (object, invocation,
permissions,
g_variant_new_variant (data));
return TRUE;
}
static void
emit_deleted (FlatpakPermissionStore *object,
emit_deleted (XdgPermissionStore *object,
const gchar *table_name,
const gchar *id,
FlatpakDbEntry *entry)
@ -232,16 +233,16 @@ emit_deleted (FlatpakPermissionStore *object,
data = flatpak_db_entry_get_data (entry);
permissions = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("{sas}"), NULL, 0));
flatpak_permission_store_emit_changed (object,
table_name, id,
TRUE,
g_variant_new_variant (data),
permissions);
xdg_permission_store_emit_changed (object,
table_name, id,
TRUE,
g_variant_new_variant (data),
permissions);
}
static void
emit_changed (FlatpakPermissionStore *object,
emit_changed (XdgPermissionStore *object,
const gchar *table_name,
const gchar *id,
FlatpakDbEntry *entry)
@ -252,15 +253,15 @@ emit_changed (FlatpakPermissionStore *object,
data = flatpak_db_entry_get_data (entry);
permissions = get_app_permissions (entry);
flatpak_permission_store_emit_changed (object,
table_name, id,
FALSE,
g_variant_new_variant (data),
permissions);
xdg_permission_store_emit_changed (object,
table_name, id,
FALSE,
g_variant_new_variant (data),
permissions);
}
static gboolean
handle_delete (FlatpakPermissionStore *object,
handle_delete (XdgPermissionStore *object,
GDBusMethodInvocation *invocation,
const gchar *table_name,
const gchar *id)
@ -291,7 +292,7 @@ handle_delete (FlatpakPermissionStore *object,
}
static gboolean
handle_set (FlatpakPermissionStore *object,
handle_set (XdgPermissionStore *object,
GDBusMethodInvocation *invocation,
const gchar *table_name,
gboolean create,
@ -349,7 +350,7 @@ handle_set (FlatpakPermissionStore *object,
}
static gboolean
handle_set_permission (FlatpakPermissionStore *object,
handle_set_permission (XdgPermissionStore *object,
GDBusMethodInvocation *invocation,
const gchar *table_name,
gboolean create,
@ -392,7 +393,7 @@ handle_set_permission (FlatpakPermissionStore *object,
}
static gboolean
handle_set_value (FlatpakPermissionStore *object,
handle_set_value (XdgPermissionStore *object,
GDBusMethodInvocation *invocation,
const gchar *table_name,
gboolean create,
@ -437,15 +438,15 @@ handle_set_value (FlatpakPermissionStore *object,
}
void
flatpak_permission_store_start (GDBusConnection *connection)
xdg_permission_store_start (GDBusConnection *connection)
{
FlatpakPermissionStore *store;
XdgPermissionStore *store;
GError *error = NULL;
tables = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify) table_free);
store = flatpak_permission_store_skeleton_new ();
store = xdg_permission_store_skeleton_new ();
g_signal_connect (store, "handle-list", G_CALLBACK (handle_list), NULL);
g_signal_connect (store, "handle-lookup", G_CALLBACK (handle_lookup), NULL);
@ -456,7 +457,7 @@ flatpak_permission_store_start (GDBusConnection *connection)
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (store),
connection,
"/org/freedesktop/Flatpak/PermissionStore",
"/org/freedesktop/impl/portal/PermissionStore",
&error))
{
g_warning ("error: %s\n", error->message);

View File

@ -23,6 +23,6 @@
#include "flatpak-dbus.h"
void flatpak_permission_store_start (GDBusConnection *connection);
void xdg_permission_store_start (GDBusConnection *connection);
#endif /* __FLATPAK_PERMISSION_STORE_H__ */

View File

@ -0,0 +1,7 @@
[Unit]
Description=sandboxed app permission store
[Service]
BusName=org.freedesktop.impl.portal.PermissionStore
ExecStart=@libexecdir@/xdg-permission-store
Type=dbus

View File

@ -10,8 +10,6 @@ dbus_service_DATA += session-helper/org.freedesktop.Flatpak.service
flatpak_session_helper_SOURCES = \
session-helper/flatpak-session-helper.c \
session-helper/flatpak-permission-store.c \
session-helper/flatpak-permission-store.h \
$(NULL)
flatpak_session_helper_LDADD = $(BASE_LIBS) libflatpak-common.la

View File

@ -25,7 +25,6 @@
#include <string.h>
#include <gio/gio.h>
#include "flatpak-dbus.h"
#include "flatpak-permission-store.h"
#include "flatpak-utils.h"
static char *monitor_dir;
@ -49,8 +48,6 @@ on_bus_acquired (GDBusConnection *connection,
FlatpakSessionHelper *helper;
GError *error = NULL;
flatpak_permission_store_start (connection);
helper = flatpak_session_helper_skeleton_new ();
g_signal_connect (helper, "handle-request-monitor", G_CALLBACK (handle_request_monitor), NULL);

View File

@ -25,23 +25,28 @@ test_doc_portal_LDADD = \
$(NULL)
test_doc_portal_SOURCES = tests/test-doc-portal.c $(xdp_dbus_built_sources)
EXTRA_test_doc_portal_DEPENDENCIES = tests/services/org.freedesktop.portal.Documents.service tests/services/org.freedesktop.Flatpak.service
EXTRA_test_doc_portal_DEPENDENCIES = tests/services/org.freedesktop.impl.portal.PermissionStore.service tests/services/org.freedesktop.portal.Documents.service tests/services/org.freedesktop.Flatpak.service
tests/services/org.freedesktop.portal.Documents.service: document-portal/org.freedesktop.portal.Documents.service.in
mkdir -p tests/services
$(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(abs_top_builddir)|" $< > $@
tests/services/org.freedesktop.impl.portal.PermissionStore.service: permission-store/org.freedesktop.impl.portal.PermissionStore.service.in
mkdir -p tests/services
$(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(abs_top_builddir)|" $< > $@
tests/services/org.freedesktop.Flatpak.service: session-helper/org.freedesktop.Flatpak.service.in
mkdir -p tests/services
$(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(abs_top_builddir)|" $< > $@
tests/libtest.sh: tests/services/org.freedesktop.portal.Documents.service tests/services/org.freedesktop.Flatpak.service
tests/libtest.sh: tests/services/org.freedesktop.impl.portal.PermissionStore.service tests/services/org.freedesktop.portal.Documents.service tests/services/org.freedesktop.Flatpak.service
install-test-data-hook:
if ENABLE_INSTALLED_TESTS
mkdir -p $(DESTDIR)$(installed_testdir)/services
ln -sf $(dbus_servicedir)/org.freedesktop.Flatpak.service $(DESTDIR)$(installed_testdir)/services/
ln -sf $(dbus_servicedir)/org.freedesktop.portal.Documents.service $(DESTDIR)$(installed_testdir)/services/
ln -sf $(dbus_servicedir)/org.freedesktop.impl.portal.PermissionStore.service $(DESTDIR)$(installed_testdir)/services/
endif
tests/package_version.txt: Makefile
@ -81,4 +86,5 @@ EXTRA_DIST += tests/flatpak-valgrind.supp tests/dbs/no_tables
CLEANFILES += \
tests/services/org.freedesktop.Flatpak.service \
tests/services/org.freedesktop.portal.Documents.service \
tests/services/org.freedesktop.impl.portal.PermissionStore.service \
$(NULL)