Implemented the approve mode, where incoming mails are searched for
confirmation cookies and the apropriate queue entries will be executed.
This commit is contained in:
parent
859f5e9887
commit
2fcd50d4c4
@ -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
|
||||
|
||||
|
||||
83
approve.c
Normal file
83
approve.c
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
$Source$
|
||||
$Revision$
|
||||
|
||||
Copyright (C) 2000 by Peter Simons <simons@computer.org>.
|
||||
|
||||
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 <regex.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
}
|
||||
4
main.c
4
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);
|
||||
|
||||
@ -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[]);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user