Skip to content

Commit a6df1d0

Browse files
mcatanzaroGeorgesStavracas
authored andcommitted
camera: fix permission check in OpenPipeWireRemote
6cd99b0 changed the logic that the camera portal uses to look up permissions for the AccessCamera method. Applications first call AccessCamera to ensure they have camera permission and to prompt the user if permission is missing, then they call OpenPipeWireRemote, which fails if permission is missing. The permission lookup logic needs to be the same in both places. Currently when running Snapshot launched by GNOME Shell (rather than launched in a terminal), Snapshot passes AccessCamera's permission check, then fails OpenPipeWireRemote's permission check, causing camera access to be denied without allowing the user to grant permission. Also, since the same commit the code uses the XdpAppInfo on a secondary thread. I suspect this is unsafe, and the original code avoided doing so; therefore, let's be careful and move this logic to the main thread so that the secondary thread only receives a copy of the app ID, as before. https://gitlab.gnome.org/GNOME/snapshot/-/issues/267
1 parent 45b5f7a commit a6df1d0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/camera.c

+13-9
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ handle_access_camera_in_thread_func (GTask *task,
7676
const char *app_id;
7777
gboolean allowed;
7878

79-
if (xdp_app_info_is_host (request->app_info))
80-
app_id = "";
81-
else
82-
app_id = (const char *)g_object_get_data (G_OBJECT (request), "app-id");
83-
79+
app_id = (const char *)g_object_get_data (G_OBJECT (request), "app-id");
8480
allowed = device_query_permission_sync (app_id, "camera", request);
8581

8682
REQUEST_AUTOLOCK (request);
@@ -102,6 +98,16 @@ handle_access_camera_in_thread_func (GTask *task,
10298
}
10399
}
104100

101+
static const char *
102+
app_id_from_app_info (XdpAppInfo *app_info)
103+
{
104+
/* Automatically grant camera access to unsandboxed apps. */
105+
if (xdp_app_info_is_host (app_info))
106+
return "";
107+
108+
return xdp_app_info_get_id (app_info);
109+
}
110+
105111
static gboolean
106112
handle_access_camera (XdpDbusCamera *object,
107113
GDBusMethodInvocation *invocation,
@@ -123,9 +129,7 @@ handle_access_camera (XdpDbusCamera *object,
123129

124130
REQUEST_AUTOLOCK (request);
125131

126-
app_id = xdp_app_info_get_id (request->app_info);
127-
128-
132+
app_id = app_id_from_app_info (request->app_info);
129133
g_object_set_data_full (G_OBJECT (request), "app-id", g_strdup (app_id), g_free);
130134

131135
request_export (request, g_dbus_method_invocation_get_connection (invocation));
@@ -200,7 +204,7 @@ handle_open_pipewire_remote (XdpDbusCamera *object,
200204
}
201205

202206
app_info = xdp_invocation_lookup_app_info_sync (invocation, NULL, &error);
203-
app_id = xdp_app_info_get_id (app_info);
207+
app_id = app_id_from_app_info (app_info);
204208
permission = device_get_permission_sync (app_id, "camera");
205209
if (permission != PERMISSION_YES)
206210
{

0 commit comments

Comments
 (0)