Merge branch 'portals-no-o-path' into 'master'

gio: do not pass O_PATH file descriptors to portal APIs

See merge request GNOME/glib!585
This commit is contained in:
Philip Withnall 2019-01-28 12:58:03 +00:00
commit 80f2c96a45
3 changed files with 10 additions and 82 deletions

View File

@ -31,9 +31,6 @@
#include "gunixfdlist.h"
#endif
#ifndef O_PATH
#define O_PATH 0
#endif
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#else
@ -92,76 +89,6 @@ init_document_portal (void)
return (documents != NULL && documents_mountpoint != NULL);
}
char *
g_document_portal_add_document (GFile *file,
GError **error)
{
char *doc_path, *basename;
char *doc_id = NULL;
char *doc_uri = NULL;
char *path = NULL;
GUnixFDList *fd_list = NULL;
int fd, fd_in, errsv;
gboolean ret;
if (!init_document_portal ())
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED,
"Document portal is not available");
goto out;
}
path = g_file_get_path (file);
fd = g_open (path, O_PATH | O_CLOEXEC);
errsv = errno;
if (fd == -1)
{
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
"Failed to open %s", path);
goto out;
}
#ifndef HAVE_O_CLOEXEC
fcntl (fd, F_SETFD, FD_CLOEXEC);
#endif
fd_list = g_unix_fd_list_new ();
fd_in = g_unix_fd_list_append (fd_list, fd, error);
g_close (fd, NULL);
if (fd_in == -1)
goto out;
ret = gxdp_documents_call_add_sync (documents,
g_variant_new_handle (fd_in),
TRUE,
TRUE,
fd_list,
&doc_id,
NULL,
NULL,
error);
if (!ret)
goto out;
basename = g_path_get_basename (path);
doc_path = g_build_filename (documents_mountpoint, doc_id, basename, NULL);
g_free (basename);
doc_uri = g_filename_to_uri (doc_path, NULL, NULL);
g_free (doc_path);
out:
if (fd_list)
g_object_unref (fd_list);
g_free (path);
g_free (doc_id);
return doc_uri;
}
/* Flags accepted by org.freedesktop.portal.Documents.AddFull */
enum {
XDP_ADD_FLAGS_REUSE_EXISTING = (1 << 0),
@ -210,7 +137,14 @@ g_document_portal_add_documents (GList *uris,
{
int fd;
fd = g_open (path, O_CLOEXEC | O_PATH);
fd = g_open (path, O_CLOEXEC | O_RDWR);
if (fd == -1 && (errno == EACCES || errno == EISDIR))
{
/* If we don't have write access, fall back to read-only,
* and stop requesting the write permission */
fd = g_open (path, O_CLOEXEC | O_RDONLY);
permissions[1] = NULL;
}
if (fd >= 0)
{
#ifndef HAVE_O_CLOEXEC

View File

@ -23,9 +23,6 @@
G_BEGIN_DECLS
char * g_document_portal_add_document (GFile *file,
GError **error);
GList * g_document_portal_add_documents (GList *uris,
const char *app_id,
GError **error);

View File

@ -31,9 +31,6 @@
#include "gunixfdlist.h"
#endif
#ifndef O_PATH
#define O_PATH 0
#endif
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#else
@ -107,7 +104,7 @@ g_openuri_portal_open_uri (const char *uri,
path = g_file_get_path (file);
fd = g_open (path, O_PATH | O_CLOEXEC);
fd = g_open (path, O_RDONLY | O_CLOEXEC);
errsv = errno;
if (fd == -1)
{
@ -318,7 +315,7 @@ g_openuri_portal_open_uri_async (const char *uri,
g_object_set_data (G_OBJECT (task), "open-file", GINT_TO_POINTER (TRUE));
path = g_file_get_path (file);
fd = g_open (path, O_PATH | O_CLOEXEC);
fd = g_open (path, O_RDONLY | O_CLOEXEC);
errsv = errno;
if (fd == -1)
{