]> git.eshelyaron.com Git - emacs.git/commitdiff
Support checking auth-source for NickServ password for rcirc
authorPhilip Kaludercic <philipk@posteo.net>
Mon, 9 Jun 2025 13:13:19 +0000 (15:13 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 18 Jun 2025 08:01:30 +0000 (10:01 +0200)
* 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)

doc/misc/rcirc.texi
lisp/net/rcirc.el

index ada20f74b372b508701ec7de2f876863f6adc319..8bc057f023cfbe5863331c331b0b18e306dfeb49 100644 (file)
@@ -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
index e4192e2d7a425eda7548d224f63a5f3ed400ff52..7c01825d431595dda5f5566f9b329650c739a021 100644 (file)
@@ -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.