Have rcirc-authenticate use ~/.authinfo

This commit is contained in:
Neale Pickett 2010-10-01 14:43:16 -06:00
parent 126c060732
commit 2146f06ca6
1 changed files with 33 additions and 58 deletions

View File

@ -45,6 +45,7 @@
(require 'ring) (require 'ring)
(require 'time-date) (require 'time-date)
(require 'netrc)
(eval-when-compile (require 'cl)) (eval-when-compile (require 'cl))
(defgroup rcirc nil (defgroup rcirc nil
@ -192,43 +193,22 @@ the window."
:type 'boolean :type 'boolean
:group 'rcirc) :group 'rcirc)
(defcustom rcirc-authinfo nil (defcustom rcirc-authinfo-file (expand-file-name "~/.authinfo")
"List of authentication passwords. "Location of authentication passwords.
Each element of the list is a list with a SERVER-REGEXP string This file is consulted for authentication to nick/channel
and a method symbol followed by method specific arguments. servers. It is formatted like a netrc file (see man ftp(1)),
with two additional keywords:
The valid METHOD symbols are `nickserv', `chanserv' and * The \"port\" keyword, if it exists, must be \"irc\".
`bitlbee'. * The \"account\" keyword, if it exists, may be \"bitlbee\",
\"chanserv\", or the name of your nickserv. If not present,
The ARGUMENTS for each METHOD symbol are: \"nickserv\" is used."
`nickserv': NICK PASSWORD [NICKSERV-NICK] :type 'file
`chanserv': NICK CHANNEL PASSWORD
`bitlbee': NICK PASSWORD
Examples:
((\"freenode\" nickserv \"bob\" \"p455w0rd\")
(\"freenode\" chanserv \"bob\" \"#bobland\" \"passwd99\")
(\"bitlbee\" bitlbee \"robert\" \"sekrit\")
(\"dal.net\" nickserv \"bob\" \"sekrit\" \"NickServ@services.dal.net\"))"
:type '(alist :key-type (string :tag "Server")
:value-type (choice (list :tag "NickServ"
(const nickserv)
(string :tag "Nick")
(string :tag "Password"))
(list :tag "ChanServ"
(const chanserv)
(string :tag "Nick")
(string :tag "Channel")
(string :tag "Password"))
(list :tag "BitlBee"
(const bitlbee)
(string :tag "Nick")
(string :tag "Password"))))
:group 'rcirc) :group 'rcirc)
(defcustom rcirc-auto-authenticate-flag t (defcustom rcirc-auto-authenticate-flag t
"*Non-nil means automatically send authentication string to server. "*Non-nil means automatically send authentication string to server.
See also `rcirc-authinfo'." See also `rcirc-authinfo-file'."
:type 'boolean :type 'boolean
:group 'rcirc) :group 'rcirc)
@ -2651,35 +2631,30 @@ keywords when no KEYWORD is given."
(defun rcirc-authenticate () (defun rcirc-authenticate ()
"Send authentication to process associated with current buffer. "Send authentication to process associated with current buffer.
Passwords are stored in `rcirc-authinfo' (which see)." Passwords are stored in `rcirc-authinfo-file'."
(interactive) (interactive)
(with-rcirc-server-buffer (with-rcirc-server-buffer
(dolist (i rcirc-authinfo) (dolist (i (netrc-parse rcirc-authinfo-file))
(let ((process (rcirc-buffer-process)) (let ((process (rcirc-buffer-process))
(server (car i)) (machine (netrc-get i "machine"))
(nick (caddr i)) (port (netrc-get i "port"))
(method (cadr i)) (account (netrc-get i "account"))
(args (cdddr i))) (nick (netrc-get i "login"))
(when (and (string-match server rcirc-server) (password (netrc-get i "password")))
(string-match nick rcirc-nick)) (when (and (or (not port) (equal port "irc"))
(cond ((equal method 'nickserv) (and machine (string-match machine rcirc-server))
(or (not nick) (string-match nick rcirc-nick)))
(message "We have a match!")
(cond ((equal account "bitlbee")
(rcirc-send-string (rcirc-send-string
process process
(concat "PRIVMSG " (or (cadr args) "nickserv") (concat "PRIVMSG &bitlbee :identify " password)))
" :identify " (car args))))
((equal method 'chanserv)
(rcirc-send-string
process
(concat
"PRIVMSG chanserv :identify "
(car args) " " (cadr args))))
((equal method 'bitlbee)
(rcirc-send-string
process
(concat "PRIVMSG &bitlbee :identify " (car args))))
(t (t
(message "No %S authentication method defined" (rcirc-send-string
method)))))))) process
(format "PRIVMSG %s :identify %s"
(or account "nickserv")
password)))))))))
(defun rcirc-handler-INVITE (process sender args text) (defun rcirc-handler-INVITE (process sender args text)
(rcirc-print process sender "INVITE" nil (mapconcat 'identity args " ") t)) (rcirc-print process sender "INVITE" nil (mapconcat 'identity args " ") t))