If you are not Russ, please let him do this one. This fixes the expand_meta for both auth (so factotum gets the expanded relay's name) and for the dns lookup for the mx record. -Steve Reference: /n/sources/patch/applied/smtp-meta Date: Tue Feb 15 14:03:12 CET 2005 --- /sys/src/cmd/upas/smtp/smtp.c Tue Feb 15 13:31:22 2005 +++ /sys/src/cmd/upas/smtp/smtp.c Tue Feb 15 13:31:18 2005 @@ -372,19 +372,19 @@ static char * doauth(char *methods) { - char *sys, *buf, *base64; + char *buf, *base64; UserPasswd *p; int n; + DS ds; - sys = expand_meta(ddomain); - //fprint(2, "expand address %s -> %s\n", ddomain, sys); + dial_string_parse(ddomain, &ds); if(user != nil) p = auth_getuserpasswd(nil, - "proto=pass service=smtp server=%q user=%q", sys, user); + "proto=pass service=smtp server=%q user=%q", ds.host, user); else p = auth_getuserpasswd(nil, - "proto=pass service=smtp server=%q", sys); + "proto=pass service=smtp server=%q", ds.host); if (p == nil) return Giveup; --- /sys/src/cmd/upas/smtp/smtp.h Tue Feb 15 13:31:36 2005 +++ /sys/src/cmd/upas/smtp/smtp.h Tue Feb 15 13:31:33 2005 @@ -19,6 +19,17 @@ int source; }; +typedef struct DS DS; +struct DS { + /* dist string */ + char buf[128]; + char exp[128]; + char *netdir; + char *proto; + char *host; + char *service; +}; + extern Field *firstfield; extern Field *lastfield; extern Node *usender; @@ -47,4 +58,4 @@ Node* whiten(Node*); void yycleanup(void); int mxdial(char*, char*, char*); -char* expand_meta(char *); +void dial_string_parse(char*, DS*); --- /sys/src/cmd/upas/smtp/mxdial.c Tue Feb 15 13:31:54 2005 +++ /sys/src/cmd/upas/smtp/mxdial.c Sat Feb 19 16:24:20 2005 @@ -1,5 +1,6 @@ #include "common.h" #include +#include /* to publish dial_string_parse */ enum { @@ -16,16 +17,6 @@ }; static Mx mx[Nmx]; -typedef struct DS DS; -struct DS { - /* dist string */ - char buf[128]; - char *netdir; - char *proto; - char *host; - char *service; -}; - Ndb *db; extern int debug; @@ -33,7 +24,6 @@ static int mxlookup1(DS*, char*); static int compar(void*, void*); static int callmx(DS*, char*, char*); -static void dial_string_parse(char*, DS*); extern int cistrcmp(char*, char*); int @@ -234,7 +224,7 @@ } /* break up an address to its component parts */ -static void +void dial_string_parse(char *str, DS *ds) { char *p, *p2; @@ -264,48 +254,46 @@ ds->service = strchr(ds->host, '!'); if(ds->service) *ds->service++ = 0; + if (*ds->host == '$') + expand_meta(ds); + +// fprint(2, "%s -> %s%s!%s!%s\n", str, ds->netdir, ds->proto, ds->host, ds->service); } -char * -expand_meta(char *addr) +static void +expand_meta(DS *ds) { - DS ds; int fd, n; - char *p, cs[128]; - static char buf[1024]; - - dial_string_parse(addr, &ds); + char *p, *net, cs[128], buf[128]; - if (*ds.host != '$') - return addr; - if (! ds.netdir) - ds.netdir = "/net"; + net = (ds->netdir)? ds->netdir: "/net"; - snprint(cs, sizeof(cs), "%s/cs", ds.netdir); + snprint(cs, sizeof(cs), "%s/cs", net); if ((fd = open(cs, ORDWR)) == -1){ - syslog(0, "smtp", "cannot open cs: %r", cs); - return addr; + syslog(0, "smtp", "%s cannot open: %r", cs); + return; } - snprint(buf, sizeof(buf), "!ipinfo %s", ds.host+1); // +1 to skip $ + snprint(buf, sizeof(buf), "!ipinfo %s", ds->host+1); // +1 to skip $ if(write(fd, buf, strlen(buf)) <= 0){ syslog(0, "smtp", "%s to %s - write failed: %r", buf, cs); close(fd); - return addr; + return; } seek(fd, 0, 0); - if((n = read(fd, buf, sizeof(buf)-1)) < 0){ + if((n = read(fd, ds->exp, sizeof(ds->exp)-1)) < 0){ syslog(0, "smtp", "%s - read failed: %r", cs); close(fd); - return addr; + return; } close(fd); - buf[n] = 0; - if((p = strchr(buf, '=')) == nil){ - syslog(0, "smtp", "%q from %s - bad response: %r", buf, cs); - return addr; + ds->exp[n] = 0; + if((p = strchr(ds->exp, '=')) == nil){ + syslog(0, "smtp", "%q from %s - bad response: %r", ds->exp, cs); + return; } - return p+1; // +1 to skip = + ds->host = p+1; // +1 to skip = } +