Hi Michael,

Michael Albinus <[email protected]> writes:

>
> Good idea. I will check, which functions coujld be merged; likely more
> than only tramp-parse-shosts and tramp-parse-sconfig.
I did some work on this, not guaranteed it work, not tested, see
patch attached.

=== modified file 'lisp/net/tramp.el'
*** lisp/net/tramp.el	2011-10-19 20:21:35 +0000
--- lisp/net/tramp.el	2011-11-05 17:50:58 +0000
***************
*** 2393,2413 ****
    (unless (zerop (+ (length user) (length host)))
      (tramp-completion-make-tramp-file-name method user host nil)))
  
! ;;;###tramp-autoload
! (defun tramp-parse-rhosts (filename)
    "Return a list of (user host) tuples allowed to access.
! Either user or host may be nil."
    ;; On Windows, there are problems in completion when
    ;; `default-directory' is remote.
!   (let ((default-directory (tramp-compat-temporary-file-directory))
! 	res)
      (when (file-readable-p filename)
        (with-temp-buffer
  	(insert-file-contents filename)
  	(goto-char (point-min))
! 	(while (not (eobp))
! 	  (push (tramp-parse-rhosts-group) res))))
!     res))
  
  (defun tramp-parse-rhosts-group ()
     "Return a (user host) tuple allowed to access.
--- 2393,2428 ----
    (unless (zerop (+ (length user) (length host)))
      (tramp-completion-make-tramp-file-name method user host nil)))
  
! ;; Generic function
! (defun tramp-parse-sgroup (regexp match-level skip-regexp)
!    "Return a (user host) tuple allowed to access.
! User is always nil."
!    (let (result)
!      (when (re-search-forward regexp (point-at-eol)  t)
!        (setq result (list nil (match-string match-level))))
!      (or
!       (> (skip-chars-forward  skip-regexp) 0)
!       (forward-line 1))
!      result))
! 
! ;; Generic function
! (defun tramp-parse-sfile (filename function)
    "Return a list of (user host) tuples allowed to access.
! User is always nil."
    ;; On Windows, there are problems in completion when
    ;; `default-directory' is remote.
!   (let ((default-directory (tramp-compat-temporary-file-directory)))
      (when (file-readable-p filename)
        (with-temp-buffer
  	(insert-file-contents filename)
  	(goto-char (point-min))
!         (loop while (not (eobp)) collect (funcall function))))))
! 
! ;;;###tramp-autoload
! (defun tramp-parse-rhosts (filename)
!   "Return a list of (user host) tuples allowed to access.
! Either user or host may be nil."
!   (tramp-parse-sfile filename 'tramp-parse-rhosts-group))
  
  (defun tramp-parse-rhosts-group ()
     "Return a (user host) tuple allowed to access.
***************
*** 2417,2426 ****
  	  (concat
  	   "^\\(" tramp-host-regexp "\\)"
  	   "\\([ \t]+" "\\(" tramp-user-regexp "\\)" "\\)?")))
!      (narrow-to-region (point) (point-at-eol))
!      (when (re-search-forward regexp nil t)
         (setq result (append (list (match-string 3) (match-string 1)))))
-      (widen)
       (forward-line 1)
       result))
  
--- 2432,2439 ----
  	  (concat
  	   "^\\(" tramp-host-regexp "\\)"
  	   "\\([ \t]+" "\\(" tramp-user-regexp "\\)" "\\)?")))
!      (when (re-search-forward regexp (point-at-eol) t)
         (setq result (append (list (match-string 3) (match-string 1)))))
       (forward-line 1)
       result))
  
***************
*** 2428,2551 ****
  (defun tramp-parse-shosts (filename)
    "Return a list of (user host) tuples allowed to access.
  User is always nil."
!   ;; On Windows, there are problems in completion when
!   ;; `default-directory' is remote.
!   (let ((default-directory (tramp-compat-temporary-file-directory))
! 	res)
!     (when (file-readable-p filename)
!       (with-temp-buffer
! 	(insert-file-contents filename)
! 	(goto-char (point-min))
! 	(while (not (eobp))
! 	  (push (tramp-parse-shosts-group) res))))
!     res))
  
  (defun tramp-parse-shosts-group ()
     "Return a (user host) tuple allowed to access.
  User is always nil."
!    (let ((result)
! 	 (regexp (concat "^\\(" tramp-host-regexp "\\)")))
!      (narrow-to-region (point) (point-at-eol))
!      (when (re-search-forward regexp nil t)
!        (setq result (list nil (match-string 1))))
!      (widen)
!      (or
!       (> (skip-chars-forward ",") 0)
!       (forward-line 1))
!      result))
  
  ;;;###tramp-autoload
  (defun tramp-parse-sconfig (filename)
    "Return a list of (user host) tuples allowed to access.
  User is always nil."
!   ;; On Windows, there are problems in completion when
!   ;; `default-directory' is remote.
!   (let ((default-directory (tramp-compat-temporary-file-directory))
! 	res)
!     (when (file-readable-p filename)
!       (with-temp-buffer
! 	(insert-file-contents filename)
! 	(goto-char (point-min))
! 	(while (not (eobp))
! 	  (push (tramp-parse-sconfig-group) res))))
!     res))
  
  (defun tramp-parse-sconfig-group ()
     "Return a (user host) tuple allowed to access.
  User is always nil."
!    (let ((result)
! 	 (regexp (concat "^[ \t]*Host[ \t]+" "\\(" tramp-host-regexp "\\)")))
!      (narrow-to-region (point) (point-at-eol))
!      (when (re-search-forward regexp nil t)
!        (setq result (list nil (match-string 1))))
!      (widen)
!      (or
!       (> (skip-chars-forward ",") 0)
!       (forward-line 1))
!      result))
  
! ;;;###tramp-autoload
! (defun tramp-parse-shostkeys (dirname)
    "Return a list of (user host) tuples allowed to access.
  User is always nil."
    ;; On Windows, there are problems in completion when
    ;; `default-directory' is remote.
    (let* ((default-directory (tramp-compat-temporary-file-directory))
! 	 (regexp (concat "^key_[0-9]+_\\(" tramp-host-regexp "\\)\\.pub$"))
! 	 (files (when (file-directory-p dirname) (directory-files dirname)))
! 	 result)
!     (while files
!       (when (string-match regexp (car files))
! 	(push (list nil (match-string 1 (car files))) result))
!       (setq files (cdr files)))
!     result))
  
  (defun tramp-parse-sknownhosts (dirname)
    "Return a list of (user host) tuples allowed to access.
  User is always nil."
!   ;; On Windows, there are problems in completion when
!   ;; `default-directory' is remote.
!   (let* ((default-directory (tramp-compat-temporary-file-directory))
! 	 (regexp (concat "^\\(" tramp-host-regexp
! 			 "\\)\\.ssh-\\(dss\\|rsa\\)\\.pub$"))
! 	 (files (when (file-directory-p dirname) (directory-files dirname)))
! 	 result)
!     (while files
!       (when (string-match regexp (car files))
! 	(push (list nil (match-string 1 (car files))) result))
!       (setq files (cdr files)))
!     result))
  
  ;;;###tramp-autoload
  (defun tramp-parse-hosts (filename)
    "Return a list of (user host) tuples allowed to access.
  User is always nil."
!   ;; On Windows, there are problems in completion when
!   ;; `default-directory' is remote.
!   (let ((default-directory (tramp-compat-temporary-file-directory))
! 	res)
!     (when (file-readable-p filename)
!       (with-temp-buffer
! 	(insert-file-contents filename)
! 	(goto-char (point-min))
! 	(while (not (eobp))
! 	  (push (tramp-parse-hosts-group) res))))
!     res))
  
  (defun tramp-parse-hosts-group ()
     "Return a (user host) tuple allowed to access.
  User is always nil."
!    (let ((result)
! 	 (regexp
! 	  (concat "^\\(" tramp-ipv6-regexp "\\|" tramp-host-regexp "\\)")))
!      (narrow-to-region (point) (point-at-eol))
!      (when (re-search-forward regexp nil t)
!        (setq result (list nil (match-string 1))))
!      (widen)
!      (or
!       (> (skip-chars-forward " \t") 0)
!       (forward-line 1))
!      result))
  
  ;; For su-alike methods it would be desirable to return "root@localhost"
  ;; as default.  Unfortunately, we have no information whether any user name
--- 2441,2502 ----
  (defun tramp-parse-shosts (filename)
    "Return a list of (user host) tuples allowed to access.
  User is always nil."
!   (tramp-parse-sfile filename 'tramp-parse-shosts-group))
  
  (defun tramp-parse-shosts-group ()
     "Return a (user host) tuple allowed to access.
  User is always nil."
!    (tramp-parse-sgroup
!     (concat "^\\(" tramp-host-regexp "\\)") 1 ","))
  
  ;;;###tramp-autoload
  (defun tramp-parse-sconfig (filename)
    "Return a list of (user host) tuples allowed to access.
  User is always nil."
!   (tramp-parse-sfile filename 'tramp-parse-sconfig-group))
  
  (defun tramp-parse-sconfig-group ()
     "Return a (user host) tuple allowed to access.
  User is always nil."
!    (tramp-parse-sgroup
!     (concat "^[ \t]*Host[ \t]+" "\\(" tramp-host-regexp "\\)") 1 ","))
  
! ;; Generic function
! (defun tramp-parse-shostkeys-sknownhosts (dirname regexp)
    "Return a list of (user host) tuples allowed to access.
  User is always nil."
    ;; On Windows, there are problems in completion when
    ;; `default-directory' is remote.
    (let* ((default-directory (tramp-compat-temporary-file-directory))
! 	 (files (and (file-directory-p dirname) (directory-files dirname))))
!     (loop for f in files when (string-match regexp f) collect
!          (list nil (match-string 1 f)))))
! 
! ;;;###tramp-autoload
! (defun tramp-parse-shostkeys (dirname)
!   "Return a list of (user host) tuples allowed to access.
! User is always nil."
!   (tramp-parse-shostkeys-sknownhosts
!    dirname (concat "^key_[0-9]+_\\(" tramp-host-regexp "\\)\\.pub$")))
  
  (defun tramp-parse-sknownhosts (dirname)
    "Return a list of (user host) tuples allowed to access.
  User is always nil."
!   (tramp-parse-shostkeys-sknownhosts
!    dirname (regexp (concat "^\\(" tramp-host-regexp
!                            "\\)\\.ssh-\\(dss\\|rsa\\)\\.pub$"))))
  
  ;;;###tramp-autoload
  (defun tramp-parse-hosts (filename)
    "Return a list of (user host) tuples allowed to access.
  User is always nil."
!   (tramp-parse-sfile filename 'tramp-parse-hosts-group))
  
  (defun tramp-parse-hosts-group ()
     "Return a (user host) tuple allowed to access.
  User is always nil."
!    (tramp-parse-sgroup
!     (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

-- 
  Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 
_______________________________________________
Tramp-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/tramp-devel

Reply via email to