Hi. Here's a small utility I wanted to share
        (and get some peer review on;)

        Serialmail seemed to me almost ideal for dialup
        links. I never liked fetchmail.. But then again,
        fetchmail could easily operate under ssh.

        qmtpoverssh is a simple wrapper for serialqmtp
        and qmail-qmtpd that runs under maildirserial.
        It runs serialqmtp on one end but tunnels the
        connection through ssh and runs qmail-qmtpd on
        the other end (note qmail-qmtpd does not have to
        be listening on a port - it will used directly).

        Usage is like this:
maildirserial dir prefix qmtpoverssh prefix2 hostname user
        prefix and prefix2 will usually be the same;
        look at the documentation of maildirserial and 
        serialqmtp. hostname and user specify where the
        ssh connection will be made.

        You have to have RSA authentication or something
        similar for this to work. I suggest making a new
        key with an empty password and limited access.

        TODO:
        give qmail-qmtpd some environment variables to
        make it log information more nicely.

-- 
Havoc Consulting | unix, linux, perl, mail, www, internet, security consulting
+358 50 5486010  | software development, unix administration, training
#include <unistd.h>
#include <stdio.h>

/* maildirserial [-b] [-tlifetime] dir prefix 
                 qmtpssh prefix2 host login */

#define PROGNAME "qmtpoverssh"
#define READ 0
#define WRITE 1

void fail(char *s) {
  fprintf(stderr,"%s: failure: %s\n",PROGNAME,s);
  exit(100);
}
void defer(char *s) {
  fprintf(stderr,"%s: deferral: %s\n",PROGNAME,s);
  exit(111);
}

int main (int argc, char **argv) {
  int pid;
  int toserial[2];
  int fromserial[2];
  if (argc<4) { fail("usage: qmtpoverssh prefix host login."); }
  if (pipe(toserial)==-1) { defer("pipe to serialqmtp failed."); }
  if (pipe(fromserial)==-1) { defer("pipe from serialqmtp failed."); }
  pid=fork();
  if (pid==-1) { defer("fork failed."); }
  if (pid==0) { /* child */
    if (dup2(toserial[READ],6)==-1) { defer("dup2 failed on stdin."); }
    if (dup2(fromserial[WRITE],7)==-1) { defer("dup2 failed on stdout."); }
    argv[0] = "serialqmtp";
    argv[2] = NULL;
    execvp("serialqmtp", argv);
    defer("exec serialqmtp failed");
  }
  else { /* parent */
    if (dup2(toserial[WRITE],1)==-1) { defer("dup2 failed on stdin."); }
    if (dup2(fromserial[READ],0)==-1) { defer("dup2 failed on stdout."); }
    execlp("ssh", "ssh","-q",argv[2],"-l",argv[3],"/usr/sbin/qmail-qmtpd");
    defer("exec ssh failed");
  }
}

Reply via email to