unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: "Michael Hoffman" <emacs-hoffman@snkmail.com>
Cc: 41218@debbugs.gnu.org
Subject: bug#41218: 26.3; Windows: file-writable-p returns t for a file owned by the Administrators group but not writable by the user, a member of the Administrators group
Date: Wed, 13 May 2020 17:25:23 +0300	[thread overview]
Message-ID: <83mu6b7vzg.fsf@gnu.org> (raw)
In-Reply-To: <29272-1589315462-76131@sneakemail.com> (emacs-hoffman@snkmail.com)

severity 41218 wishlist
thanks

> From: "Michael Hoffman" <emacs-hoffman@snkmail.com>
> Date: Tue, 12 May 2020 16:30:48 -0400
> 
> 1. Start elevated Powershell (Win+X,A) and create file C:\foo.txt owned by the Administrators group
> 
> PS C:\> $null > C:\foo.txt
> PS C:\> takeown /A /F C:\foo.txt
> 
> SUCCESS: The file (or folder): "C:\foo.txt" now owned by the administrators group.
> 
> 2. Open `emacs -Q`
> 
> 3. C-x C-f C:/foo.txt
> 
> 4. Type `(file-writable-p "foo.txt")` C-x C-e
> t
> 
> 5. C-x C-s
> Saving file c:/foo.txt...
> Cannot write backup file; backing up in ~/.emacs.d/%backup%~
> Error: (file-error "Setting ACL" "Operation not permitted" "c:/Users/mhoffman/.emacs.d/%backup%~")
> basic-save-buffer-2: Opening output file: Permission denied, c:/foo.txt
> 
> Expected that `(file-writable-p "foo.txt")` would return nil.

Emacs on MS-Windows doesn't check the ACLs when it determines whether
a file is writable.  The reason is that there doesn't seem to be a
general reliable way of doing so, given that access rights on Windows
are many times implicitly given because the user belongs to some group
that is granted access.  Basically, the only reliable way of making
sure the file is writable is to try writing to it; any other kind of
test I know of is plagued with false negatives, i.e. they frequently
tell the file is not writable when in fact it is, which I consider a
greater evil than the kind of problem you report.  And the fact that
one normally needs to jump through hoops (elevating your session,
using tools that make the file explicitly owned by a privileged group,
etc.) to create such a situation on Windows is one more reason not to
bother about this too much.  IOW, the situation is rare.

Of course, if someone can explain how to perform this test in a way
that takes ACLs into account and would be reliable, we could consider
implementing it (assuming it isn't too expensive, since such a test
will have to be performed each time a user saves a buffer to its
file).

Thanks.





  reply	other threads:[~2020-05-13 14:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12 20:30 bug#41218: 26.3; Windows: file-writable-p returns t for a file owned by the Administrators group but not writable by the user, a member of the Administrators group Michael Hoffman
2020-05-13 14:25 ` Eli Zaretskii [this message]
2020-05-13 16:05   ` Michael Hoffman
2020-05-13 16:40     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83mu6b7vzg.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=41218@debbugs.gnu.org \
    --cc=emacs-hoffman@snkmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).