Skip to content

Commit

Permalink
Split out permission store from session helper
Browse files Browse the repository at this point in the history
This is now available as org.freedesktop.impl.portal.PermissionStore
  • Loading branch information
alexlarsson committed May 9, 2016
1 parent 605b3f4 commit 28b5491
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 109 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ gtk-doc.make
flatpak
flatpak-session-helper
xdg-document-portal
xdg-permission-store
flatpak-builder
testdb
doc/*.1
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions data/Makefile.am.inc
Original file line number Diff line number Diff line change
@@ -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)
51 changes: 0 additions & 51 deletions data/org.freedesktop.Flatpak.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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'/>
Expand Down
78 changes: 78 additions & 0 deletions data/org.freedesktop.impl.portal.PermissionStore.xml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
-->

<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>
3 changes: 2 additions & 1 deletion document-portal/Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
45 changes: 23 additions & 22 deletions document-portal/xdp-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions permission-store/Makefile.am.inc
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[D-BUS Service]
Name=org.freedesktop.impl.portal.PermissionStore
Exec=@libexecdir@/xdg-permission-store
SystemdService=xdg-permission-store.service
84 changes: 84 additions & 0 deletions permission-store/permission-store.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/

#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;
}
Loading

0 comments on commit 28b5491

Please sign in to comment.