Import dbus-proxy as a submodule instead

Since we now broke out dbus-proxy to a separate module, build
the in-tree copy as a submodule.

Closes: #2092
Approved by: alexlarsson
This commit is contained in:
Alexander Larsson
2018-09-13 09:26:42 +02:00
committed by Atomic Bot
parent 1959f6bf75
commit a0a85d6aa8
7 changed files with 17 additions and 3257 deletions

4
.gitmodules vendored
View File

@@ -5,3 +5,7 @@
path = bubblewrap
url = https://github.com/projectatomic/bubblewrap.git
ignore = dirty
[submodule "dbus-proxy"]
path = dbus-proxy
url = https://github.com/flatpak/xdg-dbus-proxy.git
branch = master

View File

@@ -96,11 +96,20 @@ include app/Makefile.am.inc
include session-helper/Makefile.am.inc
include portal/Makefile.am.inc
include system-helper/Makefile.am.inc
if !WITH_SYSTEM_DBUS_PROXY
include dbus-proxy/Makefile.am.inc
endif
include tests/Makefile.am.inc
if !WITH_SYSTEM_DBUS_PROXY
libexec_PROGRAMS+=flatpak-dbus-proxy
flatpak_dbus_proxy_SOURCES = \
dbus-proxy/flatpak-proxy.c \
dbus-proxy/flatpak-proxy.h \
dbus-proxy/dbus-proxy.c \
dbus-proxy/backport-autoptr.h \
$(NULL)
flatpak_dbus_proxy_LDADD = $(AM_LDADD) $(BASE_LIBS)
flatpak_dbus_proxy_CFLAGS = $(AM_CFLAGS) $(BASE_CFLAGS)
endif
if !WITH_SYSTEM_BWRAP
bwrap_PROGRAMS = flatpak-bwrap

1
dbus-proxy Submodule

Submodule dbus-proxy added at ef4d1d05ef

View File

@@ -1,12 +0,0 @@
libexec_PROGRAMS += \
flatpak-dbus-proxy \
$(NULL)
flatpak_dbus_proxy_SOURCES = \
dbus-proxy/flatpak-proxy.c \
dbus-proxy/flatpak-proxy.h \
dbus-proxy/dbus-proxy.c \
$(NULL)
flatpak_dbus_proxy_LDADD = $(AM_LDADD) $(BASE_LIBS) libglnx.la
flatpak_dbus_proxy_CFLAGS = $(AM_CFLAGS) $(BASE_CFLAGS) -I$(srcdir)/dbus-proxy

View File

@@ -1,322 +0,0 @@
/*
* Copyright © 2015 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.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, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Alexander Larsson <alexl@redhat.com>
*/
#include "config.h"
#include <string.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "libglnx/libglnx.h"
#include "flatpak-proxy.h"
static GList *proxies;
static int sync_fd = -1;
static void
add_args (GBytes *bytes,
GPtrArray *args,
int pos)
{
gsize data_len, remainder_len;
const guchar *data = g_bytes_get_data (bytes, &data_len);
guchar *s;
const guchar *remainder;
remainder = data;
remainder_len = data_len;
s = memchr (remainder, 0, remainder_len);
while (s)
{
gsize len = s - remainder;
char *arg = g_strndup ((char *) remainder, len);
g_ptr_array_insert (args, pos++, arg);
remainder = s + 1;
remainder_len -= len + 1;
s = memchr (remainder, 0, remainder_len);
}
if (remainder_len)
{
char *arg = g_strndup ((char *) remainder, remainder_len);
g_ptr_array_insert (args, pos++, arg);
}
}
static gboolean
parse_generic_args (GPtrArray *args, int *args_i)
{
const char *arg = g_ptr_array_index (args, *args_i);
if (g_str_has_prefix (arg, "--fd="))
{
const char *fd_s = arg + strlen ("--fd=");
char *endptr;
int fd;
fd = strtol (fd_s, &endptr, 10);
if (fd < 0 || endptr == fd_s || *endptr != 0)
{
g_printerr ("Invalid fd %s\n", fd_s);
return FALSE;
}
sync_fd = fd;
*args_i += 1;
return TRUE;
}
else if (g_str_has_prefix (arg, "--args="))
{
const char *fd_s = arg + strlen ("--args=");
char *endptr;
int fd;
g_autoptr(GBytes) data = NULL;
g_autoptr(GError) error = NULL;
fd = strtol (fd_s, &endptr, 10);
if (fd < 0 || endptr == fd_s || *endptr != 0)
{
g_printerr ("Invalid --args fd %s\n", fd_s);
return FALSE;
}
data = glnx_fd_readall_bytes (fd, NULL, &error);
if (data == NULL)
{
g_printerr ("Failed to load --args: %s\n", error->message);
return FALSE;
}
*args_i += 1;
add_args (data, args, *args_i);
return TRUE;
}
else
{
g_printerr ("Unknown argument %s\n", arg);
return FALSE;
}
}
static gboolean
start_proxy (GPtrArray *args, int *args_i)
{
g_autoptr(FlatpakProxy) proxy = NULL;
g_autoptr(GError) error = NULL;
const char *bus_address, *socket_path;
const char *arg;
if (*args_i >= args->len || ((char *) g_ptr_array_index (args, *args_i))[0] == '-')
{
g_printerr ("No bus address given\n");
return FALSE;
}
bus_address = g_ptr_array_index (args, *args_i);
*args_i += 1;
if (*args_i >= args->len || ((char *) g_ptr_array_index (args, *args_i))[0] == '-')
{
g_printerr ("No socket path given\n");
return FALSE;
}
socket_path = g_ptr_array_index (args, *args_i);
*args_i += 1;
proxy = flatpak_proxy_new (bus_address, socket_path);
while (*args_i < args->len)
{
arg = g_ptr_array_index (args, *args_i);
if (arg[0] != '-')
break;
if (g_str_has_prefix (arg, "--see=") ||
g_str_has_prefix (arg, "--talk=") ||
g_str_has_prefix (arg, "--own="))
{
FlatpakPolicy policy = FLATPAK_POLICY_SEE;
g_autofree char *name = g_strdup (strchr (arg, '=') + 1);
gboolean wildcard = FALSE;
if (arg[2] == 't')
policy = FLATPAK_POLICY_TALK;
else if (arg[2] == 'o')
policy = FLATPAK_POLICY_OWN;
if (g_str_has_suffix (name, ".*"))
{
name[strlen (name) - 2] = 0;
wildcard = TRUE;
}
if (name[0] == ':' || !g_dbus_is_name (name))
{
g_printerr ("'%s' is not a valid dbus name\n", name);
return FALSE;
}
flatpak_proxy_add_policy (proxy, name, wildcard, policy);
*args_i += 1;
}
else if (g_str_has_prefix (arg, "--call=") ||
g_str_has_prefix (arg, "--broadcast="))
{
g_autofree char *rest = g_strdup (strchr (arg, '=') + 1);
char *name = rest;
char *rule;
char *name_end = strchr (rest, '=');
gboolean wildcard = FALSE;
if (name_end == NULL)
{
g_printerr ("'%s' is not a valid name + rule\n", rest);
return FALSE;
}
*name_end = 0;
rule = name_end + 1;
if (g_str_has_suffix (name, ".*"))
{
name[strlen (name) - 2] = 0;
wildcard = TRUE;
}
if (g_str_has_prefix (arg, "--call="))
flatpak_proxy_add_call_rule (proxy, name, wildcard, rule);
else
flatpak_proxy_add_broadcast_rule (proxy, name, wildcard, rule);
*args_i += 1;
}
else if (g_str_equal (arg, "--log"))
{
flatpak_proxy_set_log_messages (proxy, TRUE);
*args_i += 1;
}
else if (g_str_equal (arg, "--filter"))
{
flatpak_proxy_set_filter (proxy, TRUE);
*args_i += 1;
}
else if (g_str_equal (arg, "--sloppy-names"))
{
/* This means we're reporing the name changes for all unique names,
which is needed for the a11y bus */
flatpak_proxy_set_sloppy_names (proxy, TRUE);
*args_i += 1;
}
else
{
if (!parse_generic_args (args, args_i))
return FALSE;
}
}
if (!flatpak_proxy_start (proxy, &error))
{
g_printerr ("Failed to start proxy for %s: %s\n", bus_address, error->message);
return FALSE;
}
proxies = g_list_prepend (proxies, g_object_ref (proxy));
return TRUE;
}
static gboolean
sync_closed_cb (GIOChannel *source,
GIOCondition condition,
gpointer data)
{
GList *l;
for (l = proxies; l != NULL; l = l->next)
flatpak_proxy_stop (FLATPAK_PROXY (l->data));
exit (0);
return TRUE;
}
int
main (int argc, const char *argv[])
{
GMainLoop *service_loop;
int i, args_i;
g_autoptr(GPtrArray) args = g_ptr_array_new_with_free_func (g_free);
for (i = 1; i < argc; i++)
g_ptr_array_add (args, g_strdup ((char *) argv[i]));
args_i = 0;
while (args_i < args->len)
{
const char *arg = g_ptr_array_index (args, args_i);
if (arg[0] == '-')
{
if (!parse_generic_args (args, &args_i))
return 1;
}
else
{
if (!start_proxy (args, &args_i))
return 1;
}
}
if (proxies == NULL)
{
g_printerr ("No proxies specified\n");
return 1;
}
if (sync_fd >= 0)
{
ssize_t written;
GIOChannel *sync_channel;
written = write (sync_fd, "x", 1);
if (written != 1)
g_warning ("Can't write to sync socket");
sync_channel = g_io_channel_unix_new (sync_fd);
g_io_add_watch (sync_channel, G_IO_ERR | G_IO_HUP,
sync_closed_cb, NULL);
}
service_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (service_loop);
g_main_loop_unref (service_loop);
return 0;
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,68 +0,0 @@
/*
* Copyright © 2015 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.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, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Alexander Larsson <alexl@redhat.com>
*/
#ifndef __FLATPAK_PROXY_H__
#define __FLATPAK_PROXY_H__
#include <gio/gio.h>
#include "libglnx/libglnx.h"
typedef enum {
FLATPAK_POLICY_NONE,
FLATPAK_POLICY_SEE,
FLATPAK_POLICY_TALK,
FLATPAK_POLICY_OWN
} FlatpakPolicy;
typedef struct FlatpakProxy FlatpakProxy;
#define FLATPAK_TYPE_PROXY flatpak_proxy_get_type ()
#define FLATPAK_PROXY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FLATPAK_TYPE_PROXY, FlatpakProxy))
#define FLATPAK_IS_PROXY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FLATPAK_TYPE_PROXY))
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FlatpakProxy, g_object_unref)
GType flatpak_proxy_get_type (void);
FlatpakProxy *flatpak_proxy_new (const char *dbus_address,
const char *socket_path);
void flatpak_proxy_set_log_messages (FlatpakProxy *proxy,
gboolean log);
void flatpak_proxy_set_filter (FlatpakProxy *proxy,
gboolean filter);
void flatpak_proxy_set_sloppy_names (FlatpakProxy *proxy,
gboolean sloppy_names);
void flatpak_proxy_add_policy (FlatpakProxy *proxy,
const char *name,
gboolean name_is_subtree,
FlatpakPolicy policy);
void flatpak_proxy_add_call_rule (FlatpakProxy *proxy,
const char *name,
gboolean name_is_subtree,
const char *rule);
void flatpak_proxy_add_broadcast_rule (FlatpakProxy *proxy,
const char *name,
gboolean name_is_subtree,
const char *rule);
gboolean flatpak_proxy_start (FlatpakProxy *proxy,
GError **error);
void flatpak_proxy_stop (FlatpakProxy *proxy);
#endif /* __FLATPAK_PROXY_H__ */