Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenURI: open file with write access when requested #26

Merged
merged 1 commit into from
Apr 22, 2020

Conversation

grulja
Copy link
Contributor

@grulja grulja commented Mar 25, 2020

When user specifies to open a file with write access, we need to open it with specified permission, otherwise xdg-desktop-portal will fail as it checks for write access.

Also follow glib and do not use O_PATH, because since xdg-desktop-portal 1.0.1, regular file descriptors are also accepted.

For reference:

  1. Glib change
  2. Portal bug

@grulja
Copy link
Contributor Author

grulja commented Mar 25, 2020

The check for write access in xdg-desktop-portal is here.

@hadess
Copy link
Contributor

hadess commented Mar 27, 2020

The check for write access in xdg-desktop-portal is here.

Should that check also be reversed? !writable && fd_is_writable
If the check was also made, then libportal would trigger a warning, which this MR would fix.

If you can check that that's the case, then I'm happy with this change.

@grulja
Copy link
Contributor Author

grulja commented Mar 27, 2020

The check for write access in xdg-desktop-portal is here.

Should that check also be reversed? !writable && fd_is_writable
If the check was also made, then libportal would trigger a warning, which this MR would fix.

That check is correct in my opinion. It checks whether we specified the file should be writable (you can request that with a flag in libportal) and whether the passed file descriptor is writable. If we specify it is writable, but we don't open the file with write access, then it obviously fails the check and you are not allowed to open the file.

@hadess
Copy link
Contributor

hadess commented Mar 27, 2020

That check is correct in my opinion.

I meant we should have both checks, not that this one was incorrect

eg:

Should that check also be reversed?

@grulja
Copy link
Contributor Author

grulja commented Mar 27, 2020

I meant we should have both checks, not that this one was incorrect

I misunderstood before what you meant.

We should have both:
if (!writable && fd_is_writable || writable &&!fd_is_writable)
This would also disallow a fd with write access which we didn't request, this however doesn't need any change on libportal side, while the condition writable &&!fd_is_writable needs this change, otherwise it will silently fail.

@hadess
Copy link
Contributor

hadess commented Mar 27, 2020

This would also disallow a fd with write access which we didn't request, this however doesn't need any change on libportal side, while the condition writable &&!fd_is_writable needs this change, otherwise it will silently fail.

I'd like xdg-desktop-portal to throw a warning for the current libportal code. Then the patch in this MR becomes obviously correct.

@grulja
Copy link
Contributor Author

grulja commented Mar 27, 2020

I will try to write a test case for xdg-desktop-portal. I had planned this anyway.

@grulja
Copy link
Contributor Author

grulja commented Apr 17, 2020

I discussed this with @matthiasclasen yesterday, the test case for this requires a sandbox environment and we don't do the tests this way in xdg-desktop-portal yet and I don't want to spend that much time on it since it shouldn't be mandatory for this fix, because it's clear and obvious. Can we merge it then?

@hadess
Copy link
Contributor

hadess commented Apr 17, 2020

I didn't ask for a test case to be written, I said:

I'd like xdg-desktop-portal to throw a warning for the current libportal code. Then the patch in this MR becomes obviously correct.

So, one commit to add the warning. One commit that fixes that warning with some details like a backtrace, or at least the error message.

hadess added a commit to flatpak/xdg-desktop-portal that referenced this pull request Apr 17, 2020
Also reject non-writable requests that come with writable file
descriptors.

See flatpak/libportal#26
@hadess
Copy link
Contributor

hadess commented Apr 17, 2020

So, one commit to add the warning. One commit that fixes that warning with some details like a backtrace, or at least the error message.

Can you try reproducing the issue with this patch and running xdg-desktop-portal with G_MESSAGES_DEBUG=all:
flatpak/xdg-desktop-portal#474

It should print a warning about Rejecting open request as opening... which you can add in the commit message for this patch. Thanks!

@hadess
Copy link
Contributor

hadess commented Apr 17, 2020

The error message is:

DEBUG: 23:48:22.586: Rejecting open request for /tmp/xdp-test-263CJ0/test.txt as opening not writable but fd is writable

hadess added a commit to flatpak/xdg-desktop-portal that referenced this pull request Apr 17, 2020
Also reject non-writable requests that come with writable file
descriptors.

See flatpak/libportal#26
@grulja
Copy link
Contributor Author

grulja commented Apr 19, 2020

I already had an error message there as I put it there myself when I was debugging this issue, based on that I wrote this patch.

Anyway, I built xdg-desktop-portal from your branch, dropped this patch from my local Dolphin build and I got your error message:
** (/usr/libexec/xdg-desktop-portal:55877): DEBUG: 21:32:54.753: Rejecting open request for /home/jgrulich/xdp-kde.patch as opening writable but fd is not writable

@hadess
Copy link
Contributor

hadess commented Apr 22, 2020

Can you update the commit message to include the error message as we discussed, so we can merge this?

When user specifies to open a file with write access, we need to open it with specified
permission, otherwise xdg-desktop-portal will fail as it checks for write access.

Also follow glib and do not use O_PATH, because since xdg-desktop-portal 1.0.1, regular file descriptors
are also accepted.

Not opening the file with write access results into following error in xdg-desktop-portal:
** (/usr/libexec/xdg-desktop-portal:55877): DEBUG: 21:32:54.753: Rejecting open request for xxx
    as opening writable but fd is not writable
@grulja
Copy link
Contributor Author

grulja commented Apr 22, 2020

Can you update the commit message to include the error message as we discussed, so we can merge this?

Done.

@hadess hadess merged commit bff3289 into flatpak:master Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants