[Daniel Pittman]

>  > Shall I submit my changes as a patch to the TRAMP list?  

OK, below follows the contents of my *cvs-diff* buffer.  


Henrik



Index: tramp.el
===================================================================
RCS file: /services/emacs-rcp/cvsroot/tramp/lisp/tramp.el,v
retrieving revision 1.421
diff -u -r1.421 tramp.el
--- tramp.el    2000/09/25 04:14:44     1.421
+++ tramp.el    2000/09/25 04:52:41
@@ -743,6 +743,19 @@
   :group 'tramp
   :type 'string)
 
+;; HHH: New.  This format spec is made to handle the cases where the
+;;      user does not provide a user name for the connection.
+(defcustom tramp-make-tramp-file-user-nil-format "/r@%m:%h:%p"
+  "*Format string saying how to construct tramp file name when the user name is not 
+known.
+`%m' is replaced by the method name.
+`%h' is replaced by the host name.
+`%p' is replaced by the file name.
+`%%' is replaced by %.
+
+Also see `tramp-make-tramp-file-format', `tramp-file-name-structure', and 
+`tramp-file-name-regexp'."
+  :group 'tramp
+  :type 'string)
+
 (defcustom tramp-multi-file-name-structure
   (list (concat
          ;; prefix
@@ -2497,12 +2510,25 @@
                (or switch "")
                (tramp-shell-quote-argument path2))))))
 
+;; HHH: Changed.  Handles the case when USER is nil.
+;;
+;;      There might be a bug in this, I believe that the second 
+;;      (if ...) should actually be the ELSE for the first (if ...).  
+;;      See for instance `tramp-debug-buffer-name'.
 (defun tramp-buffer-name (multi-method method user host)
-  "A name for the connection buffer for USER at HOST using METHOD."
+  "A name for the connection buffer for USER at HOST using METHOD. 
+
+When USER is not provided, name the buffer only according to METHOD
+and HOST."
   (if multi-method
       (tramp-buffer-name-multi-method "tramp" multi-method method user host))
-    (format "*tramp/%s %s@%s*" method user host))
-
+  (if user
+      (format "*tramp/%s %s@%s*" method user host)
+    (format "*tramp/%s %s*" method host)))
+
+;; HHH: Not Changed.  Multi method.  What should be done with this
+;;      function when the user name is not provided for any of the
+;;      connections?
 (defun tramp-buffer-name-multi-method (prefix multi-method method user host)
   "A name for the multi method connection buffer.
 MULTI-METHOD gives the multi method, METHOD the array of methods,
@@ -2528,11 +2554,17 @@
   "Get the connection buffer to be used for USER at HOST using METHOD."
   (get-buffer-create (tramp-buffer-name multi-method method user host)))
 
+;; HHH: Changed.  Handles the case when USER is nil.
 (defun tramp-debug-buffer-name (multi-method method user host)
-  "A name for the debug buffer for USER at HOST using METHOD."
+  "A name for the debug buffer for USER at HOST using METHOD. 
+
+When USER is not provided, name the buffer only according to METHOD
+and HOST."
   (if multi-method
       (tramp-buffer-name-multi-method "debug tramp" multi-method method user host)
-    (format "*debug tramp/%s %s@%s*" method user host)))
+    (if user 
+       (format "*debug tramp/%s %s@%s*" method user host)
+      (format "*debug tramp/%s %s*" method host)))
 
 (defun tramp-get-debug-buffer (multi-method method user host)
   "Get the debug buffer for USER at HOST using METHOD."
@@ -2721,6 +2753,7 @@
 ;; -- Functions for establishing connection -- 
 ;; ------------------------------------------------------------ 
 
+;; HHH: Changed.  Now utilizes (or user (user-login-name)) instead of USER.
 (defun tramp-open-connection-telnet (multi-method method user host)
   "Open a connection using a telnet METHOD.
 This starts the command `telnet HOST'[*], then waits for a remote login
@@ -2728,6 +2761,8 @@
 prompt.  It queries the user for the password, then sends the password
 to the remote host.
 
+If USER is nil, uses value returned by user-login-name instead.
+
 Recognition of the remote shell prompt is based on the variable
 `shell-prompt-pattern' which must be set up correctly.
 
@@ -2745,12 +2780,17 @@
              method))
     (when multi-method
       (error "Cannot multi-connect using telnet connection method"))
-    (tramp-pre-connection multi-method method user host)
-    (tramp-message 7 "Opening connection for %s@%s using %s..." user host method)
+    (tramp-pre-connection multi-method method (or user (user-login-name)) host)
+    (tramp-message 7 "Opening connection for %s@%s using %s..." 
+                  (or user (user-login-name)) host method)
     (let* ((default-directory (tramp-temporary-file-directory))
           (coding-system-for-read 'undecided-dos)
-           (p (start-process (tramp-buffer-name multi-method method user host)
-                             (tramp-get-buffer multi-method method user host)
+           (p (start-process (tramp-buffer-name 
+                             multi-method method 
+                             (or user (user-login-name)) host)
+                             (tramp-get-buffer 
+                             multi-method method 
+                             (or user (user-login-name)) host)
                              (tramp-get-telnet-program multi-method method) host))
            (found nil)
            (pw nil))
@@ -2761,8 +2801,9 @@
         (kill-process p)
         (error "Couldn't find remote login prompt"))
       (erase-buffer)
-      (tramp-message 9 "Sending login name %s" user)
-      (process-send-string p (concat user tramp-rsh-end-of-line))
+      (tramp-message 9 "Sending login name %s" (or user (user-login-name)))
+      (process-send-string p (concat (or user (user-login-name)) 
+                                    tramp-rsh-end-of-line))
       (tramp-message 9 "Waiting for password prompt...")
       (unless (setq found (tramp-wait-for-regexp p nil
                                                tramp-password-prompt-regexp))
@@ -2785,9 +2826,11 @@
         (kill-process p)
         (error "Login failed: %s" (match-string 1)))
       (tramp-open-connection-setup-interactive-shell
-       p multi-method method user host)
-      (tramp-post-connection multi-method method user host))))
+       p multi-method method (or user (user-login-name)) host)
+      (tramp-post-connection multi-method method 
+                            (or user (user-login-name)) host))))
 
+;; HHH: Changed to handle the case when USER is nil.
 (defun tramp-open-connection-rsh (multi-method method user host)
   "Open a connection using an rsh METHOD.
 This starts the command `rsh HOST -l USER'[*], then waits for a remote
@@ -2795,6 +2838,8 @@
 queried for a password, this function sends the password to the remote
 host and waits for a shell prompt.
 
+If USER is nil, start the command `rsh HOST'[*] instead
+
 Recognition of the remote shell prompt is based on the variable
 `shell-prompt-pattern' which must be set up correctly.
 
@@ -2810,14 +2855,25 @@
     (when multi-method
       (error "Cannot multi-connect using rsh connection method"))
     (tramp-pre-connection multi-method method user host)
-    (tramp-message 7 "Opening connection for %s@%s using %s..." user host method)
+    (if user 
+       (tramp-message 7 "Opening connection for %s@%s using %s..." 
+                      user host method)
+      (tramp-message 7 "Opening connection at %s using %s..." host method))
     (let* ((default-directory (tramp-temporary-file-directory))
           (coding-system-for-read 'undecided-dos)
-           (p (apply #'start-process
-                     (tramp-buffer-name multi-method method user host)
-                     (tramp-get-buffer multi-method method user host)
-                     (tramp-get-rsh-program multi-method method) host "-l" user
-                     (tramp-get-rsh-args multi-method method)))
+           (p (if user
+                 (apply #'start-process
+                        (tramp-buffer-name multi-method method user host)
+                        (tramp-get-buffer multi-method method user host)
+                        (tramp-get-rsh-program multi-method method) 
+                        host "-l" user
+                        (tramp-get-rsh-args multi-method method))
+               (apply #'start-process
+                      (tramp-buffer-name multi-method method user host)
+                      (tramp-get-buffer multi-method method user host)
+                      (tramp-get-rsh-program multi-method method) 
+                      host
+                      (tramp-get-rsh-args multi-method method))))
            (found nil))
       (process-kill-without-query p)
       (tramp-message 9 "Waiting 60s for shell or passwd prompt from %s" host)
@@ -2860,11 +2916,14 @@
        p multi-method method user host)
       (tramp-post-connection multi-method method user host))))
 
+;; HHH: Changed.  Now utilizes (or user (user-login-name)) instead of USER.
 (defun tramp-open-connection-su (multi-method method user host)
   "Open a connection using the `su' program with METHOD.
 This starts `su - USER', then waits for a password prompt.  The HOST
 name must be equal to the local host name or to `localhost'.
 
+If USER is nil, uses value returned by user-login-name instead.
+
 Recognition of the remote shell prompt is based on the variable
 `shell-prompt-pattern' which must be set up correctly.  Note that the
 other user may have a different shell prompt than you do, so it is not
@@ -2879,16 +2938,19 @@
       (error
        "Cannot connect to different host `%s' with `su' connection method"
        host))
-    (tramp-pre-connection multi-method method user host)
-    (tramp-message 7 "Opening connection for `%s' using `%s'..." user method)
+    (tramp-pre-connection multi-method method (or user (user-login-name)) host)
+    (tramp-message 7 "Opening connection for `%s' using `%s'..." 
+                  (or user (user-login-name)) method)
     (let* ((default-directory (tramp-temporary-file-directory))
           (coding-system-for-read 'undecided-dos)
            (p (apply 'start-process
-                     (tramp-buffer-name multi-method method user host)
-                     (tramp-get-buffer multi-method method user host)
+                     (tramp-buffer-name multi-method method 
+                                       (or user (user-login-name)) host)
+                     (tramp-get-buffer multi-method method 
+                                      (or user (user-login-name)) host)
                      (tramp-get-su-program multi-method method)
                      (mapcar '(lambda (x)
-                                (format-spec x (list (cons ?u user))))
+                                (format-spec x (list (cons ?u (or user 
+(user-login-name))))))
                              (tramp-get-su-args multi-method method))))
            (found nil)
            (pw nil))
@@ -2919,9 +2981,18 @@
           (kill-process p)
           (error "`su' failed: %s" (match-string 1))))
       (tramp-open-connection-setup-interactive-shell
-       p multi-method method user host)
-      (tramp-post-connection multi-method method user host))))
+       p multi-method method (or user (user-login-name)) host)
+      (tramp-post-connection multi-method method 
+                            (or user (user-login-name)) host))))
 
+;; HHH: Not Changed.  Multi method.  It is not clear to me how this can 
+;;      handle not giving a user name in the "file name".
+;;
+;;      This is more difficult than for the single-hop method.  In the
+;;      multi-hop-method, the desired behaviour should be that the
+;;      user must specify names for the telnet hops of which the user
+;;      name is different than the "original" name (or different from
+;;      the previous hop.
 (defun tramp-open-connection-multi (multi-method method user host)
   "Open a multi-hop connection using METHOD.
 This uses a slightly changed file name syntax.  The idea is to say
@@ -2974,13 +3045,19 @@
        p multi-method method user host)
       (tramp-post-connection multi-method method user host))))
 
+;; HHH: Changed.  Multi method.  Don't know how to handle this in the case
+;;      of no user name provided.  Hack to make it work as it did before:  
+;;      changed `user' to `(or user (user-login-name))' in the places where
+;;      the value is actually used.
 (defun tramp-multi-connect-telnet (p method user host command)
   "Issue `telnet' command.
 Uses shell COMMAND to issue a `telnet' command to log in as USER to
 HOST.  You can use percent escapes in COMMAND: `%h' is replaced with
 the host name, and `%n' is replaced with an end of line character, as
 set in `tramp-rsh-end-of-line'.  Use `%%' if you want a literal percent
-character."
+character.
+
+If USER is nil, uses the return value of (user-login-name) instead."
   (let ((cmd (format-spec command (list (cons ?h host)
                                         (cons ?n tramp-rsh-end-of-line))))
         (cmd1 (format-spec command (list (cons ?h host)
@@ -2995,8 +3072,8 @@
       (kill-process p)
       (error "Couldn't find login prompt from host %s" host))
     (erase-buffer)
-    (tramp-message 9 "Sending login name %s" user)
-    (process-send-string p (concat user tramp-rsh-end-of-line))
+    (tramp-message 9 "Sending login name %s" (or user (user-login-name)))
+    (process-send-string p (concat (or user (user-login-name)) tramp-rsh-end-of-line))
     (tramp-message 9 "Waiting for password prompt")
     (unless (setq found (tramp-wait-for-regexp p nil tramp-password-prompt-regexp))
       (pop-to-buffer (buffer-name))
@@ -3004,7 +3081,7 @@
       (error "Couldn't find password prompt from host %s" host))
     (erase-buffer)
     (setq pw (tramp-read-passwd
-              (format "Password for %s@%s, %s" user host found)))
+              (format "Password for %s@%s, %s" (or user (user-login-name)) host 
+found)))
     (tramp-message 9 "Sending password")
     (process-send-string p (concat pw tramp-rsh-end-of-line))
     (tramp-message 9 "Waiting 60s for remote shell to come up...")
@@ -3019,18 +3096,24 @@
       (kill-process p)
       (error "Login to %s failed: %s" (match-string 2)))))
 
+;; HHH: Changed.  Multi method.  Don't know how to handle this in the case 
+;;      of no user name provided.  Hack to make it work as it did before:  
+;;      changed `user' to `(or user (user-login-name))' in the places where
+;;      the value is actually used.
 (defun tramp-multi-connect-rlogin (p method user host command)
   "Issue `rlogin' command.
 Uses shell COMMAND to issue an `rlogin' command to log in as USER to
 HOST.  You can use percent escapes in COMMAND.  `%u' will be replaced
 with the user name, `%h' will be replaced with the host name, and `%n'
 will be replaced with the value of `tramp-rsh-end-of-line'.  You can use
-`%%' if you want to use a literal percent character."
+`%%' if you want to use a literal percent character.
+
+If USER is nil, uses the return value of (user-login-name) instead."
   (let ((cmd (format-spec command (list (cons ?h host)
-                                        (cons ?u user)
+                                        (cons ?u (or user (user-login-name)))
                                         (cons ?n tramp-rsh-end-of-line))))
         (cmd1 (format-spec command (list (cons ?h host)
-                                         (cons ?u user)
+                                         (cons ?u (or user (user-login-name)))
                                          (cons ?n ""))))
         found pw)
     (erase-buffer)
@@ -3063,31 +3146,38 @@
       (kill-process p)
       (error "Login failed: %s" (match-string 1)))))
 
+;; HHH: Changed.  Multi method.  Don't know how to handle this in the case 
+;;      of no user name provided.  Hack to make it work as it did before:  
+;;      changed `user' to `(or user (user-login-name))' in the places where
+;;      the value is actually used.
 (defun tramp-multi-connect-su (p method user host command)
   "Issue `su' command.
 Uses shell COMMAND to issue a `su' command to log in as USER on
 HOST.  The HOST name is ignored, this just changes the user id on the
 host currently logged in to.
 
+If USER is nil, uses the return value of (user-login-name) instead.
+
 You can use percent escapes in the COMMAND.  `%u' is replaced with the
 user name, and `%n' is replaced with the value of
 `tramp-rsh-end-of-line'.  Use `%%' if you want a literal percent
 character."
-  (let ((cmd (format-spec command (list (cons ?u user)
+  (let ((cmd (format-spec command (list (cons ?u (or user (user-login-name)))
                                         (cons ?n tramp-rsh-end-of-line))))
-        (cmd1 (format-spec command (list (cons ?u user)
+        (cmd1 (format-spec command (list (cons ?u (or user (user-login-name)))
                                          (cons ?n ""))))
         found)
     (erase-buffer)
     (tramp-message 9 "Sending su command `%s'" cmd1)
     (process-send-string p cmd)
-    (tramp-message 9 "Waiting 60s for shell or passwd prompt for %s" user)
+    (tramp-message 9 "Waiting 60s for shell or passwd prompt for %s" (or user 
+(user-login-name)))
     (unless (tramp-wait-for-regexp p 60 (format "\\(%s\\)\\|\\(%s\\)"
                                               tramp-password-prompt-regexp
                                               shell-prompt-pattern))
       (pop-to-buffer (buffer-name))
       (kill-process p)
-      (error "Couldn't find shell or passwd prompt for %s" user))
+      (error "Couldn't find shell or passwd prompt for %s" 
+            (or user (user-login-name))))
     (if (not (match-string 1))
         (setq found t)
       (tramp-message 9 "Sending password...")
@@ -3155,6 +3245,9 @@
   (let ((pw (tramp-read-passwd prompt)))
     (process-send-string p (concat pw tramp-rsh-end-of-line))))
 
+;; HHH: Not Changed.  This might handle the case where USER is not
+;;      given in the "File name" very poorly.  Then, the local
+;;      variable tramp-current user will be set to nil.
 (defun tramp-pre-connection (multi-method method user host)
   "Do some setup before actually logging in.
 METHOD, USER and HOST specify the connection."
@@ -3660,7 +3753,10 @@
   "Return t iff NAME is an tramp file."
   (save-match-data
     (string-match tramp-file-name-regexp name)))
-
+ 
+;; HHH: Changed.  Used to assign the return value of (user-login-name)
+;;      to the `user' part of the structure if a user name was not
+;;      provided, now it assigns nil.
 (defun tramp-dissect-file-name (name)
   "Return an `tramp-file-name' structure.
 The structure consists of remote method, remote user, remote host and
@@ -3680,10 +3776,12 @@
          :multi-method nil
          :method method
          :user (or (match-string (nth 2 tramp-file-name-structure) name)
-                   (user-login-name))
+                   nil)
          :host (match-string (nth 3 tramp-file-name-structure) name)
          :path (match-string (nth 4 tramp-file-name-structure) name))))))
 
+;; HHH: Not Changed.  Multi method.  Will probably not handle the case where
+;;      a user name is not provided in the "file name" very well.
 (defun tramp-dissect-multi-file-name (name)
   "Not implemented yet."
   (let ((regexp           (nth 0 tramp-multi-file-name-structure))
@@ -3718,18 +3816,29 @@
      :host         (apply 'vector (reverse hop-hosts))
      :path         path)))
 
+
+;; HHH: Changed.  Have made new tramp-make-tramp-file-user-nil-format
+;;      spec, uses this instead of tramp-make-tramp-file-format when
+;;      USER is nil.
 (defun tramp-make-tramp-file-name (multi-method method user host path)
   "Constructs an tramp file name from METHOD, USER, HOST and PATH."
   (unless tramp-make-tramp-file-format
     (error "`tramp-make-tramp-file-format' is nil"))
   (if multi-method
       (tramp-make-tramp-multi-file-name multi-method method user host path)
-    (format-spec tramp-make-tramp-file-format
-                 (list (cons ?m method)
-                       (cons ?u user)
-                       (cons ?h host)
-                       (cons ?p path)))))
+    (if user
+       (format-spec tramp-make-tramp-file-format
+                    (list (cons ?m method)
+                          (cons ?u user)
+                          (cons ?h host)
+                          (cons ?p path)))
+      (format-spec tramp-make-tramp-file-user-nil-format
+                  (list (cons ?m method)
+                        (cons ?h host)
+                        (cons ?p path))))))
+
 
+;; HHH: Not Changed.  Multi Method.  What should be done with this when USER is nil?
 (defun tramp-make-tramp-multi-file-name (multi-method method user host path)
   "Constructs an tramp file name for a multi-hop method."
   (unless tramp-make-multi-tramp-file-format
@@ -3755,9 +3864,13 @@
         (incf i)))
     (concat prefix hops path)))
 
+;; HHH: Changed.  Handles the case where no user name is given in the
+;;      file name.
 (defun tramp-make-rcp-program-file-name (user host path)
   "Create a file name suitable to be passed to `rcp'."
-  (format "%s@%s:%s" user host path))
+  (if user
+      (format "%s@%s:%s" user host path)
+    (format "%s:%s" host path)))
 
 (defun tramp-method-out-of-band-p (multi-method method)
   "Return t if this is an out-of-band method, nil otherwise.

Reply via email to