From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Leon Vack Newsgroups: gmane.emacs.bugs Subject: bug#45340: erc-services.el: Auth-source support for passwords Date: Sun, 20 Dec 2020 10:54:03 GMT Message-ID: <87v9cw7np1.fsf@sol.hw.lgcl.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33682"; mail-complaints-to="usenet@ciao.gmane.io" To: 45340@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 20 15:55:30 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kr07M-0008aH-5p for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Dec 2020 15:55:28 +0100 Original-Received: from localhost ([::1]:43058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kr07J-0003gV-Cw for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Dec 2020 09:55:26 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kr06x-0003Uw-Gd for bug-gnu-emacs@gnu.org; Sun, 20 Dec 2020 09:55:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60749) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kr06x-00068q-99 for bug-gnu-emacs@gnu.org; Sun, 20 Dec 2020 09:55:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kr06x-0006Co-7r for bug-gnu-emacs@gnu.org; Sun, 20 Dec 2020 09:55:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Leon Vack Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Dec 2020 14:55:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 45340 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.160847605923712 (code B ref -1); Sun, 20 Dec 2020 14:55:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Dec 2020 14:54:19 +0000 Original-Received: from localhost ([127.0.0.1]:44004 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kr06E-0006AI-Fk for submit@debbugs.gnu.org; Sun, 20 Dec 2020 09:54:19 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:57108) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kqwLv-0006ZD-Iq for submit@debbugs.gnu.org; Sun, 20 Dec 2020 05:54:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqwLu-0000jM-AC for bug-gnu-emacs@gnu.org; Sun, 20 Dec 2020 05:54:15 -0500 Original-Received: from out0.migadu.com ([2001:41d0:2:267::]:35924) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqwLq-0006DR-K6 for bug-gnu-emacs@gnu.org; Sun, 20 Dec 2020 05:54:14 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lgcl.de; s=key1; t=1608461643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=Ma+Wksxqky9MxXVTt2aJBBMgdcBYzQlamdd/nWyR6KE=; b=XnZlZu9Jci8MFEPdmfaGyL2SiQs4lYljJ+M4P8u/Cuz3Fzc8RhAekR2B27SKkEqPpNJBAq 3tn17ZvFty0JSzXrmvJ9k/9zDtm+OnD9N9AwPcC06gHjBkgLLD+02KLRtVw+UdfJ0pKAqm fr91CMV1R0PEdraVmtCIRkz3+826x9Z23rpWHUktsnzvsqmu5z8IusrZ/YJBGg9f+8IiXf NdXy5epCkiTXChlDn8ywgVAeJXYvaW+U79UdjQur44h4wZlTvKG8EXkjqA0WntiNRaw7ki o8pYYLNKZrFZnbSKMy03bq79Wxf3h7HWO96tOic0vDR+qTwc9Y2EgrxEF5Q2nQ== X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: dev@lgcl.de Received-SPF: pass client-ip=2001:41d0:2:267::; envelope-from=dev@lgcl.de; helo=out0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 20 Dec 2020 09:54:16 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:196470 Archived-At: --=-=-= Content-Type: text/plain Adds an option to erc-services.el to query auth-source for NickServ passwords. This is my first patch to emacs, so please let me know if I missed any standards. I am about to start the process of assigning the copyright to the FSF. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-erc-services.el-Auth-source-support-for-passwords.patch >From 367593cc4cbfdfbdac778fd15ceb79fd61d7f64c Mon Sep 17 00:00:00 2001 From: Leon Vack Date: Sun, 20 Dec 2020 10:53:33 +0100 Subject: [PATCH] erc-services.el: Auth-source support for passwords * lisp/etc/erc-services.el (erc-nickserv-passwords): Document that the passwords are only used when erc-prompt-for-nickserv-password is nil. * lisp/etc/erc-services.el (erc-use-auth-source-for-nickserv-password): New customizable variable to enable checking auth-source for NickServ passwords. * lisp/etc/erc-services.el (etc-nickserv-get-password): New function to handle the lookup of the NickServ password from both auth-source and the erc-nickserv-passwords variable. * lisp/etc/erc-services.el (erc-nickserv-call-identify-function): Use new erc-nickserv-get-password function to lookup NickServ passwords. * lisp/etc/erc-services.el (erc-nickserv-identify-autodetect) (erc-nickserv-identify-on-connect) (erc-nickserv-identify-on-nick-change): Call erc-nickserv-call-identify-function when erc-use-auth-source-for-nickserv-password is set. --- etc/NEWS | 4 ++++ lisp/erc/erc-services.el | 50 ++++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 4a8e70e6a6..c9e0fa7459 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1283,6 +1283,10 @@ https://www.w3.org/TR/xml/#charsets). Now it rejects such strings. ** erc +*** erc-services.el now supports NickServ passwords from auth-source. +The 'erc-use-auth-source-for-nickserv-password' enables querying +auth-source for NickServ passwords. + --- *** The '/ignore' command will now ask for a timeout to stop ignoring the user. Allowed inputs are seconds or ISO8601-like periods like "1h" or "4h30m". diff --git a/lisp/erc/erc-services.el b/lisp/erc/erc-services.el index c0011f9808..0710813e9d 100644 --- a/lisp/erc/erc-services.el +++ b/lisp/erc/erc-services.el @@ -168,9 +168,23 @@ erc-prompt-for-nickserv-password :group 'erc-services :type 'boolean) +(defcustom erc-use-auth-source-for-nickserv-password nil + "Query auth-source for a password when identifiying to NickServ. + + +This option has an no effect `erc-prompt-for-nickserv-password' +is not nil and passwords from `erc-nickserv-passwords' take +precedence." + :version "28.1" + :group 'erc-services + :type 'boolean) + (defcustom erc-nickserv-passwords nil "Passwords used when identifying to NickServ automatically. +`erc-prompt-for-nickserv-password' must be nil for these +passwords to be used. + Example of use: (setq erc-nickserv-passwords \\='((freenode ((\"nick-one\" . \"password\") @@ -199,7 +213,7 @@ erc-nickserv-passwords (cons :tag "Identity" (string :tag "Nick") (string :tag "Password" - :secret ?*)))))) + :secret ?*)))))) ;; Variables: @@ -375,7 +389,8 @@ erc-nickserv-identify-autodetect If `erc-prompt-for-nickserv-password' is non-nil, prompt the user for the password for this nickname, otherwise try to send it automatically." (unless (and (null erc-nickserv-passwords) - (null erc-prompt-for-nickserv-password)) + (null erc-prompt-for-nickserv-password) + (null erc-use-auth-source-for-nickserv-password)) (let* ((network (erc-network)) (sender (erc-nickserv-alist-sender network)) (identify-regex (erc-nickserv-alist-regexp network)) @@ -394,7 +409,8 @@ erc-nickserv-identify-autodetect (defun erc-nickserv-identify-on-connect (_server nick) "Identify to Nickserv after the connection to the server is established." (unless (or (and (null erc-nickserv-passwords) - (null erc-prompt-for-nickserv-password)) + (null erc-prompt-for-nickserv-password) + (null erc-use-auth-source-for-nickserv-password)) (and (eq erc-nickserv-identify-mode 'both) (erc-nickserv-alist-regexp (erc-network)))) (erc-nickserv-call-identify-function nick))) @@ -402,22 +418,38 @@ erc-nickserv-identify-on-connect (defun erc-nickserv-identify-on-nick-change (nick _old-nick) "Identify to Nickserv whenever your nick changes." (unless (or (and (null erc-nickserv-passwords) - (null erc-prompt-for-nickserv-password)) + (null erc-prompt-for-nickserv-password) + (null erc-use-auth-source-for-nickserv-password)) (and (eq erc-nickserv-identify-mode 'both) (erc-nickserv-alist-regexp (erc-network)))) (erc-nickserv-call-identify-function nick))) +(defun erc-nickserv-get-password (nickname) + "Return the password for NICKNAME from configured sources. + +It uses `erc-nickserv-passwords' and additionally auth-source +when `erc-use-auth-source-for-nickserv-password' is not nil." + (or (when erc-nickserv-passwords + (cdr (assoc nickname + (nth 1 (assoc (erc-network) + erc-nickserv-passwords))))) + (when erc-use-auth-source-for-nickserv-password + (let* ((secret (nth 0 (auth-source-search + :max 1 :require '(:secret) + :host (erc-with-server-buffer erc-session-server) + :port (format ; ensure we have a string + "%s" (erc-with-server-buffer erc-session-port)) + :user nickname)))) + (when secret (let ((passwd (plist-get secret :secret))) + (if (functionp passwd) (funcall passwd) passwd))))))) + (defun erc-nickserv-call-identify-function (nickname) "Call `erc-nickserv-identify'. Either call it interactively or run it with NICKNAME's password, depending on the value of `erc-prompt-for-nickserv-password'." (if erc-prompt-for-nickserv-password (call-interactively 'erc-nickserv-identify) - (when erc-nickserv-passwords - (erc-nickserv-identify - (cdr (assoc nickname - (nth 1 (assoc (erc-network) - erc-nickserv-passwords)))))))) + (when password (erc-nickserv-identify (erc-nickserv-get-password nickname))))) (defvar erc-auto-discard-away) -- 2.28.0 --=-=-=--