]> code.delx.au - gnu-emacs/blob - lisp/erc/erc-identd.el
(Info-build-node-completions): Signal error if tag-table marker is not
[gnu-emacs] / lisp / erc / erc-identd.el
1 ;;; erc-identd.el --- RFC1413 (identd authentication protocol) server
2
3 ;; Copyright (C) 2003, 2006 Free Software Foundation, Inc.
4
5 ;; Author: John Wiegley <johnw@gnu.org>
6 ;; Keywords: comm, processes
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
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
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Commentary:
26
27 ;; This module allows you to run a local identd server on port 8113.
28 ;; You will need to set up DNAT to bind 113->8113, or use a proxy.
29
30 ;; To use this module, add identd to `erc-modules' and run
31 ;; `erc-update-modules'.
32
33 ;; Here is an example /etc/inetd.conf rule that forwards identd
34 ;; traffic to port 8113. You will need simpleproxy installed for it
35 ;; to work.
36
37 ;; 113 stream tcp nowait nobody /usr/sbin/tcpd /usr/bin/simpleproxy simpleproxy -i -R 127.0.0.1:8113
38
39 ;;; Code:
40
41 (require 'erc)
42
43 (defvar erc-identd-process nil)
44
45 ;;;###autoload (autoload 'erc-identd-mode "erc-identd")
46 (define-erc-module identd nil
47 "This mode launches an identd server on port 8113."
48 ((add-hook 'erc-connect-pre-hook 'erc-identd-start)
49 (add-hook 'erc-disconnected-hook 'erc-identd-stop))
50 ((remove-hook 'erc-connect-pre-hook 'erc-identd-start)
51 (remove-hook 'erc-disconnected-hook 'erc-identd-stop)))
52
53 (defun erc-identd-filter (proc string)
54 "This filter implements RFC1413 (identd authentication protocol)."
55 (let ((erc-identd-process proc))
56 (when (string-match "\\([0-9]+\\)\\s-*,\\s-*\\([0-9]+\\)" string)
57 (let ((port-on-server (match-string 1 string))
58 (port-on-client (match-string 2 string)))
59 (send-string erc-identd-process
60 (format "%s, %s : USERID : %s : %s\n"
61 port-on-server port-on-client
62 system-type (user-login-name)))
63 (process-send-eof erc-identd-process)))))
64
65 ;;;###autoload
66 (defun erc-identd-start (&optional port)
67 "Start an identd server listening to port 8113.
68 Port 113 (auth) will need to be redirected to port 8113 on your
69 machine -- using iptables, or a program like redir which can be
70 run from inetd. The idea is to provide a simple identd server
71 when you need one, without having to install one globally on your
72 system."
73 (interactive (list (read-string "Serve identd requests on port: " "8113")))
74 (if (null port)
75 (setq port 8113)
76 (if (stringp port)
77 (setq port (string-to-number port))))
78 (if erc-identd-process
79 (delete-process erc-identd-process))
80 (setq erc-identd-process
81 (make-network-process :name "identd"
82 :buffer nil
83 :host 'local :service port
84 :server t :noquery t :nowait t
85 :filter 'erc-identd-filter))
86 (set-process-query-on-exit-flag erc-identd-process nil))
87
88 ;;;###autoload
89 (defun erc-identd-stop (&rest ignore)
90 (interactive)
91 (when erc-identd-process
92 (delete-process erc-identd-process)
93 (setq erc-identd-process nil)))
94
95 (provide 'erc-identd)
96
97 ;;; erc-identd.el ends here
98 ;;
99 ;; Local Variables:
100 ;; indent-tabs-mode: t
101 ;; tab-width: 8
102 ;; End:
103
104 ;; arch-tag: e0b5f926-0f35-40b9-8ddb-ca06b62a7544