diff options
| author | spew <devnull@localhost> | 2017-03-22 17:10:35 -0500 |
|---|---|---|
| committer | spew <devnull@localhost> | 2017-03-22 17:10:35 -0500 |
| commit | b7ee84c65da44dfed3d8ceca424da511b0c1412f (patch) | |
| tree | e1850af8637e8f6be94a89e3948804782425852f | |
| parent | 8b6621a36032d2ff8b98ce89f995c8277aeb935f (diff) | |
| download | plan9front-b7ee84c65da44dfed3d8ceca424da511b0c1412f.tar.xz | |
upas/smtp: Revert smtp dial string behavior to match that of old upas (thanks sam-d)
Also do some cleanup around buffers and memory management
| -rw-r--r-- | sys/src/cmd/upas/smtp/smtp.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/sys/src/cmd/upas/smtp/smtp.c b/sys/src/cmd/upas/smtp/smtp.c index 99e5e631d..a9880de02 100644 --- a/sys/src/cmd/upas/smtp/smtp.c +++ b/sys/src/cmd/upas/smtp/smtp.c @@ -493,20 +493,26 @@ smtpcram(DS *ds) static char * doauth(char *methods) { - char *buf, *err; + static char buf[1024]; + char *s, *se, *err; 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", - ds.host, user); - if (p == nil) + se = buf+sizeof(buf); + s = seprint(buf, se, "proto=pass service=smtp server=%q", ds.host); + if(user) + seprint(s, se, " user=%q", user); + + p = auth_getuserpasswd(nil, "%s", buf); + if (p == nil) { + syslog(0, "smtp.fail", "failed to get userpasswd for %s", buf); return Giveup; + } err = Retry; if (strstr(methods, "LOGIN")){ @@ -524,18 +530,9 @@ doauth(char *methods) err = nil; } - else - if (strstr(methods, "PLAIN")){ - n = strlen(p->user) + strlen(p->passwd) + 2; - buf = malloc(n+1); - if (buf == nil) { - free(buf); - goto out; /* Out of memory */ - } - snprint(buf, n, "%c%s%c%s", 0, p->user, 0, p->passwd); - dBprint("AUTH PLAIN %.*[\r\n", n, buf); - memset(buf, 0, n); - free(buf); + else if (strstr(methods, "PLAIN")){ + s = seprint(buf, se, "%c%s%c%s", 0, p->user, 0, p->passwd); + dBprint("AUTH PLAIN %.*[\r\n", s-buf, buf); if (getreply() != 2) goto out; err = nil; |
