9 * hack to allow smtp forwarding.
10 * hide the peer IP address under a rock in the ratifier FS.
13 enableForwarding(void)
15 char buf[64], peer[64], *p;
28 fd = open("/srv/ratify", ORDWR);
31 if(!mount(fd, -1, "/mail/ratify", MBEFORE, "")){
37 strncpy(peer, remote, sizeof(peer));
38 peer[sizeof(peer) - 1] = '\0';
39 p = strchr(peer, '!');
43 snprint(buf, sizeof(buf), "/mail/ratify/trusted/%s#32", peer);
46 * if the address is already there and the user owns it,
47 * remove it and recreate it to give him a new time quanta.
49 if(access(buf, 0) >= 0 && remove(buf) < 0)
52 fd = create(buf, OREAD, 0666);
58 setupuser(AuthInfo *ai)
64 strecpy(username, username+sizeof username, ai->cuid);
66 if(auth_chuid(ai, nil) < 0)
67 bye("user auth failed: %r");
70 strecpy(username, username+sizeof username, getuser());
72 if(newns(username, 0) < 0)
73 bye("user login failed: %r");
76 * hack to allow access to outgoing smtp forwarding
80 snprint(mboxDir, MboxNameLen, "/mail/box/%s", username);
81 if(myChdir(mboxDir) < 0)
82 bye("can't open user's mailbox");
86 bye("can't initialize mail system");
89 execl("/bin/upas/fs", "upas/fs", "-np", nil);
96 if((w=wait()) == nil || w->pid != pid || w->msg[0] != '\0')
97 bye("can't initialize mail system");
107 t = Brdline(&bin, '\n');
115 if(n == 0 || strcmp(t, "*") == 0)
118 s = binalloc(&parseBin, n + 1, 0);
119 n = dec64((uchar*)s, n, t, n);
125 * rfc 2195 cram-md5 authentication
135 if((cs = auth_challenge("proto=cram role=server")) == nil)
136 return "couldn't get cram challenge";
139 s = binalloc(&parseBin, n * 2, 0);
140 n = enc64(s, n * 2, (uchar*)cs->chal, n);
143 Bprint(&bout, "\r\n");
144 if(Bflush(&bout) < 0)
149 return "client cancelled authentication";
153 bye("bad auth response");
155 strncpy(username, s, UserNameLen);
156 username[UserNameLen-1] = '\0';
160 cs->nresp = strlen(t);
161 if((ai = auth_response(cs)) == nil)
162 return "login failed";
169 passLogin(char *user, char *secret)
173 uchar digest[MD5dlen];
174 char response[2*MD5dlen+1];
177 if((cs = auth_challenge("proto=cram role=server")) == nil)
180 hmac_md5((uchar*)cs->chal, strlen(cs->chal),
181 (uchar*)secret, strlen(secret), digest,
183 for(i = 0; i < MD5dlen; i++)
184 snprint(response + 2*i, sizeof(response) - 2*i, "%2.2ux", digest[i]);
188 cs->nresp = strlen(response);
189 ai = auth_response(cs);