29#define WHO "qmail-dksign"
31#define DOMAINKEYS "ssl/domainkeys/"
64void out(
char *s) {
if (buffer_puts(&
bo,s) == -1)
_exit(111); }
83 out(
"ZOut of memory. (#4.3.0)\n");
88 out(
"ZUnable to switch to target directory. (#4.3.0)\n");
93 out(
"ZUnable to create DKIM stage file: ");
94 out(error_str(errno));
100 out(
"ZUnable to unlink DKIM stage file. (#4.3.0)\n");
105 out(
"ZUnable to read DKIM control files. (#4.3.0)\n");
110 out(
"Zqmail-dksign was invoked improperly. (#5.3.5)\n");
115 out(
"DUnable to read message for DKIM signing. (#4.3.0)\n");
120 out(
"DCan't read sign key: ");
131 stralloc domname = {0};
191 if (unlink(
fndkin.s) == -1)
216 r = buffer_get(&
bi,&ch,1);
219 if (ch ==
'\r')
continue;
222 buffer_put(&
bo,&ch,1);
223 r = buffer_get(&
bi,&ch,1);
226 buffer_put(&
bo,
"\r\n",2);
229 if (buffer_flush(&
bo) == -1)
die(51);
264int dkim_sign(
const char *rsakeyfile,
const char *ecckeyfile,
const char *fnin,
const char *fnout)
271 args[i] =
"qmail-dkim"; ++i;
274 if (
sdid.len > 3) { args[i] =
sdid.s; ++i; }
277 if (
auid.len > 3) { args[i] =
auid.s; ++i; }
279 if (
canon.len > 2) { args[i] =
canon.s; ++i; }
280 if (
hash.len > 2) { args[i] =
hash.s; ++i; }
283 args[i] = rsakeyfile; ++i;
284 args[i] = fnout; ++i;
285 if (str_len(ecckeyfile) > 3) { args[i] = ecckeyfile; ++i; }
288 if (!(child = vfork())) {
290 if (errno)
_exit(111);
294 wait_pid(&wstat,child);
295 if (wait_crashed(wstat))
return 1;
297 switch (wait_exitcode(wstat)) {
309 args[0] =
"qmail-remote";
315 if (!(child = vfork())) {
317 if (fd_move(0,
fd) == -1)
_exit(111);
318 if (fd_copy(2,1) == -1)
_exit(111);
321 if (errno)
_exit(111);
325 wait_pid(&wstat,child);
326 if (wait_crashed(wstat))
return 1;
328 switch (wait_exitcode(wstat)) {
358 if (*pos ==
'|' || *pos ==
'\0') {
376 if (*pos ==
'|' || *pos ==
'\0') {
384 if (*pos ==
'|' || *pos ==
'\0') {
396 if (*pos ==
'|' || *pos ==
'\0') {
405 if (*opt ==
'\0')
return;
410 ++opt;
if (*opt ==
'\0')
return;
412 if (*opt !=
':' || *opt ==
'\0')
return;
413 if (*opt ==
':') ++opt;
418 ++opt;
if (*opt ==
'\0')
return;
420 if (*opt !=
':' || *opt ==
'\0')
return;
421 if (*opt ==
':') ++opt;
422 if (*opt !=
':' && *opt ==
'l') {
453 if (str_len(args[2]) > 2) {
454 i = str_chr(args[2],
'@');
455 if (*(args[2] + i) ==
'@')
483 if (stat(
rsakey.s,&st) != -1)
484 if (open_read(
rsakey.s) > 0) ++nkey;
490 if (stat(
ecckey.s,&st) != -1)
491 if (open_read(
ecckey.s) > 0) ++nkey;
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)
int qmail_remote(char **qargs, int fd)
int dkim_sign(const char *rsakeyfile, const char *ecckeyfile, const char *fnin, const char *fnout)
void fnmake_dkim(unsigned long id)
struct constmap mapdkimdomains