aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2020-06-14 15:31:17 +0200
committerMichael Albinus2020-06-14 15:31:17 +0200
commitb3e7d046c3a94556fcaf6f9ce72aa2ecb20262a6 (patch)
treec70f1f11e7fd7f34dfd836bb5da3aa1059562e05
parent82a632edc8b80bf16d9b9f205474bf9724b084c0 (diff)
downloademacs-b3e7d046c3a94556fcaf6f9ce72aa2ecb20262a6.tar.gz
emacs-b3e7d046c3a94556fcaf6f9ce72aa2ecb20262a6.zip
Rearrange detecting remote uid and gid in Tramp
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist): * lisp/net/tramp-archive.el (tramp-archive-file-name-handler-alist): * lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist): * lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist): Add `tramp-get-remote-gid' and 'tramp-get-remote-uid'. * lisp/net/tramp-crypt.el (tramp-crypt-file-name-handler-alist): Add `file-ownership-preserved-p'. (tramp-crypt-add-directory): Check, that NAME is not quoted. (tramp-crypt-handle-file-ownership-preserved-p): New defun. (tramp-crypt-handle-insert-directory): Fix docstring. * lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist): Add `tramp-get-remote-gid' and 'tramp-get-remote-uid'. (tramp-gvfs-handle-file-readable-p): Call `tramp-get-remote-uid'. (tramp-gvfs-handle-get-remote-uid) (tramp-gvfs-handle-get-remote-gid): Rename from `tramp-gvfs-get-remote-{uid,gid}'. Do not cache result. (tramp-gvfs-maybe-open-connection): No special handling for remote uid and gid. * lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist): Add `tramp-get-remote-gid' and 'tramp-get-remote-uid'. (tramp-sh-handle-get-remote-uid, tramp-sh-handle-get-remote-gid): Rename from `tramp-get-remote-{uid,gid}'. Do not cache result. (tramp-sh-handle-file-ownership-preserved-p): Distinguish by GROUP when caching. * lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist): Add `tramp-get-remote-gid' and 'tramp-get-remote-uid'. (tramp-sudoedit-handle-get-remote-uid) (tramp-sudoedit-handle-get-remote-gid): Rename from `tramp-sudoedit-get-remote-{uid,gid}'. Do not cache result. (tramp-sudoedit-handle-set-file-uid-gid) (tramp-sudoedit-handle-write-region): Call `tramp-get-remote-uid' and `tramp-get-remote-gid'. (tramp-sudoedit-maybe-open-connection): No special handling for remote uid and gid. * lisp/net/tramp.el (tramp-file-name-for-operation): Add `tramp-get-remote-gid' and 'tramp-get-remote-uid'. (tramp-handle-write-region, tramp-check-cached-permissions): Call `tramp-get-remote-uid' and `tramp-get-remote-gid'. (tramp-get-remote-uid, tramp-get-remote-gid): New defuns. (tramp-local-host-p): Simplify `tramp-get-remote-uid' call. * test/lisp/net/tramp-tests.el (tramp-test17-dired-with-wildcards) Skip if needed.
-rw-r--r--lisp/net/tramp-adb.el2
-rw-r--r--lisp/net/tramp-archive.el4
-rw-r--r--lisp/net/tramp-crypt.el14
-rw-r--r--lisp/net/tramp-gvfs.el68
-rw-r--r--lisp/net/tramp-rclone.el2
-rw-r--r--lisp/net/tramp-sh.el70
-rw-r--r--lisp/net/tramp-smb.el2
-rw-r--r--lisp/net/tramp-sudoedit.el37
-rw-r--r--lisp/net/tramp.el51
-rw-r--r--test/lisp/net/tramp-tests.el2
10 files changed, 126 insertions, 126 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index fb98805cc39..a7a5047ed49 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -160,6 +160,8 @@ It is used for TCP/IP devices."
160 (start-file-process . tramp-handle-start-file-process) 160 (start-file-process . tramp-handle-start-file-process)
161 (substitute-in-file-name . tramp-handle-substitute-in-file-name) 161 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
162 (temporary-file-directory . tramp-handle-temporary-file-directory) 162 (temporary-file-directory . tramp-handle-temporary-file-directory)
163 (tramp-get-remote-gid . ignore)
164 (tramp-get-remote-uid . ignore)
163 (tramp-set-file-uid-gid . ignore) 165 (tramp-set-file-uid-gid . ignore)
164 (unhandled-file-name-directory . ignore) 166 (unhandled-file-name-directory . ignore)
165 (vc-registered . ignore) 167 (vc-registered . ignore)
diff --git a/lisp/net/tramp-archive.el b/lisp/net/tramp-archive.el
index 24ee6fa51f3..9502cc35300 100644
--- a/lisp/net/tramp-archive.el
+++ b/lisp/net/tramp-archive.el
@@ -279,7 +279,9 @@ It must be supported by libarchive(3).")
279 (start-file-process . tramp-archive-handle-not-implemented) 279 (start-file-process . tramp-archive-handle-not-implemented)
280 ;; `substitute-in-file-name' performed by default handler. 280 ;; `substitute-in-file-name' performed by default handler.
281 (temporary-file-directory . tramp-archive-handle-temporary-file-directory) 281 (temporary-file-directory . tramp-archive-handle-temporary-file-directory)
282 ;; `tramp-set-file-uid-gid' performed by default handler. 282 (tramp-get-remote-gid . ignore)
283 (tramp-get-remote-uid . ignore)
284 (tramp-set-file-uid-gid . ignore)
283 (unhandled-file-name-directory . ignore) 285 (unhandled-file-name-directory . ignore)
284 (vc-registered . ignore) 286 (vc-registered . ignore)
285 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) 287 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el
index e63d83628a3..4f01f1bf6c4 100644
--- a/lisp/net/tramp-crypt.el
+++ b/lisp/net/tramp-crypt.el
@@ -182,7 +182,7 @@ If NAME doesn't belong to a crypted remote directory, retun nil."
182 (file-notify-add-watch . ignore) 182 (file-notify-add-watch . ignore)
183 (file-notify-rm-watch . ignore) 183 (file-notify-rm-watch . ignore)
184 (file-notify-valid-p . ignore) 184 (file-notify-valid-p . ignore)
185 ;; (file-ownership-preserved-p . ignore) 185 (file-ownership-preserved-p . tramp-crypt-handle-file-ownership-preserved-p)
186 (file-readable-p . tramp-crypt-handle-file-readable-p) 186 (file-readable-p . tramp-crypt-handle-file-readable-p)
187 (file-regular-p . tramp-handle-file-regular-p) 187 (file-regular-p . tramp-handle-file-regular-p)
188 ;; `file-remote-p' performed by default handler. 188 ;; `file-remote-p' performed by default handler.
@@ -213,6 +213,8 @@ If NAME doesn't belong to a crypted remote directory, retun nil."
213 (start-file-process . ignore) 213 (start-file-process . ignore)
214 ;; `substitute-in-file-name' performed by default handler. 214 ;; `substitute-in-file-name' performed by default handler.
215 ;; (temporary-file-directory . tramp-crypt-handle-temporary-file-directory) 215 ;; (temporary-file-directory . tramp-crypt-handle-temporary-file-directory)
216 ;; `tramp-get-remote-gid' performed by default handler.
217 ;; `tramp-get-remote-uid' performed by default handler.
216 (tramp-set-file-uid-gid . tramp-crypt-handle-set-file-uid-gid) 218 (tramp-set-file-uid-gid . tramp-crypt-handle-set-file-uid-gid)
217 ;; (unhandled-file-name-directory . ignore) 219 ;; (unhandled-file-name-directory . ignore)
218 (vc-registered . ignore) 220 (vc-registered . ignore)
@@ -465,6 +467,8 @@ directory. File names will be also encrypted."
465 (tramp-user-error nil "Feature is not enabled.")) 467 (tramp-user-error nil "Feature is not enabled."))
466 (unless (and (tramp-tramp-file-p name) (file-directory-p name)) 468 (unless (and (tramp-tramp-file-p name) (file-directory-p name))
467 (tramp-user-error nil "%s must be an existing remote directory." name)) 469 (tramp-user-error nil "%s must be an existing remote directory." name))
470 (when (tramp-compat-file-name-quoted-p name)
471 (tramp-user-error nil "%s must not be quoted." name))
468 (setq name (file-name-as-directory (expand-file-name name))) 472 (setq name (file-name-as-directory (expand-file-name name)))
469 (unless (member name tramp-crypt-directories) 473 (unless (member name tramp-crypt-directories)
470 (setq tramp-crypt-directories (cons name tramp-crypt-directories))) 474 (setq tramp-crypt-directories (cons name tramp-crypt-directories)))
@@ -694,6 +698,11 @@ absolute file names."
694 (let (tramp-crypt-enabled) 698 (let (tramp-crypt-enabled)
695 (file-readable-p (tramp-crypt-encrypt-file-name filename)))) 699 (file-readable-p (tramp-crypt-encrypt-file-name filename))))
696 700
701(defun tramp-crypt-handle-file-ownership-preserved-p (filename &optional group)
702 "Like `file-ownership-preserved-p' for Tramp files."
703 (let (tramp-crypt-enabled)
704 (file-ownership-preserved-p (tramp-crypt-encrypt-file-name filename) group)))
705
697(defun tramp-crypt-handle-file-system-info (filename) 706(defun tramp-crypt-handle-file-system-info (filename)
698 "Like `file-system-info' for Tramp files." 707 "Like `file-system-info' for Tramp files."
699 (tramp-crypt-run-real-handler 708 (tramp-crypt-run-real-handler
@@ -708,7 +717,8 @@ absolute file names."
708 717
709(defun tramp-crypt-handle-insert-directory 718(defun tramp-crypt-handle-insert-directory
710 (filename switches &optional wildcard full-directory-p) 719 (filename switches &optional wildcard full-directory-p)
711 "Like `insert-directory' for Tramp files." 720 "Like `insert-directory' for Tramp files.
721WILDCARD is not supported."
712 ;; This package has been added to Emacs 27.1. 722 ;; This package has been added to Emacs 27.1.
713 (when (load "text-property-search" 'noerror 'nomessage) 723 (when (load "text-property-search" 'noerror 'nomessage)
714 (let (tramp-crypt-enabled) 724 (let (tramp-crypt-enabled)
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index 89e9b132304..36166ad1966 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -821,6 +821,8 @@ It has been changed in GVFS 1.14.")
821 (start-file-process . ignore) 821 (start-file-process . ignore)
822 (substitute-in-file-name . tramp-handle-substitute-in-file-name) 822 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
823 (temporary-file-directory . tramp-handle-temporary-file-directory) 823 (temporary-file-directory . tramp-handle-temporary-file-directory)
824 (tramp-get-remote-gid . tramp-gvfs-handle-get-remote-gid)
825 (tramp-get-remote-uid . tramp-gvfs-handle-get-remote-uid)
824 (tramp-set-file-uid-gid . tramp-gvfs-handle-set-file-uid-gid) 826 (tramp-set-file-uid-gid . tramp-gvfs-handle-set-file-uid-gid)
825 (unhandled-file-name-directory . ignore) 827 (unhandled-file-name-directory . ignore)
826 (vc-registered . ignore) 828 (vc-registered . ignore)
@@ -1506,7 +1508,7 @@ If FILE-SYSTEM is non-nil, return file system attributes."
1506 ;; If the user is different from what we guess to be 1508 ;; If the user is different from what we guess to be
1507 ;; the user, we don't know. Let's check, whether 1509 ;; the user, we don't know. Let's check, whether
1508 ;; access is restricted explicitly. 1510 ;; access is restricted explicitly.
1509 (and (/= (tramp-gvfs-get-remote-uid v 'integer) 1511 (and (/= (tramp-get-remote-uid v 'integer)
1510 (tramp-compat-file-attribute-user-id 1512 (tramp-compat-file-attribute-user-id
1511 (file-attributes filename 'integer))) 1513 (file-attributes filename 'integer)))
1512 (not 1514 (not
@@ -1589,6 +1591,26 @@ If FILE-SYSTEM is non-nil, return file system attributes."
1589 (current-time) 1591 (current-time)
1590 time))))) 1592 time)))))
1591 1593
1594(defun tramp-gvfs-handle-get-remote-uid (vec id-format)
1595 "The uid of the remote connection VEC, in ID-FORMAT.
1596ID-FORMAT valid values are `string' and `integer'."
1597 (if (equal id-format 'string)
1598 (tramp-file-name-user vec)
1599 (when-let
1600 ((localname (tramp-get-connection-property vec "default-location" nil)))
1601 (tramp-compat-file-attribute-user-id
1602 (file-attributes
1603 (tramp-make-tramp-file-name vec localname) id-format)))))
1604
1605(defun tramp-gvfs-handle-get-remote-gid (vec id-format)
1606 "The gid of the remote connection VEC, in ID-FORMAT.
1607ID-FORMAT valid values are `string' and `integer'."
1608 (when-let
1609 ((localname (tramp-get-connection-property vec "default-location" nil)))
1610 (tramp-compat-file-attribute-group-id
1611 (file-attributes
1612 (tramp-make-tramp-file-name vec localname) id-format))))
1613
1592(defun tramp-gvfs-handle-set-file-uid-gid (filename &optional uid gid) 1614(defun tramp-gvfs-handle-set-file-uid-gid (filename &optional uid gid)
1593 "Like `tramp-set-file-uid-gid' for Tramp files." 1615 "Like `tramp-set-file-uid-gid' for Tramp files."
1594 (with-parsed-tramp-file-name filename nil 1616 (with-parsed-tramp-file-name filename nil
@@ -2057,39 +2079,6 @@ and \"org.gtk.Private.RemoteVolumeMonitor.VolumeRemoved\" signals."
2057 2079
2058;; Connection functions. 2080;; Connection functions.
2059 2081
2060(defun tramp-gvfs-get-remote-uid (vec id-format)
2061 "The uid of the remote connection VEC, in ID-FORMAT.
2062ID-FORMAT valid values are `string' and `integer'."
2063 (with-tramp-connection-property vec (format "uid-%s" id-format)
2064 (let ((user (tramp-file-name-user vec))
2065 (localname
2066 (tramp-get-connection-property vec "default-location" nil)))
2067 (cond
2068 ((and (equal id-format 'string) user))
2069 (localname
2070 (tramp-compat-file-attribute-user-id
2071 (file-attributes
2072 (tramp-make-tramp-file-name vec localname) id-format)))
2073 ((equal id-format 'integer) tramp-unknown-id-integer)
2074 ((equal id-format 'string) tramp-unknown-id-string)))))
2075
2076(defun tramp-gvfs-get-remote-gid (vec id-format)
2077 "The gid of the remote connection VEC, in ID-FORMAT.
2078ID-FORMAT valid values are `string' and `integer'."
2079 (with-tramp-connection-property vec (format "gid-%s" id-format)
2080 (let ((localname
2081 (tramp-get-connection-property vec "default-location" nil)))
2082 (cond
2083 (localname
2084 (tramp-compat-file-attribute-group-id
2085 (file-attributes
2086 (tramp-make-tramp-file-name vec localname) id-format)))
2087 ((equal id-format 'integer) tramp-unknown-id-integer)
2088 ((equal id-format 'string) tramp-unknown-id-string)))))
2089
2090(defvar tramp-gvfs-get-remote-uid-gid-in-progress nil
2091 "Indication, that remote uid and gid determination is in progress.")
2092
2093(defun tramp-gvfs-get-remote-prefix (vec) 2082(defun tramp-gvfs-get-remote-prefix (vec)
2094 "The prefix of the remote connection VEC. 2083 "The prefix of the remote connection VEC.
2095This is relevant for GNOME Online Accounts." 2084This is relevant for GNOME Online Accounts."
@@ -2229,16 +2218,7 @@ connection if a previous connection has died for some reason."
2229 2218
2230 ;; Mark it as connected. 2219 ;; Mark it as connected.
2231 (tramp-set-connection-property 2220 (tramp-set-connection-property
2232 (tramp-get-connection-process vec) "connected" t)))) 2221 (tramp-get-connection-process vec) "connected" t)))))
2233
2234 ;; In `tramp-check-cached-permissions', the connection properties
2235 ;; "{uid,gid}-{integer,string}" are used. We set them to proper values.
2236 (unless tramp-gvfs-get-remote-uid-gid-in-progress
2237 (let ((tramp-gvfs-get-remote-uid-gid-in-progress t))
2238 (tramp-gvfs-get-remote-uid vec 'integer)
2239 (tramp-gvfs-get-remote-gid vec 'integer)
2240 (tramp-gvfs-get-remote-uid vec 'string)
2241 (tramp-gvfs-get-remote-gid vec 'string))))
2242 2222
2243(defun tramp-gvfs-gio-tool-p (vec) 2223(defun tramp-gvfs-gio-tool-p (vec)
2244 "Check, whether the gio tool is available." 2224 "Check, whether the gio tool is available."
diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el
index 08bba33afed..f635d3cbb68 100644
--- a/lisp/net/tramp-rclone.el
+++ b/lisp/net/tramp-rclone.el
@@ -135,6 +135,8 @@
135 (start-file-process . ignore) 135 (start-file-process . ignore)
136 (substitute-in-file-name . tramp-handle-substitute-in-file-name) 136 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
137 (temporary-file-directory . tramp-handle-temporary-file-directory) 137 (temporary-file-directory . tramp-handle-temporary-file-directory)
138 (tramp-get-remote-gid . ignore)
139 (tramp-get-remote-uid . ignore)
138 (tramp-set-file-uid-gid . ignore) 140 (tramp-set-file-uid-gid . ignore)
139 (unhandled-file-name-directory . ignore) 141 (unhandled-file-name-directory . ignore)
140 (vc-registered . ignore) 142 (vc-registered . ignore)
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index bcbb7240ec6..fad841a6ace 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1039,6 +1039,8 @@ of command line.")
1039 (start-file-process . tramp-handle-start-file-process) 1039 (start-file-process . tramp-handle-start-file-process)
1040 (substitute-in-file-name . tramp-handle-substitute-in-file-name) 1040 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
1041 (temporary-file-directory . tramp-handle-temporary-file-directory) 1041 (temporary-file-directory . tramp-handle-temporary-file-directory)
1042 (tramp-get-remote-gid . tramp-sh-handle-get-remote-gid)
1043 (tramp-get-remote-uid . tramp-sh-handle-get-remote-uid)
1042 (tramp-set-file-uid-gid . tramp-sh-handle-set-file-uid-gid) 1044 (tramp-set-file-uid-gid . tramp-sh-handle-set-file-uid-gid)
1043 (unhandled-file-name-directory . ignore) 1045 (unhandled-file-name-directory . ignore)
1044 (vc-registered . tramp-sh-handle-vc-registered) 1046 (vc-registered . tramp-sh-handle-vc-registered)
@@ -1467,6 +1469,26 @@ of."
1467 (if (eq flag 'nofollow) "-h" "") 1469 (if (eq flag 'nofollow) "-h" "")
1468 (tramp-shell-quote-argument localname))))))) 1470 (tramp-shell-quote-argument localname)))))))
1469 1471
1472(defun tramp-sh-handle-get-remote-uid (vec id-format)
1473 "The uid of the remote connection VEC, in ID-FORMAT.
1474ID-FORMAT valid values are `string' and `integer'."
1475 (ignore-errors
1476 (cond
1477 ((tramp-get-remote-id vec) (tramp-get-remote-uid-with-id vec id-format))
1478 ((tramp-get-remote-perl vec) (tramp-get-remote-uid-with-perl vec id-format))
1479 ((tramp-get-remote-python vec)
1480 (tramp-get-remote-uid-with-python vec id-format)))))
1481
1482(defun tramp-sh-handle-get-remote-gid (vec id-format)
1483 "The gid of the remote connection VEC, in ID-FORMAT.
1484ID-FORMAT valid values are `string' and `integer'."
1485 (ignore-errors
1486 (cond
1487 ((tramp-get-remote-id vec) (tramp-get-remote-gid-with-id vec id-format))
1488 ((tramp-get-remote-perl vec) (tramp-get-remote-gid-with-perl vec id-format))
1489 ((tramp-get-remote-python vec)
1490 (tramp-get-remote-gid-with-python vec id-format)))))
1491
1470(defun tramp-sh-handle-set-file-uid-gid (filename &optional uid gid) 1492(defun tramp-sh-handle-set-file-uid-gid (filename &optional uid gid)
1471 "Like `tramp-set-file-uid-gid' for Tramp files." 1493 "Like `tramp-set-file-uid-gid' for Tramp files."
1472 ;; Modern Unices allow chown only for root. So we might need 1494 ;; Modern Unices allow chown only for root. So we might need
@@ -1669,8 +1691,10 @@ of."
1669(defun tramp-sh-handle-file-ownership-preserved-p (filename &optional group) 1691(defun tramp-sh-handle-file-ownership-preserved-p (filename &optional group)
1670 "Like `file-ownership-preserved-p' for Tramp files." 1692 "Like `file-ownership-preserved-p' for Tramp files."
1671 (with-parsed-tramp-file-name filename nil 1693 (with-parsed-tramp-file-name filename nil
1672 (with-tramp-file-property v localname "file-ownership-preserved-p" 1694 (with-tramp-file-property
1673 (let ((attributes (file-attributes filename))) 1695 v localname
1696 (format "file-ownership-preserved-p%s" (if group "-group" ""))
1697 (let ((attributes (file-attributes filename 'integer)))
1674 ;; Return t if the file doesn't exist, since it's true that no 1698 ;; Return t if the file doesn't exist, since it's true that no
1675 ;; information would be lost by an (attempted) delete and create. 1699 ;; information would be lost by an (attempted) delete and create.
1676 (or (null attributes) 1700 (or (null attributes)
@@ -5778,27 +5802,6 @@ This command is returned only if `delete-by-moving-to-trash' is non-nil."
5778 "import os; print (os.getuid())" 5802 "import os; print (os.getuid())"
5779 "import os, pwd; print ('\\\"' + pwd.getpwuid(os.getuid())[0] + '\\\"')")))) 5803 "import os, pwd; print ('\\\"' + pwd.getpwuid(os.getuid())[0] + '\\\"')"))))
5780 5804
5781(defun tramp-get-remote-uid (vec id-format)
5782 "The uid of the remote connection VEC, in ID-FORMAT.
5783ID-FORMAT valid values are `string' and `integer'."
5784 (with-tramp-connection-property vec (format "uid-%s" id-format)
5785 (let ((res
5786 (ignore-errors
5787 (cond
5788 ((tramp-get-remote-id vec)
5789 (tramp-get-remote-uid-with-id vec id-format))
5790 ((tramp-get-remote-perl vec)
5791 (tramp-get-remote-uid-with-perl vec id-format))
5792 ((tramp-get-remote-python vec)
5793 (tramp-get-remote-uid-with-python vec id-format))))))
5794 ;; Ensure there is a valid result.
5795 (cond
5796 ((and (equal id-format 'integer) (not (integerp res)))
5797 tramp-unknown-id-integer)
5798 ((and (equal id-format 'string) (not (stringp res)))
5799 tramp-unknown-id-string)
5800 (t res)))))
5801
5802(defun tramp-get-remote-gid-with-id (vec id-format) 5805(defun tramp-get-remote-gid-with-id (vec id-format)
5803 "Implement `tramp-get-remote-gid' for Tramp files using `id'." 5806 "Implement `tramp-get-remote-gid' for Tramp files using `id'."
5804 (tramp-send-command-and-read 5807 (tramp-send-command-and-read
@@ -5829,27 +5832,6 @@ ID-FORMAT valid values are `string' and `integer'."
5829 "import os; print (os.getgid())" 5832 "import os; print (os.getgid())"
5830 "import os, grp; print ('\\\"' + grp.getgrgid(os.getgid())[0] + '\\\"')")))) 5833 "import os, grp; print ('\\\"' + grp.getgrgid(os.getgid())[0] + '\\\"')"))))
5831 5834
5832(defun tramp-get-remote-gid (vec id-format)
5833 "The gid of the remote connection VEC, in ID-FORMAT.
5834ID-FORMAT valid values are `string' and `integer'."
5835 (with-tramp-connection-property vec (format "gid-%s" id-format)
5836 (let ((res
5837 (ignore-errors
5838 (cond
5839 ((tramp-get-remote-id vec)
5840 (tramp-get-remote-gid-with-id vec id-format))
5841 ((tramp-get-remote-perl vec)
5842 (tramp-get-remote-gid-with-perl vec id-format))
5843 ((tramp-get-remote-python vec)
5844 (tramp-get-remote-gid-with-python vec id-format))))))
5845 ;; Ensure there is a valid result.
5846 (cond
5847 ((and (equal id-format 'integer) (not (integerp res)))
5848 tramp-unknown-id-integer)
5849 ((and (equal id-format 'string) (not (stringp res)))
5850 tramp-unknown-id-string)
5851 (t res)))))
5852
5853(defun tramp-get-remote-busybox (vec) 5835(defun tramp-get-remote-busybox (vec)
5854 "Determine remote `busybox' command." 5836 "Determine remote `busybox' command."
5855 (with-tramp-connection-property vec "busybox" 5837 (with-tramp-connection-property vec "busybox"
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index 2088d236288..3980add7c41 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -293,6 +293,8 @@ See `tramp-actions-before-shell' for more info.")
293 (start-file-process . tramp-smb-handle-start-file-process) 293 (start-file-process . tramp-smb-handle-start-file-process)
294 (substitute-in-file-name . tramp-smb-handle-substitute-in-file-name) 294 (substitute-in-file-name . tramp-smb-handle-substitute-in-file-name)
295 (temporary-file-directory . tramp-handle-temporary-file-directory) 295 (temporary-file-directory . tramp-handle-temporary-file-directory)
296 (tramp-get-remote-gid . ignore)
297 (tramp-get-remote-uid . ignore)
296 (tramp-set-file-uid-gid . ignore) 298 (tramp-set-file-uid-gid . ignore)
297 (unhandled-file-name-directory . ignore) 299 (unhandled-file-name-directory . ignore)
298 (vc-registered . ignore) 300 (vc-registered . ignore)
diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el
index 68e68a242c9..05242ffd970 100644
--- a/lisp/net/tramp-sudoedit.el
+++ b/lisp/net/tramp-sudoedit.el
@@ -132,6 +132,8 @@ See `tramp-actions-before-shell' for more info.")
132 (start-file-process . ignore) 132 (start-file-process . ignore)
133 (substitute-in-file-name . tramp-handle-substitute-in-file-name) 133 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
134 (temporary-file-directory . tramp-handle-temporary-file-directory) 134 (temporary-file-directory . tramp-handle-temporary-file-directory)
135 (tramp-get-remote-gid . tramp-sudoedit-handle-get-remote-gid)
136 (tramp-get-remote-uid . tramp-sudoedit-handle-get-remote-uid)
135 (tramp-set-file-uid-gid . tramp-sudoedit-handle-set-file-uid-gid) 137 (tramp-set-file-uid-gid . tramp-sudoedit-handle-set-file-uid-gid)
136 (unhandled-file-name-directory . ignore) 138 (unhandled-file-name-directory . ignore)
137 (vc-registered . ignore) 139 (vc-registered . ignore)
@@ -689,21 +691,19 @@ component is used as the target of the symlink."
689 (tramp-flush-file-property v localname "file-selinux-context")) 691 (tramp-flush-file-property v localname "file-selinux-context"))
690 t))))) 692 t)))))
691 693
692(defun tramp-sudoedit-get-remote-uid (vec id-format) 694(defun tramp-sudoedit-handle-get-remote-uid (vec id-format)
693 "The uid of the remote connection VEC, in ID-FORMAT. 695 "The uid of the remote connection VEC, in ID-FORMAT.
694ID-FORMAT valid values are `string' and `integer'." 696ID-FORMAT valid values are `string' and `integer'."
695 (with-tramp-connection-property vec (format "uid-%s" id-format) 697 (if (equal id-format 'integer)
696 (if (equal id-format 'integer) 698 (tramp-sudoedit-send-command-and-read vec "id" "-u")
697 (tramp-sudoedit-send-command-and-read vec "id" "-u") 699 (tramp-sudoedit-send-command-string vec "id" "-un")))
698 (tramp-sudoedit-send-command-string vec "id" "-un"))))
699 700
700(defun tramp-sudoedit-get-remote-gid (vec id-format) 701(defun tramp-sudoedit-handle-get-remote-gid (vec id-format)
701 "The gid of the remote connection VEC, in ID-FORMAT. 702 "The gid of the remote connection VEC, in ID-FORMAT.
702ID-FORMAT valid values are `string' and `integer'." 703ID-FORMAT valid values are `string' and `integer'."
703 (with-tramp-connection-property vec (format "gid-%s" id-format) 704 (if (equal id-format 'integer)
704 (if (equal id-format 'integer) 705 (tramp-sudoedit-send-command-and-read vec "id" "-g")
705 (tramp-sudoedit-send-command-and-read vec "id" "-g") 706 (tramp-sudoedit-send-command-string vec "id" "-gn")))
706 (tramp-sudoedit-send-command-string vec "id" "-gn"))))
707 707
708(defun tramp-sudoedit-handle-set-file-uid-gid (filename &optional uid gid) 708(defun tramp-sudoedit-handle-set-file-uid-gid (filename &optional uid gid)
709 "Like `tramp-set-file-uid-gid' for Tramp files." 709 "Like `tramp-set-file-uid-gid' for Tramp files."
@@ -711,8 +711,8 @@ ID-FORMAT valid values are `string' and `integer'."
711 (tramp-sudoedit-send-command 711 (tramp-sudoedit-send-command
712 v "chown" 712 v "chown"
713 (format "%d:%d" 713 (format "%d:%d"
714 (or uid (tramp-sudoedit-get-remote-uid v 'integer)) 714 (or uid (tramp-get-remote-uid v 'integer))
715 (or gid (tramp-sudoedit-get-remote-gid v 'integer))) 715 (or gid (tramp-get-remote-gid v 'integer)))
716 (tramp-unquote-file-local-name filename)))) 716 (tramp-unquote-file-local-name filename))))
717 717
718(defun tramp-sudoedit-handle-write-region 718(defun tramp-sudoedit-handle-write-region
@@ -721,10 +721,10 @@ ID-FORMAT valid values are `string' and `integer'."
721 (with-parsed-tramp-file-name filename nil 721 (with-parsed-tramp-file-name filename nil
722 (let* ((uid (or (tramp-compat-file-attribute-user-id 722 (let* ((uid (or (tramp-compat-file-attribute-user-id
723 (file-attributes filename 'integer)) 723 (file-attributes filename 'integer))
724 (tramp-sudoedit-get-remote-uid v 'integer))) 724 (tramp-get-remote-uid v 'integer)))
725 (gid (or (tramp-compat-file-attribute-group-id 725 (gid (or (tramp-compat-file-attribute-group-id
726 (file-attributes filename 'integer)) 726 (file-attributes filename 'integer))
727 (tramp-sudoedit-get-remote-gid v 'integer))) 727 (tramp-get-remote-gid v 'integer)))
728 (flag (and (eq mustbenew 'excl) 'nofollow)) 728 (flag (and (eq mustbenew 'excl) 'nofollow))
729 (modes (tramp-default-file-modes filename flag))) 729 (modes (tramp-default-file-modes filename flag)))
730 (prog1 730 (prog1
@@ -785,14 +785,7 @@ connection if a previous connection has died for some reason."
785 (tramp-set-connection-local-variables vec) 785 (tramp-set-connection-local-variables vec)
786 786
787 ;; Mark it as connected. 787 ;; Mark it as connected.
788 (tramp-set-connection-property p "connected" t)) 788 (tramp-set-connection-property p "connected" t))))
789
790 ;; In `tramp-check-cached-permissions', the connection properties
791 ;; "{uid,gid}-{integer,string}" are used. We set them to proper values.
792 (tramp-sudoedit-get-remote-uid vec 'integer)
793 (tramp-sudoedit-get-remote-gid vec 'integer)
794 (tramp-sudoedit-get-remote-uid vec 'string)
795 (tramp-sudoedit-get-remote-gid vec 'string)))
796 789
797(defun tramp-sudoedit-send-command (vec &rest args) 790(defun tramp-sudoedit-send-command (vec &rest args)
798 "Send commands ARGS to connection VEC. 791 "Send commands ARGS to connection VEC.
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index b045e411093..f3c065e9e7a 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -2280,6 +2280,9 @@ Must be handled by the callers."
2280 (when (processp (nth 0 args)) 2280 (when (processp (nth 0 args))
2281 (with-current-buffer (process-buffer (nth 0 args)) 2281 (with-current-buffer (process-buffer (nth 0 args))
2282 default-directory))) 2282 default-directory)))
2283 ;; VEC.
2284 ((member operation '(tramp-get-remote-gid tramp-get-remote-uid))
2285 (tramp-make-tramp-file-name (nth 0 args)))
2283 ;; Unknown file primitive. 2286 ;; Unknown file primitive.
2284 (t (error "Unknown file I/O primitive: %s" operation)))) 2287 (t (error "Unknown file I/O primitive: %s" operation))))
2285 2288
@@ -3903,10 +3906,12 @@ of."
3903 (let ((tmpfile (tramp-compat-make-temp-file filename)) 3906 (let ((tmpfile (tramp-compat-make-temp-file filename))
3904 (modes (tramp-default-file-modes 3907 (modes (tramp-default-file-modes
3905 filename (and (eq mustbenew 'excl) 'nofollow))) 3908 filename (and (eq mustbenew 'excl) 'nofollow)))
3906 (uid (tramp-compat-file-attribute-user-id 3909 (uid (or (tramp-compat-file-attribute-user-id
3907 (file-attributes filename 'integer))) 3910 (file-attributes filename 'integer))
3908 (gid (tramp-compat-file-attribute-group-id 3911 (tramp-get-remote-uid v 'integer)))
3909 (file-attributes filename 'integer)))) 3912 (gid (or (tramp-compat-file-attribute-group-id
3913 (file-attributes filename 'integer))
3914 (tramp-get-remote-gid v 'integer))))
3910 (when (and append (file-exists-p filename)) 3915 (when (and append (file-exists-p filename))
3911 (copy-file filename tmpfile 'ok)) 3916 (copy-file filename tmpfile 'ok))
3912 ;; The permissions of the temporary file should be set. If 3917 ;; The permissions of the temporary file should be set. If
@@ -4612,12 +4617,8 @@ be granted."
4612 (concat "file-attributes-" suffix) nil) 4617 (concat "file-attributes-" suffix) nil)
4613 (file-attributes 4618 (file-attributes
4614 (tramp-make-tramp-file-name vec) (intern suffix)))) 4619 (tramp-make-tramp-file-name vec) (intern suffix))))
4615 (remote-uid 4620 (remote-uid (tramp-get-remote-uid vec (intern suffix)))
4616 (tramp-get-connection-property 4621 (remote-gid (tramp-get-remote-gid vec (intern suffix)))
4617 vec (concat "uid-" suffix) nil))
4618 (remote-gid
4619 (tramp-get-connection-property
4620 vec (concat "gid-" suffix) nil))
4621 (unknown-id 4622 (unknown-id
4622 (if (string-equal suffix "string") 4623 (if (string-equal suffix "string")
4623 tramp-unknown-id-string tramp-unknown-id-integer))) 4624 tramp-unknown-id-string tramp-unknown-id-integer)))
@@ -4651,6 +4652,32 @@ be granted."
4651 (tramp-compat-file-attribute-group-id 4652 (tramp-compat-file-attribute-group-id
4652 file-attr)))))))))))) 4653 file-attr))))))))))))
4653 4654
4655(defun tramp-get-remote-uid (vec id-format)
4656 "The uid of the remote connection VEC, in ID-FORMAT.
4657ID-FORMAT valid values are `string' and `integer'."
4658 (with-tramp-connection-property vec (format "uid-%s" id-format)
4659 (or (when-let
4660 ((handler
4661 (find-file-name-handler
4662 (tramp-make-tramp-file-name vec) 'tramp-get-remote-uid)))
4663 (funcall handler #'tramp-get-remote-uid vec id-format))
4664 ;; Ensure there is a valid result.
4665 (and (equal id-format 'integer) tramp-unknown-id-integer)
4666 (and (equal id-format 'string) tramp-unknown-id-string))))
4667
4668(defun tramp-get-remote-gid (vec id-format)
4669 "The gid of the remote connection VEC, in ID-FORMAT.
4670ID-FORMAT valid values are `string' and `integer'."
4671 (with-tramp-connection-property vec (format "gid-%s" id-format)
4672 (or (when-let
4673 ((handler
4674 (find-file-name-handler
4675 (tramp-make-tramp-file-name vec) 'tramp-get-remote-uid)))
4676 (funcall handler #'tramp-get-remote-gid vec id-format))
4677 ;; Ensure there is a valid result.
4678 (and (equal id-format 'integer) tramp-unknown-id-integer)
4679 (and (equal id-format 'string) tramp-unknown-id-string))))
4680
4654(defun tramp-local-host-p (vec) 4681(defun tramp-local-host-p (vec)
4655 "Return t if this points to the local host, nil otherwise. 4682 "Return t if this points to the local host, nil otherwise.
4656This handles also chrooted environments, which are not regarded as local." 4683This handles also chrooted environments, which are not regarded as local."
@@ -4673,9 +4700,7 @@ This handles also chrooted environments, which are not regarded as local."
4673 vec (tramp-compat-temporary-file-directory) 'nohop)) 4700 vec (tramp-compat-temporary-file-directory) 'nohop))
4674 ;; On some systems, chown runs only for root. 4701 ;; On some systems, chown runs only for root.
4675 (or (zerop (user-uid)) 4702 (or (zerop (user-uid))
4676 ;; This is defined in tramp-sh.el. Let's assume this is 4703 (zerop (tramp-get-remote-uid vec 'integer))))))
4677 ;; loaded already.
4678 (zerop (tramp-compat-funcall 'tramp-get-remote-uid vec 'integer))))))
4679 4704
4680(defun tramp-get-remote-tmpdir (vec) 4705(defun tramp-get-remote-tmpdir (vec)
4681 "Return directory for temporary files on the remote host identified by VEC." 4706 "Return directory for temporary files on the remote host identified by VEC."
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 9667b34c667..cb30a360225 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -2998,6 +2998,8 @@ This tests also `file-directory-p' and `file-accessible-directory-p'."
2998 (skip-unless (tramp--test-enabled)) 2998 (skip-unless (tramp--test-enabled))
2999 (skip-unless (tramp--test-sh-p)) 2999 (skip-unless (tramp--test-sh-p))
3000 (skip-unless (not (tramp--test-rsync-p))) 3000 (skip-unless (not (tramp--test-rsync-p)))
3001 ;; Wildcards are not supported in tramp-crypt.el.
3002 (skip-unless (not (tramp--test-crypt-p)))
3001 ;; Since Emacs 26.1. 3003 ;; Since Emacs 26.1.
3002 (skip-unless (fboundp 'insert-directory-wildcard-in-dir-p)) 3004 (skip-unless (fboundp 'insert-directory-wildcard-in-dir-p))
3003 3005