From 3f48d8b93328c6dec35261b82a0714794a6b7544 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Wed, 8 Jul 2009 12:53:07 +0000 Subject: [PATCH] * net/tramp.el (tramp-set-file-uid-gid): Handle the case the remote user is root, on the local host. (tramp-local-host-p): Either the local user or the remote user must be root. (Bug#3771) --- lisp/ChangeLog | 7 +++++++ lisp/net/tramp.el | 34 ++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3c2be95238f..c9bdc0722a0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2009-07-08 Michael Albinus + + * net/tramp.el (tramp-set-file-uid-gid): Handle the case the + remote user is root, on the local host. + (tramp-local-host-p): Either the local user or the remote user + must be root. (Bug#3771) + 2009-07-08 E. Jay Berkenbilt (tiny change) * mail/unrmail.el (unrmail): Make sure the message ends with two diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 01ce21698a4..021535250a3 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -2687,14 +2687,17 @@ and gid of the corresponding user is taken. Both parameters must be integers." ;; succeed in the majority of cases. (if (file-remote-p filename) (with-parsed-tramp-file-name filename nil - (let ((uid (or (and (integerp uid) uid) - (tramp-get-remote-uid v 'integer))) - (gid (or (and (integerp gid) gid) - (tramp-get-remote-gid v 'integer)))) - (tramp-send-command - v (format - "chown %d:%d %s" uid gid - (tramp-shell-quote-argument localname))))) + (if (and (zerop (user-uid)) (tramp-local-host-p v)) + ;; If we are root on the local host, we can do it directly. + (tramp-set-file-uid-gid localname uid gid) + (let ((uid (or (and (integerp uid) uid) + (tramp-get-remote-uid v 'integer))) + (gid (or (and (integerp gid) gid) + (tramp-get-remote-gid v 'integer)))) + (tramp-send-command + v (format + "chown %d:%d %s" uid gid + (tramp-shell-quote-argument localname)))))) ;; We handle also the local part, because there doesn't exist ;; `set-file-uid-gid'. On Win32 "chown" might not work. @@ -4356,7 +4359,7 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file." (tramp-get-remote-gid v 'integer)))) (if (and (tramp-local-host-p v) - ;; `file-writable-p' calls 'file-expand-file-name'. We + ;; `file-writable-p' calls `file-expand-file-name'. We ;; cannot use `tramp-run-real-handler' therefore. (let (file-name-handler-alist) (and @@ -4364,10 +4367,10 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file." (or (file-directory-p localname) (file-writable-p localname))))) ;; Short track: if we are on the local host, we can run directly. - (prog1 - (tramp-run-real-handler - 'write-region - (list start end localname append 'no-message lockname confirm)) + (progn + (tramp-run-real-handler + 'write-region + (list start end localname append 'no-message lockname confirm)) (tramp-flush-file-property v localname)) (let ((rem-dec (tramp-get-remote-coding v "remote-decoding")) @@ -7161,7 +7164,10 @@ necessary only. This function will be used in file name completion." (tramp-file-name-method vec) (tramp-file-name-user vec) host - (tramp-compat-temporary-file-directory)))))) + (tramp-compat-temporary-file-directory))) + ;; On some systems, chown runs only for root. + (or (zerop (user-uid)) + (zerop (tramp-get-remote-uid vec 'integer)))))) ;; Variables local to connection. -- 2.39.2