1 ;;; erc-identd.el --- RFC1413 (identd authentication protocol) server
3 ;; Copyright (C) 2003, 2006-2015 Free Software Foundation, Inc.
5 ;; Author: John Wiegley <johnw@gnu.org>
6 ;; Maintainer: emacs-devel@gnu.org
7 ;; Keywords: comm, processes
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This module allows you to run a local identd server on port 8113.
27 ;; You will need to set up DNAT to bind 113->8113, or use a proxy.
29 ;; To use this module, add identd to `erc-modules' and run
30 ;; `erc-update-modules'.
32 ;; Here is an example /etc/inetd.conf rule that forwards identd
33 ;; traffic to port 8113. You will need simpleproxy installed for it
36 ;; 113 stream tcp nowait nobody /usr/sbin/tcpd /usr/bin/simpleproxy simpleproxy -i -R 127.0.0.1:8113
42 (defvar erc-identd-process nil
)
44 (defgroup erc-identd nil
45 "Run a local identd server."
48 (defcustom erc-identd-port
8113
49 "Port to run the identd server on if not specified in the argument for
52 This can be either a string or a number."
54 :type
'(choice (const :tag
"None" nil
)
55 (integer :tag
"Port number")
56 (string :tag
"Port string")))
58 ;;;###autoload (autoload 'erc-identd-mode "erc-identd")
59 (define-erc-module identd nil
60 "This mode launches an identd server on port 8113."
61 ((add-hook 'erc-connect-pre-hook
'erc-identd-quickstart
)
62 (add-hook 'erc-disconnected-hook
'erc-identd-stop
))
63 ((remove-hook 'erc-connect-pre-hook
'erc-identd-quickstart
)
64 (remove-hook 'erc-disconnected-hook
'erc-identd-stop
)))
66 (defun erc-identd-filter (proc string
)
67 "This filter implements RFC1413 (identd authentication protocol)."
68 (let ((erc-identd-process proc
))
69 (when (string-match "\\([0-9]+\\)\\s-*,\\s-*\\([0-9]+\\)" string
)
70 (let ((port-on-server (match-string 1 string
))
71 (port-on-client (match-string 2 string
)))
72 (send-string erc-identd-process
73 (format "%s, %s : USERID : %s : %s\n"
74 port-on-server port-on-client
75 system-type
(user-login-name)))
76 (stop-process erc-identd-process
)
77 (delete-process proc
)))))
80 (defun erc-identd-start (&optional port
)
81 "Start an identd server listening to port 8113.
82 Port 113 (auth) will need to be redirected to port 8113 on your
83 machine -- using iptables, or a program like redir which can be
84 run from inetd. The idea is to provide a simple identd server
85 when you need one, without having to install one globally on your
87 (interactive (list (read-string "Serve identd requests on port: " "8113")))
88 (unless port
(setq port erc-identd-port
))
90 (setq port
(string-to-number port
)))
91 (when erc-identd-process
92 (delete-process erc-identd-process
))
93 (setq erc-identd-process
94 (make-network-process :name
"identd"
96 :host
'local
:service port
97 :server t
:noquery t
:nowait t
98 :filter
'erc-identd-filter
))
99 (set-process-query-on-exit-flag erc-identd-process nil
))
101 (defun erc-identd-quickstart (&rest ignored
)
102 "Start the identd server with the default port.
103 The default port is specified by `erc-identd-port'."
107 (defun erc-identd-stop (&rest ignore
)
109 (when erc-identd-process
110 (delete-process erc-identd-process
)
111 (setq erc-identd-process nil
)))
113 (provide 'erc-identd
)
115 ;;; erc-identd.el ends here
118 ;; indent-tabs-mode: t