From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/86330 Path: news.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.gnus.general Subject: Re: auth-source backend stuff Date: Tue, 24 Nov 2015 14:05:24 +0800 Message-ID: <87y4do6ifv.fsf@ericabrahamsen.net> References: <87d1v9kye0.fsf@ericabrahamsen.net> <8737w0psm7.fsf@lifelogs.com> <8737w0atwb.fsf@ericabrahamsen.net> <87lh9on2lo.fsf@lifelogs.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1448345230 28141 80.91.229.3 (24 Nov 2015 06:07:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 24 Nov 2015 06:07:10 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M34562@lists.math.uh.edu Tue Nov 24 07:06:54 2015 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from lists1.math.uh.edu ([129.7.128.208]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1a16kf-0004sx-Kf for ding-account@gmane.org; Tue, 24 Nov 2015 07:06:53 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by lists1.math.uh.edu with smtp (Exim 4.85) (envelope-from ) id 1a16jo-0005WS-AJ; Tue, 24 Nov 2015 00:06:00 -0600 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by lists1.math.uh.edu with esmtps (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.85) (envelope-from ) id 1a16jm-0005W2-4U for ding@lists.math.uh.edu; Tue, 24 Nov 2015 00:05:58 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtps (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.85) (envelope-from ) id 1a16jk-00026O-Sf for ding@lists.math.uh.edu; Tue, 24 Nov 2015 00:05:57 -0600 Original-Received: from plane.gmane.org ([80.91.229.3]) by quimby.gnus.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1a16ji-0003Ps-Bk for ding@gnus.org; Tue, 24 Nov 2015 07:05:54 +0100 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1a16jb-0002bf-63 for ding@gnus.org; Tue, 24 Nov 2015 07:05:48 +0100 Original-Received: from 114.250.129.184 ([114.250.129.184]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 24 Nov 2015 07:05:47 +0100 Original-Received: from eric by 114.250.129.184 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 24 Nov 2015 07:05:47 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 112 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 114.250.129.184 User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.1.50 (gnu/linux) Cancel-Lock: sha1:oy9ZtqBJHGsyGQdQygqoC3Ky/J0= X-Spam-Score: -1.4 (-) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:86330 Archived-At: Ted Zlatanov writes: > On Sat, 21 Nov 2015 11:55:16 +0800 Eric Abrahamsen wrote: > > EA> Ted Zlatanov writes: >>> On Tue, 17 Nov 2015 13:06:47 +0800 Eric Abrahamsen wrote: >>> > EA> I see that auth-source.el is written to provide backend subclassing, but > EA> I've found the system as a whole a bit confusing to grasp. I've got a > EA> couple of questions I'm hoping someone can provide pointers for. >>> >>> I wrote docs for it here: >>> http://thread.gmane.org/gmane.emacs.devel/143198/focus=144282 but the >>> demand hasn't been high for custom backends. >>> >>> I think the :create stuff is what confuses people the most. > > EA> Thanks for this! It was also enough to clue me in to the fact that > EA> auth-source has its own info manual, which I hadn't realized. Between > EA> the various explanations I ought to be able to make this work. > > I would really appreciate it if you added your experience to the > developer section of the auth-source manual, and especially let me know > if you think the code needs changing. As far as I know Daiki Ueno is > the only one to have added a backend, so with you we'd have enough > experience to improve the code and simplify or expand it as needed. I have to admit it's still a bit hazy to me. Do I really have to edit the auth-source.el source code in order to add a new backend? I can see the utility of allowing users to refer to backend types using a simple string, but this makes it hard to add ad-hoc backends from outside the code base. Could `auth-source-backend-parse' be edited to look like: (defun auth-source-backend-parse (entry) (if (child-of-class-p entry 'auth-source-backend) entry (auth-source-backend-parse-parameters ....))) That would allow me to instantiate a backend in my own config code, and then just slap it into `auth-sources'. My other comment (admittedly totally unhelpful at this point) is that it seems a bit odd to be using classes, but then not using subclassing, or generic methods. The :type slot seems to be doing work that should be done by subclassing, and the :create-function and :search-function slots seem like they ought to be generic methods. Generic methods would probably also be the right solution for a unified prompt interface. Perhaps there are other considerations that prevent this -- I'm not that familiar with the code. And, practically, it would probably be too much work to re-write at that level, now. But I thought I'd mention it anyway! Right now the :initform arg to :create-function and :search-function is "ignore". I'm not certain, but it looks like this isn't working the way it's supposed to -- I was obliged to actually write stump functions before the class definition could be eval'ed. It appears that the current way to do this is to set the :allow-nil-initforms class-level option. Otherwise, here's how far I've gotten with this. The create function seems like it will be a nightmare of prompting, so I'm punting on that for now. Users would almost certainly have to create their own mapping between host/port/user combinations and pass entries, as I doubt anyone's going to want to structure their pass entries so that they're somehow programmatically findable given the host and user. Here's code that doesn't currently work, but I wish it would: (defun my-stub-create-function () nil) (defcustom my-server-to-pass-entry-map ;; Does :host correspond to the Gnus server name, or to the actual ;; nnimap-address host? '((:host "mail.ericabrahamsen.net" :user "eric@ericabrahamsen.net" :entry "email/ea") (:host "mail.paper-republic.org" :user "eric@paper-republic.org" :entry "email/pr"))) (defun* my-pass-search-function (&rest spec &key backend create delete max &allow-other-keys) (let ((pass-arg (catch 'found (dolist (m my-server-to-pass-entry-map) (when (and (string= (plist-get m :host) (plist-get spec :host)) (string= (plist-get m :user) (plist-get spec :user))) (throw 'found (plist-get m :entry))))))) (when pass-arg (shell-command-to-string (format "pass show %s" pass-arg))))) (setq my-halfassed-pass-backend (make-instance 'auth-source-backend :type 'pass-utility :source "dummy string" :create-function 'my-stub-create-function :search-function 'my-pass-search-function)) (setq auth-sources (list my-halfassed-pass-backend)) I won't waste time apologizing for this awful code, but this is the bare outline of what I'm trying to do. The other search functions for other backends are pretty enormously complex, and I don't yet know why. Thanks! Eric