| 1 | /* |
| 2 | * Copyright 2021-2022 Endless OS Foundation, LLC |
| 3 | * Copyright 2023 Red Hat, Inc |
| 4 | * |
| 5 | * SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include "config.h"cxx . . $ `<file>/build/config.h`/ |
| 23 | |
| 24 | #include "xdp-session-persistence.h"cxx . . $ `<file>/src/xdp-session-persistence.h`/ |
| 25 | |
| 26 | #include "xdp-permissions.h"cxx . . $ `<file>/src/xdp-permissions.h`/ |
| 27 | |
| 28 | static GMutexcxx . . $ GMutex# transient_permissions_lockcxx . . $ transient_permissions_lock.; |
| 29 | static GHashTablecxx . . $ GHashTable# *transient_permissionscxx . . $ transient_permissions.; |
| 30 | |
| 31 | #define RESTORE_DATA_TYPEcxx . . $ `src/xdp-session-persistence.c:31:9`! "(suv)" |
| 32 | |
| 33 | static void |
| 34 | on_peer_disconnectcxx . . $ on_peer_disconnect(d6fd0b445f519d6). (XdpContextcxx . . $ XdpContext# *context, |
| 35 | const char *peer, |
| 36 | gpointercxx . . $ gpointer# user_data) |
| 37 | { |
| 38 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GMutexLocker) locker = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 39 | GHashTableItercxx . . $ GHashTableIter# iter; |
| 40 | const char *key; |
| 41 | |
| 42 | locker = g_mutex_locker_newcxx . . $ g_mutex_locker_new(3c345ff2ce91af48). (&transient_permissions_lockcxx . . $ transient_permissions_lock.); |
| 43 | |
| 44 | if (!transient_permissionscxx . . $ transient_permissions.) |
| 45 | return; |
| 46 | |
| 47 | g_hash_table_iter_initcxx . . $ g_hash_table_iter_init(1fd6bbae530c3b4). (&iter, transient_permissionscxx . . $ transient_permissions.); |
| 48 | while (g_hash_table_iter_nextcxx . . $ g_hash_table_iter_next(1740d3f8cffea03c). (&iter, (gpointercxx . . $ gpointer# *) &key, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)) |
| 49 | { |
| 50 | g_autocxx . . $ `<external>/12741050725406041920/gmacros.h:1428:9`!(GStrv) split = g_strsplitcxx . . $ g_strsplit(656a2b498280081). (key, "/", 2); |
| 51 | |
| 52 | if (split && split[0] && g_strcmp0cxx . . $ g_strcmp0(5ae29d726ae57f88). (split[0], peer) == 0) |
| 53 | g_hash_table_iter_removecxx . . $ g_hash_table_iter_remove(9647bc02074e2e65). (&iter); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * Transient permissions are scoped by session->sender: the hash key is |
| 59 | * "sender/token", so a token is only valid for the peer that created it. |
| 60 | */ |
| 61 | void |
| 62 | xdp_session_persistence_set_transient_permissionscxx . . $ xdp_session_persistence_set_transient_permissions(39535d30e1370bee). (XdpSessioncxx . . $ XdpSession# *session, |
| 63 | const char *restore_token, |
| 64 | GVariantcxx . . $ GVariant# *restore_data) |
| 65 | { |
| 66 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GMutexLocker) locker = g_mutex_locker_newcxx . . $ g_mutex_locker_new(3c345ff2ce91af48). (&transient_permissions_lockcxx . . $ transient_permissions_lock.); |
| 67 | |
| 68 | if (!transient_permissionscxx . . $ transient_permissions.) |
| 69 | { |
| 70 | transient_permissionscxx . . $ transient_permissions. = |
| 71 | g_hash_table_new_fullcxx . . $ g_hash_table_new_full(e2dd12b570de7430). (g_str_hashcxx . . $ g_str_hash(b11f534102b1ad6)., g_str_equalcxx . . $ g_str_equal(9148c8c3ff42c9d8)., |
| 72 | g_freecxx . . $ g_free(5d22bdacc48458e8)., (GDestroyNotifycxx . . $ GDestroyNotify#) g_variant_unrefcxx . . $ g_variant_unref(86dbca581f53fd84).); |
| 73 | |
| 74 | g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (session->context, "peer-disconnect", |
| 75 | G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (on_peer_disconnect), |
| 76 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 77 | } |
| 78 | |
| 79 | g_hash_table_insertcxx . . $ g_hash_table_insert(6a7c46015dd5ef26). (transient_permissionscxx . . $ transient_permissions., |
| 80 | g_strdup_printfcxx . . $ g_strdup_printf(a849077ff1b8d812). ("%s/%s", session->sendercxx . . $ _XdpSession#sender., restore_token), |
| 81 | g_variant_refcxx . . $ g_variant_ref(3606eab35379b54a). (restore_data)); |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | xdp_session_persistence_delete_transient_permissionscxx . . $ xdp_session_persistence_delete_transient_permissions(81a88252364aabd7). (XdpSessioncxx . . $ XdpSession# *session, |
| 86 | const char *restore_token) |
| 87 | { |
| 88 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GMutexLocker) locker = g_mutex_locker_newcxx . . $ g_mutex_locker_new(3c345ff2ce91af48). (&transient_permissions_lockcxx . . $ transient_permissions_lock.); |
| 89 | g_autofreecxx . . $ `<external>/12741050725406041920/gmacros.h:1429:9`! char *id = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 90 | |
| 91 | if (!transient_permissionscxx . . $ transient_permissions.) |
| 92 | return; |
| 93 | |
| 94 | id = g_strdup_printfcxx . . $ g_strdup_printf(a849077ff1b8d812). ("%s/%s", session->sendercxx . . $ _XdpSession#sender., restore_token); |
| 95 | g_hash_table_removecxx . . $ g_hash_table_remove(453ebbf4abdbe50e). (transient_permissionscxx . . $ transient_permissions., id); |
| 96 | } |
| 97 | |
| 98 | GVariantcxx . . $ GVariant# * |
| 99 | xdp_session_persistence_get_transient_permissionscxx . . $ xdp_session_persistence_get_transient_permissions(d0d712aff29b2784). (XdpSessioncxx . . $ XdpSession# *session, |
| 100 | const char *restore_token) |
| 101 | { |
| 102 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GMutexLocker) locker = g_mutex_locker_newcxx . . $ g_mutex_locker_new(3c345ff2ce91af48). (&transient_permissions_lockcxx . . $ transient_permissions_lock.); |
| 103 | g_autofreecxx . . $ `<external>/12741050725406041920/gmacros.h:1429:9`! char *id = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 104 | GVariantcxx . . $ GVariant# *permissions; |
| 105 | |
| 106 | if (!transient_permissionscxx . . $ transient_permissions.) |
| 107 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 108 | |
| 109 | id = g_strdup_printfcxx . . $ g_strdup_printf(a849077ff1b8d812). ("%s/%s", session->sendercxx . . $ _XdpSession#sender., restore_token); |
| 110 | permissions = g_hash_table_lookupcxx . . $ g_hash_table_lookup(8183d62c39a6a245). (transient_permissionscxx . . $ transient_permissions., id); |
| 111 | return permissions ? g_variant_refcxx . . $ g_variant_ref(3606eab35379b54a). (permissions) : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * Persistent permissions are scoped by session->app_id: the permission |
| 116 | * store entry is keyed by token, but lookup checks that app_id has access. |
| 117 | */ |
| 118 | void |
| 119 | xdp_session_persistence_set_persistent_permissionscxx . . $ xdp_session_persistence_set_persistent_permissions(715bb496ef4c0a67). (XdpSessioncxx . . $ XdpSession# *session, |
| 120 | const char *table, |
| 121 | const char *restore_token, |
| 122 | GVariantcxx . . $ GVariant# *restore_data) |
| 123 | { |
| 124 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GError) error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 125 | g_autocxx . . $ `<external>/12741050725406041920/gmacros.h:1428:9`!(GVariantBuilder) permissions_builder = |
| 126 | G_VARIANT_BUILDER_INITcxx . . $ `<external>/10279604295420929244/gvariant.h:369:9`! (G_VARIANT_TYPEcxx . . $ `<external>/14064154155447831270/gvarianttype.h:298:10`! ("a{sas}")); |
| 127 | g_autocxx . . $ `<external>/12741050725406041920/gmacros.h:1428:9`!(GStrv) permission = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 128 | |
| 129 | permission = xdp_permissions_from_tristatecxx . . $ xdp_permissions_from_tristate(742f30fe6dafc281). (XDP_PERMISSION_YEScxx . . $ XDP_PERMISSION_YES.); |
| 130 | |
| 131 | g_variant_builder_addcxx . . $ g_variant_builder_add(a422658e2ec2035a). (&permissions_builder, "{s^a&s}", session->app_idcxx . . $ _XdpSession#app_id., permission); |
| 132 | |
| 133 | if (!xdp_dbus_impl_permission_store_call_set_synccxx . . $ xdp_dbus_impl_permission_store_call_set_sync(ebbed47b1b8832). (xdp_get_permission_storecxx . . $ xdp_get_permission_store(ac6178aae3a00722). (), |
| 134 | table, |
| 135 | TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!, |
| 136 | restore_token, |
| 137 | g_variant_builder_endcxx . . $ g_variant_builder_end(6d60952e65fc2b86). (&permissions_builder), |
| 138 | g_variant_new_variantcxx . . $ g_variant_new_variant(3606eab35379b54a). (restore_data), |
| 139 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 140 | &error)) |
| 141 | { |
| 142 | g_dbus_error_strip_remote_errorcxx . . $ g_dbus_error_strip_remote_error(425e103a815b829). (error); |
| 143 | g_warningcxx . . $ `<external>/5169755362661750954/gmessages.h:365:9`! ("Error setting permission store value: %s", error->message); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void |
| 148 | xdp_session_persistence_delete_persistent_permissionscxx . . $ xdp_session_persistence_delete_persistent_permissions(5d9e194d3a3141c9). (XdpSessioncxx . . $ XdpSession# *session, |
| 149 | const char *table, |
| 150 | const char *restore_token) |
| 151 | { |
| 152 | |
| 153 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GError) error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 154 | |
| 155 | if (!xdp_dbus_impl_permission_store_call_delete_synccxx . . $ xdp_dbus_impl_permission_store_call_delete_sync(98dc9b18e9d74261). (xdp_get_permission_storecxx . . $ xdp_get_permission_store(ac6178aae3a00722). (), |
| 156 | table, |
| 157 | restore_token, |
| 158 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 159 | &error)) |
| 160 | { |
| 161 | g_dbus_error_strip_remote_errorcxx . . $ g_dbus_error_strip_remote_error(425e103a815b829). (error); |
| 162 | g_warningcxx . . $ `<external>/5169755362661750954/gmessages.h:365:9`! ("Error deleting permission: %s", error->message); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | GVariantcxx . . $ GVariant# * |
| 167 | xdp_session_persistence_get_persistent_permissionscxx . . $ xdp_session_persistence_get_persistent_permissions(10291f328a9f44da). (XdpSessioncxx . . $ XdpSession# *session, |
| 168 | const char *table, |
| 169 | const char *restore_token) |
| 170 | { |
| 171 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GVariant) perms = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 172 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GVariant) data = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 173 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GError) error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 174 | g_autofreecxx . . $ `<external>/12741050725406041920/gmacros.h:1429:9`! const char **permissions = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 175 | |
| 176 | if (!xdp_dbus_impl_permission_store_call_lookup_synccxx . . $ xdp_dbus_impl_permission_store_call_lookup_sync(b4ce393c2c779376). (xdp_get_permission_storecxx . . $ xdp_get_permission_store(ac6178aae3a00722). (), |
| 177 | table, |
| 178 | restore_token, |
| 179 | &perms, |
| 180 | &data, |
| 181 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 182 | &error)) |
| 183 | { |
| 184 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 185 | } |
| 186 | |
| 187 | if (!perms || !g_variant_lookupcxx . . $ g_variant_lookup(7f27c6838ade8909). (perms, session->app_idcxx . . $ _XdpSession#app_id., "^a&s", &permissions)) |
| 188 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 189 | |
| 190 | if (!data) |
| 191 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 192 | |
| 193 | return g_variant_get_child_valuecxx . . $ g_variant_get_child_value(8aa5a571b04b0b30). (data, 0); |
| 194 | } |
| 195 | |
| 196 | void |
| 197 | xdp_session_persistence_replace_restore_token_with_datacxx . . $ xdp_session_persistence_replace_restore_token_with_data(6fd49f6574b5027b). (XdpSessioncxx . . $ XdpSession# *session, |
| 198 | const char *table, |
| 199 | GVariantcxx . . $ GVariant# **in_out_options, |
| 200 | char **out_restore_token) |
| 201 | { |
| 202 | GVariantItercxx . . $ GVariantIter# options_iter; |
| 203 | g_autocxx . . $ `<external>/12741050725406041920/gmacros.h:1428:9`!(GVariantBuilder) options_builder = |
| 204 | G_VARIANT_BUILDER_INITcxx . . $ `<external>/10279604295420929244/gvariant.h:369:9`! (G_VARIANT_TYPE_VARDICTcxx . . $ `<external>/14064154155447831270/gvarianttype.h:279:9`!); |
| 205 | char *key; |
| 206 | GVariantcxx . . $ GVariant# *value; |
| 207 | |
| 208 | g_variant_iter_initcxx . . $ g_variant_iter_init(83d0c9c646e4f22c). (&options_iter, *in_out_options); |
| 209 | |
| 210 | while (g_variant_iter_nextcxx . . $ g_variant_iter_next(eaf615a8ce2e43df). (&options_iter, "{&sv}", &key, &value)) |
| 211 | { |
| 212 | if (g_strcmp0cxx . . $ g_strcmp0(5ae29d726ae57f88). (key, "restore_token") == 0) |
| 213 | { |
| 214 | g_autofreecxx . . $ `<external>/12741050725406041920/gmacros.h:1429:9`! char *restore_token = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 215 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GVariant) restore_data = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 216 | |
| 217 | restore_token = g_variant_dup_stringcxx . . $ g_variant_dup_string(99f549e0b90183de). (value, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 218 | |
| 219 | /* Lookup permissions in memory first, and fallback to the permission |
| 220 | * store if not found. Immediately delete them now as a safety measure, |
| 221 | * since they'll be stored again when the session is closed. |
| 222 | * |
| 223 | * Notice that transient mode uses the sender name, whereas persistent |
| 224 | * mode uses the app id. |
| 225 | */ |
| 226 | restore_data = |
| 227 | xdp_session_persistence_get_transient_permissionscxx . . $ xdp_session_persistence_get_transient_permissions(d0d712aff29b2784). (session, |
| 228 | restore_token); |
| 229 | if (restore_data) |
| 230 | { |
| 231 | xdp_session_persistence_delete_transient_permissionscxx . . $ xdp_session_persistence_delete_transient_permissions(81a88252364aabd7). (session, |
| 232 | restore_token); |
| 233 | } |
| 234 | else |
| 235 | { |
| 236 | restore_data = |
| 237 | xdp_session_persistence_get_persistent_permissionscxx . . $ xdp_session_persistence_get_persistent_permissions(10291f328a9f44da). (session, |
| 238 | table, |
| 239 | restore_token); |
| 240 | if (restore_data) |
| 241 | { |
| 242 | xdp_session_persistence_delete_persistent_permissionscxx . . $ xdp_session_persistence_delete_persistent_permissions(5d9e194d3a3141c9). (session, |
| 243 | table, |
| 244 | restore_token); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | if (restore_data && |
| 249 | g_variant_check_format_stringcxx . . $ g_variant_check_format_string(a76104a983d13bdd). (restore_data, RESTORE_DATA_TYPEcxx . . $ `src/xdp-session-persistence.c:31:9`!, FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!)) |
| 250 | { |
| 251 | g_debugcxx . . $ `<external>/5169755362661750954/gmessages.h:371:9`! ("Replacing 'restore_token' with portal-specific data"); |
| 252 | g_variant_builder_addcxx . . $ g_variant_builder_add(a422658e2ec2035a). (&options_builder, "{sv}", |
| 253 | "restore_data", restore_data); |
| 254 | *out_restore_token = g_steal_pointercxx . . $ `<external>/1123956534522462559/gmem.h:250:9`! (&restore_token); |
| 255 | } |
| 256 | } |
| 257 | else |
| 258 | { |
| 259 | g_variant_builder_addcxx . . $ g_variant_builder_add(a422658e2ec2035a). (&options_builder, "{sv}", |
| 260 | key, value); |
| 261 | } |
| 262 | |
| 263 | g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&value, g_variant_unref); |
| 264 | } |
| 265 | |
| 266 | *in_out_options = g_variant_ref_sinkcxx . . $ g_variant_ref_sink(3606eab35379b54a). (g_variant_builder_endcxx . . $ g_variant_builder_end(6d60952e65fc2b86). (&options_builder)); |
| 267 | } |
| 268 | |
| 269 | void |
| 270 | xdp_session_persistence_generate_and_save_restore_tokencxx . . $ xdp_session_persistence_generate_and_save_restore_token(2087e7161d3dc2ca). (XdpSessioncxx . . $ XdpSession# *session, |
| 271 | const char *table, |
| 272 | XdpSessionPersistenceModecxx . . $ XdpSessionPersistenceMode# persist_mode, |
| 273 | char **in_out_restore_token, |
| 274 | GVariantcxx . . $ GVariant# **in_out_restore_data) |
| 275 | { |
| 276 | if (!*in_out_restore_data) |
| 277 | { |
| 278 | if (*in_out_restore_token) |
| 279 | { |
| 280 | xdp_session_persistence_delete_persistent_permissionscxx . . $ xdp_session_persistence_delete_persistent_permissions(5d9e194d3a3141c9). (session, |
| 281 | table, |
| 282 | *in_out_restore_token); |
| 283 | xdp_session_persistence_delete_transient_permissionscxx . . $ xdp_session_persistence_delete_transient_permissions(81a88252364aabd7). (session, |
| 284 | *in_out_restore_token); |
| 285 | } |
| 286 | |
| 287 | g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (in_out_restore_token, g_free); |
| 288 | return; |
| 289 | } |
| 290 | |
| 291 | switch (persist_mode) |
| 292 | { |
| 293 | case XDP_SESSION_PERSISTENCE_MODE_NONEcxx . . $ XDP_SESSION_PERSISTENCE_MODE_NONE.: |
| 294 | if (*in_out_restore_token) |
| 295 | { |
| 296 | xdp_session_persistence_delete_persistent_permissionscxx . . $ xdp_session_persistence_delete_persistent_permissions(5d9e194d3a3141c9). (session, |
| 297 | table, |
| 298 | *in_out_restore_token); |
| 299 | xdp_session_persistence_delete_transient_permissionscxx . . $ xdp_session_persistence_delete_transient_permissions(81a88252364aabd7). (session, |
| 300 | *in_out_restore_token); |
| 301 | } |
| 302 | |
| 303 | g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (in_out_restore_token, g_free); |
| 304 | g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (in_out_restore_data, g_variant_unref); |
| 305 | break; |
| 306 | |
| 307 | case XDP_SESSION_PERSISTENCE_MODE_TRANSIENTcxx . . $ XDP_SESSION_PERSISTENCE_MODE_TRANSIENT.: |
| 308 | if (!*in_out_restore_token) |
| 309 | *in_out_restore_token = xdp_generate_tokencxx . . $ xdp_generate_token(41208ce6ca65dd58). (); |
| 310 | |
| 311 | xdp_session_persistence_set_transient_permissionscxx . . $ xdp_session_persistence_set_transient_permissions(39535d30e1370bee). (session, |
| 312 | *in_out_restore_token, |
| 313 | *in_out_restore_data); |
| 314 | break; |
| 315 | |
| 316 | case XDP_SESSION_PERSISTENCE_MODE_PERSISTENTcxx . . $ XDP_SESSION_PERSISTENCE_MODE_PERSISTENT.: |
| 317 | if (!*in_out_restore_token) |
| 318 | *in_out_restore_token = xdp_generate_tokencxx . . $ xdp_generate_token(41208ce6ca65dd58). (); |
| 319 | |
| 320 | xdp_session_persistence_set_persistent_permissionscxx . . $ xdp_session_persistence_set_persistent_permissions(715bb496ef4c0a67). (session, |
| 321 | table, |
| 322 | *in_out_restore_token, |
| 323 | *in_out_restore_data); |
| 324 | |
| 325 | break; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | void |
| 330 | xdp_session_persistence_replace_restore_data_with_tokencxx . . $ xdp_session_persistence_replace_restore_data_with_token(97c9ce3fc2c5d9dc). (XdpSessioncxx . . $ XdpSession# *session, |
| 331 | const char *table, |
| 332 | GVariantcxx . . $ GVariant# **in_out_results, |
| 333 | XdpSessionPersistenceModecxx . . $ XdpSessionPersistenceMode# *in_out_persist_mode, |
| 334 | char **in_out_restore_token, |
| 335 | GVariantcxx . . $ GVariant# **in_out_restore_data) |
| 336 | { |
| 337 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GVariant) results = *in_out_results; |
| 338 | g_autocxx . . $ `<external>/12741050725406041920/gmacros.h:1428:9`!(GVariantBuilder) results_builder = |
| 339 | G_VARIANT_BUILDER_INITcxx . . $ `<external>/10279604295420929244/gvariant.h:369:9`! (G_VARIANT_TYPE_VARDICTcxx . . $ `<external>/14064154155447831270/gvarianttype.h:279:9`!); |
| 340 | GVariantItercxx . . $ GVariantIter# iter; |
| 341 | const char *key; |
| 342 | GVariantcxx . . $ GVariant# *value; |
| 343 | gbooleancxx . . $ gboolean# found_restore_data = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 344 | |
| 345 | g_variant_iter_initcxx . . $ g_variant_iter_init(83d0c9c646e4f22c). (&iter, results); |
| 346 | while (g_variant_iter_nextcxx . . $ g_variant_iter_next(eaf615a8ce2e43df). (&iter, "{&sv}", &key, &value)) |
| 347 | { |
| 348 | if (g_strcmp0cxx . . $ g_strcmp0(5ae29d726ae57f88). (key, "restore_data") == 0) |
| 349 | { |
| 350 | if (g_variant_check_format_stringcxx . . $ g_variant_check_format_string(a76104a983d13bdd). (value, RESTORE_DATA_TYPEcxx . . $ `src/xdp-session-persistence.c:31:9`!, FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!)) |
| 351 | { |
| 352 | *in_out_restore_data = g_variant_refcxx . . $ g_variant_ref(3606eab35379b54a). (value); |
| 353 | found_restore_data = TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 354 | } |
| 355 | else |
| 356 | { |
| 357 | g_warningcxx . . $ `<external>/5169755362661750954/gmessages.h:365:9`! ("Received restore data in invalid variant format ('%s'; expected '%s')", |
| 358 | g_variant_get_type_string (value), |
| 359 | RESTORE_DATA_TYPEcxx . . $ `src/xdp-session-persistence.c:31:9`!); |
| 360 | } |
| 361 | } |
| 362 | else if (g_strcmp0cxx . . $ g_strcmp0(5ae29d726ae57f88). (key, "persist_mode") == 0) |
| 363 | { |
| 364 | *in_out_persist_mode = MINcxx . . $ `<external>/12741050725406041920/gmacros.h:978:9`! (*in_out_persist_mode, |
| 365 | g_variant_get_uint32 (value)); |
| 366 | } |
| 367 | else |
| 368 | { |
| 369 | g_variant_builder_addcxx . . $ g_variant_builder_add(a422658e2ec2035a). (&results_builder, "{sv}", key, value); |
| 370 | } |
| 371 | g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&value, g_variant_unref); |
| 372 | } |
| 373 | |
| 374 | if (found_restore_data) |
| 375 | { |
| 376 | g_debugcxx . . $ `<external>/5169755362661750954/gmessages.h:371:9`! ("Replacing restore data received from portal impl with a token"); |
| 377 | |
| 378 | xdp_session_persistence_generate_and_save_restore_tokencxx . . $ xdp_session_persistence_generate_and_save_restore_token(2087e7161d3dc2ca). (session, |
| 379 | table, |
| 380 | *in_out_persist_mode, |
| 381 | in_out_restore_token, |
| 382 | in_out_restore_data); |
| 383 | if (*in_out_restore_token) |
| 384 | { |
| 385 | g_variant_builder_addcxx . . $ g_variant_builder_add(a422658e2ec2035a). (&results_builder, "{sv}", "restore_token", |
| 386 | g_variant_new_stringcxx . . $ g_variant_new_string(8d35775da1697fc2). (*in_out_restore_token)); |
| 387 | } |
| 388 | } |
| 389 | else |
| 390 | { |
| 391 | *in_out_persist_mode = XDP_SESSION_PERSISTENCE_MODE_NONEcxx . . $ XDP_SESSION_PERSISTENCE_MODE_NONE.; |
| 392 | g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (in_out_restore_token, g_free); |
| 393 | } |
| 394 | |
| 395 | *in_out_results = g_variant_ref_sinkcxx . . $ g_variant_ref_sink(3606eab35379b54a). (g_variant_builder_endcxx . . $ g_variant_builder_end(6d60952e65fc2b86). (&results_builder)); |
| 396 | } |
| 397 | |
| 398 | |
| 399 | gbooleancxx . . $ gboolean# |
| 400 | xdp_session_persistence_validate_restore_tokencxx . . $ xdp_session_persistence_validate_restore_token(5dde6684fab02cd7). (const char *restore_token, |
| 401 | GErrorcxx . . $ GError# **error) |
| 402 | { |
| 403 | /* Accept both xdp_generate_token() format and legacy UUID strings |
| 404 | * from older portal versions */ |
| 405 | if (!xdp_is_valid_tokencxx . . $ xdp_is_valid_token(5c4306d8553b3696). (restore_token) && |
| 406 | !g_uuid_string_is_validcxx . . $ g_uuid_string_is_valid(5c4306d8553b3696). (restore_token)) |
| 407 | { |
| 408 | g_set_errorcxx . . $ g_set_error(ca0c191bc68fc328). (error, |
| 409 | XDG_DESKTOP_PORTAL_ERRORcxx . . $ `src/xdp-utils.h:115:9`!, |
| 410 | XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENTcxx . . $ XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT., |
| 411 | "Restore token is not valid"); |
| 412 | return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 413 | } |
| 414 | |
| 415 | return TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 416 | } |
| 417 | |
| 418 | gbooleancxx . . $ gboolean# |
| 419 | xdp_session_persistence_validate_persist_modecxx . . $ xdp_session_persistence_validate_persist_mode(4307366c3e94ee1c). (XdpSessionPersistenceModecxx . . $ XdpSessionPersistenceMode# mode, |
| 420 | GErrorcxx . . $ GError# **error) |
| 421 | { |
| 422 | if (mode > XDP_SESSION_PERSISTENCE_MODE_PERSISTENTcxx . . $ XDP_SESSION_PERSISTENCE_MODE_PERSISTENT.) |
| 423 | { |
| 424 | g_set_errorcxx . . $ g_set_error(ca0c191bc68fc328). (error, |
| 425 | XDG_DESKTOP_PORTAL_ERRORcxx . . $ `src/xdp-utils.h:115:9`!, |
| 426 | XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENTcxx . . $ XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT., |
| 427 | "Invalid persist mode %x", mode); |
| 428 | return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 429 | } |
| 430 | |
| 431 | return TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 432 | } |