Two changes, the major one allows meta chars in the destination address so when you are using an smtp relay you can get the relay's name from ndb ($smtp). The second is more parochial and controlled by a #ifdef :-). We require authentication but do not support TLS encryption at work so allow this mode perhaps it should be a seperate command line option (-i insecure mode)? -Steve Notes: Sat Oct 16 00:38:13 EDT 2004 rsc i put a -i insecure flag in. please change meta to use csipinfo instead of ndbipinfo so that the code doesn't look in the wrong network database. (csipinfo uses /net/cs, which is guaranteed to be what dial is going to use later). thanks. Reference: /n/sources/patch/sorry/metas-in-smtp Date: Sat Oct 16 22:57:24 CES 2004 Reviewed-by: rsc --- /sys/src/cmd/upas/smtp/smtp.c Sat Oct 16 22:57:24 2004 +++ /sys/src/cmd/upas/smtp/smtp.c Sat Oct 16 22:57:24 2004 @@ -4,6 +4,7 @@ #include #include #include +#include static char* connect(char*); static char* dotls(char*); @@ -339,21 +340,50 @@ return(hello(me, 1)); } +char * +meta(char *m) +{ + Ndb *db; + char *r, *s = m +1; + Ndbtuple *t; + + if ((db = ndbopen(nil)) == nil) + return m; + + if ((t = ndbipinfo(db, "sys", alt_sysname_read(), &s, 1)) == nil){ + ndbclose(db); + return m; + } + r = strdup(t->val); + ndbfree(t); + ndbclose(db); + return r; +} + + static char * doauth(void) { - char *buf, *base64; + char *sys, *buf, *base64; UserPasswd *p; int n; + sys = ddomain; + if (*sys == '$') + sys = meta(sys); + if(user != nil) p = auth_getuserpasswd(nil, - "proto=pass service=smtp server=%q user=%q", ddomain, user); + "proto=pass service=smtp server=%q user=%q", sys, user); else p = auth_getuserpasswd(nil, - "proto=pass service=smtp server=%q", ddomain); - if (p == nil) + "proto=pass service=smtp server=%q", sys); + + if (p == nil){ + syslog(0, "smtp.fail", "%r"); return Giveup; + } + n = strlen(p->user) + strlen(p->passwd) + 3; buf = malloc(n); base64 = malloc(2 * n); @@ -421,7 +451,10 @@ s_free(r); return(dotls(me)); } - if(tryauth && encrypted && + if(tryauth && +#ifdef AUTH_ON_TLS_SESSIONS_ONLY +encrypted && +#endif (strncmp(s, "250 AUTH", strlen("250 AUTH")) == 0 || strncmp(s, "250-AUTH", strlen("250 AUTH")) == 0) && strstr(s, "PLAIN") != nil){