20static stralloc
key = {0};
21static stralloc domain = {0};
22static stralloc wildhost = {0};
24static stralloc rcptline = {0};
25static stralloc vkey = {0};
26static stralloc verp = {0};
27static stralloc
user = {0};
28static stralloc ukey = {0};
29static int flagrcpts = 0;
51 if (flagrcpts != 1)
return flagrcpts;
66 static stralloc mailaddress = {0};
68 char *
childargs[7] = {0, 0, 0, 0, 0, 0, 0};
69 stralloc pamarg = {0};
70 stralloc pamname = {0};
71 stralloc pamarg1 = {0};
72 stralloc pamarg2 = {0};
73 stralloc pamarg3 = {0};
74 stralloc pamarg4 = {0};
75 stralloc pamarg5 = {0};
77 for (i = 0; (ch = pam[i]); i++) {
80 if (!stralloc_append(&pamarg,&ch))
return -2;
81 if (ch ==
' ' || ch ==
'\n' || i == str_len(pam) - 1) {
82 if (!stralloc_0(&pamarg))
return -2;
85 if (!stralloc_copy(&pamname,&pamarg))
return -2;
88 if (!stralloc_copy(&pamarg1,&pamarg))
return -2;
91 if (!stralloc_copy(&pamarg2,&pamarg))
return -2;
94 if (!stralloc_copy(&pamarg3,&pamarg))
return -2;
97 if (!stralloc_copy(&pamarg4,&pamarg))
return -2;
100 if (!stralloc_copy(&pamarg5,&pamarg))
return -2;
111 if (pipe(pi) == -1)
return -3;
112 if (pi[0] !=
FDAUTH)
return -3;
114 switch (child = fork()) {
119 if (fd_copy(
FDAUTH,pi[0]) == -1)
return -3;
129 if (!stralloc_0(&mailaddress))
return -2;
130 if (!stralloc_0(&mailaddress))
return -2;
131 if (!stralloc_0(&mailaddress))
return -2;
134 if (buffer_put(&
br,mailaddress.s,mailaddress.len) == -1)
return -3;
135 if (buffer_flush(&
br) == -1)
return -3;
138 if (wait_pid(&wstat,child) == -1)
return -3;
139 if (wait_crashed(wstat))
return -3;
140 return wait_exitcode(wstat);
143int recipients_parse(
char *rhost,
int rlen,
char *
addr,
char *rkey,
int klen,
char *vaddr,
char *vkey,
int vlen,
char *ukey,
int ulen)
150 static stralloc
line = {0};
155 if (!stralloc_cats(&wildhost,rhost))
return -2;
156 if (!stralloc_0(&wildhost))
return -2;
158 for (i = 0; i < rcptline.len; ++i) {
159 if (!stralloc_append(&
line,&rcptline.s[i]))
return -2;
161 if (rcptline.s[i] ==
'\0') {
162 if (!stralloc_0(&
line))
return -2;
168 if (!str_diffn(
line.s,wildhost.s,wildhost.len - 1))
return 4;
170 if (!str_diffn(
line.s,
"@",1))
171 if (!str_diffn(
line.s + 1,rhost,rlen - 1)) seenhost = 1;
175 if (!str_diffn(
line.s,rhost,
j - 1)) seenhost = 2;
177 if (!str_diffn(
line.s,rhost,
k - 1)) seenhost = 3;
179 if (!str_diffn(
line.s,rhost,u - 1)) seenhost = 4;
182 if (!str_diffn(
line.s,
"!*",2))
return 5;
185 if (seenhost || !str_diffn(
line.s,
"*",1)) {
187 if (vlen > 0 && r != 0)
189 if (r == 0)
return 2;
192 if (u && u <
line.len)
193 if (seenhost || !str_diffn(
line.s,
"*",1)) {
194 fdrcps = open_read(
"users/assign.cdb");
196 cdb_init(&
cdb,fdrcps);
197 r = cdb_find(&
cdb,ukey,ulen - 1);
205 if (seenhost || !str_diffn(
line.s,
"*",1)) {
206 fdrcps = open_read(
line.s +
j + 1);
208 cdb_init(&
cdb,fdrcps);
210 r = cdb_find(&
cdb,rkey,klen - 2);
211 if (vlen > 2 && r == 0)
212 r = cdb_find(&
cdb,vkey,vlen - 2);
220 fdrcps = open_read(
line.s);
222 cdb_init(&
cdb,fdrcps);
223 r = cdb_find(&
cdb,rkey,klen - 2);
224 if (vlen > 0 && r == 0)
225 r = cdb_find(&
cdb,vkey,vlen - 2);
244 if (flagrcpts != 1)
return 10;
246 at = byte_rchr(
buf,len,
'@');
247 if (at && at < len) {
248 if (!stralloc_copyb(&domain,
buf + at + 1,len - at - 1))
return -2;
249 if (!stralloc_copyb(&
address,
buf,len))
return -2;
251 if (!stralloc_copyb(&
address,
buf,len))
return -2;
252 if (!stralloc_append(&
address,
"@"))
return -2;
254 if (!stralloc_cat(&
address,&domain))
return -2;
256 if (!stralloc_copyb(&
user,
buf,at))
return -2;
258 if (!stralloc_0(&
user))
return -2;
259 if (!stralloc_0(&
address))
return -2;
260 if (!stralloc_0(&domain))
return -2;
264 if (!stralloc_0(&
key))
return -2;
265 case_lowerb(
key.s,
key.len);
266 case_lowerb(domain.s,domain.len);
269 if (!stralloc_cat(&ukey,&
user))
return -2;
270 if (!stralloc_0(&ukey))
return -2;
271 case_lowerb(ukey.s,ukey.len);
274 for (i = 0; i < at; i++) {
276 if (!stralloc_copyb(&verp,
buf,i + 1))
return -2;
277 if (!stralloc_append(&verp,
"@"))
return -2;
278 if (!stralloc_cat(&verp,&domain))
return -2;
280 if (!stralloc_cat(&vkey,&verp))
return -2;
281 if (!stralloc_0(&vkey))
return -2;
282 case_lowerb(vkey.s,vkey.len);
int control_readfile(stralloc *sa, char *fn, int flagme)
int stralloc_copys(stralloc *, char const *)
int recipients_parse(char *rhost, int rlen, char *addr, char *rkey, int klen, char *vaddr, char *vkey, int vlen, char *ukey, int ulen)
int callapam(char *pam, char *addr)
int recipients(char *buf, int len)
char rcptbuf[BUFSIZE_AUTH]
ssize_t safewrite(int, char *, int)