From 03cbcba7b2b0e42a04033a008c7fac87595e7f35 Mon Sep 17 00:00:00 2001 From: Jan Grulich Date: Tue, 2 May 2023 11:19:29 +0200 Subject: [PATCH] OpenFile portal: do not use O_PATH fds Using O_PATH requires correctly specifying whether the fd is writable or not. Stating that the fd is writable without it actually being writable results into rejection on xdg-desktop-portal side. Other implementations like xdg-open or gtk have also moved away from O_PATH fds so this will make a matching implementation and avoid possible rejections from xdp. Fixes: QTBUG-113143 Pick-to: 6.5 5.15 Change-Id: Icc171752d73ee091282b7c655f71da3cb59179b1 Reviewed-by: Thiago Macieira --- src/gui/platform/unix/qgenericunixservices.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/gui/platform/unix/qgenericunixservices.cpp b/src/gui/platform/unix/qgenericunixservices.cpp index e834ad1f079..34d9c37e246 100644 --- a/src/gui/platform/unix/qgenericunixservices.cpp +++ b/src/gui/platform/unix/qgenericunixservices.cpp @@ -177,8 +177,7 @@ static inline QDBusMessage xdgDesktopPortalOpenFile(const QUrl &url, const QStri // handle_token (s) - A string that will be used as the last element of the @handle. // writable (b) - Whether to allow the chosen application to write to the file. -#ifdef O_PATH - const int fd = qt_safe_open(QFile::encodeName(url.toLocalFile()), O_PATH); + const int fd = qt_safe_open(QFile::encodeName(url.toLocalFile()), O_RDONLY); if (fd != -1) { QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.portal.Desktop"_L1, "/org/freedesktop/portal/desktop"_L1, @@ -188,7 +187,7 @@ static inline QDBusMessage xdgDesktopPortalOpenFile(const QUrl &url, const QStri QDBusUnixFileDescriptor descriptor; descriptor.giveFileDescriptor(fd); - QVariantMap options = { { "writable"_L1, true } }; + QVariantMap options = {}; if (!xdgActivationToken.isEmpty()) { options.insert("activation_token"_L1, xdgActivationToken); @@ -198,11 +197,6 @@ static inline QDBusMessage xdgDesktopPortalOpenFile(const QUrl &url, const QStri return QDBusConnection::sessionBus().call(message); } -#else - Q_UNUSED(url); - Q_UNUSED(parentWindow) - Q_UNUSED(xdgActivationToken) -#endif return QDBusMessage::createError(QDBusError::InternalError, qt_error_string()); }