X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/1259009aa17da6dc038afff96963f6d9bbd3b8e1..44f853c4acda0634a3541116834c3e768bef650d:/lisp/net/tramp-gw.el diff --git a/lisp/net/tramp-gw.el b/lisp/net/tramp-gw.el index de42c402a6..a1ddceb468 100644 --- a/lisp/net/tramp-gw.el +++ b/lisp/net/tramp-gw.el @@ -1,6 +1,6 @@ ;;; tramp-gw.el --- Tramp utility functions for HTTP tunnels and SOCKS gateways -;; Copyright (C) 2007-2012 Free Software Foundation, Inc. +;; Copyright (C) 2007-2016 Free Software Foundation, Inc. ;; Author: Michael Albinus ;; Keywords: comm, processes @@ -33,16 +33,11 @@ (require 'tramp) -;; Pacify byte-compiler +;; Pacify byte-compiler. (eval-when-compile (require 'cl) (require 'custom)) - -;; Avoid byte-compiler warnings if the byte-compiler supports this. -;; Currently, XEmacs supports this. -(eval-when-compile - (when (featurep 'xemacs) - (byte-compiler-options (warnings (- unused-vars))))) +(defvar socks-noproxy) ;; We don't add the following methods to `tramp-methods', in order to ;; exclude them from file name completion. @@ -50,20 +45,20 @@ ;; Define HTTP tunnel method ... ;;;###tramp-autoload (defconst tramp-gw-tunnel-method "tunnel" - "*Method to connect HTTP gateways.") + "Method to connect HTTP gateways.") ;; ... and port. (defconst tramp-gw-default-tunnel-port 8080 - "*Default port for HTTP gateways.") + "Default port for HTTP gateways.") ;; Define SOCKS method ... ;;;###tramp-autoload (defconst tramp-gw-socks-method "socks" - "*Method to connect SOCKS servers.") + "Method to connect SOCKS servers.") ;; ... and port. (defconst tramp-gw-default-socks-port 1080 - "*Default port for SOCKS servers.") + "Default port for SOCKS servers.") ;; Autoload the socks library. It is used only when we access a SOCKS server. (autoload 'socks-open-network-stream "socks") @@ -96,16 +91,16 @@ (defvar tramp-gw-aux-proc nil "Process listening on local port, as mediation between SSH and the gateway.") -(defun tramp-gw-gw-proc-sentinel (proc event) +(defun tramp-gw-gw-proc-sentinel (proc _event) "Delete auxiliary process when we are deleted." (unless (memq (process-status proc) '(run open)) (tramp-message tramp-gw-vector 4 "Deleting auxiliary process `%s'" tramp-gw-gw-proc) - (let* (tramp-verbose + (let* ((tramp-verbose 0) (p (tramp-get-connection-property proc "process" nil))) (when (processp p) (delete-process p))))) -(defun tramp-gw-aux-proc-sentinel (proc event) +(defun tramp-gw-aux-proc-sentinel (proc _event) "Activate the different filters for involved gateway and auxiliary processes." (when (memq (process-status proc) '(run open)) ;; A new process has been spawned from `tramp-gw-aux-proc'. @@ -113,10 +108,10 @@ tramp-gw-vector 4 "Opening auxiliary process `%s', speaking with process `%s'" proc tramp-gw-gw-proc) - (tramp-compat-set-process-query-on-exit-flag proc nil) + (set-process-query-on-exit-flag proc nil) ;; We don't want debug messages, because the corresponding debug ;; buffer might be undecided. - (let (tramp-verbose) + (let ((tramp-verbose 0)) (tramp-set-connection-property tramp-gw-gw-proc "process" proc) (tramp-set-connection-property proc "process" tramp-gw-gw-proc)) ;; Set the process-filter functions for both processes. @@ -130,9 +125,12 @@ (tramp-gw-process-filter tramp-gw-gw-proc s)))))) (defun tramp-gw-process-filter (proc string) - (let (tramp-verbose) - (process-send-string - (tramp-get-connection-property proc "process" nil) string))) + (let ((tramp-verbose 0)) + ;; The other process might have been stopped already. We don't + ;; want to be interrupted then. + (ignore-errors + (process-send-string + (tramp-get-connection-property proc "process" nil) string)))) ;;;###tramp-autoload (defun tramp-gw-open-connection (vec gw-vec target-vec) @@ -154,13 +152,13 @@ instead of the host name declared in TARGET-VEC." (memq (process-status tramp-gw-aux-proc) '(listen))) (let ((aux-vec (vector "aux" (tramp-file-name-user gw-vec) - (tramp-file-name-host gw-vec) nil))) + (tramp-file-name-host gw-vec) nil nil))) (setq tramp-gw-aux-proc (make-network-process :name (tramp-buffer-name aux-vec) :buffer nil :host 'local :server t :noquery t :service t :coding 'binary)) (set-process-sentinel tramp-gw-aux-proc 'tramp-gw-aux-proc-sentinel) - (tramp-compat-set-process-query-on-exit-flag tramp-gw-aux-proc nil) + (set-process-query-on-exit-flag tramp-gw-aux-proc nil) (tramp-message vec 4 "Opening auxiliary process `%s', listening on port %d" tramp-gw-aux-proc (process-contact tramp-gw-aux-proc :service)))) @@ -200,12 +198,13 @@ instead of the host name declared in TARGET-VEC." (setq tramp-gw-gw-proc (funcall socks-function - (tramp-get-connection-name gw-vec) - (tramp-get-connection-buffer gw-vec) + (let ((tramp-verbose 0)) (tramp-get-connection-name gw-vec)) + (let ((tramp-verbose 0)) (tramp-get-connection-buffer gw-vec)) (tramp-file-name-real-host target-vec) (tramp-file-name-port target-vec))) (set-process-sentinel tramp-gw-gw-proc 'tramp-gw-gw-proc-sentinel) - (tramp-compat-set-process-query-on-exit-flag tramp-gw-gw-proc nil) + (set-process-coding-system tramp-gw-gw-proc 'binary 'binary) + (set-process-query-on-exit-flag tramp-gw-gw-proc nil) (tramp-message vec 4 "Opened %s process `%s'" (case gw-method ('tunnel "HTTP tunnel") ('socks "SOCKS")) @@ -236,7 +235,7 @@ authentication is requested from proxy server, provide it." (setq proc (open-network-stream name buffer (nth 1 socks-server) (nth 2 socks-server))) (set-process-coding-system proc 'binary 'binary) - (tramp-compat-set-process-query-on-exit-flag proc nil) + (set-process-query-on-exit-flag proc nil) ;; Send CONNECT command. (process-send-string proc (format "%s%s\r\n" command authentication)) (tramp-message @@ -250,7 +249,7 @@ authentication is requested from proxy server, provide it." ;; proxies have a timeout of 60". We wait 65" in order to ;; receive an answer this case. (ignore-errors - (let (tramp-verbose) + (let ((tramp-verbose 0)) (tramp-wait-for-regexp proc 65 "\r?\n\r?\n"))) ;; Check return code. (goto-char (point-min)) @@ -265,6 +264,10 @@ authentication is requested from proxy server, provide it." (200 (setq found t)) ;; We need basic authentication. (401 (setq authentication (tramp-gw-basic-authentication nil first))) + ;; Access forbidden. + (403 (tramp-error-with-buffer + (current-buffer) tramp-gw-vector 'file-error + "Connection to %s:%d forbidden." host service)) ;; Target host not found. (404 (tramp-error-with-buffer (current-buffer) tramp-gw-vector 'file-error