/* processmail.c - Checkpayment and strippayment frontend Copyright (C) 2003 Ian Gulliver This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include "firemake.h" int main(int argc, char *argv[]) { struct firestring_estr_t message; struct firestring_estr_t result; int l; int p[2],p2[2]; int i; int status; if (argc < 3) { firestring_fprintf(stderr,"Usage: %s [ ... ]\n",argv[0]); exit(100); } if (argc > 255) { firestring_fprintf(stderr,"Too many arguments\n"); exit(100); } firestring_estr_alloc(&message,4096); while ((l = read(0,&message.s[message.l],message.a - message.l)) > 0) { message.l += l; firestring_estr_expand(&message,message.l + 4096); } if (pipe(p) != 0) { perror("Error running pipe()"); exit(111); } if (pipe(p2) != 0) { perror("Error running pipe()"); exit(111); } i = fork(); if (i == -1) { perror("Error running fork()"); exit(111); } else if (i == 0) { /* i'm the baby, gotta love me */ char *args[256]; int j; args[0] = "checkpayment"; args[1] = argv[1]; for (j = 2; j < argc; j++) args[j] = argv[j]; args[j] = NULL; if (dup2(p[0],0) != 0) { perror("Error running dup2()"); exit(111); } if (dup2(p2[1],2) != 2) { perror("Error running dup2()"); exit(111); } close(p[1]); close(p2[0]); execvp("checkpayment",args); perror("Error running exexvp(checkpayment)"); exit(111); } close(p[0]); close(p2[1]); if (write(p[1],message.s,message.l) != message.l) { perror("Error running write()"); exit(111); } close(p[1]); firestring_estr_alloc(&result,4096); while ((l = read(p2[0],&result.s[result.l],result.a - result.l)) > 0) result.l += l; close(p2[0]); if (wait(&l) <= 0) { perror("Error running wait()"); exit(111); } if (!WIFEXITED(l)) { firestring_fprintf(stderr,"Child exited abnormally\n"); exit(111); } status = WEXITSTATUS(l); if (status == 0) firestring_fprintf(stdout,"X-HashCashMIME-Passed: %e",&result); else firestring_fprintf(stdout,"X-HashCashMIME-Failed: %e",&result); if (pipe(p) != 0) { perror("Error running pipe()"); exit(111); } i = fork(); if (i == -1) { perror("Error running fork()"); exit(111); } else if (i == 0) { /* i'm the baby, gotta love me */ if (dup2(p[0],0) != 0) { perror("Error running dup2()"); exit(111); } close(p[1]); execlp("strippayment","strippayment",NULL); perror("Error running exexlp(strippayment)"); exit(111); } close(p[0]); if (write(p[1],message.s,message.l) != message.l) { perror("Error running write()"); exit(111); } close(p[1]); wait(NULL); return 0; }