> On May 9, 2006, at 12:57 PM, Jeremy Kitchen wrote:
>> the problem is that vpopmail is using qmail-inject to forward messages.
>> qmail-inject does not tolerate malformed messages.
>>
>> it's that simple.
>
> Any volunteers to review the code in vdelivermail.c and modify it to
> use qmail-queue instead of qmail-inject?
>
OK, here's a quick stab at a basic patch - I modified qmail_inject_open to
open qmail-queue appropriately (no args), and changed deliver_mail to talk
to it.  I THINK :)

There's no bounds checking and so forth in here, there are a few places
where there really needs to be some extra code to make sure that the data
acquired is valid, but it's designed to be proof-of-concept.  It compiles,
but that's all I can guarantee.

Use at your own risk, yada yada...  Feel free to modify it as needed, I
have no ego attached to this code :)

Josh
-- 
Joshua Megerman
SJGames MIB #5273 - OGRE AI Testing Division
You can't win; You can't break even; You can't even quit the game.
  - Layman's translation of the Laws of Thermodynamics
[EMAIL PROTECTED]
--- vdelivermail.c.orig	2006-05-09 17:35:00.000000000 -0400
+++ vdelivermail.c	2006-05-09 18:02:34.000000000 -0400
@@ -72,6 +72,7 @@
 
 #define BUFF_SIZE 300
 int fdm;
+int fde;
 
 #define EXIT_BOUNCE 100
 #define EXIT_DEFER 111
@@ -304,33 +305,41 @@
 }
 #endif
 
-/* Forks off qmail-inject.  Returns PID of child, or 0 for failure. */
-pid_t qmail_inject_open(char *address)
+/* Forks off qmail-queue.  Returns PID of child, or 0 for failure. */
+pid_t qmail_queue_open(char *address)
 {
  int pim[2];
+ int pie[2];
+
  pid_t pid;
- static char *binqqargs[4];
+ static char *binqqargs[2];
 
     if ( pipe(pim) == -1) return 0;
+    if ( pipe(pie) == -1) return 0;
 
     switch(pid=vfork()){
       case -1:
         close(pim[0]);
         close(pim[1]);
+        close(pie[0]);
+        close(pie[1]);
         printf ("Unable to fork: %d.", errno);
         return 0;
       case 0:
         close(pim[1]);
+        close(pie[1]);
         if (vfd_move(0,pim[0]) == -1 ) _exit(-1);
+        if (vfd_move(1,pie[0]) == -1 ) _exit(-1);
         binqqargs[0] = QMAILINJECT;
-        binqqargs[1] = "--";
-        binqqargs[2] = (*address == '&' ? &address[1] : &address[0]);
+	binqqargs[1] = 0;
         execv(*binqqargs, binqqargs);
-        printf ("Unable to launch qmail-inject.");
+        printf ("Unable to launch qmail-queue.");
         exit (EXIT_DEFER);    /* child's exit caught later */
     }
     fdm = pim[1];
+    fde = pie[1];
     close(pim[0]);
+    close(pie[0]);
     return(pid);
 }
 
@@ -628,10 +637,12 @@
       char *dtline;
       char *atpos;
       int dtlen;
+      char qenv[BUFF_SIZE];
+      int qenvsz;
 
       if (*address=='&') ++address;  /* will this case ever happen? */
-      inject_pid = qmail_inject_open(address);
-      if (inject_pid == 0) vexiterr (EXIT_DEFER, "system error, can't open qmail-inject");
+      inject_pid = qmail_queue_open(address);
+      if (inject_pid == 0) vexiterr (EXIT_DEFER, "system error, can't open qmail-queue");
       
       /* use the DTLINE variable, but skip past the dash in 
        * [EMAIL PROTECTED] 
@@ -665,13 +676,24 @@
       }
       
       if (fdcopy (fdm, 0, DeliveredTo, strlen(DeliveredTo)) != 0) {
-          printf ("write to qmail-inject failed: %d\n", errno);
+          printf ("write to qmail-queue failed: %d\n", errno);
           close(fdm);
+          close(fde);
           waitpid(inject_pid,&child,0);
           vexiterr (EXIT_DEFER, "system error");
       }
 
+      qenvsz = snprintf("F%s\0T%s", BUFF_SIZE, getenv("SENDER"), address);
+      qenvsz++;
+      if ((write(fde, (void *)qenv, qenvsz)) != qenvsz) {
+          printf ("write to qmail-queue failed: %d\n", errno);
+          close(fdm);
+          close(fde);
+          vexiterr (EXIT_DEFER, "system error");
+      }
+
       close(fdm);
+      close(fde);
       waitpid(inject_pid,&child,0);
       if (wait_exitcode(child) == 0) return;
       vexiterr (EXIT_DEFER, "system error");

Reply via email to