9front - general discussion about 9front
 help / color / mirror / Atom feed
From: inkswinc@gmail.com
To: 9front@9front.org
Subject: nupas auth: incompatibility and error messaging
Date: Wed, 22 Mar 2017 00:02:23 +0000	[thread overview]
Message-ID: <197eef1bfc064ad154d32b26d2c10001@youmu.sam-d.org> (raw)

Nupas' smtp.c file uses a different var in the 'server=' part of the
string it queries from factotum than upas did: where upas used
'server=smtp.gmail.com' (from the dialstring passed on the
commandline), nupas uses 'server=gmail-smtp-msa.l.google.com' (result
of some lookup, I presume) Not only does this break backwards
compatibility, but it also feels a little more brittle to me; the
latter name seems likely to change.

Not sure where else this difference occurs; it doesn't seem to in
imaps, which I also use, but it does seem to in /sys/lib/tls/smtp
(though with gmail that needs to change all the time anyways, so...)

It also doesn't do a good job of error messaging when auth fails; it
just shows up as an error in the 'hello' phase, which sucks.

Following patch is an attempt at resolving those issues; it works for
me.  This is the first time I've ever given anyone else any C code
I've written, so feel free to be ruthless if you see anything
suboptimal.

diff -r a01d0802d023 sys/src/cmd/upas/smtp/smtp.c
--- a/sys/src/cmd/upas/smtp/smtp.c	Mon Mar 20 19:15:40 2017 +0100
+++ b/sys/src/cmd/upas/smtp/smtp.c	Tue Mar 21 23:49:01 2017 +0000
@@ -493,20 +493,27 @@
 static char *
 doauth(char *methods)
 {
-	char *buf, *err;
+	char *buf, *err, *factstring;
 	UserPasswd *p;
 	int n;
 	DS ds;
 
-	dialstringparse(ddomain, &ds);
+	dialstringparse(farend, &ds);
 	if(strstr(methods, "CRAM-MD5"))
 		return smtpcram(&ds);
 
-	p = auth_getuserpasswd(nil,
-		user?"proto=pass service=smtp server=%q user=%q":"proto=pass service=smtp server=%q",
+	factstring = smprint(user?
+		"proto=pass service=smtp server=%q user=%q":
+		"proto=pass service=smtp server=%q",
 		ds.host, user);
-	if (p == nil)
+
+	p = auth_getuserpasswd(nil,factstring);
+	if (p == nil) {
+		syslog(0, "smtp.fail", "failed to get userpasswd for %s", factstring);
+		free(factstring);
 		return Giveup;
+	}
+	free(factstring);
 
 	err = Retry;
 	if (strstr(methods, "LOGIN")){


Thanks,
sam-d


             reply	other threads:[~2017-03-22  0:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-22  0:02 inkswinc [this message]
2017-03-22  2:53 ` [9front] " Benjamin Purcell
2017-03-22  2:58   ` Benjamin Purcell

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=197eef1bfc064ad154d32b26d2c10001@youmu.sam-d.org \
    --to=inkswinc@gmail.com \
    --cc=9front@9front.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.
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).