| 1 | /* |
| 2 | * Copyright © 2016 Red Hat, Inc |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * Authors: |
| 20 | * Alexander Larsson <[email protected]> |
| 21 | * Matthias Clasen <[email protected]> |
| 22 | */ |
| 23 | |
| 24 | #include "config.h"cxx . . $ `<file>/build/config.h`/ |
| 25 | |
| 26 | #include <errno.h> |
| 27 | |
| 28 | #include <sys/types.h> |
| 29 | #include <sys/stat.h> |
| 30 | #include <fcntl.h> |
| 31 | |
| 32 | #include <gio/gio.h> |
| 33 | #include <gio/gunixfdlist.h> |
| 34 | |
| 35 | #include "xdp-app-info.h"cxx . . $ `<file>/src/xdp-app-info.h`/ |
| 36 | #include "xdp-dbus.h"cxx . . $ `<file>/build/src/xdp-dbus.h`/ |
| 37 | #include "xdp-utils.h"cxx . . $ `<file>/src/xdp-utils.h`/ |
| 38 | #include "xdp-documents.h"cxx . . $ `<file>/src/xdp-documents.h`/ |
| 39 | #include "document-enums.h"cxx . . $ `<file>/document-portal/document-enums.h`/ |
| 40 | |
| 41 | static XdpDbusDocumentscxx . . $ XdpDbusDocuments# *documentscxx . . $ documents. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 42 | static char *documents_mountpointcxx . . $ documents_mountpoint. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 43 | |
| 44 | gbooleancxx . . $ gboolean# |
| 45 | xdp_init_document_proxycxx . . $ xdp_init_document_proxy(3bd67427cbb778d0). (GDBusConnectioncxx . . $ GDBusConnection# *connection, |
| 46 | GErrorcxx . . $ GError# **error) |
| 47 | { |
| 48 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GError) local_error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 49 | |
| 50 | documentscxx . . $ documents. = xdp_dbus_documents_proxy_new_synccxx . . $ xdp_dbus_documents_proxy_new_sync(7b6d35bd44bd25b8). (connection, 0, |
| 51 | "org.freedesktop.portal.Documents", |
| 52 | "/org/freedesktop/portal/documents", |
| 53 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, error); |
| 54 | if (!documentscxx . . $ documents.) |
| 55 | return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 56 | |
| 57 | if (!xdp_dbus_documents_call_get_mount_point_synccxx . . $ xdp_dbus_documents_call_get_mount_point_sync(f924b110f5021ce2). (documentscxx . . $ documents., |
| 58 | &documents_mountpointcxx . . $ documents_mountpoint., |
| 59 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &local_error)) |
| 60 | { |
| 61 | g_warningcxx . . $ `<external>/5169755362661750954/gmessages.h:365:9`! ("Document portal fuse mount point unknown: %s", |
| 62 | local_error->message); |
| 63 | } |
| 64 | |
| 65 | xdp_set_documents_mountpointcxx . . $ xdp_set_documents_mountpoint(85c52e162fed56f9). (documents_mountpointcxx . . $ documents_mountpoint.); |
| 66 | |
| 67 | return TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 68 | } |
| 69 | |
| 70 | char * |
| 71 | xdp_register_documentcxx . . $ xdp_register_document(e16c043bff209580). (const char *uri, |
| 72 | const char *app_id, |
| 73 | XdpDocumentFlagscxx . . $ XdpDocumentFlags# flags, |
| 74 | GErrorcxx . . $ GError# **error) |
| 75 | { |
| 76 | g_autofreecxx . . $ `<external>/12741050725406041920/gmacros.h:1429:9`! char *doc_id = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 77 | g_autocxx . . $ `<external>/12741050725406041920/gmacros.h:1428:9`!(GStrv) doc_ids = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 78 | g_autofreecxx . . $ `<external>/12741050725406041920/gmacros.h:1429:9`! char *path = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 79 | g_autofreecxx . . $ `<external>/12741050725406041920/gmacros.h:1429:9`! char *basename = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 80 | g_autofreecxx . . $ `<external>/12741050725406041920/gmacros.h:1429:9`! char *dirname = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 81 | GUnixFDListcxx . . $ GUnixFDList# *fd_list = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 82 | int fd, fd_in; |
| 83 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GFile) file = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 84 | gbooleancxx . . $ gboolean# ret = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 85 | const char *permissions[5]; |
| 86 | g_autofreecxx . . $ `<external>/12741050725406041920/gmacros.h:1429:9`! char *doc_path = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 87 | int i; |
| 88 | int version; |
| 89 | gbooleancxx . . $ gboolean# handled_permissions = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 90 | DocumentAddFullFlagscxx . . $ DocumentAddFullFlags# full_flags; |
| 91 | |
| 92 | g_return_val_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:665:9`! (app_id != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && *app_id != '\0', NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 93 | |
| 94 | file = g_file_new_for_uricxx . . $ g_file_new_for_uri(ba1fd5950b7d7bd5). (uri); |
| 95 | path = g_file_get_pathcxx . . $ g_file_get_path(bd69fa69840f32a9). (file); |
| 96 | basename = g_path_get_basenamecxx . . $ g_path_get_basename(a8b8e32347182212). (path); |
| 97 | dirname = g_path_get_dirnamecxx . . $ g_path_get_dirname(a8b8e32347182212). (path); |
| 98 | |
| 99 | if (flags & XDP_DOCUMENT_FLAG_FOR_SAVEcxx . . $ XDP_DOCUMENT_FLAG_FOR_SAVE.) |
| 100 | fd = opencxx . . $ open(e156e3aa1e5c4ad1). (dirname, O_PATHcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:148:10`! | O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!); |
| 101 | else |
| 102 | fd = opencxx . . $ open(e156e3aa1e5c4ad1). (path, O_PATHcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:148:10`! | O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!); |
| 103 | |
| 104 | if (fd == -1) |
| 105 | { |
| 106 | g_set_errorcxx . . $ g_set_error(ca0c191bc68fc328). (error, G_IO_ERRORcxx . . $ `<external>/13894955190784973534/gioerror.h:42:9`!, g_io_error_from_errnocxx . . $ g_io_error_from_errno(b47e8a466716fd56). (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!), |
| 107 | "Failed to open %s", uri); |
| 108 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 109 | } |
| 110 | fd_list = g_unix_fd_list_newcxx . . $ g_unix_fd_list_new(2f03ba904a9d4e55). (); |
| 111 | fd_in = g_unix_fd_list_appendcxx . . $ g_unix_fd_list_append(57b895fb290201ec). (fd_list, fd, error); |
| 112 | closecxx . . $ close(7864480464b09eea). (fd); |
| 113 | |
| 114 | if (fd_in == -1) |
| 115 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 116 | |
| 117 | i = 0; |
| 118 | permissions[i++] = "read"; |
| 119 | if ((flags & XDP_DOCUMENT_FLAG_WRITABLEcxx . . $ XDP_DOCUMENT_FLAG_WRITABLE.) || (flags & XDP_DOCUMENT_FLAG_FOR_SAVEcxx . . $ XDP_DOCUMENT_FLAG_FOR_SAVE.)) |
| 120 | permissions[i++] = "write"; |
| 121 | permissions[i++] = "grant-permissions"; |
| 122 | if (flags & XDP_DOCUMENT_FLAG_DELETABLEcxx . . $ XDP_DOCUMENT_FLAG_DELETABLE.) |
| 123 | permissions[i++] = "delete"; |
| 124 | permissions[i++] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 125 | |
| 126 | version = xdp_dbus_documents_get_versioncxx . . $ xdp_dbus_documents_get_version(b3c34875a46a66a4). (documentscxx . . $ documents.); |
| 127 | full_flags = DOCUMENT_ADD_FLAGS_REUSE_EXISTINGcxx . . $ DOCUMENT_ADD_FLAGS_REUSE_EXISTING. | DOCUMENT_ADD_FLAGS_PERSISTENTcxx . . $ DOCUMENT_ADD_FLAGS_PERSISTENT. | DOCUMENT_ADD_FLAGS_AS_NEEDED_BY_APPcxx . . $ DOCUMENT_ADD_FLAGS_AS_NEEDED_BY_APP.; |
| 128 | if (flags & XDP_DOCUMENT_FLAG_DIRECTORYcxx . . $ XDP_DOCUMENT_FLAG_DIRECTORY.) |
| 129 | full_flags |= DOCUMENT_ADD_FLAGS_DIRECTORYcxx . . $ DOCUMENT_ADD_FLAGS_DIRECTORY.; |
| 130 | |
| 131 | if (flags & XDP_DOCUMENT_FLAG_FOR_SAVEcxx . . $ XDP_DOCUMENT_FLAG_FOR_SAVE.) |
| 132 | { |
| 133 | if (version >= 3) |
| 134 | { |
| 135 | ret = xdp_dbus_documents_call_add_named_full_synccxx . . $ xdp_dbus_documents_call_add_named_full_sync(be8984d86830bf56). (documentscxx . . $ documents., |
| 136 | g_variant_new_handlecxx . . $ g_variant_new_handle(d662e1c280be90d3). (fd_in), |
| 137 | basename, |
| 138 | full_flags, |
| 139 | app_id, |
| 140 | permissions, |
| 141 | fd_list, |
| 142 | &doc_id, |
| 143 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 144 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 145 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 146 | error); |
| 147 | handled_permissions = TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 148 | } |
| 149 | else |
| 150 | ret = xdp_dbus_documents_call_add_named_synccxx . . $ xdp_dbus_documents_call_add_named_sync(9285050a3cebf544). (documentscxx . . $ documents., |
| 151 | g_variant_new_handlecxx . . $ g_variant_new_handle(d662e1c280be90d3). (fd_in), |
| 152 | basename, |
| 153 | TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!, |
| 154 | TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!, |
| 155 | fd_list, |
| 156 | &doc_id, |
| 157 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 158 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 159 | error); |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | if (version >= 2) |
| 164 | { |
| 165 | ret = xdp_dbus_documents_call_add_full_synccxx . . $ xdp_dbus_documents_call_add_full_sync(3565c662c2ec8664). (documentscxx . . $ documents., |
| 166 | g_variant_new_fixed_arraycxx . . $ g_variant_new_fixed_array(68571e015fb2a4d7). (G_VARIANT_TYPE_HANDLEcxx . . $ `<external>/14064154155447831270/gvarianttype.h:172:9`!, &fd_in, 1, sizeof (gint32cxx . . $ gint32#)), |
| 167 | full_flags, |
| 168 | app_id, |
| 169 | permissions, |
| 170 | fd_list, |
| 171 | &doc_ids, |
| 172 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 173 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 174 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 175 | error); |
| 176 | handled_permissions = TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 177 | } |
| 178 | else |
| 179 | ret = xdp_dbus_documents_call_add_synccxx . . $ xdp_dbus_documents_call_add_sync(d7d56fb74cd0e6f). (documentscxx . . $ documents., |
| 180 | g_variant_new_handlecxx . . $ g_variant_new_handle(d662e1c280be90d3). (fd_in), |
| 181 | TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!, |
| 182 | TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!, |
| 183 | fd_list, |
| 184 | &doc_id, |
| 185 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 186 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 187 | error); |
| 188 | } |
| 189 | |
| 190 | g_object_unrefcxx . . $ g_object_unref(5d22bdacc48458e8). (fd_list); |
| 191 | |
| 192 | if (!ret) |
| 193 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 194 | |
| 195 | if (doc_ids && doc_ids[0]) { |
| 196 | doc_id = g_strdupcxx . . $ `<external>/7822753393113922331/gstrfuncs.h:324:9`! (doc_ids[0]); |
| 197 | } |
| 198 | |
| 199 | if (!handled_permissions) |
| 200 | { |
| 201 | if (!xdp_dbus_documents_call_grant_permissions_synccxx . . $ xdp_dbus_documents_call_grant_permissions_sync(c3c81aa7d040b381). (documentscxx . . $ documents., |
| 202 | doc_id, |
| 203 | app_id, |
| 204 | permissions, |
| 205 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 206 | error)) |
| 207 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 208 | } |
| 209 | |
| 210 | if (!g_strcmp0cxx . . $ g_strcmp0(5ae29d726ae57f88). (doc_id, "")) |
| 211 | { |
| 212 | doc_path = g_build_filenamecxx . . $ g_build_filename(a849077ff1b8d812). (path, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 213 | return g_filename_to_uricxx . . $ g_filename_to_uri(aa426d2e062653f5). (doc_path, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 214 | } |
| 215 | |
| 216 | doc_path = g_build_filenamecxx . . $ g_build_filename(a849077ff1b8d812). (documents_mountpointcxx . . $ documents_mountpoint., doc_id, basename, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 217 | return g_filename_to_uricxx . . $ g_filename_to_uri(aa426d2e062653f5). (doc_path, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 218 | } |
| 219 | |
| 220 | char * |
| 221 | xdp_get_real_path_for_doc_pathcxx . . $ xdp_get_real_path_for_doc_path(87547275904bc700). (const char *path, |
| 222 | XdpAppInfocxx . . $ XdpAppInfo# *app_info) |
| 223 | { |
| 224 | g_autofreecxx . . $ `<external>/12741050725406041920/gmacros.h:1429:9`! char *doc_id = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 225 | gbooleancxx . . $ gboolean# ret = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 226 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GError) error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 227 | |
| 228 | if (xdp_app_info_is_hostcxx . . $ xdp_app_info_is_host(ac6b23a20a03546d). (app_info)) |
| 229 | return g_strdupcxx . . $ `<external>/7822753393113922331/gstrfuncs.h:324:9`! (path); |
| 230 | |
| 231 | ret = xdp_dbus_documents_call_lookup_synccxx . . $ xdp_dbus_documents_call_lookup_sync(65fb1d1cc0d452a9). (documentscxx . . $ documents., path, &doc_id, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &error); |
| 232 | if (!ret) |
| 233 | { |
| 234 | g_debugcxx . . $ `<external>/5169755362661750954/gmessages.h:371:9`! ("document portal error for path '%s': %s", path, error->message); |
| 235 | return g_strdupcxx . . $ `<external>/7822753393113922331/gstrfuncs.h:324:9`! (path); |
| 236 | } |
| 237 | |
| 238 | if (!g_strcmp0cxx . . $ g_strcmp0(5ae29d726ae57f88). (doc_id, "")) |
| 239 | { |
| 240 | g_debugcxx . . $ `<external>/5169755362661750954/gmessages.h:371:9`! ("document portal returned empty doc id for path '%s'", path); |
| 241 | return g_strdupcxx . . $ `<external>/7822753393113922331/gstrfuncs.h:324:9`! (path); |
| 242 | } |
| 243 | |
| 244 | return xdp_get_real_path_for_doc_idcxx . . $ xdp_get_real_path_for_doc_id(a8b8e32347182212). (doc_id); |
| 245 | } |
| 246 | |
| 247 | char * |
| 248 | xdp_get_real_path_for_doc_idcxx . . $ xdp_get_real_path_for_doc_id(a8b8e32347182212). (const char *doc_id) |
| 249 | { |
| 250 | gbooleancxx . . $ gboolean# ret = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 251 | char *real_path = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 252 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`! (GError) error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 253 | |
| 254 | ret = xdp_dbus_documents_call_info_synccxx . . $ xdp_dbus_documents_call_info_sync(e586a82f185a310d). (documentscxx . . $ documents., doc_id, &real_path, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &error); |
| 255 | if (!ret) |
| 256 | { |
| 257 | g_debugcxx . . $ `<external>/5169755362661750954/gmessages.h:371:9`! ("document portal error for doc id '%s': %s", doc_id, error->message); |
| 258 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 259 | } |
| 260 | |
| 261 | return real_path; |
| 262 | } |