Re: QMAILREMOTE patch

Kai Peter <[email protected]> Sun, 21 May 2017 17:05:17 +0200
Newsgroups gmane.mail.qmail.general
Message-ID <[email protected]>
On 2017-05-21 14:27, Amitai Schleier wrote:
> A friend wants to DKIM-sign outgoing mail, probably using Kyle
> Wheeler's DKIM wrapper around qmail-remote
> (http://www.memoryhole.net/qmail/#dkim). But he doesn't want to
> confuse his package manager by moving aside the real qmail-remote
> binary and putting something else in its place.
Renaming qmail-remote shouldn't be a recommended way.
> 
> Inspired by the QMAILQUEUE patch, we patched qmail-rspawn to look for
> QMAILREMOTE in its environment. The 0th arg to execvp() is either the
> value of the env var (if set), or "qmail-remote" as usual. We tested
> with various arguments to qmail-start.
> 
> When QMAILREMOTE is not set:
> 
>     May 21 08:13:29 magnetic-babysitter-netbsd7 nbqmailsend: delivery
> 1: success:
> 166.84.7.144_accepted_message./Remote_host_said:_250_ok_1495368789_qp_3818/
> 
> 
> When QMAILREMOTE is set to an empty string, or a non-empty path (full
> or unqualified) of a program that does not exist:
> 
>     May 21 08:16:34 magnetic-babysitter-netbsd7 nbqmailsend: delivery
> 1: failure: Unable_to_run_qmail-remote./
> 
> 
> When QMAILREMOTE is set to /var/tmp/schmonz (a shell script that runs
> 'exec qmail-remote "$@"'):
> 
>     May 21 08:22:19 magnetic-babysitter-netbsd7 nbqmailsend: delivery
> 1: success:
> 166.84.7.144_accepted_message./Remote_host_said:_250_ok_1495369319_qp_19267/
> 
> 
> Does this patch look reasonable?

My first question: where do you set the env var?

However, I announced some time ago my netqmail-1.06-before-remote.patch. 
See https://blog.dyndn.es/doku.php/blog/2016/02/01_netqmail-bfrmt. 
Meanwhile the code changed a bit, I no longer use <string.h> (as I 
initially made it, I have had more less glue of djb's libs ;-) ):

#include "auto_qmail.h"
char *np = "qmail-bfrmt";   /* next program to call */
  ...
   struct stat st;
   stralloc sa = {0};

   if(!stralloc_copys(&sa,auto_qmail)) err_sys(errno);
   if(!stralloc_catb(&sa,"/bin/qmail-bfrmt",16)) err_sys(errno); /* len: 
16 + \0 */
   if(!stralloc_0(&sa)) err_sys(errno);
   char *x = sa.s;
   if (stat(x,&st) != 0) { np = "qmail-remote"; }

   int f;
   char *(args[5]);
   args[0] = np;

'err_sys' comes from a new lib in djb style replacing strerr/error* - 
use something like the 'die_nomem()' function instead.

The functionality is the same as describe in the link, including:

- qmail-remote will be executed directly if an error occurs
- a log message will be written if there is an error
- changes can be done on the fly (no restart required)

This is part of eQmail too. In preparation of **a**Qmail I there will be 
additional improvements, like to use multiple plugins (e.g. srs) more 
flexible. There are no plans to make a new version of the patch above.

regards
Kai

PS: As a preview: there will be coming soon a full featured DKIM package 
as installable plugin - it will be part of aQmail too. Beware that the 
latest libdkim-1.0.21 has a security bug which is not solved officially 
- AFAIK.

> 
> 
> --- Makefile.orig	2007-11-30 20:22:54.000000000 +0000
> +++ Makefile
> @@ -1462,19 +1462,19 @@ tcpto.h readwrite.h timeoutconn.h timeou
> 
>  qmail-rspawn: \
>  load qmail-rspawn.o spawn.o tcpto_clean.o now.o coe.o sig.a open.a \
> -seek.a lock.a wait.a fd.a stralloc.a alloc.a substdio.a error.a str.a 
> \
> +seek.a lock.a wait.a fd.a stralloc.a alloc.a substdio.a error.a env.a 
> str.a \
>  auto_qmail.o auto_uids.o auto_spawn.o
>  	./load qmail-rspawn spawn.o tcpto_clean.o now.o coe.o \
>  	sig.a open.a seek.a lock.a wait.a fd.a stralloc.a alloc.a \
> -	substdio.a error.a str.a auto_qmail.o auto_uids.o \
> -	auto_spawn.o
> +	substdio.a error.a env.a str.a auto_qmail.o auto_uids.o \
> +	auto_spawn.o
> 
>  qmail-rspawn.0: \
>  qmail-rspawn.8
>  	nroff -man qmail-rspawn.8 > qmail-rspawn.0
> 
>  qmail-rspawn.o: \
> -compile qmail-rspawn.c fd.h wait.h substdio.h exit.h fork.h error.h \
> +compile qmail-rspawn.c fd.h wait.h substdio.h exit.h fork.h error.h 
> env.h \
>  tcpto.h
>  	./compile qmail-rspawn.c
> 
> --- qmail-rspawn.c.orig	1998-06-15 10:53:16.000000000 +0000
> +++ qmail-rspawn.c
> @@ -5,6 +5,17 @@
>  #include "fork.h"
>  #include "error.h"
>  #include "tcpto.h"
> +#include "env.h"
> +
> +static char *qrargs[1] = { 0 };
> +
> +static void setup_qrargs()
> +{
> + if (!qrargs[0])
> +  qrargs[0] = env_get("QMAILREMOTE");
> + if(!qrargs[0])
> +  qrargs[0] = "qmail-remote";
> +}
> 
>  void initialize(argc,argv)
>  int argc;
> @@ -84,7 +95,9 @@ char *s; char *r; int at;
>   int f;
>   char *(args[5]);
> 
> - args[0] = "qmail-remote";
> + setup_qrargs();
> +
> + args[0] = qrargs[0];
>   args[1] = r + at + 1;
>   args[2] = s;
>   args[3] = r;

-- 
Sent with eQmail-1.10