]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve user name completion in Tramp
authorMichael Albinus <michael.albinus@gmx.de>
Sat, 23 Jan 2016 15:20:21 +0000 (16:20 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Sat, 23 Jan 2016 15:20:21 +0000 (16:20 +0100)
* lisp/net/tramp.el (tramp-parse-passwd, tramp-parse-etc-group):
Call also "getent passwd" or "getent group", if possible.
(tramp-parse-putty): Cache the result.

lisp/net/tramp-cmds.el
lisp/net/tramp-sh.el
lisp/net/tramp.el

index f9b66d43074c6a707d12c57d836e0d77e9d5a8fc..5e9af0b18ebbe71ffca4b176ed44e6ef1c9ebef5 100644 (file)
@@ -145,7 +145,7 @@ This includes password cache, file cache, connection cache, buffers."
   "Kill all remote buffers."
   (interactive)
 
-  ;; Remove all Tramp related buffers.
+  ;; Remove all Tramp related connections.
   (tramp-cleanup-all-connections)
 
   ;; Remove all buffers with a remote default-directory.
index baebb13dd228352d0551a40dc724ed2d8886164b..ab4f07fc020a514889f37e7994cac5657376ced5 100644 (file)
@@ -5739,7 +5739,5 @@ function cell is returned to be applied on a buffer."
 ;;   rsync).
 ;; * Keep a second connection open for out-of-band methods like scp or
 ;;   rsync.
-;; * Check, whether we could also use "getent passwd" and "getent
-;;   group" for user/group name completion.
 
 ;;; tramp-sh.el ends here
index e52f1958592336eba7ce358c0ffa8de6dcd5c4c2..4543c0d1a472febecea13308f3d2046b1235f883 100644 (file)
@@ -1048,7 +1048,7 @@ entry does not exist, return nil."
         (replace-regexp-in-string "^tramp-" "" (symbol-name param))))
     (if (tramp-connection-property-p vec hash-entry)
        ;; We use the cached property.
-       (tramp-get-connection-property  vec hash-entry nil)
+       (tramp-get-connection-property vec hash-entry nil)
       ;; Use the static value from `tramp-methods'.
       (let ((methods-entry
             (assoc param (assoc (tramp-file-name-method vec) tramp-methods))))
@@ -2624,17 +2624,18 @@ User is always nil."
    (tramp-parse-group
     (concat "^\\(" tramp-ipv6-regexp "\\|" tramp-host-regexp "\\)") 1 " \t"))
 
-;; For su-alike methods it would be desirable to return "root@localhost"
-;; as default.  Unfortunately, we have no information whether any user name
-;; has been typed already.  So we use `tramp-current-user' as indication,
-;; assuming it is set in `tramp-completion-handle-file-name-all-completions'.
 ;;;###tramp-autoload
 (defun tramp-parse-passwd (filename)
   "Return a list of (user host) tuples allowed to access.
 Host is always \"localhost\"."
-  (if (zerop (length tramp-current-user))
-      '(("root" nil))
-    (tramp-parse-file filename 'tramp-parse-passwd-group)))
+  (with-tramp-connection-property nil "parse-passwd"
+    (if (executable-find "getent")
+       (with-temp-buffer
+         (when (zerop (tramp-call-process nil "getent" nil t nil "passwd"))
+           (goto-char (point-min))
+           (loop while (not (eobp)) collect
+                 (tramp-parse-etc-group-group))))
+      (tramp-parse-file filename 'tramp-parse-passwd-group))))
 
 (defun tramp-parse-passwd-group ()
    "Return a (user host) tuple allowed to access.
@@ -2650,7 +2651,14 @@ Host is always \"localhost\"."
 (defun tramp-parse-etc-group (filename)
   "Return a list of (group host) tuples allowed to access.
 Host is always \"localhost\"."
-  (tramp-parse-file filename 'tramp-parse-etc-group-group))
+  (with-tramp-connection-property nil "parse-group"
+    (if (executable-find "getent")
+       (with-temp-buffer
+         (when (zerop (tramp-call-process nil "getent" nil t nil "group"))
+           (goto-char (point-min))
+           (loop while (not (eobp)) collect
+                 (tramp-parse-etc-group-group))))
+      (tramp-parse-file filename 'tramp-parse-etc-group-group))))
 
 (defun tramp-parse-etc-group-group ()
    "Return a (group host) tuple allowed to access.
@@ -2686,12 +2694,13 @@ User may be nil."
   "Return a list of (user host) tuples allowed to access.
 User is always nil."
   (if (memq system-type '(windows-nt))
-      (with-temp-buffer
-       (when (zerop (tramp-call-process
-                     nil "reg" nil t nil "query" registry-or-dirname))
-         (goto-char (point-min))
-         (loop while (not (eobp)) collect
-               (tramp-parse-putty-group registry-or-dirname))))
+      (with-tramp-connection-property nil "parse-putty"
+       (with-temp-buffer
+         (when (zerop (tramp-call-process
+                       nil "reg" nil t nil "query" registry-or-dirname))
+           (goto-char (point-min))
+           (loop while (not (eobp)) collect
+                 (tramp-parse-putty-group registry-or-dirname)))))
     ;; UNIX case.
     (tramp-parse-shostkeys-sknownhosts
      registry-or-dirname (concat "^\\(" tramp-host-regexp "\\)$"))))