Skip to content

Commit

Permalink
utils: Introduce XDP_APP_INFO_KIND_CONTAINERS1
Browse files Browse the repository at this point in the history
This new app kind is authenticated by D-Bus and x-d-p gets all the
information about the app from D-Bus which itself get the information
from the sandbox engine which set up the sandbox of the app.

Currently only flatpak and dbus (dbus-daemon) supports this mechanism
but it can be supported by any other sandbox engine, such as snap and
firejail.

This also means that an app with XDP_APP_INFO_KIND_CONTAINERS1 can still
be a flatpak or a snap app.

The goal is to make as many paths in x-d-p agnostic to the actual
sandbox engine and handle all XDP_APP_INFO_KIND_CONTAINERS1 apps the
same. Eventually we can then remove any other XDP_APP_INFO_KIND
variants.

This commit sets up a XdpAppInfo object with all the metadata x-d-p will
need. The follow up commit implements various XdpAppInfo
functionalities.
  • Loading branch information
swick committed Feb 8, 2024
1 parent 9e0bee0 commit 3a88810
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
55 changes: 54 additions & 1 deletion src/xdp-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ struct _XdpAppInfo {
{
GKeyFile *keyfile;
} snap;
struct
{
char *container_type;
char *instance_id;
int pidfd;
char *desktop_file;
gboolean has_network;
} containers1;
} u;
};

Expand Down Expand Up @@ -266,6 +274,13 @@ xdp_app_info_free (XdpAppInfo *app_info)
g_clear_pointer (&app_info->u.snap.keyfile, g_key_file_free);
break;

case XDP_APP_INFO_KIND_CONTAINERS1:
g_clear_pointer (&app_info->u.containers1.container_type, g_free);
g_clear_pointer (&app_info->u.containers1.instance_id, g_free);
g_clear_pointer (&app_info->u.containers1.desktop_file, g_free);
xdp_close_fd (&app_info->u.containers1.pidfd);
break;

default:
break;
}
Expand Down Expand Up @@ -844,7 +859,45 @@ xdp_app_info_from_containers1 (GVariant *containers1_data,
int pidfd,
GError **error)
{
return NULL;
XdpAppInfo *app_info = NULL;
const char *container_type;
const char *app_id;
const char *instance_id;
GVariant *metadata;
const char *desktop_file;
gboolean network_access;

if (!containers1_data || pidfd < 0)
return NULL;

g_variant_get (containers1_data, "(o@a{sv}sss@a{sv})",
NULL,
NULL,
&container_type,
&app_id,
&instance_id,
&metadata);

if (!app_id || !instance_id || !container_type)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Bad Containers1 metadata");
return NULL;
}

app_info = xdp_app_info_new (XDP_APP_INFO_KIND_CONTAINERS1);
app_info->id = g_strdup (app_id);
app_info->u.containers1.container_type = g_strdup (container_type);
app_info->u.containers1.instance_id = g_strdup (instance_id);
app_info->u.containers1.pidfd = pidfd;

if (g_variant_lookup (metadata, "DesktopFile", "&s", &desktop_file))
app_info->u.containers1.desktop_file = g_strdup (desktop_file);

app_info->u.containers1.has_network = TRUE;
if (g_variant_lookup (metadata, "NetworkAccess", "b", &network_access))
app_info->u.containers1.has_network = network_access;

return app_info;
}

static gboolean
Expand Down
7 changes: 4 additions & 3 deletions src/xdp-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@

typedef enum
{
XDP_APP_INFO_KIND_HOST = 0,
XDP_APP_INFO_KIND_FLATPAK = 1,
XDP_APP_INFO_KIND_SNAP = 2,
XDP_APP_INFO_KIND_HOST = 0,
XDP_APP_INFO_KIND_FLATPAK = 1,
XDP_APP_INFO_KIND_SNAP = 2,
XDP_APP_INFO_KIND_CONTAINERS1 = 3,
} XdpAppInfoKind;

gint xdp_mkstempat (int dir_fd,
Expand Down

0 comments on commit 3a88810

Please sign in to comment.