From: Philip Kaludercic Date: Mon, 9 Jun 2025 13:13:19 +0000 (+0200) Subject: Support checking auth-source for NickServ password for rcirc X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=44037ae9b5f5b54c3b461d6a1ea476ced6645e8f;p=emacs.git Support checking auth-source for NickServ password for rcirc * doc/misc/rcirc.texi: Mention new feature. * etc/NEWS: Mention new feature. * lisp/net/rcirc.el (rcirc-authinfo): Update type and documentation. (rcirc-authenticate): Handle a special type to indicate that the password is stored via auth-source. (cherry picked from commit 1009e3d1fd6a40cf7a07a0f75a24f704737e4c6b) --- diff --git a/doc/misc/rcirc.texi b/doc/misc/rcirc.texi index ada20f74b37..8bc057f023c 100644 --- a/doc/misc/rcirc.texi +++ b/doc/misc/rcirc.texi @@ -592,6 +592,10 @@ Before you can use this method, you will have to register your nick and pick a password for it. Contact @code{nickserv} and check out the details. (Using @code{/msg nickserv help}, for example.) +You can set the password to the symbol @code{:auth-source}, to fetch the +password from auth-source (@pxref{auth-source}), if you to not hard-code +your password in your configuration. + @item chanserv @cindex chanserv authentication Use this symbol if you need to identify yourself as follows if you want diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el index e4192e2d7a4..7c01825d431 100644 --- a/lisp/net/rcirc.el +++ b/lisp/net/rcirc.el @@ -270,8 +270,13 @@ The ARGUMENTS for each METHOD symbol are: `sasl': NICK PASSWORD `certfp': KEY CERT +For `nickserv', PASSWORD may be the symbol `:auth-source', in which case +the host, nick and port will be used to query a password from an +available `auth-source' backend. + Examples: ((\"Libera.Chat\" nickserv \"bob\" \"p455w0rd\") + (\"Libera.Chat\" nickserv \"bob\" :auth-source) (\"Libera.Chat\" chanserv \"bob\" \"#bobland\" \"passwd99\") (\"Libera.Chat\" certfp \"/path/to/key\" \"/path/to/cert\") (\"bitlbee\" bitlbee \"robert\" \"sekrit\") @@ -282,7 +287,9 @@ Examples: :value-type (choice (list :tag "NickServ" (const nickserv) (string :tag "Nick") - (string :tag "Password")) + (choice + (string :tag "Password") + (const :tag "Use Auth-Source" :auth-source))) (list :tag "ChanServ" (const chanserv) (string :tag "Nick") @@ -3652,40 +3659,44 @@ specified in RFC2812, where 005 stood for RPL_BOUNCE." Passwords are stored in `rcirc-authinfo' (which see)." (interactive) (with-rcirc-server-buffer - (dolist (i rcirc-authinfo) - (let ((process (rcirc-buffer-process)) - (server (car i)) - (nick (nth 2 i)) - (method (cadr i)) - (args (cdddr i))) - (when (and (string-match server rcirc-server)) - (if (and (memq method '(nickserv chanserv bitlbee)) - (string-match nick rcirc-nick)) - ;; the following methods rely on the user's nickname. - (cl-case method - (nickserv - (rcirc-send-privmsg - process - (or (cadr args) "NickServ") - (concat "IDENTIFY " (car args)))) - (chanserv - (rcirc-send-privmsg - process - "ChanServ" - (format "IDENTIFY %s %s" (car args) (cadr args)))) - (bitlbee - (rcirc-send-privmsg - process - "&bitlbee" - (concat "IDENTIFY " (car args)))) - (sasl nil)) - ;; quakenet authentication doesn't rely on the user's nickname. - ;; the variable `nick' here represents the Q account name. - (when (eq method 'quakenet) - (rcirc-send-privmsg - process - "Q@CServe.quakenet.org" - (format "AUTH %s %s" nick (car args)))))))))) + (pcase-dolist (`(,(rx (regexp rcirc-server)) . ,ai) rcirc-authinfo) + (pcase ai + (`(nickserv ,(rx (regexp rcirc-nick)) :auth-source . ,(or `(,nickserv) '())) + (if-let* ((auth (auth-source-search + :host rcirc-server + :port (nth 1 rcirc-connection-info) + :user (nth 2 rcirc-connection-info))) + (password (auth-info-password (car auth)))) + (rcirc-send-privmsg + (rcirc-buffer-process) + (or nickserv "NickServ") + (concat "IDENTIFY " password)) + (rcirc-print + (rcirc-buffer-process) rcirc-nick "ERROR" nil + "No auth-source entry found for `nickserv' authentication"))) + (`(nickserv ,(rx (regexp rcirc-nick)) ,password . ,(or `(,nickserv) '())) + (rcirc-send-privmsg + (rcirc-buffer-process) + (or nickserv "NickServ") + (concat "IDENTIFY " password))) + (`(chanserv ,(rx (regexp rcirc-nick)) ,channel ,password) + (rcirc-send-privmsg + (rcirc-buffer-process) + "ChanServ" + (format "IDENTIFY %s %s" channel password))) + (`(bitlbee ,(rx (regexp rcirc-nick)) ,password) + (rcirc-send-privmsg + (rcirc-buffer-process) + "&bitlbee" + (concat "IDENTIFY " password))) + (`(quakenet ,account ,password) + ;; quakenet authentication doesn't rely on the user's + ;; nickname. the variable `account' here represents the Q + ;; account name. + (rcirc-send-privmsg + (rcirc-buffer-process) + "Q@CServe.quakenet.org" + (format "AUTH %s %s" account password))))))) (defun rcirc-handler-INVITE (process sender args _text) "Notify user of an invitation from SENDER.