From 2fcd50d4c4582e51538866f8660e222085c28776 Mon Sep 17 00:00:00 2001 From: Peter Simons Date: Mon, 15 Jan 2001 18:48:49 +0000 Subject: [PATCH] Implemented the approve mode, where incoming mails are searched for confirmation cookies and the apropriate queue entries will be executed. --- Makefile.in | 2 +- approve.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ main.c | 4 +++ petidomo.h | 4 +++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 approve.c diff --git a/Makefile.in b/Makefile.in index 630da52..1276c24 100644 --- a/Makefile.in +++ b/Makefile.in @@ -27,7 +27,7 @@ OBJS = acl.o archive.o authen.o config.o generate_cookie.o \ filter.o handleacl.o help.o hermes.o index.o io.o listserv.o \ mailer.o members.o parsearray.o password.o rfcparse.o \ subscribe.o tool.o unsubscribe.o main.o queue_command.o \ - queue_posting.o + queue_posting.o approve.o LIBS = librfc822/librfc822.a libmpools/libmpools.a liblists/liblists.a libargv/libargv.a \ libconfigfile/libconfigfile.a libtext/libtext.a diff --git a/approve.c b/approve.c new file mode 100644 index 0000000..dbee541 --- /dev/null +++ b/approve.c @@ -0,0 +1,83 @@ +/* + $Source$ + $Revision$ + + Copyright (C) 2000 by Peter Simons . + + This file is part of OpenPetidomo. + + OpenPetidomo is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + OpenPetidomo 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. +*/ + +#include "petidomo.h" +#include +#include +#include + +int approve_main(char* mail) + { + const struct PD_Config* MasterConfig = getMasterConfig(); + static const char* cookie_regex = "[0-9a-f]{32}"; + regex_t preg; + regmatch_t match[3]; + int offset; + + if (chdir(MasterConfig->ack_queue_dir) == -1) + { + syslog(LOG_ERR, "Can't change directory to \"%s\": %m", MasterConfig->ack_queue_dir); + exit(1); + } + + if (regcomp(&preg, cookie_regex, REG_EXTENDED | REG_ICASE) != 0) + { + syslog(LOG_CRIT, "Can't compile my internal regular expressions. This is serious!"); + exit(1); + } + + offset = 0; + while(regexec(&preg, mail + offset, sizeof(match)/sizeof(regmatch_t), match, 0) == 0) + { + struct stat sb; + char buffer[33]; + char* src; + char* dst = buffer; + unsigned int i; + + /* Copy found string into buffer. */ + + src = mail + offset + match[0].rm_so; + for (i = 0; i < 32; ++i) + *dst++ = *src++; + *dst = '\0'; + + /* Correct offset for the next match. */ + + offset += match[0].rm_so + 1; + + /* Do we have a hit here? If, execute the file and remove it. + Then go on. */ + + if (stat(buffer, &sb) == 0) + { + char cmd[128]; + + sprintf(cmd, "/bin/sh %s && /bin/rm -f %s", buffer, buffer); + if (((signed char)system(cmd)) == -1) + { + syslog(LOG_ERR, "system() failed: %m", MasterConfig->ack_queue_dir); + exit(1); + } + } + + } + + return 0; + } diff --git a/main.c b/main.c index bedea4a..799ea76 100644 --- a/main.c +++ b/main.c @@ -91,6 +91,10 @@ main(int argc, char * argv[]) exit(1); } } + else if (strcasecmp("approve", mode) == 0) + { + approve_main(incoming_mail); + } else { syslog(LOG_ERR, "I don't know anything about mode \"%s\".", mode); diff --git a/petidomo.h b/petidomo.h index a13ad11..fad92ed 100644 --- a/petidomo.h +++ b/petidomo.h @@ -191,6 +191,10 @@ int savefile(const char *filename, const char *buffer); int listserv_main(char *incoming_mail, char *default_list); +/********** approve.c **********/ + +int approve_main(char *incoming_mail); + /********** mailer.c **********/ FILE *OpenMailer(const char *envelope, const char *recipients[]);