From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: nntp over rlogin-and-netcat Date: Mon, 11 Dec 2006 15:15:04 -0500 Message-ID: NNTP-Posting-Host: dough.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1165868141 17523 80.91.229.10 (11 Dec 2006 20:15:41 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 11 Dec 2006 20:15:41 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Dec 11 21:15:39 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by dough.gmane.org with esmtp (Exim 4.50) id 1GtrYl-0007kh-2p for ged-emacs-devel@m.gmane.org; Mon, 11 Dec 2006 21:15:35 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GtrYk-0004mG-BS for ged-emacs-devel@m.gmane.org; Mon, 11 Dec 2006 15:15:34 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GtrYa-0004mA-9V for emacs-devel@gnu.org; Mon, 11 Dec 2006 15:15:24 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GtrYX-0004jy-J6 for emacs-devel@gnu.org; Mon, 11 Dec 2006 15:15:23 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GtrYX-0004jl-8X for emacs-devel@gnu.org; Mon, 11 Dec 2006 15:15:21 -0500 Original-Received: from [132.204.24.67] (helo=mercure.iro.umontreal.ca) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GtrYW-0002pn-IN for emacs-devel@gnu.org; Mon, 11 Dec 2006 15:15:20 -0500 Original-Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id 14D992CEB71; Mon, 11 Dec 2006 15:15:18 -0500 (EST) Original-Received: from faina.iro.umontreal.ca (faina.iro.umontreal.ca [132.204.26.177]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id C05E33FE1; Mon, 11 Dec 2006 15:15:04 -0500 (EST) Original-Received: by faina.iro.umontreal.ca (Postfix, from userid 20848) id 98AF66CABA; Mon, 11 Dec 2006 15:15:04 -0500 (EST) Original-To: emacs-devel@gnu.org, bugs@gnus.org User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.91 (gnu/linux) X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=-2.82, requis 5, autolearn=not spam, ALL_TRUSTED -2.82) X-DIRO-MailScanner-From: monnier@iro.umontreal.ca X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:63587 Archived-At: I recently started to access a news server via an SSH tunnel. I first tried to do it with nntp-open-via-rlogin-and-telnet, but it couldn't post new messages (the problem seems to be that the server expects a CR-LF-.-CR-LF byte-sequence, which didn't work when going through tty code (which seems to turn all CR into LFs) and then through telnet (which, did something very funny with LF)). So I wrote the function nntp-open-via-rlogin-and-netcat below, which seems much saner: rather than use telnet and then try to undo what telnet does, using netcat gives us directly what we want. I use it with the following entry in my select-methods: (nntp "news" (nntp-address "news") (nntp-open-connection-function nntp-open-via-rlogin-and-netcat) (nntp-via-rlogin-command "ssh") (nntp-via-address "iro")) -- Stefan --- orig/lisp/gnus/nntp.el +++ mod/lisp/gnus/nntp.el @@ -99,6 +99,13 @@ (defvoo nntp-telnet-switches '("-8") "*Switches given to the telnet command `nntp-telnet-command'.") +(defvoo nntp-netcat-command "nc" + "*Netcat command used to connect to the nntp server. +This command is used by the `nntp-open-via-rlogin-and-netcat' method.") + +(defvoo nntp-netcat-switches '() + "*Switches given to the telnet command `nntp-netcat-command'.") + (defvoo nntp-end-of-line "\r\n" "*String to use on the end of lines when talking to the NNTP server. This is \"\\r\\n\" by default, but should be \"\\n\" when @@ -1818,6 +1831,53 @@ (delete-region (point) (point-max))) proc)) +(defun nntp-service-to-port (svc) + (cond + ((integerp svc) (number-to-string svc)) + ((string-match "\\`[[:digit:]]\\'" svc) svc) + (t + (with-temp-buffer + (insert-file-contents "/etc/services") + (goto-char (point-min)) + (if (re-search-forward (concat "^" (regexp-quote svc) "[ \t]+\\([[:digit:]]+\\)/tcp")) + (match-string 1) + svc))))) + +(defun nntp-open-via-rlogin-and-netcat (buffer) + "Open a connection to an nntp server through an intermediate host. +First rlogin to the remote host, and then use netcat to connect to the real +news server from there. + +Please refer to the following variables to customize the connection: +- `nntp-pre-command', +- `nntp-via-rlogin-command', +- `nntp-via-rlogin-command-switches', +- `nntp-via-user-name', +- `nntp-via-address', +- `nntp-netcat-command', +- `nntp-netcat-switches', +- `nntp-address', +- `nntp-port-number', +- `nntp-end-of-line'." + (let ((command `(,nntp-via-address + ,nntp-netcat-command + ,@nntp-netcat-switches + ,nntp-address + ,(nntp-service-to-port nntp-port-number))) + proc) + (when nntp-via-user-name + (setq command `("-l" ,nntp-via-user-name ,@command))) + (when nntp-via-rlogin-command-switches + (setq command (append nntp-via-rlogin-command-switches command))) + (push nntp-via-rlogin-command command) + (and nntp-pre-command + (push nntp-pre-command command)) + ;; A non-nil connection type results in mightily odd behavior where + ;; (process-send-string proc "\^M") ends up sending a "\n" to the + ;; ssh process. --Stef + (let ((process-connection-type nil)) + (apply 'start-process "nntpd" buffer command)))) + (defun nntp-open-via-telnet-and-telnet (buffer) "Open a connection to an nntp server through an intermediate host. First telnet the remote host, and then telnet the real news server @@ -1895,5 +1954,5 @@ (provide 'nntp) -;;; arch-tag: 8655466a-b1b5-4929-9c45-7b1b2e767271 +;; arch-tag: 8655466a-b1b5-4929-9c45-7b1b2e767271 ;;; nntp.el ends here