| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
(require 'erc) |
|---|
| 42 |
|
|---|
| 43 |
(defvar erc-identd-process nil) |
|---|
| 44 |
|
|---|
| 45 |
(defgroup erc-identd nil |
|---|
| 46 |
"Run a local identd server." |
|---|
| 47 |
:group 'erc) |
|---|
| 48 |
|
|---|
| 49 |
(defcustom erc-identd-port 8113 |
|---|
| 50 |
"Port to run the identd server on if not specified in the argument for |
|---|
| 51 |
`erc-identd-start'. |
|---|
| 52 |
|
|---|
| 53 |
This can be either a string or a number." |
|---|
| 54 |
:group 'erc-identd |
|---|
| 55 |
:type '(choice (const :tag "None" nil) |
|---|
| 56 |
(integer :tag "Port number") |
|---|
| 57 |
(string :tag "Port string"))) |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
(define-erc-module identd nil |
|---|
| 61 |
"This mode launches an identd server on port 8113." |
|---|
| 62 |
((add-hook 'erc-connect-pre-hook 'erc-identd-quickstart) |
|---|
| 63 |
(add-hook 'erc-disconnected-hook 'erc-identd-stop)) |
|---|
| 64 |
((remove-hook 'erc-connect-pre-hook 'erc-identd-quickstart) |
|---|
| 65 |
(remove-hook 'erc-disconnected-hook 'erc-identd-stop))) |
|---|
| 66 |
|
|---|
| 67 |
(defun erc-identd-filter (proc string) |
|---|
| 68 |
"This filter implements RFC1413 (identd authentication protocol)." |
|---|
| 69 |
(let ((erc-identd-process proc)) |
|---|
| 70 |
(when (string-match "\\([0-9]+\\)\\s-*,\\s-*\\([0-9]+\\)" string) |
|---|
| 71 |
(let ((port-on-server (match-string 1 string)) |
|---|
| 72 |
(port-on-client (match-string 2 string))) |
|---|
| 73 |
(send-string erc-identd-process |
|---|
| 74 |
(format "%s, %s : USERID : %s : %s\n" |
|---|
| 75 |
port-on-server port-on-client |
|---|
| 76 |
system-type (user-login-name))) |
|---|
| 77 |
(process-send-eof erc-identd-process))))) |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 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 |
|---|
| 86 |
system." |
|---|
| 87 |
(interactive (list (read-string "Serve identd requests on port: " "8113"))) |
|---|
| 88 |
(unless port (setq port erc-identd-port)) |
|---|
| 89 |
(when (stringp 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" |
|---|
| 95 |
:buffer nil |
|---|
| 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)) |
|---|
| 100 |
|
|---|
| 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'." |
|---|
| 104 |
(erc-identd-start)) |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
(defun erc-identd-stop (&rest ignore) |
|---|
| 108 |
(interactive) |
|---|
| 109 |
(when erc-identd-process |
|---|
| 110 |
(delete-process erc-identd-process) |
|---|
| 111 |
(setq erc-identd-process nil))) |
|---|
| 112 |
|
|---|
| 113 |
(provide 'erc-identd) |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|