erc-identd.el 4.0 KB

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