From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs 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 Message-ID: <83mu6b7vzg.fsf@gnu.org> References: <29272-1589315462-76131@sneakemail.com> Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="94246"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 41218@debbugs.gnu.org To: "Michael Hoffman" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 13 16:26:10 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jYsKn-000OOM-4q for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 13 May 2020 16:26:09 +0200 Original-Received: from localhost ([::1]:40182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYsKm-0000LH-6x for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 13 May 2020 10:26:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYsKf-0000L2-UL for bug-gnu-emacs@gnu.org; Wed, 13 May 2020 10:26:01 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47485) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYsKf-0000W1-LS for bug-gnu-emacs@gnu.org; Wed, 13 May 2020 10:26:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jYsKf-0002Ap-IU for bug-gnu-emacs@gnu.org; Wed, 13 May 2020 10:26:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 13 May 2020 14:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41218 X-GNU-PR-Package: emacs Original-Received: via spool by 41218-submit@debbugs.gnu.org id=B41218.15893799548338 (code B ref 41218); Wed, 13 May 2020 14:26:01 +0000 Original-Received: (at 41218) by debbugs.gnu.org; 13 May 2020 14:25:54 +0000 Original-Received: from localhost ([127.0.0.1]:59031 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jYsKX-0002AQ-PF for submit@debbugs.gnu.org; Wed, 13 May 2020 10:25:53 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:51986) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jYsKR-00029v-BU; Wed, 13 May 2020 10:25:50 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:37687) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYsKL-0000Td-RZ; Wed, 13 May 2020 10:25:41 -0400 Original-Received: from [176.228.60.248] (port=2258 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jYsKL-000391-66; Wed, 13 May 2020 10:25:41 -0400 In-Reply-To: <29272-1589315462-76131@sneakemail.com> (emacs-hoffman@snkmail.com) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:180152 Archived-At: severity 41218 wishlist thanks > From: "Michael Hoffman" > 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.