Mercurial > emacs
annotate lisp/erc/erc-identd.el @ 98544:bc9970afd5be
(Vbefore_init_time, Vafter_init_time): Moved from startup.el.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Mon, 06 Oct 2008 16:16:56 +0000 |
parents | 2a734255bcc7 |
children | a9dc0e7c3f2b |
rev | line source |
---|---|
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
1 ;;; erc-identd.el --- RFC1413 (identd authentication protocol) server |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
2 |
79706 | 3 ;; Copyright (C) 2003, 2006, 2007, 2008 Free Software Foundation, Inc. |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
4 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
5 ;; Author: John Wiegley <johnw@gnu.org> |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
6 ;; Keywords: comm, processes |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
7 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
9 |
94660
2a734255bcc7
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
94660
2a734255bcc7
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
2a734255bcc7
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
13 ;; (at your option) any later version. |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
14 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
18 ;; GNU General Public License for more details. |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
19 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
94660
2a734255bcc7
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
22 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
23 ;;; Commentary: |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
24 |
71883 | 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. | |
27 | |
28 ;; To use this module, add identd to `erc-modules' and run | |
29 ;; `erc-update-modules'. | |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
30 |
71883 | 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 | |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
36 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
37 ;;; Code: |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
38 |
71883 | 39 (require 'erc) |
40 | |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
41 (defvar erc-identd-process nil) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
42 |
76856 | 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 | |
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"))) | |
56 | |
71883 | 57 ;;;###autoload (autoload 'erc-identd-mode "erc-identd") |
58 (define-erc-module identd nil | |
59 "This mode launches an identd server on port 8113." | |
76856 | 60 ((add-hook 'erc-connect-pre-hook 'erc-identd-quickstart) |
71883 | 61 (add-hook 'erc-disconnected-hook 'erc-identd-stop)) |
76856 | 62 ((remove-hook 'erc-connect-pre-hook 'erc-identd-quickstart) |
71883 | 63 (remove-hook 'erc-disconnected-hook 'erc-identd-stop))) |
64 | |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
65 (defun erc-identd-filter (proc string) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
66 "This filter implements RFC1413 (identd authentication protocol)." |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
67 (let ((erc-identd-process proc)) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
68 (when (string-match "\\([0-9]+\\)\\s-*,\\s-*\\([0-9]+\\)" string) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
69 (let ((port-on-server (match-string 1 string)) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
70 (port-on-client (match-string 2 string))) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
71 (send-string erc-identd-process |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
72 (format "%s, %s : USERID : %s : %s\n" |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
73 port-on-server port-on-client |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
74 system-type (user-login-name))) |
84387
4ee03308c9b6
Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents:
78219
diff
changeset
|
75 (stop-process erc-identd-process) |
4ee03308c9b6
Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents:
78219
diff
changeset
|
76 (delete-process proc))))) |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
77 |
69690
a90c92cb9783
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-179
Miles Bader <miles@gnu.org>
parents:
68822
diff
changeset
|
78 ;;;###autoload |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
79 (defun erc-identd-start (&optional port) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
80 "Start an identd server listening to port 8113. |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
81 Port 113 (auth) will need to be redirected to port 8113 on your |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
82 machine -- using iptables, or a program like redir which can be |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
83 run from inetd. The idea is to provide a simple identd server |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
84 when you need one, without having to install one globally on your |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
85 system." |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
86 (interactive (list (read-string "Serve identd requests on port: " "8113"))) |
76856 | 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)) | |
69690
a90c92cb9783
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-179
Miles Bader <miles@gnu.org>
parents:
68822
diff
changeset
|
92 (setq erc-identd-process |
a90c92cb9783
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-179
Miles Bader <miles@gnu.org>
parents:
68822
diff
changeset
|
93 (make-network-process :name "identd" |
71883 | 94 :buffer nil |
69690
a90c92cb9783
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-179
Miles Bader <miles@gnu.org>
parents:
68822
diff
changeset
|
95 :host 'local :service port |
71883 | 96 :server t :noquery t :nowait t |
97 :filter 'erc-identd-filter)) | |
98 (set-process-query-on-exit-flag erc-identd-process nil)) | |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
99 |
76856 | 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)) | |
104 | |
69690
a90c92cb9783
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-179
Miles Bader <miles@gnu.org>
parents:
68822
diff
changeset
|
105 ;;;###autoload |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
106 (defun erc-identd-stop (&rest ignore) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
107 (interactive) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
108 (when erc-identd-process |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
109 (delete-process erc-identd-process) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
110 (setq erc-identd-process nil))) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
111 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
112 (provide 'erc-identd) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
113 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
114 ;;; erc-identd.el ends here |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
115 ;; |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
116 ;; Local Variables: |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
117 ;; indent-tabs-mode: t |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
118 ;; tab-width: 8 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
119 ;; End: |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
120 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
121 ;; arch-tag: e0b5f926-0f35-40b9-8ddb-ca06b62a7544 |