shr.el (shr-tag-color-check): Convert colors to hexadecimal with shr-color->hexadecimal.
[emacs.git] / lisp / erc / erc-identd.el
blobd889dbdc846ae8be4dba44ed55fb9141c8de9e62
1 ;;; erc-identd.el --- RFC1413 (identd authentication protocol) server
3 ;; Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 ;; Author: John Wiegley <johnw@gnu.org>
6 ;; Keywords: comm, processes
8 ;; This file is part of GNU Emacs.
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 3 of the License, or
13 ;; (at your option) any later version.
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
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.
28 ;; To use this module, add identd to `erc-modules' and run
29 ;; `erc-update-modules'.
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.
35 ;; 113 stream tcp nowait nobody /usr/sbin/tcpd /usr/bin/simpleproxy simpleproxy -i -R 127.0.0.1:8113
37 ;;; Code:
39 (require 'erc)
41 (defvar erc-identd-process nil)
43 (defgroup erc-identd nil
44 "Run a local identd server."
45 :group 'erc)
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'.
51 This 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")))
57 ;;;###autoload (autoload 'erc-identd-mode "erc-identd")
58 (define-erc-module identd nil
59 "This mode launches an identd server on port 8113."
60 ((add-hook 'erc-connect-pre-hook 'erc-identd-quickstart)
61 (add-hook 'erc-disconnected-hook 'erc-identd-stop))
62 ((remove-hook 'erc-connect-pre-hook 'erc-identd-quickstart)
63 (remove-hook 'erc-disconnected-hook 'erc-identd-stop)))
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)))
75 (stop-process erc-identd-process)
76 (delete-process proc)))))
78 ;;;###autoload
79 (defun erc-identd-start (&optional port)
80 "Start an identd server listening to port 8113.
81 Port 113 (auth) will need to be redirected to port 8113 on your
82 machine -- using iptables, or a program like redir which can be
83 run from inetd. The idea is to provide a simple identd server
84 when you need one, without having to install one globally on your
85 system."
86 (interactive (list (read-string "Serve identd requests on port: " "8113")))
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))
92 (setq erc-identd-process
93 (make-network-process :name "identd"
94 :buffer nil
95 :host 'local :service port
96 :server t :noquery t :nowait t
97 :filter 'erc-identd-filter))
98 (set-process-query-on-exit-flag erc-identd-process nil))
100 (defun erc-identd-quickstart (&rest ignored)
101 "Start the identd server with the default port.
102 The default port is specified by `erc-identd-port'."
103 (erc-identd-start))
105 ;;;###autoload
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)))
112 (provide 'erc-identd)
114 ;;; erc-identd.el ends here
116 ;; Local Variables:
117 ;; indent-tabs-mode: t
118 ;; tab-width: 8
119 ;; End:
121 ;; arch-tag: e0b5f926-0f35-40b9-8ddb-ca06b62a7544