Debian Codegraph @

src/scripts/client/access-default.lua

raw
1 -- WirePlumber
2 --
3 -- Copyright © 2021 Collabora Ltd.
4 -- @author George Kiagiadakis <[email protected]>
5 --
6 -- SPDX-License-Identifier: MIT
7
8 log = Log.open_topic ("s-client")
9
10 config = {}
11 config.rules = Conf.get_section_as_json ("access.rules")
12
13 function getAccess (properties)
14 local access = properties["pipewire.access"]
15 local client_access = properties["pipewire.client.access"]
16 local is_flatpak = properties["pipewire.sec.flatpak"]
17
18 if is_flatpak then
19 client_access = "flatpak"
20 end
21
22 if client_access == nil then
23 return access
24 elseif access == "unrestricted" or access == "default" then
25 if client_access ~= "unrestricted" then
26 return client_access
27 end
28 end
29
30 return access
31 end
32
33 function getDefaultPermissions (properties)
34 local access = properties["access"]
35 local media_category = properties["media.category"]
36
37 if access == "flatpak" and media_category == "Manager" then
38 return "all", "flatpak-manager"
39 elseif access == "flatpak" or access == "restricted" then
40 return "rx", access
41 elseif access == "default" then
42 return "all", access
43 end
44
45 return nil, nil
46 end
47
48 function getPermissions (properties)
49 if config.rules then
50 local mprops, matched = JsonUtils.match_rules_update_properties (
51 config.rules, properties)
52 if (matched > 0 and mprops["default_permissions"]) then
53 return mprops["default_permissions"], mprops["access"]
54 end
55 end
56
57 return nil, nil
58 end
59
60 clients_om = ObjectManager {
61 Interest { type = "client" }
62 }
63
64 clients_om:connect("object-added", function (om, client)
65 local id = client["bound-id"]
66 local properties = client["properties"]
67 local access = getAccess (properties)
68
69 properties["access"] = access
70
71 local perms, effective_access = getPermissions (properties)
72 if perms == nil then
73 perms, effective_access = getDefaultPermissions (properties)
74 end
75 if effective_access == nil then
76 effective_access = access
77 end
78
79 if perms ~= nil then
80 log:info(client, "Granting permissions to client " .. id .. " (access " ..
81 effective_access .. "): " .. perms)
82 client:update_permissions { ["any"] = perms }
83 client:update_properties { ["pipewire.access.effective"] = effective_access }
84 else
85 log:debug(client, "No rule for client " .. id .. " (access " .. access .. ")")
86 end
87 end)
88
89 clients_om:activate()