30#define WHO "qmail-dksign"
32#define DOMAINKEYS "/ssl/domainkeys/"
65static void out(
char *s) {
if (buffer_puts(&
bo,s) == -1)
_exit(111); }
66static void zero() {
if (buffer_put(&
bo,
"\0",1) == -1)
_exit(111); }
84 out(
"ZOut of memory. (#4.3.0)\n");
87static void temp_chdir()
89 out(
"ZUnable to switch to target directory. (#4.3.0)\n");
92static void temp_unlink()
94 out(
"ZUnable to unlink DKIM stage file. (#4.3.0)\n");
97static void temp_control()
99 out(
"ZUnable to read DKIM control files. (#4.3.0)\n");
102static void perm_usage()
104 out(
"Zqmail-dksign was invoked improperly. (#5.3.5)\n");
107static void temp_nosignkey()
109 out(
"DCan't read sign key: ");
117static int get_controls()
120 stralloc domname = {0};
171static void fnmake_dkim(
unsigned long id)
178static void dkim_unlink()
180 if (unlink(
fndkin.s) == -1)
181 if (errno != ENOENT) temp_unlink();
183 if (errno != ENOENT) temp_unlink();
186static void dkim_stage()
199 fnmake_dkim(getpid());
209 if (
inbuf[
in] ==
'\r')
continue;
220 if (buffer_flush(&
bo) == -1)
die(51);
255static int dkim_sign(
const char *rsakeyfile,
const char *ecckeyfile,
const char *fnin,
const char *fnout)
262 args[i] =
"qmail-dkim"; ++i;
265 if (
sdid.len > 3) { args[i] =
sdid.s; ++i; }
268 if (
auid.len > 3) { args[i] =
auid.s; ++i; }
270 if (
canon.len > 2) { args[i] =
canon.s; ++i; }
271 if (
hash.len > 2) { args[i] =
hash.s; ++i; }
274 args[i] = rsakeyfile; ++i;
275 args[i] = fnout; ++i;
276 if (str_len(ecckeyfile) > 3) { args[i] = ecckeyfile; ++i; }
279 if (!(child = vfork())) {
281 if (errno)
_exit(111);
285 wait_pid(&wstat,child);
286 if (wait_crashed(wstat))
return 1;
288 switch (wait_exitcode(wstat)) {
294static int qmail_remote(
char **qargs,
int fd)
300 args[0] =
"qmail-remote";
306 if (!(child = vfork())) {
308 if (fd_move(0,
fd) == -1)
_exit(111);
309 if (fd_copy(2,1) == -1)
_exit(111);
312 if (errno)
_exit(111);
316 wait_pid(&wstat,child);
317 if (wait_crashed(wstat))
return 1;
319 switch (wait_exitcode(wstat)) {
325static void dkim_setup()
349 if (*pos ==
'|' || *pos ==
'\0') {
368 if (*pos ==
'|' || *pos ==
'\0') {
376 if (*pos ==
'|' || *pos ==
'\0') {
388 if (*pos ==
'|' || *pos ==
'\0') {
397 if (*opt ==
'\0')
return;
402 ++opt;
if (*opt ==
'\0')
return;
404 if (*opt !=
':' || *opt ==
'\0')
return;
405 if (*opt ==
':') ++opt;
410 ++opt;
if (*opt ==
'\0')
return;
412 if (*opt !=
':' || *opt ==
'\0')
return;
413 if (*opt ==
':') ++opt;
414 if (*opt !=
':' && *opt ==
'l') {
425int main(
int argc,
char *
const *args)
440 if (argc < 4) perm_usage();
443 if (str_len(args[2]) > 2) {
444 i = str_chr(args[2],
'@');
445 if (*(args[2] + i) ==
'@')
451 if (!get_controls()) {
452 qmail_remote(qargs,
fdin);
475 if (stat(
rsakey.s,&st) != -1)
476 if (open_read(
rsakey.s) > 0) ++nkey;
482 if (stat(
ecckey.s,&st) != -1)
483 if (open_read(
ecckey.s) > 0) ++nkey;
498 qmail_remote(qargs,
fdin);
499 if (nkey) dkim_unlink();
int constmap_init(struct constmap *cm, char *s, int len, int flagcolon)
int control_readline(stralloc *sa, char *fn)
int control_readfile(stralloc *sa, char *fn, int flagme)
int stralloc_copys(stralloc *, char const *)
unsigned int fmtqfn(char *s, char *dirslash, unsigned long id, int flagsplit)
void c(char *, char *, char *, int, int, int)
char tmpbuf[BUFSIZE_LINE]
char outbuf[BUFSIZE_MESS]
struct constmap mapdkimdomains
int rcpthosts(char *, int)