Commit f77b9afa authored by Christian Hergert's avatar Christian Hergert

proxy: stub out proxy essentials

This gets a new bonsai-proxy process compiled and imports the xdg desktop
portal utils to get information about peer applications on the D-Bus.
parent 266c2c6d
......@@ -19,6 +19,7 @@ gio_unix_dep = dependency('gio-unix-2.0', version: '>= @0@'.format(glib_req_vers
gnutls_dep = dependency('gnutls')
gcrypt_dep = dependency('libgcrypt')
lmdb_dep = dependency('lmdb')
json_glib_dep = dependency('json-glib-1.0')
gnome = import('gnome')
......
......@@ -6,4 +6,5 @@ subdir('libbonsai')
subdir('libbonsai-storage')
subdir('libbonsai-dao')
subdir('daemon')
subdir('proxy')
subdir('tools')
/* bonsai-proxy.c
*
* Copyright 2020 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#define G_LOG_DOMAIN "bonsai-proxy"
#include "config.h"
#include <glib/gi18n.h>
#include <libbonsai.h>
static GMainLoop *main_loop;
gint
main (gint argc,
gchar *argv[])
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(GDBusConnection) bus = NULL;
g_autoptr(GError) error = NULL;
context = g_option_context_new (_("- A sandboxing proxy for Bonsai applications"));
if (!g_option_context_parse (context, &argc, &argv, &error))
{
g_printerr ("%s\n", error->message);
return EXIT_FAILURE;
}
main_loop = g_main_loop_new (NULL, FALSE);
if (!(bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error)))
{
g_printerr ("%s\n", error->message);
return EXIT_FAILURE;
}
g_main_loop_run (main_loop);
g_printerr ("%s exiting.\n", argv[0]);
return EXIT_FAILURE;
}
bonsai_proxy_sources = [
'bonsai-proxy.c',
'xdp-utils.c',
]
bonsai_proxy_deps = [
gio_dep,
gio_unix_dep,
json_glib_dep,
libbonsai_dep,
]
bonsai_proxy = executable('bonsai-proxy', bonsai_proxy_sources,
dependencies: bonsai_proxy_deps,
install_dir: get_option('bindir'),
install: true,
)
This diff is collapsed.
/*
* Copyright © 2014, 2016 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>
* Matthias Clasen <mclasen@redhat.com>
*/
#pragma once
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <gio/gio.h>
#include <errno.h>
#define DESKTOP_PORTAL_OBJECT_PATH "/org/freedesktop/portal/desktop"
#define FLATPAK_METADATA_GROUP_APPLICATION "Application"
#define FLATPAK_METADATA_KEY_NAME "name"
#define FLATPAK_METADATA_GROUP_INSTANCE "Instance"
#define FLATPAK_METADATA_KEY_APP_PATH "app-path"
#define FLATPAK_METADATA_KEY_RUNTIME_PATH "runtime-path"
#define FLATPAK_METADATA_KEY_INSTANCE_ID "instance-id"
gint xdp_mkstempat (int dir_fd,
gchar *tmpl,
int flags,
int mode);
gboolean xdp_is_valid_app_id (const char *string);
typedef void (*XdpPeerDiedCallback) (const char *name);
typedef struct _XdpAppInfo XdpAppInfo;
XdpAppInfo *xdp_app_info_ref (XdpAppInfo *app_info);
void xdp_app_info_unref (XdpAppInfo *app_info);
const char *xdp_app_info_get_id (XdpAppInfo *app_info);
char * xdp_app_info_get_instance (XdpAppInfo *app_info);
gboolean xdp_app_info_is_host (XdpAppInfo *app_info);
gboolean xdp_app_info_supports_opath (XdpAppInfo *app_info);
char * xdp_app_info_remap_path (XdpAppInfo *app_info,
const char *path);
gboolean xdg_app_info_map_pids (XdpAppInfo *app_info,
pid_t *pids,
guint n_pids,
GError **error);
gboolean xdg_app_info_pidfds_to_pids (XdpAppInfo *app_info,
const int *fds,
pid_t *pids,
gint count,
GError **error);
char * xdp_app_info_get_path_for_fd (XdpAppInfo *app_info,
int fd,
int require_st_mode,
struct stat *st_buf,
gboolean *writable_out);
gboolean xdp_app_info_has_network (XdpAppInfo *app_info);
XdpAppInfo *xdp_get_app_info_from_pid (pid_t pid,
GError **error);
GAppInfo * xdp_app_info_load_app_info (XdpAppInfo *app_info);
char ** xdp_app_info_rewrite_commandline (XdpAppInfo *app_info,
const char *const *commandline);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(XdpAppInfo, xdp_app_info_unref)
XdpAppInfo *xdp_invocation_lookup_app_info_sync (GDBusMethodInvocation *invocation,
GCancellable *cancellable,
GError **error);
void xdp_connection_track_name_owners (GDBusConnection *connection,
XdpPeerDiedCallback peer_died_cb);
typedef struct {
const char *key;
const GVariantType *type;
gboolean (* validate) (const char *key, GVariant *value, GVariant *options, GError **error);
} XdpOptionKey;
gboolean xdp_filter_options (GVariant *options_in,
GVariantBuilder *options_out,
XdpOptionKey *supported_options,
int n_supported_options,
GError **error);
typedef enum {
XDG_DESKTOP_PORTAL_ERROR_FAILED = 0,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
XDG_DESKTOP_PORTAL_ERROR_NOT_FOUND,
XDG_DESKTOP_PORTAL_ERROR_EXISTS,
XDG_DESKTOP_PORTAL_ERROR_NOT_ALLOWED,
XDG_DESKTOP_PORTAL_ERROR_CANCELLED,
XDG_DESKTOP_PORTAL_ERROR_WINDOW_DESTROYED
} XdgDesktopPortalErrorEnum;
#define XDG_DESKTOP_PORTAL_ERROR xdg_desktop_portal_error_quark ()
GQuark xdg_desktop_portal_error_quark (void);
static inline int
xdp_steal_fd (int *fdp)
{
int fd = *fdp;
*fdp = -1;
return fd;
}
static inline void
xdp_close_fd (int *fdp)
{
int errsv;
int fd;
g_assert (fdp);
fd = xdp_steal_fd (fdp);
if (fd >= 0)
{
errsv = errno;
if (close (fd) < 0)
g_assert (errno != EBADF);
errno = errsv;
}
}
#define xdp_autofd __attribute__((cleanup(xdp_close_fd)))
static inline void
xdp_auto_unlock_helper (GMutex **mutex)
{
if (*mutex)
g_mutex_unlock (*mutex);
}
static inline GMutex *
xdp_auto_lock_helper (GMutex *mutex)
{
if (mutex)
g_mutex_lock (mutex);
return mutex;
}
#define XDP_AUTOLOCK(name) G_GNUC_UNUSED __attribute__((cleanup (xdp_auto_unlock_helper))) GMutex * G_PASTE (auto_unlock, __LINE__) = xdp_auto_lock_helper (&G_LOCK_NAME (name))
char * xdp_quote_argv (const char *argv[]);
gboolean xdp_spawn (GFile *dir,
char **output,
GSubprocessFlags flags,
GError **error,
const gchar *argv0,
va_list ap);
gboolean xdp_spawnv (GFile *dir,
char **output,
GSubprocessFlags flags,
GError **error,
const gchar * const *argv);
char * xdp_canonicalize_filename (const char *path);
gboolean xdp_has_path_prefix (const char *str,
const char *prefix);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment