Gnus development mailing list
 help / color / mirror / Atom feed
* smtpmail-auth-credentials from authinfo
@ 2002-04-19 14:21 Ted Zlatanov
  2002-04-19 14:47 ` Simon Josefsson
  2002-04-19 15:33 ` Kai Großjohann
  0 siblings, 2 replies; 9+ messages in thread
From: Ted Zlatanov @ 2002-04-19 14:21 UTC (permalink / raw)
  Cc: scranefield

(this is regarding the smtpmail.el with authentication, which is not
yet in the mainstream Emacs but will be, I understand.  I cc-ed the
AUTH author)

I had to write this for my own authentication (so I could share my
.gnus.el).  I didn't want my smtpmail-auth-credentials to be in the
clear, and it seemed like a better idea to do it through authinfo.

I don't like the double setq statement, but I don't know enough Lisp
to eval the function in place, so I could have one setq only.

Has anyone else done something similar?  The solution below requires
.authinfo lines formatted "machine xyz port 25 login abc password ijk"
which is, perhaps, too inflexible.  Suggestions are welcome.
.authinfo support should probably go into the next smtpmail.el as
well, at least as an option.

Thanks
Ted

--------------------------------------------------------------------

(defun tzz-get-authinfo (authinfo-file)
  (interactive "Ffilename: ")
  (setq retlist nil)
  (if (file-exists-p authinfo-file)
      (with-temp-buffer
      (insert-file-contents authinfo-file)
      (goto-char (point-min))
      (while (re-search-forward
       "machine[ \t]+\\(\\S +\\)\\s +port[ \t]+\\(\\S +\\)\\s +login[ \t]+\\(\\S +\\)\\s +password[ \t]+\\(\\S +\\)"
   nil t)
   (let ((machine (match-string 1))
         (port (string-to-number (match-string 2)))
               (login (match-string 3))
                     (passwd (match-string 4)))
                           (setq l (list machine port login passwd))
                             (push l retlist)))))
  retlist)

(setq authinfo-list (tzz-get-authinfo "~/.authinfo"))
(setq smtpmail-auth-credentials authinfo-list)





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: smtpmail-auth-credentials from authinfo
  2002-04-19 14:21 smtpmail-auth-credentials from authinfo Ted Zlatanov
@ 2002-04-19 14:47 ` Simon Josefsson
  2002-04-19 15:41   ` Ted Zlatanov
  2002-04-19 15:33 ` Kai Großjohann
  1 sibling, 1 reply; 9+ messages in thread
From: Simon Josefsson @ 2002-04-19 14:47 UTC (permalink / raw)
  Cc: ding, scranefield

On Fri, 19 Apr 2002, Ted Zlatanov wrote:

> I had to write this for my own authentication (so I could share my
> .gnus.el).  I didn't want my smtpmail-auth-credentials to be in the
> clear, and it seemed like a better idea to do it through authinfo.

You can set `smtpmail-auth-credentials' from some other place than
.gnus.el, and protect that file in the same way you protect .authinfo.

> Has anyone else done something similar?  The solution below requires
> .authinfo lines formatted "machine xyz port 25 login abc password ijk"
> which is, perhaps, too inflexible.  Suggestions are welcome.
> .authinfo support should probably go into the next smtpmail.el as
> well, at least as an option.

Isolating authinfo into a separate package and making it available for all
emacs applications, and then making Gnus and smtpmail use the new
interface, seems like a good idea.  Do you want to do it or should I?




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: smtpmail-auth-credentials from authinfo
  2002-04-19 14:21 smtpmail-auth-credentials from authinfo Ted Zlatanov
  2002-04-19 14:47 ` Simon Josefsson
@ 2002-04-19 15:33 ` Kai Großjohann
  1 sibling, 0 replies; 9+ messages in thread
From: Kai Großjohann @ 2002-04-19 15:33 UTC (permalink / raw)
  Cc: scranefield

Ted Zlatanov <teodor.zlatanov@divine.com> writes:

> I had to write this for my own authentication (so I could share my
> .gnus.el).  I didn't want my smtpmail-auth-credentials to be in the
> clear, and it seemed like a better idea to do it through authinfo.

I use something similar for POP retrieval, but my code is quite a bit
shorter...

(defun ls6-pop-passwd-from-authinfo ()
  "Get POP password from ~/.authinfo file.
Example line: machine pop password verysecret"
  (require 'nntp)
  (let* ((x (gnus-parse-netrc nntp-authinfo-file))
         (item (gnus-netrc-machine x "pop"))
         (pw (gnus-netrc-get item "password")))
    pw))

But this code does something else.  It appears that you would want to
do gnus-parse-netrc and walk the resulting list to look that the port
is "smtp" or 25, and then you would add a corresponding entry to the
smtpmail-auth-credentials.

Or maybe smtpmail could be changed to grok stuff that comes from
gnus-parse-netrc?  That would be cool.

It seems that Simon's suggestion of factoring out a library for
~/.authinfo handling seems to be the way to go.

kai
-- 
Silence is foo!



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: smtpmail-auth-credentials from authinfo
  2002-04-19 14:47 ` Simon Josefsson
@ 2002-04-19 15:41   ` Ted Zlatanov
  2002-04-19 15:55     ` Simon Josefsson
  0 siblings, 1 reply; 9+ messages in thread
From: Ted Zlatanov @ 2002-04-19 15:41 UTC (permalink / raw)
  Cc: ding, scranefield

On Fri, 19 Apr 2002, jas@extundo.com wrote:
> On Fri, 19 Apr 2002, Ted Zlatanov wrote:
> 
>> I had to write this for my own authentication (so I could share my
>> .gnus.el).  I didn't want my smtpmail-auth-credentials to be in the
>> clear, and it seemed like a better idea to do it through authinfo.
> 
> You can set `smtpmail-auth-credentials' from some other place than
> .gnus.el, and protect that file in the same way you protect
> .authinfo.

Right, but that increases the number of places I have a cleartext
password.  I like the idea of the .authinfo file, and it's already
supported by most aspects of Gnus.

>> Has anyone else done something similar?  The solution below
>> requires .authinfo lines formatted "machine xyz port 25 login abc
>> password ijk" which is, perhaps, too inflexible.  Suggestions are
>> welcome.  .authinfo support should probably go into the next
>> smtpmail.el as well, at least as an option.
> 
> Isolating authinfo into a separate package and making it available
> for all emacs applications, and then making Gnus and smtpmail use
> the new interface, seems like a good idea.  Do you want to do it or
> should I?

It looks like gnus-parse-netrc already does all the work, actually (I
looked for authinfo parsing, and missed the netrc parsing
functionality).  It's much better than what I wrote, it handles all
the quoting and optional tokens.

Should I extract that to authinfo.el (or netrc.el?)  so it can be
integrated with smtpmail.el?  Also smtpmail.el needs to be patched so
it accepts the old-style flat lists and the gnus-parse-netrc style
output.

Thanks
Ted




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: smtpmail-auth-credentials from authinfo
  2002-04-19 15:41   ` Ted Zlatanov
@ 2002-04-19 15:55     ` Simon Josefsson
  2002-04-23 15:53       ` Ted Zlatanov
  0 siblings, 1 reply; 9+ messages in thread
From: Simon Josefsson @ 2002-04-19 15:55 UTC (permalink / raw)
  Cc: ding, scranefield

On Fri, 19 Apr 2002, Ted Zlatanov wrote:

> Should I extract that to authinfo.el (or netrc.el?)  so it can be
> integrated with smtpmail.el?

I think that would be a good idea.  nntp.el, imap.el and sieve.el would 
also need to be changed, and maybe more stuff.

> Also smtpmail.el needs to be patched so it accepts the old-style flat
> lists and the gnus-parse-netrc style output.

I think it would be better if smtpmail.el looked in .authinfo by default, 
and not touch the `smtpmail-auth-credentials' stuff.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: smtpmail-auth-credentials from authinfo
  2002-04-19 15:55     ` Simon Josefsson
@ 2002-04-23 15:53       ` Ted Zlatanov
  2002-04-23 17:23         ` Simon Josefsson
  0 siblings, 1 reply; 9+ messages in thread
From: Ted Zlatanov @ 2002-04-23 15:53 UTC (permalink / raw)
  Cc: ding, scranefield

[-- Attachment #1: Type: text/plain, Size: 1793 bytes --]

On Fri, 19 Apr 2002, jas@extundo.com wrote:
> On Fri, 19 Apr 2002, Ted Zlatanov wrote:
> 
>> Should I extract that to authinfo.el (or netrc.el?)  so it can be
>> integrated with smtpmail.el?
> 
> I think that would be a good idea.  nntp.el, imap.el and sieve.el
> would also need to be changed, and maybe more stuff.

I am attaching the netrc.el file, and the patch to gnus-util.el that
will provide backward compatibility (via defalias calls) until the
maintainers of the respective modules want to move to the netrc
function names.

I had to do

(eval-and-compile
  (defalias 'netrc-point-at-eol
    (if (fboundp 'point-at-eol)
	'point-at-eol
      'line-end-position)))

instead of 

(defalias 'netrc-point-at-eol
  (if (fboundp 'point-at-eol)
      'point-at-eol
    'line-end-position))

I'm not sure why the compilation was having problems with the
function without the eval-and-compile...  The rest was very easy
though.

>> Also smtpmail.el needs to be patched so it accepts the old-style
>> flat lists and the gnus-parse-netrc style output.
> 
> I think it would be better if smtpmail.el looked in .authinfo by
> default, and not touch the `smtpmail-auth-credentials' stuff.

When I know that the netrc.el functionality is accepted, I will try to
modify smtpmail.el further to work with the netrc interface.
smtpmail.el ships with Emacs, while netrc.el does not (yet?), so it
doesn't make sense to modify smtpmail.el to rely on the netrc
functionality only.  It should look for netrc first, and failing that
it should try the smtpmail-auth-credentials.  I would appreciate
comments from Stephen Cranefield, who's noted in the smtpmail.el
credits as the AUTH support author.  It would also be good to know the
chances of having netrc.el included in the main Emacs distro.

Thanks
Ted


[-- Attachment #2: netrc.el --]
[-- Type: application/emacs-lisp, Size: 3858 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: gnus-util-netrc.patch --]
[-- Type: text/x-patch, Size: 3414 bytes --]

--- gnus-util.el	Tue Apr 23 11:50:53 2002
+++ gnus-util.el.new	Tue Apr 23 11:39:58 2002
@@ -38,6 +38,7 @@
   (defvar nnmail-pathname-coding-system))
 (require 'nnheader)
 (require 'time-date)
+(require 'netrc)
 
 (eval-and-compile
   (autoload 'message-fetch-field "message")
@@ -62,6 +63,11 @@
 	  (setq start (- (length string) tail))))
       string))))
 
+;;; bring in the netrc functions as aliases
+(defalias 'gnus-netrc-get 'netrc-get)
+(defalias 'gnus-netrc-machine 'netrc-machine)
+(defalias 'gnus-parse-netrc 'netrc-parse)
+
 (defun gnus-boundp (variable)
   "Return non-nil if VARIABLE is bound and non-nil."
   (and (boundp variable)
@@ -899,93 +905,6 @@
     (unwind-protect
 	(apply 'run-hooks funcs)
       (set-buffer buf))))
-
-;;;
-;;; .netrc and .authinforc parsing
-;;;
-
-(defun gnus-parse-netrc (file)
-  "Parse FILE and return an list of all entries in the file."
-  (when (file-exists-p file)
-    (with-temp-buffer
-      (let ((tokens '("machine" "default" "login"
-		      "password" "account" "macdef" "force"
-		      "port"))
-	    alist elem result pair)
-	(insert-file-contents file)
-	(goto-char (point-min))
-	;; Go through the file, line by line.
-	(while (not (eobp))
-	  (narrow-to-region (point) (gnus-point-at-eol))
-	  ;; For each line, get the tokens and values.
-	  (while (not (eobp))
-	    (skip-chars-forward "\t ")
-	    ;; Skip lines that begin with a "#".
-	    (if (eq (char-after) ?#)
-		(goto-char (point-max))
-	      (unless (eobp)
-		(setq elem
-		      (if (= (following-char) ?\")
-			  (read (current-buffer))
-			(buffer-substring
-			 (point) (progn (skip-chars-forward "^\t ")
-					(point)))))
-		(cond
-		 ((equal elem "macdef")
-		  ;; We skip past the macro definition.
-		  (widen)
-		  (while (and (zerop (forward-line 1))
-			      (looking-at "$")))
-		  (narrow-to-region (point) (point)))
-		 ((member elem tokens)
-		  ;; Tokens that don't have a following value are ignored,
-		  ;; except "default".
-		  (when (and pair (or (cdr pair)
-				      (equal (car pair) "default")))
-		    (push pair alist))
-		  (setq pair (list elem)))
-		 (t
-		  ;; Values that haven't got a preceding token are ignored.
-		  (when pair
-		    (setcdr pair elem)
-		    (push pair alist)
-		    (setq pair nil)))))))
-	  (when alist
-	    (push (nreverse alist) result))
-	  (setq alist nil
-		pair nil)
-	  (widen)
-	  (forward-line 1))
-	(nreverse result)))))
-
-(defun gnus-netrc-machine (list machine &optional port defaultport)
-  "Return the netrc values from LIST for MACHINE or for the default entry.
-If PORT specified, only return entries with matching port tokens.
-Entries without port tokens default to DEFAULTPORT."
-  (let ((rest list)
-	result)
-    (while list
-      (when (equal (cdr (assoc "machine" (car list))) machine)
-	(push (car list) result))
-      (pop list))
-    (unless result
-      ;; No machine name matches, so we look for default entries.
-      (while rest
-	(when (assoc "default" (car rest))
-	  (push (car rest) result))
-	(pop rest)))
-    (when result
-      (setq result (nreverse result))
-      (while (and result
-		  (not (equal (or port defaultport "nntp")
-			      (or (gnus-netrc-get (car result) "port")
-				  defaultport "nntp"))))
-	(pop result))
-      (car result))))
-
-(defun gnus-netrc-get (alist type)
-  "Return the value of token TYPE from ALIST."
-  (cdr (assoc type alist)))
 
 ;;; Various
 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: smtpmail-auth-credentials from authinfo
  2002-04-23 15:53       ` Ted Zlatanov
@ 2002-04-23 17:23         ` Simon Josefsson
  2002-04-25 19:25           ` Ted Zlatanov
  0 siblings, 1 reply; 9+ messages in thread
From: Simon Josefsson @ 2002-04-23 17:23 UTC (permalink / raw)
  Cc: scranefield

Ted Zlatanov <teodor.zlatanov@divine.com> writes:

> I am attaching the netrc.el file, and the patch to gnus-util.el that
> will provide backward compatibility (via defalias calls) until the
> maintainers of the respective modules want to move to the netrc
> function names.

I commited it to CVS.  Have you signed FSF papers?  I'm not sure it is
required, strictly speaking the contribution was less than 10 lines, I
think.

>>> Also smtpmail.el needs to be patched so it accepts the old-style
>>> flat lists and the gnus-parse-netrc style output.
>> 
>> I think it would be better if smtpmail.el looked in .authinfo by
>> default, and not touch the `smtpmail-auth-credentials' stuff.
>
> When I know that the netrc.el functionality is accepted, I will try to
> modify smtpmail.el further to work with the netrc interface.
> smtpmail.el ships with Emacs, while netrc.el does not (yet?), so it
> doesn't make sense to modify smtpmail.el to rely on the netrc
> functionality only.  It should look for netrc first, and failing that
> it should try the smtpmail-auth-credentials.  I would appreciate
> comments from Stephen Cranefield, who's noted in the smtpmail.el
> credits as the AUTH support author.  It would also be good to know the
> chances of having netrc.el included in the main Emacs distro.

I agree.  Adding netrc.el to XEmacs mail-lib and patching smtpmail.el
in (X)Emacs shouldn't be a problem, I'll ask if it is OK to add
netrc.el on emacs-devel (altough patches could probably help
illustrating how it would work).  If you start patching smtpmail.el,
look at the latest Emacs CVS version.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: smtpmail-auth-credentials from authinfo
  2002-04-23 17:23         ` Simon Josefsson
@ 2002-04-25 19:25           ` Ted Zlatanov
  0 siblings, 0 replies; 9+ messages in thread
From: Ted Zlatanov @ 2002-04-25 19:25 UTC (permalink / raw)
  Cc: scranefield

On Tue, 23 Apr 2002, jas@extundo.com wrote:
> Ted Zlatanov <teodor.zlatanov@divine.com> writes:
> 
>> I am attaching the netrc.el file, and the patch to gnus-util.el
>> that will provide backward compatibility (via defalias calls) until
>> the maintainers of the respective modules want to move to the netrc
>> function names.
> 
> I commited it to CVS.  Have you signed FSF papers?  I'm not sure it
> is required, strictly speaking the contribution was less than 10
> lines, I think.

I've signed the papers already.

> I agree.  Adding netrc.el to XEmacs mail-lib and patching
> smtpmail.el in (X)Emacs shouldn't be a problem, I'll ask if it is OK
> to add netrc.el on emacs-devel (altough patches could probably help
> illustrating how it would work).  If you start patching smtpmail.el,
> look at the latest Emacs CVS version.

I see you already made the changes - thanks.  Let me know if I need to
do anything else, it seems like all the modifications we discussed are
in.

Thanks
Ted




^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: smtpmail-auth-credentials from authinfo
@ 2002-04-23 21:51 Stephen Cranefield
  0 siblings, 0 replies; 9+ messages in thread
From: Stephen Cranefield @ 2002-04-23 21:51 UTC (permalink / raw)
  Cc: ding

Ted Zlatanov wrote:
>                                                  I would appreciate
> comments from Stephen Cranefield, who's noted in the smtpmail.el
> credits as the AUTH support author.

Hi Ted,

I can't make any intelligent comment on your proposal because I only
ever became a reluctant emacs hacker when the mail server I used
had its configuration changed to require authentication.  I haven't
touched any emacs lisp since then and I have to confess that I have
never heard of authinfo.el and netrc.el before.

However, in general terms I think it is a good idea to allow users
to set their password once and have it stored for future sessions -
but not in plain text.  I have just been setting my password when
prompted each time I send my first mail message for the session,
but I'd certainly like to have a better way, so I'm all for any
enhancements that support this.

Regards,
Stephen



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2002-04-25 19:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-19 14:21 smtpmail-auth-credentials from authinfo Ted Zlatanov
2002-04-19 14:47 ` Simon Josefsson
2002-04-19 15:41   ` Ted Zlatanov
2002-04-19 15:55     ` Simon Josefsson
2002-04-23 15:53       ` Ted Zlatanov
2002-04-23 17:23         ` Simon Josefsson
2002-04-25 19:25           ` Ted Zlatanov
2002-04-19 15:33 ` Kai Großjohann
2002-04-23 21:51 Stephen Cranefield

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).