2001-01-15 18:48:49 +00:00
|
|
|
/*
|
|
|
|
|
$Source$
|
|
|
|
|
$Revision$
|
|
|
|
|
|
2010-02-18 15:28:52 +00:00
|
|
|
Copyright (C) 2000 by Peter Simons <simons@cryp.to>.
|
2001-01-15 18:48:49 +00:00
|
|
|
|
2001-01-18 20:30:50 +00:00
|
|
|
This file is part of Petidomo.
|
2001-01-15 18:48:49 +00:00
|
|
|
|
2001-01-18 20:30:50 +00:00
|
|
|
Petidomo is free software; you can redistribute it and/or modify
|
2001-01-15 18:48:49 +00:00
|
|
|
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.
|
|
|
|
|
|
2001-01-18 20:30:50 +00:00
|
|
|
Petidomo is distributed in the hope that it will be useful, but
|
2001-01-15 18:48:49 +00:00
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2001-01-16 10:47:15 +00:00
|
|
|
#include <sys/types.h>
|
2001-01-15 18:48:49 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <unistd.h>
|
2001-01-16 10:47:15 +00:00
|
|
|
#include <regex.h>
|
2001-01-19 14:56:33 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
2001-01-20 14:57:04 +00:00
|
|
|
#include <ctype.h>
|
2001-01-19 14:56:33 +00:00
|
|
|
|
|
|
|
|
#include "petidomo.h"
|
2001-01-20 14:57:04 +00:00
|
|
|
#include "libtext/text.h"
|
2001-01-15 18:48:49 +00:00
|
|
|
|
2001-01-20 14:30:50 +00:00
|
|
|
void approve_main(char* mail)
|
2001-01-15 18:48:49 +00:00
|
|
|
{
|
|
|
|
|
const struct PD_Config* MasterConfig = getMasterConfig();
|
2001-01-20 14:30:50 +00:00
|
|
|
struct Mail* MailStruct;
|
|
|
|
|
char* originator;
|
2001-01-20 14:57:04 +00:00
|
|
|
char* envelope;
|
|
|
|
|
FILE* fh;
|
2001-01-15 18:48:49 +00:00
|
|
|
static const char* cookie_regex = "[0-9a-f]{32}";
|
|
|
|
|
regex_t preg;
|
|
|
|
|
regmatch_t match[3];
|
|
|
|
|
int offset;
|
2001-01-20 14:57:04 +00:00
|
|
|
int number_of_hits = 0;
|
2001-01-15 18:48:49 +00:00
|
|
|
|
|
|
|
|
if (chdir(MasterConfig->ack_queue_dir) == -1)
|
|
|
|
|
{
|
2001-01-19 14:56:33 +00:00
|
|
|
syslog(LOG_ERR, "Can't change directory to \"%s\": %s", MasterConfig->ack_queue_dir, strerror(errno));
|
2001-01-15 18:48:49 +00:00
|
|
|
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;
|
|
|
|
|
|
2001-01-20 14:57:04 +00:00
|
|
|
/* Copy found string into buffer and convert it to all
|
|
|
|
|
upper-case while doing so. */
|
2001-01-15 18:48:49 +00:00
|
|
|
|
|
|
|
|
src = mail + offset + match[0].rm_so;
|
|
|
|
|
for (i = 0; i < 32; ++i)
|
2001-01-20 14:57:04 +00:00
|
|
|
*dst++ = toupper(*src++);
|
2001-01-15 18:48:49 +00:00
|
|
|
*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];
|
|
|
|
|
|
2001-01-20 14:57:04 +00:00
|
|
|
syslog(LOG_INFO, "Received valid approval code for spool file \"%s\".", buffer);
|
|
|
|
|
++number_of_hits;
|
2001-01-15 18:48:49 +00:00
|
|
|
sprintf(cmd, "/bin/sh %s && /bin/rm -f %s", buffer, buffer);
|
|
|
|
|
if (((signed char)system(cmd)) == -1)
|
|
|
|
|
{
|
2001-01-19 14:56:33 +00:00
|
|
|
syslog(LOG_ERR, "system() failed for \"%s\": %s", buffer, strerror(errno));
|
2001-01-15 18:48:49 +00:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-20 14:57:04 +00:00
|
|
|
else
|
|
|
|
|
syslog(LOG_INFO, "Received approval code \"%s\", but there is no corresponding posting.", buffer);
|
2001-01-20 14:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Report results back to the originator */
|
|
|
|
|
|
|
|
|
|
if (ParseMail(&MailStruct, mail, MasterConfig->fqdn) != 0)
|
|
|
|
|
{
|
|
|
|
|
syslog(LOG_ERR, "Parsing the incoming mail failed.");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
2001-01-15 18:48:49 +00:00
|
|
|
|
2001-01-20 14:30:50 +00:00
|
|
|
if (MailStruct->From == NULL)
|
|
|
|
|
{
|
|
|
|
|
syslog(LOG_NOTICE, "Received mail without From: line.");
|
|
|
|
|
return;
|
2001-01-15 18:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
2001-01-20 14:30:50 +00:00
|
|
|
originator = (MailStruct->Reply_To) ? MailStruct->Reply_To : MailStruct->From;
|
2001-01-20 14:57:04 +00:00
|
|
|
envelope = text_easy_sprintf("petidomo-manager@%s", MasterConfig->fqdn);
|
2001-01-20 14:30:50 +00:00
|
|
|
|
2001-01-20 14:57:04 +00:00
|
|
|
fh = vOpenMailer(envelope, originator, NULL);
|
|
|
|
|
if (fh != NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(fh, "From: petidomo@%s (Petidomo Mailing List Server)\n", MasterConfig->fqdn);
|
|
|
|
|
fprintf(fh, "To: %s\n", originator);
|
|
|
|
|
fprintf(fh, "Subject: Petidomo: Your approval mail has been received\n");
|
|
|
|
|
if (MailStruct->Message_Id != NULL)
|
|
|
|
|
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
|
|
|
|
|
fprintf(fh, "Precedence: junk\n");
|
|
|
|
|
fprintf(fh, "Sender: %s\n", envelope);
|
|
|
|
|
fprintf(fh, "\n");
|
|
|
|
|
if (number_of_hits > 0)
|
|
|
|
|
fprintf(fh, "Your approval mail has been received and been processed sucessfully.");
|
|
|
|
|
else
|
|
|
|
|
fprintf(fh, "I couldn't find any approval codes in your mail.");
|
|
|
|
|
CloseMailer(fh);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
syslog(LOG_ERR, "Failed to send email to \"%s\" concerning his request.", originator);
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
2001-01-15 18:48:49 +00:00
|
|
|
}
|