all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: emacs-devel@gnu.org
Subject: Re: more on starttls, gnutls-cli and using tls for mail
Date: Mon, 26 Sep 2011 12:22:48 -0500	[thread overview]
Message-ID: <871uv343rr.fsf@lifelogs.com> (raw)
In-Reply-To: 87ty80h6tr.fsf@red-bean.com

On Sun, 25 Sep 2011 13:26:08 -0400 Karl Fogel <kfogel@red-bean.com> wrote: 

KF> Ted Zlatanov <tzz@lifelogs.com> writes:
>> `smtpmail-auth-credentials' is not a good interface for many reasons.
>> It was very, very well discussed in the past.  Everything it can do,
>> should be possible with `auth-source-search'.
>> 
>> `auth-source' supports multiple backends.  There's no reason we can't
>> provide a backend that does the dynamic fetching you want and does not
>> use a authinfo/netrc file.  The authinfo/netrc backend supports entry
>> creation and can share the file with other consumers such as libcurl;
>> this is the main reason why it's the default now.
>> 
>> You should also note that you can configure `auth-sources' to use any
>> combination of backends.  So your custom ELisp backend could be first,
>> then you'd hit the Secrets API, then the authinfo/netrc backend. [...]

KF> Thanks.  This all sounds good in principle.  As a user (even as an
KF> Elisp-literate user) I have no idea yet how to take advantage of the
KF> functionality you describe above, but I assume that's just a matter of
KF> reading the documentation.  From what I've read so far, auth-source
KF> seems to be a superset of everything anyone could ever want.

KF> It may be that after I set up something dynamic, it will be
KF> contributable back to Emacs, either as code or as examples for the
KF> auth-source Info manual.  I'll try to keep that in mind.

KF> For now, I'm dynamically constructing ~/.authinfo and then destroying it
KF> after the mail is sent, because I got that working and its undeniable
KF> awkwardness is a mere annoyance, not a showstopper.

Heheh.  OK.  You really, really want a dynamic backend then.  No
problem.

First, look at the definition of `auth-sources'.  You need to augment
the list of backends:

                 (choice
                  (string :tag "Just a file")
                  (const :tag "Default Secrets API Collection" 'default)
                  (const :tag "Login Secrets API Collection" "secrets:Login")
                  (const :tag "Temp Secrets API Collection" "secrets:session")
+                  (const :tag "Karl's Dynamic Backend" 'dynamic-data)

Then look at `auth-source-backend-parse'.  Add your new backend to the
cond statement so it's parsed properly.  Here you can parse a string
prefix like "dynamic-data:karl-dynamic-variable" (as the Sessions API does) so
your users can point to a variable easily without customizing
`auth-sources' too much.  They would just have to add a string.  The
prefix doesn't have to match the backend name.

The last step is to create your backend instance when needed and return
it:

       (auth-source-backend
        (plist-get entry :source)
        :source (plist-get entry :source)
        :type 'dynamic-data
        :search-function 'auth-source-dynamic-data-search
        :create-function 'auth-source-dynamic-data-create)))

Your create function can be a stub, that's not a problem.

Finally your search function...  Copy the `auth-source-netrc-search'
template:

(defun* auth-source-netrc-search (&rest
                                  spec
                                  &key backend require create delete
                                  type max host user port
                                  &allow-other-keys)

1) the backend is the backend you created earlier, you'll need the
"source" slot which in your case is e.g. karl-dynamic-variable.  You'd
map that to a symbol name and manipulate the value, obviously.

2) require is a list of required keys

3) max is the maximum number of results you should return

4) create can be ignored if your create-function is a stub

5) delete can be ignored if your backend doesn't delete entries,
otherwise delete everything you found up to max

6) host, user, port are the only search criteria accepted by the
netrc/authinfo backend; yours could take more

7) type is the backend type, you should return nothing if it's not
dynamic-data (the `auth-source-search' caller may ask for this).

If you want to allow creation, look at `auth-source-netrc-create'.
There's a lot of code to deal with prompting that should IMO be factored
out but I haven't had the time.  It sounds like you'd be OK with letting
the user modify the data externally though.

Daiki Ueno went through this with his plstore backend so you're the
second one to possibly write a custom backend.  If it goes well for you
I'll put these instructions in the auth-source texinfo pages.

If you think this is too complicated or you're busy, I'll do it.  Please
let me know.

Thanks
Ted




  reply	other threads:[~2011-09-26 17:22 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-14  1:19 more on starttls, gnutls-cli and using tls for mail T. V. Raman
2011-08-14  1:26 ` Karl Fogel
2011-08-14  3:40   ` Leo
2011-08-14  5:42     ` Karl Fogel
2011-08-14 12:02       ` Vijay Lakshminarayanan
2011-08-14 21:07         ` Leo
2011-08-15  3:53           ` Vijay Lakshminarayanan
2011-08-15  4:27             ` Leo
2011-08-15  7:41               ` Vijay Lakshminarayanan
2011-08-15  6:03         ` Tim Cross
2011-08-15  7:38           ` Vijay Lakshminarayanan
2011-08-17  1:54             ` Tim Cross
2011-08-17 14:28               ` Karl Fogel
2011-08-17 22:48                 ` Tim Cross
2011-08-18  0:33                   ` chad
2011-08-18  3:11                   ` Stephen J. Turnbull
2011-08-17 17:27               ` Vijay Lakshminarayanan
2011-08-15  7:47           ` Richard Riley
2011-08-15  9:21           ` David Engster
2011-08-17  2:03             ` Tim Cross
2011-08-17  7:03               ` David Engster
2011-08-15 16:25           ` Dimitri Fontaine
2011-08-16  9:33             ` Leo
2011-08-16 10:12               ` Dimitri Fontaine
2011-08-17  2:13                 ` Tim Cross
2011-08-17  1:08               ` Richard Riley
2011-08-14  6:24   ` Roland Winkler
2011-08-14  6:32     ` Roland Winkler
2011-08-14 16:23     ` Karl Fogel
2011-08-15 15:21       ` Roland Winkler
2011-08-17  2:09         ` Tim Cross
2011-09-25 13:08       ` Ted Zlatanov
2011-09-25 17:26         ` Karl Fogel
2011-09-26 17:22           ` Ted Zlatanov [this message]
2011-09-27 15:28             ` Karl Fogel
2011-08-17 21:06   ` Multiple SMTP accounts with smtpmail.el (was: more on starttls, gnutls-cli and using tls for mail) Lars Magne Ingebrigtsen
2011-08-18  3:19     ` Multiple SMTP accounts with smtpmail.el Leo
2011-08-18 14:20     ` Karl Fogel
2011-08-18 16:41       ` Vijay Lakshminarayanan
2011-08-19 14:42       ` Lars Magne Ingebrigtsen
2011-08-21  2:13         ` Karl Fogel
2011-08-21  4:16           ` Lars Magne Ingebrigtsen
2011-08-22  7:22             ` Glenn Morris
2011-09-25 13:10     ` Ted Zlatanov
2011-09-26 18:06       ` Lars Magne Ingebrigtsen
2011-09-26 19:24         ` Ted Zlatanov
2011-09-25 22:46     ` Rasmus
2011-08-14 17:12 ` more on starttls, gnutls-cli and using tls for mail Chong Yidong
2011-08-17 20:58 ` Lars Magne Ingebrigtsen
  -- strict thread matches above, loose matches on Subject: below --
2011-08-14  2:10 raman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871uv343rr.fsf@lifelogs.com \
    --to=tzz@lifelogs.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.