GNU bug report logs - #9002
file-error Doing chown operation not permitted

Previous Next

Package: emacs;

Reported by: jidanni <at> jidanni.org

Date: Tue, 5 Jul 2011 13:06:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 9002 in the body.
You can then email your comments to 9002 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#9002; Package emacs. (Tue, 05 Jul 2011 13:06:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to jidanni <at> jidanni.org:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 05 Jul 2011 13:06:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: jidanni <at> jidanni.org
To: bug-gnu-emacs <at> gnu.org
Subject: file-error Doing chown operation not permitted
Date: Tue, 05 Jul 2011 20:55:51 +0800
R runs the command dired-do-rename.

Try this:

Have two directories, both owned by you, but on separate disks.

Try to move a file that is NOT owned by you from one to the other.

Move `/cf/updates/df.j3d' to `/home/jidanni/df.j3d' failed:
(file-error Doing chown operation not permitted /home/jidanni/df.j3d)

That is because emacs is not using the mv(1) command like it should, but
instead resorting to a different error prone half home baked method or
something.

Tested on Debian.

P.S.,
file-error: Doing chown #looks better than
file-error Doing chown




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#9002; Package emacs. (Sat, 16 Jul 2011 21:28:02 GMT) Full text and rfc822 format available.

Message #8 received at 9002 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 9002 <at> debbugs.gnu.org
Subject: Re: bug#9002: file-error Doing chown operation not permitted
Date: Sat, 16 Jul 2011 17:27:50 -0400
jidanni <at> jidanni.org wrote:

> Have two directories, both owned by you, but on separate disks.
>
> Try to move a file that is NOT owned by you from one to the other.
>
> Move `/cf/updates/df.j3d' to `/home/jidanni/df.j3d' failed:
> (file-error Doing chown operation not permitted /home/jidanni/df.j3d)

Emacs 23.3 does not give this error, but the trunk does. This seems to
be a result of the changes in

http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8306




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Sat, 16 Jul 2011 22:00:04 GMT) Full text and rfc822 format available.

Notification sent to jidanni <at> jidanni.org:
bug acknowledged by developer. (Sat, 16 Jul 2011 22:00:05 GMT) Full text and rfc822 format available.

Message #13 received at 9002-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 8306 <at> debbugs.gnu.org, 9002-done <at> debbugs.gnu.org, jidanni <at> jidanni.org
Subject: Re: bug#9002: file-error Doing chown operation not permitted
Date: Sat, 16 Jul 2011 14:59:10 -0700
On 07/16/11 14:27, Glenn Morris wrote:
> Emacs 23.3 does not give this error, but the trunk does. This seems to
> be a result of the changes in
> 
> http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8306

Right you are, and thanks for reporting it.  I fixed it in
bzr 105261 on the trunk.  copy-file's help string says "try to
transfer the uid and gid", with the implication that it's OK
if the attempt fails and no diagnosis should be made.

The doc uses stronger language for file modes ("This function always
sets the file modes") so a diagnostic is more appropriate there
and I left that one alone.




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#9002; Package emacs. (Sun, 17 Jul 2011 01:22:02 GMT) Full text and rfc822 format available.

Message #16 received at 9002 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 9002 <at> debbugs.gnu.org
Subject: Re: bug#9002: file-error Doing chown operation not permitted
Date: Sat, 16 Jul 2011 18:21:15 -0700
On 07/16/11 14:59, Paul Eggert wrote:
> copy-file's help string says "try to
> transfer the uid and gid", with the implication that it's OK
> if the attempt fails and no diagnosis should be made.

In further building/testing I ran into a problem with that patch:
it runs afoul of fchown's __attribute__((warn_unused_result)) in
recent glibc versions.  I've installed the following further patch
to address this:

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2011-07-16 23:40:44 +0000
+++ src/ChangeLog	2011-07-17 01:18:51 +0000
@@ -1,3 +1,11 @@
+2011-07-17  Paul Eggert  <eggert <at> cs.ucla.edu>
+
+	* fileio.c (Fcopy_file): Pacify gcc re fchown.  (Bug#9002)
+	This works around a problem with the previous change to Fcopy_file.
+	Recent glibc declares fchown with __attribute__((warn_unused_result)),
+	and without this change, GCC might complain about discarding
+	fchown's return value.
+
 2011-07-16  Juanma Barranquero  <lekktu <at> gmail.com>
 
 	* makefile.w32-in (GLOBAL_SOURCES): Add gnutls.c (followup to bug#9059).

=== modified file 'src/fileio.c'
--- src/fileio.c	2011-07-16 21:53:38 +0000
+++ src/fileio.c	2011-07-17 01:18:51 +0000
@@ -38,6 +38,8 @@
 #include <selinux/context.h>
 #endif
 
+#include <ignore-value.h>
+
 #include "lisp.h"
 #include "intervals.h"
 #include "buffer.h"
@@ -1960,7 +1962,7 @@
   if (input_file_statable_p)
     {
       if (!NILP (preserve_uid_gid))
-	fchown (ofd, st.st_uid, st.st_gid);
+	ignore_value (fchown (ofd, st.st_uid, st.st_gid));
       if (fchmod (ofd, st.st_mode & 07777) != 0)
 	report_file_error ("Doing chmod", Fcons (newname, Qnil));
     }





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#9002; Package emacs. (Mon, 18 Jul 2011 17:25:02 GMT) Full text and rfc822 format available.

Message #19 received at 9002 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: 9002 <at> debbugs.gnu.org
Subject: Re: bug#9002: file-error Doing chown operation not permitted
Date: Mon, 18 Jul 2011 10:24:06 -0700
In yet more testing I found a couple more issues.
First, many systems allow you to change gid on files
that you can't set the uid of, if you're a member of
the group and own the file.  Second, if we can't set
the uid and/or gid we shouldn't enable the setuid and/or
gid bits, as the result would be setuid and/or setgid
to the wrong user.  I pushed the following further
patch into the trunk.

* fileio.c (Fcopy_file): Adjust mode if fchown fails.  (Bug#9002)
If fchown fails to set both uid and gid, try to set just gid,
as that is sometimes allowed.  Adjust the file's mode to eliminate
setuid or setgid bits that are inappropriate if fchown fails.
=== modified file 'src/fileio.c'
--- src/fileio.c	2011-07-17 01:18:51 +0000
+++ src/fileio.c	2011-07-18 17:15:29 +0000
@@ -38,8 +38,6 @@
 #include <selinux/context.h>
 #endif

-#include <ignore-value.h>
-
 #include "lisp.h"
 #include "intervals.h"
 #include "buffer.h"
@@ -1961,9 +1959,21 @@
      owner and group.  */
   if (input_file_statable_p)
     {
+      int mode_mask = 07777;
       if (!NILP (preserve_uid_gid))
-	ignore_value (fchown (ofd, st.st_uid, st.st_gid));
-      if (fchmod (ofd, st.st_mode & 07777) != 0)
+	{
+	  /* Attempt to change owner and group.  If that doesn't work
+	     attempt to change just the group, as that is sometimes allowed.
+	     Adjust the mode mask to eliminate setuid or setgid bits
+	     that are inappropriate if the owner and group are wrong.  */
+	  if (fchown (ofd, st.st_uid, st.st_gid) != 0)
+	    {
+	      mode_mask &= ~06000;
+	      if (fchown (ofd, -1, st.st_gid) == 0)
+		mode_mask |= 02000;
+	    }
+	}
+      if (fchmod (ofd, st.st_mode & mode_mask) != 0)
 	report_file_error ("Doing chmod", Fcons (newname, Qnil));
     }
 #endif	/* not MSDOS */





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 16 Aug 2011 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 315 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.