41int tapcontrol(stralloc *,stralloc *,stralloc *);
44stralloc tapcontrols = {0};
47stralloc fromaddr = {0};
48stralloc toaddrs = {0};
49stralloc tapaddr = {0};
71 if (unlink(
intdfn) == -1)
return;
75 if (unlink(
messfn) == -1)
return;
94static unsigned int receivedfmt(
char *s)
100 i = fmt_str(s,
"Received: (qmail "); len += i;
if (s) s += i;
101 i = fmt_ulong(s,
mypid); len += i;
if (s) s += i;
102 i = fmt_str(s,
" invoked "); len += i;
if (s) s += i;
104 i = fmt_str(s,
"by alias"); len += i;
if (s) s += i;
106 i = fmt_str(s,
"from network"); len += i;
if (s) s += i;
108 i = fmt_str(s,
"for bounce"); len += i;
if (s) s += i;
110 i = fmt_str(s,
"by uid "); len += i;
if (s) s += i;
111 i = fmt_ulong(s,
uid); len += i;
if (s) s += i;
113 i = fmt_str(s,
"); "); len += i;
if (s) s += i;
126unsigned int pidfmt(
char *s,
unsigned long seq)
132 i = fmt_str(s,
"pid/"); len += i;
if (s) s += i;
133 i = fmt_ulong(s,
mypid); len += i;
if (s) s += i;
134 i = fmt_str(s,
"."); len += i;
if (s) s += i;
135 i = fmt_ulong(s,
starttime); len += i;
if (s) s += i;
136 i = fmt_str(s,
"."); len += i;
if (s) s += i;
137 i = fmt_ulong(s,seq); len += i;
if (s) s += i;
138 ++len;
if (s) *s++ = 0;
143char *
fnnum(
char *dirslash,
int flagsplit)
159 len =
pidfmt((
char *) 0,seq);
163 for (seq = 1; seq < 10; ++seq) {
164 if (
pidfmt((
char *) 0,seq) > len)
die(81);
179 char *qhpsiargs[6] = { 0, 0, 0, 0, 0, 0 };
185 unsigned int qhpsiminsize = 0;
186 unsigned int qhpsimaxsize = 0;
191 size = (
unsigned int) st.st_size;
193 x = env_get(
"QHPSIMINSIZE");
194 if (x) { scan_ulong(x,&u); qhpsiminsize = (
int) u; }
195 if (qhpsiminsize)
if (
size < qhpsiminsize)
return;
196 x = env_get(
"QHPSIMAXSIZE");
197 if (x) { scan_ulong(x,&u); qhpsimaxsize = (
int) u; }
198 if (qhpsimaxsize)
if (
size > qhpsimaxsize)
return;
201 switch (child = fork()) {
207 qhpsiargs[2] = env_get(
"QHPSIARG1");
208 if (!qhpsiargs[2]) qhpsiargs[2] = 0;
209 qhpsiargs[3] = env_get(
"QHPSIARG2");
210 if (!qhpsiargs[3]) qhpsiargs[3] = 0;
211 qhpsiargs[4] = env_get(
"QHPSIARG3");
212 if (!qhpsiargs[4]) qhpsiargs[4] = 0;
213 x = env_get(
"QHPSIRC");
214 if (x) { scan_ulong(x,&u); qhpsirc = (
int) u; }
215 execvp(*qhpsiargs,qhpsiargs);
218 if (wait_pid(&wstat,child) == -1)
die_qhpsi();
220 childrc = wait_exitcode(wstat);
221 if (childrc == qhpsirc) {
cleanup();
die(32); }
237 if (chdir(
"queue") == -1)
die(62);
243 qhpsi = env_get(
"QHPSI");
249 sig_alarmcatch((
void *)
sigalrm);
250 sig_bugcatch((
void *)
sigbug);
258 if (!stralloc_cats(&tapcontrols,
"/control/tapaddresses")) die_mem();
259 if (!stralloc_0(&tapcontrols)) die_mem();
283 switch (buffer_copy(&
bo,&
bi)) {
306 if (ch !=
'F')
die(91);
309 if (!stralloc_copyb(&fromaddr,
"<",1)) die_mem();
311 for (len = 0; len <
ADDRL; ++len) {
316 if (!stralloc_catb(&fromaddr,&ch,1)) die_mem();
329 if (ch ==
'Q') {
qhpsi = 0;
break; }
330 if (ch !=
'T')
die(91);
333 if (!stralloc_catb(&toaddrs,
">",1)) die_mem();
335 for (len = 0; len <
ADDRL; ++len) {
340 if (!stralloc_catb(&toaddrs,&ch,1)) die_mem();
347 if (tapcontrol(&tapaddr,&fromaddr,&toaddrs) > 0) {
348 if (buffer_put(&
bo,tapaddr.s,tapaddr.len) == -1)
die_write();
358 if ((
fd = open(
todofn,O_RDONLY)) < 0 || fsync(
fd) < 0 || close(
fd))
die(66);
365int tapcontrol(stralloc *tapaddress,stralloc *
mailfrom,stralloc *rcpttos)
372 stralloc chkaddr = {0};
373 stralloc rcptaddr = {0};
379 if (!stralloc_copyb(&chkaddr,
"!",1)) die_mem();
381 if (
constmap(&maptaps,chkaddr.s,chkaddr.len))
return -1;
387 j = 0;
k = str_len(tapaddr);
388 if (
k)
if (!stralloc_catb(tapaddress,
"T",1)) die_mem();
392 if (!stralloc_0(tapaddress)) die_mem();
393 if (!stralloc_catb(tapaddress,
"T",1)) die_mem();
395 if (!stralloc_catb(tapaddress,&ch,1)) die_mem();
397 if (!stralloc_0(tapaddress)) die_mem();
404 if (at < mailfrom->len) {
405 if (!stralloc_copyb(&chkaddr,
"<",1)) die_mem();
406 if (!stralloc_catb(&chkaddr,
mailfrom->s + at,
mailfrom->len - at)) die_mem();
408 tapaddr =
constmap(&maptaps,chkaddr.s,chkaddr.len);
410 j = 0;
k = str_len(tapaddr);
411 if (
k)
if (!stralloc_catb(tapaddress,
"T",1)) die_mem();
415 if (!stralloc_0(tapaddress)) die_mem();
416 if (!stralloc_catb(tapaddress,
"T",1)) die_mem();
418 if (!stralloc_catb(tapaddress,&ch,1)) die_mem();
420 if (!stralloc_0(tapaddress)) die_mem();
428 for (
int n = 0; n < rcpttos->len; n++) {
429 if (n > 1) r = byte_chr(rcpttos->s + n,rcpttos->len,
'>');
430 if (!stralloc_copyb(&rcptaddr,rcpttos->s + n,r)) die_mem();
433 tapaddr =
constmap(&maptaps,rcptaddr.s,rcptaddr.len);
435 j = 0;
k = str_len(tapaddr);
436 if (
k)
if (!stralloc_catb(tapaddress,
"T",1)) die_mem();
440 if (!stralloc_0(tapaddress)) die_mem();
441 if (!stralloc_catb(tapaddress,
"T",1)) die_mem();
443 if (!stralloc_catb(tapaddress,&ch,1)) die_mem();
445 if (!stralloc_0(tapaddress)) die_mem();
451 at = byte_rchr(rcptaddr.s,rcptaddr.len,
'@');
452 if (at < rcptaddr.len) {
453 if (!stralloc_copyb(&chkaddr,
">",1)) die_mem();
454 if (!stralloc_catb(&chkaddr,rcptaddr.s + at,rcptaddr.len - at)) die_mem();
456 tapaddr =
constmap(&maptaps,chkaddr.s,chkaddr.len);
458 j = 0;
k = str_len(tapaddr);
459 if (
k)
if (!stralloc_catb(tapaddress,
"T",1)) die_mem();
463 if (!stralloc_0(tapaddress)) die_mem();
464 if (!stralloc_catb(tapaddress,
"T",1)) die_mem();
466 if (!stralloc_catb(tapaddress,&ch,1)) die_mem();
468 if (!stralloc_0(tapaddress)) die_mem();
int constmap_init(struct constmap *cm, char *s, int len, int flagcolon)
int control_readfile(stralloc *sa, char *fn, int flagme)
unsigned int date822fmt(char *s, struct datetime *dt)
void datetime_tai(struct datetime *dt, datetime_sec t)
int stralloc_copys(stralloc *, char const *)
unsigned int fmtqfn(char *s, char *dirslash, unsigned long id, int flagsplit)
unsigned int pidfmt(char *s, unsigned long seq)
char * fnnum(char *dirslash, int flagsplit)
void qhpsiprog(char *arg)
char outbuf[BUFSIZE_LINE]