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