unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#9002: file-error Doing chown operation not permitted
@ 2011-07-05 12:55 jidanni
  2011-07-16 21:27 ` Glenn Morris
  0 siblings, 1 reply; 5+ messages in thread
From: jidanni @ 2011-07-05 12:55 UTC (permalink / raw)
  To: 9002

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





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#9002: file-error Doing chown operation not permitted
  2011-07-05 12:55 bug#9002: file-error Doing chown operation not permitted jidanni
@ 2011-07-16 21:27 ` Glenn Morris
  2011-07-16 21:59   ` Paul Eggert
  0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2011-07-16 21:27 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 9002

jidanni@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





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#9002: file-error Doing chown operation not permitted
  2011-07-16 21:27 ` Glenn Morris
@ 2011-07-16 21:59   ` Paul Eggert
  2011-07-17  1:21     ` Paul Eggert
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Eggert @ 2011-07-16 21:59 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 8306, 9002-done, jidanni

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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#9002: file-error Doing chown operation not permitted
  2011-07-16 21:59   ` Paul Eggert
@ 2011-07-17  1:21     ` Paul Eggert
  2011-07-18 17:24       ` Paul Eggert
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Eggert @ 2011-07-17  1:21 UTC (permalink / raw)
  Cc: 9002

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@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@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));
     }






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#9002: file-error Doing chown operation not permitted
  2011-07-17  1:21     ` Paul Eggert
@ 2011-07-18 17:24       ` Paul Eggert
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Eggert @ 2011-07-18 17:24 UTC (permalink / raw)
  To: 9002

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 */






^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-07-18 17:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-05 12:55 bug#9002: file-error Doing chown operation not permitted jidanni
2011-07-16 21:27 ` Glenn Morris
2011-07-16 21:59   ` Paul Eggert
2011-07-17  1:21     ` Paul Eggert
2011-07-18 17:24       ` Paul Eggert

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).