Add 2012 to FSF copyright years for Emacs files (do not merge to trunk)
[bpt/emacs.git] / lisp / erc / erc-identd.el
CommitLineData
597993cf
MB
1;;; erc-identd.el --- RFC1413 (identd authentication protocol) server
2
49f70d46 3;; Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
597993cf
MB
4
5;; Author: John Wiegley <johnw@gnu.org>
6;; Keywords: comm, processes
7
8;; This file is part of GNU Emacs.
9
4ee57b2a 10;; GNU Emacs is free software: you can redistribute it and/or modify
597993cf 11;; it under the terms of the GNU General Public License as published by
4ee57b2a
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
597993cf
MB
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
4ee57b2a 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
597993cf
MB
22
23;;; Commentary:
24
0b6bb130
MB
25;; This module allows you to run a local identd server on port 8113.
26;; You will need to set up DNAT to bind 113->8113, or use a proxy.
597993cf 27
0b6bb130
MB
28;; To use this module, add identd to `erc-modules' and run
29;; `erc-update-modules'.
30
31;; Here is an example /etc/inetd.conf rule that forwards identd
32;; traffic to port 8113. You will need simpleproxy installed for it
33;; to work.
34
35;; 113 stream tcp nowait nobody /usr/sbin/tcpd /usr/bin/simpleproxy simpleproxy -i -R 127.0.0.1:8113
597993cf
MB
36
37;;; Code:
38
0b6bb130
MB
39(require 'erc)
40
597993cf
MB
41(defvar erc-identd-process nil)
42
ff59d266
MB
43(defgroup erc-identd nil
44 "Run a local identd server."
45 :group 'erc)
46
47(defcustom erc-identd-port 8113
48 "Port to run the identd server on if not specified in the argument for
49`erc-identd-start'.
50
51This can be either a string or a number."
52 :group 'erc-identd
53 :type '(choice (const :tag "None" nil)
54 (integer :tag "Port number")
55 (string :tag "Port string")))
56
0b6bb130
MB
57;;;###autoload (autoload 'erc-identd-mode "erc-identd")
58(define-erc-module identd nil
59 "This mode launches an identd server on port 8113."
ff59d266 60 ((add-hook 'erc-connect-pre-hook 'erc-identd-quickstart)
0b6bb130 61 (add-hook 'erc-disconnected-hook 'erc-identd-stop))
ff59d266 62 ((remove-hook 'erc-connect-pre-hook 'erc-identd-quickstart)
0b6bb130
MB
63 (remove-hook 'erc-disconnected-hook 'erc-identd-stop)))
64
597993cf
MB
65(defun erc-identd-filter (proc string)
66 "This filter implements RFC1413 (identd authentication protocol)."
67 (let ((erc-identd-process proc))
68 (when (string-match "\\([0-9]+\\)\\s-*,\\s-*\\([0-9]+\\)" string)
69 (let ((port-on-server (match-string 1 string))
70 (port-on-client (match-string 2 string)))
71 (send-string erc-identd-process
72 (format "%s, %s : USERID : %s : %s\n"
73 port-on-server port-on-client
74 system-type (user-login-name)))
526dc846
MO
75 (stop-process erc-identd-process)
76 (delete-process proc)))))
597993cf 77
c89e5cd7 78;;;###autoload
597993cf
MB
79(defun erc-identd-start (&optional port)
80 "Start an identd server listening to port 8113.
81Port 113 (auth) will need to be redirected to port 8113 on your
82machine -- using iptables, or a program like redir which can be
83run from inetd. The idea is to provide a simple identd server
84when you need one, without having to install one globally on your
85system."
86 (interactive (list (read-string "Serve identd requests on port: " "8113")))
ff59d266
MB
87 (unless port (setq port erc-identd-port))
88 (when (stringp port)
89 (setq port (string-to-number port)))
90 (when erc-identd-process
91 (delete-process erc-identd-process))
c89e5cd7
MB
92 (setq erc-identd-process
93 (make-network-process :name "identd"
0b6bb130 94 :buffer nil
c89e5cd7 95 :host 'local :service port
0b6bb130
MB
96 :server t :noquery t :nowait t
97 :filter 'erc-identd-filter))
98 (set-process-query-on-exit-flag erc-identd-process nil))
c89e5cd7 99
ff59d266
MB
100(defun erc-identd-quickstart (&rest ignored)
101 "Start the identd server with the default port.
102The default port is specified by `erc-identd-port'."
103 (erc-identd-start))
104
c89e5cd7 105;;;###autoload
597993cf
MB
106(defun erc-identd-stop (&rest ignore)
107 (interactive)
108 (when erc-identd-process
109 (delete-process erc-identd-process)
110 (setq erc-identd-process nil)))
111
112(provide 'erc-identd)
113
114;;; erc-identd.el ends here
115;;
116;; Local Variables:
117;; indent-tabs-mode: t
118;; tab-width: 8
119;; End:
120
121;; arch-tag: e0b5f926-0f35-40b9-8ddb-ca06b62a7544