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: Tue, 29 Dec 2020 08:24:25 GMT Message-ID: <87h7o5vx3b.fsf@sol.hw.lgcl.de> References: <87v9cw7np1.fsf@sol.hw.lgcl.de> <874kk5jwqr.fsf@gnu.org> 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="37565"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , 45340@debbugs.gnu.org To: Amin Bandali Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 29 09:25:34 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 1kuAJx-0009de-M4 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 29 Dec 2020 09:25:34 +0100 Original-Received: from localhost ([::1]:42380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kuAJw-000647-8i for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 29 Dec 2020 03:25:32 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kuAJS-00063z-BD for bug-gnu-emacs@gnu.org; Tue, 29 Dec 2020 03:25:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54214) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kuAJS-0006E3-2l for bug-gnu-emacs@gnu.org; Tue, 29 Dec 2020 03:25:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kuAJR-0001x0-Vr for bug-gnu-emacs@gnu.org; Tue, 29 Dec 2020 03:25:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Leon Vack Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 29 Dec 2020 08:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45340 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 45340-submit@debbugs.gnu.org id=B45340.16092302707453 (code B ref 45340); Tue, 29 Dec 2020 08:25:01 +0000 Original-Received: (at 45340) by debbugs.gnu.org; 29 Dec 2020 08:24:30 +0000 Original-Received: from localhost ([127.0.0.1]:37527 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kuAIv-0001w9-UJ for submit@debbugs.gnu.org; Tue, 29 Dec 2020 03:24:30 -0500 Original-Received: from out1.migadu.com ([91.121.223.63]:34082) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kuAIt-0001w0-64 for 45340@debbugs.gnu.org; Tue, 29 Dec 2020 03:24:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lgcl.de; s=key1; t=1609230265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=b7tD3G12zwDcezq+/5EPJ1qEpGGBIUF3FUAVE5KKwWc=; b=Vg44BW4yOmnoYfBOwvkYcWlE+xx+3VKc73AnTD8QWpSGa5tb7sFbim0s3qYU35ZbEYu3Gj SR1PanB1RSvjtVfbFJs8TIw9+wONTk3ykyYhDYMiViHnE8KgZiJbvWNbSkhtGhy54Xgu3V hAzjvb6lN+t36oJr2eWQmo0gC1bTj/O8q2I5xNKf7KtiTASTMKPeOqvyGefzrIjHpsYTff 6sn/vQEdNWv6esUiqsMCKSO0d9jgws19pE1HC6YizOf/t01fIOfRthcgEYNfWXi2JPLNAL REsIzDhNDEyW4amq+nTgIzKq2so6yInaUy13D2UvtfEBFpXu3p/NvsBMAwDW4g== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: <874kk5jwqr.fsf@gnu.org> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: dev@lgcl.de 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:196917 Archived-At: --=-=-= Content-Type: text/plain Hello Amin, > > Thanks for your patch, Leon. I've left some stylistic comments below, > until I get a chance to have a closer look at your patch and take it for > a test run in the next week or so. :-) > Thanks for the pointers. I attached a new patch with all of them addressed. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Support-using-auth-source-for-NickServ-passwords-in-.patch >From 45544bbf6b197e545297430f511bf7ca75962673 Mon Sep 17 00:00:00 2001 From: Leon Vack Date: Sun, 20 Dec 2020 10:53:33 +0100 Subject: [PATCH] Support using auth-source for NickServ passwords in ERC * lisp/etc/erc-services.el (erc-nickserv-passwords): Document that the passwords are only used when erc-prompt-for-nickserv-password is nil. * (erc-use-auth-source-for-nickserv-password): New customizable variable to enable checking auth-source for NickServ passwords. * (etc-nickserv-get-password): New function to handle the lookup of the NickServ password from both auth-source and the erc-nickserv-passwords variable. * (erc-nickserv-call-identify-function): Use new erc-nickserv-get-password function to lookup NickServ passwords. * (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: Document change. --- etc/NEWS | 9 ++++++ lisp/erc/erc-services.el | 59 ++++++++++++++++++++++++++++++++-------- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 4a8e70e6a6..d722592fd3 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1283,6 +1283,15 @@ 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. To enable this, add the following +to your init file: + + (setq erc-prompt-for-nickserv-password nil + erc-use-auth-source-for-nickserv-password t) + + --- *** 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..a367873090 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 if `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\") @@ -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,30 +409,50 @@ 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)) - (and (eq erc-nickserv-identify-mode 'both) - (erc-nickserv-alist-regexp (erc-network)))) + (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-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)) - (and (eq erc-nickserv-identify-mode 'both) - (erc-nickserv-alist-regexp (erc-network)))) + (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 --=-=-= Content-Type: text/plain >>> Have you already started the assignment process, or do you need the >>> assignment form to get started? >> >> Yes, I have the form and started the assignment process with it. Thanks >> for asking. > > Great. Please let me know when you hear from the copyright clerk about > the completion of the process. > I have already sent the singed paperwork and will let you know once I have the copy singed by the FSF. --=-=-=--