s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
qmail-rspawn.c
Go to the documentation of this file.
1#include <unistd.h>
2#include <sys/stat.h>
3#include "fd.h"
4#include "wait.h"
5#include "buffer.h"
6#include "exit.h"
7#include "error.h"
8#include "ipalloc.h"
9#include "tcpto.h"
10#include "auto_qmail.h"
11#include "open.h"
12#include "pathexec.h"
13
14void initialize(int argc,char **argv) { tcpto_clean(); }
15
17
18void report(buffer *log,int wstat,char *s,int len)
19{
20 int j;
21 int k;
22 int result;
23 int orr;
24
25 if (wait_crashed(wstat)) { buffer_putsflush(log,"Zqmail-spawn: qmail-remote crashed.\n"); return; }
26
27 switch (wait_exitcode(wstat)) {
28 case 0: break;
29 case 111: buffer_putsflush(log,"Zqmail-rspawn: Unable to run qmail-remote.\n"); break;
30 default: buffer_putsflush(log,"Dqmail-rspawn: Unable to run qmail-remote. \n"); return;
31 }
32
33 if (!len) { buffer_putsflush(log,"Zqmail-rspawn: qmail-remote produced no output.\n"); return; }
34
35 result = -1;
36 j = 0;
37
38 for (k = 0; k < len; ++k)
39 if (!s[k]) {
40 if (s[j] == 'K') { result = 1; break; }
41 if (s[j] == 'Z') { result = 0; break; }
42 if (s[j] == 'D') break;
43 j = k + 1;
44 }
45
46 orr = result;
47
48 switch (s[0]) {
49 case 's': orr = 0; break;
50 case 'h': orr = -1;
51 }
52
53 switch (orr) {
54 case 1: buffer_put(log,"K",1); break;
55 case 0: buffer_put(log,"Z",1); break;
56 case -1: buffer_put(log,"D",1); break;
57 }
58
59 for (k = 1; k < len;)
60 if (!s[k++]) {
61 buffer_puts(log,s + 1);
62 if (result <= orr)
63 if (k < len)
64 switch (s[k]) {
65 case 'Z': case 'D': case 'K':
66 buffer_puts(log,s + k + 1);
67 }
68 break;
69 }
70}
71
72int spawn(int fdmess,int fdout,const char *s,char *r,const int at)
73{
74 int f;
75 char *(args[5]);
76 struct stat st;
77
78 if (chdir(auto_qmail) == -1) _exit(110);
79 if (!stat("control/dkimdomains",&st))
80 args[0] = "qmail-dksign";
81 else
82 args[0] = "qmail-remote";
83 args[1] = r + at + 1;
84 args[2] = s;
85 args[3] = r;
86 args[4] = 0;
87
88 if (chdir("queue/mess") == -1) _exit(110);
89
90 if (!(f = vfork())) {
91 if (fd_move(0,fdmess) == -1) _exit(111);
92 if (fd_move(1,fdout) == -1) _exit(111);
93 if (fd_copy(2,1) == -1) _exit(111);
94 pathexec(args);
95 if (errno) _exit(111);
96 _exit(100);
97 }
98 return f;
99}
char auto_qmail[]
void _exit()
int truncreport
Definition: qmail-rspawn.c:16
int j
Definition: qmail-send.c:920
int fdout
Definition: qmail-todo.c:143
uint32_t k[64]
Definition: sha256.c:26
void initialize()
int spawn()
void report()
void tcpto_clean()
Definition: tcpto_clean.c:8