2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2001-11-04 16:41:54 +00:00
|
|
|
* $Id$
|
|
|
|
* Purpose: Process Fidonet style mail and files.
|
2001-08-17 05:46:24 +00:00
|
|
|
*
|
|
|
|
*****************************************************************************
|
2005-08-10 18:57:22 +00:00
|
|
|
* Copyright (C) 1997-2005
|
2001-08-17 05:46:24 +00:00
|
|
|
*
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
* Beekmansbos 10
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
* the Netherlands
|
|
|
|
*
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
*
|
|
|
|
* This BBS 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.
|
|
|
|
*
|
|
|
|
* MBSE BBS 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 MBSE BBS; see the file COPYING. If not, write to the Free
|
2003-08-15 20:05:34 +00:00
|
|
|
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
2001-08-17 05:46:24 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../config.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbselib.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "../lib/mbse.h"
|
2002-01-07 19:16:03 +00:00
|
|
|
#include "../lib/users.h"
|
2002-12-28 17:29:06 +00:00
|
|
|
#include "../lib/nodelist.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbsedb.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "../lib/msg.h"
|
|
|
|
#include "flock.h"
|
|
|
|
#include "tosspkt.h"
|
2002-08-05 13:30:44 +00:00
|
|
|
#include "unpack.h"
|
2005-11-12 12:52:30 +00:00
|
|
|
#include "orphans.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "tic.h"
|
|
|
|
#include "fsort.h"
|
|
|
|
#include "scan.h"
|
|
|
|
#include "mbfido.h"
|
|
|
|
#include "tracker.h"
|
|
|
|
#include "notify.h"
|
|
|
|
#include "rollover.h"
|
|
|
|
#include "hatch.h"
|
|
|
|
#include "scannews.h"
|
|
|
|
#include "maketags.h"
|
|
|
|
#include "makestat.h"
|
|
|
|
#include "newspost.h"
|
|
|
|
#include "rnews.h"
|
2002-04-27 21:06:51 +00:00
|
|
|
#include "mgrutil.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "backalias.h"
|
2001-08-25 19:53:11 +00:00
|
|
|
#include "rfc2ftn.h"
|
2002-08-03 19:52:57 +00:00
|
|
|
#include "dirsession.h"
|
2002-08-05 13:30:44 +00:00
|
|
|
#include "dirlock.h"
|
|
|
|
#include "queue.h"
|
2004-07-23 21:24:09 +00:00
|
|
|
#include "msg.h"
|
2005-08-10 18:57:22 +00:00
|
|
|
#include "createm.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define UNPACK_FACTOR 300
|
|
|
|
|
|
|
|
|
2005-08-26 18:26:38 +00:00
|
|
|
int do_obs_a = FALSE; /* Obsolete command used */
|
2002-04-27 21:06:51 +00:00
|
|
|
int do_areas = FALSE; /* Process area taglists */
|
2001-08-17 05:46:24 +00:00
|
|
|
int do_toss = FALSE; /* Toss flag */
|
|
|
|
int do_scan = FALSE; /* Scan flag */
|
|
|
|
int do_tic = FALSE; /* Process .tic files */
|
|
|
|
int do_notify = FALSE; /* Create notify messages */
|
|
|
|
int do_roll = FALSE; /* Rollover only */
|
|
|
|
int do_full = FALSE; /* Full mailscan */
|
|
|
|
int do_tags = FALSE; /* Create taglists */
|
|
|
|
int do_stat = FALSE; /* Create statistic HTML pages */
|
|
|
|
int do_test = FALSE; /* Test routing */
|
|
|
|
int do_news = FALSE; /* Process NNTP news */
|
|
|
|
int do_uucp = FALSE; /* Process UUCP newsbatch */
|
2001-08-25 19:53:11 +00:00
|
|
|
int do_mail = FALSE; /* Process MTA email message */
|
2001-08-17 05:46:24 +00:00
|
|
|
int do_unsec = FALSE; /* Unsecure tossing */
|
|
|
|
int do_learn = FALSE; /* News articles learnmode */
|
|
|
|
int check_crc = TRUE; /* Check .tic crc values */
|
|
|
|
int check_dupe = TRUE; /* Check duplicates */
|
2002-08-05 13:30:44 +00:00
|
|
|
int do_flush = FALSE; /* Flush outbound queue */
|
2002-08-28 20:34:50 +00:00
|
|
|
int flushed = FALSE; /* If anything was flushed */
|
2005-08-10 18:57:22 +00:00
|
|
|
int areas_changed = FALSE; /* If echoareas are changed */
|
2001-08-17 05:46:24 +00:00
|
|
|
extern int do_quiet; /* Quiet flag */
|
|
|
|
extern int e_pid; /* Pid of child process */
|
|
|
|
extern int show_log; /* Show logging on screen */
|
|
|
|
int do_unprot = FALSE; /* Unprotected inbound flag */
|
|
|
|
time_t t_start; /* Start time */
|
|
|
|
time_t t_end; /* End time */
|
|
|
|
int packets = 0; /* Tossed packets */
|
|
|
|
int packets_ok = 0; /* Tossed packets Ok. */
|
|
|
|
char *envptr = NULL;
|
|
|
|
|
2004-07-23 21:24:09 +00:00
|
|
|
extern int net_in, net_imp, net_out, net_bad, net_msgs;
|
2001-08-17 05:46:24 +00:00
|
|
|
extern int echo_in, echo_imp, echo_out, echo_bad, echo_dupe;
|
|
|
|
extern int email_in, email_imp, email_out, email_bad;
|
|
|
|
extern int news_in, news_imp, news_out, news_bad, news_dupe;
|
|
|
|
extern int tic_in, tic_imp, tic_out, tic_bad, tic_dup;
|
|
|
|
extern int Magics, Hatched;
|
|
|
|
extern int notify, filemgr, areamgr;
|
|
|
|
|
2005-08-10 18:57:22 +00:00
|
|
|
void editor_configs(void);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we don't know what to type
|
|
|
|
*/
|
|
|
|
void Help(void)
|
|
|
|
{
|
2002-08-05 13:30:44 +00:00
|
|
|
do_quiet = FALSE;
|
|
|
|
ProgName();
|
|
|
|
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_colour(LIGHTCYAN, BLACK);
|
2002-08-05 13:30:44 +00:00
|
|
|
printf("\nUsage: mbfido [command(s)] <options>\n\n");
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_colour(LIGHTBLUE, BLACK);
|
2002-08-05 13:30:44 +00:00
|
|
|
printf(" Commands are:\n\n");
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_colour(CYAN, BLACK);
|
2002-08-05 13:30:44 +00:00
|
|
|
printf(" a areas Process Areas taglists\n");
|
|
|
|
printf(" m mail <recipient> ... MTA Mail mode\n");
|
|
|
|
printf(" ne news Scan for new news\n");
|
|
|
|
printf(" no notify <nodes> Send notify messages\n");
|
|
|
|
printf(" r roll Rollover statistic counters\n");
|
|
|
|
printf(" s scan Scan outgoing Fido mail\n");
|
|
|
|
printf(" ta tag Create taglists\n");
|
|
|
|
printf(" te test <node> Do routing test for node\n");
|
|
|
|
printf(" ti tic Process .tic files\n");
|
|
|
|
printf(" to toss Toss incoming Fido mail\n");
|
|
|
|
printf(" u uucp Process UUCP batchfile\n");
|
|
|
|
printf(" w web Create WWW statistics\n\n");
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_colour(LIGHTBLUE, BLACK);
|
2002-08-05 13:30:44 +00:00
|
|
|
printf(" Options are:\n\n");
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_colour(CYAN, BLACK);
|
2002-08-05 13:30:44 +00:00
|
|
|
printf(" -f -full Full Mailscan\n");
|
|
|
|
printf(" -l -learn Learn News dupes\n");
|
|
|
|
printf(" -noc -nocrc Skip CRC checking\n");
|
|
|
|
printf(" -nod -nodupe Skip dupe checking\n");
|
|
|
|
printf(" -q -quiet Quiet mode\n");
|
|
|
|
printf(" -uns -unsecure Toss unsecure\n");
|
|
|
|
printf(" -unp -unprotect Toss unprotected inbound\n");
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_colour(LIGHTGRAY, BLACK);
|
2002-10-20 20:58:55 +00:00
|
|
|
ExitClient(MBERR_COMMANDLINE);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Header, only if not quiet.
|
|
|
|
*/
|
|
|
|
void ProgName(void)
|
|
|
|
{
|
2002-08-05 13:30:44 +00:00
|
|
|
if (do_quiet)
|
|
|
|
return;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_colour(WHITE, BLACK);
|
2002-08-05 13:30:44 +00:00
|
|
|
printf("\nMBFIDO: MBSE BBS %s - Fidonet File and Mail processor\n", VERSION);
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_colour(YELLOW, BLACK);
|
2002-08-05 13:30:44 +00:00
|
|
|
printf(" %s\n", COPYRIGHT);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-08-10 18:57:22 +00:00
|
|
|
/*
|
|
|
|
* Create ~/etc/msg.txt for MsgEd and ~/etc/golded.inc for GoldED.
|
|
|
|
*/
|
|
|
|
void editor_configs(void)
|
|
|
|
{
|
|
|
|
char *temp;
|
|
|
|
FILE *fp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
temp = calloc(PATH_MAX, sizeof(char));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Export ~/etc/msg.txt for MsgEd.
|
|
|
|
*/
|
2005-08-28 14:52:14 +00:00
|
|
|
snprintf(temp, PATH_MAX, "%s/etc/msg.txt", getenv("MBSE_ROOT"));
|
2005-08-10 18:57:22 +00:00
|
|
|
if ((fp = fopen(temp, "w")) != NULL) {
|
|
|
|
fprintf(fp, "; msg.txt -- Automatic created by mbsetup %s -- Do not edit!\n;\n", VERSION);
|
|
|
|
fprintf(fp, "; Mail areas for MsgEd.\n;\n");
|
|
|
|
msged_areas(fp);
|
|
|
|
fclose(fp);
|
|
|
|
Syslog('+', "Created new %s", temp);
|
|
|
|
} else {
|
|
|
|
WriteError("$Could not create %s", temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Export ~/etc/golded.inc for GoldED
|
|
|
|
*/
|
2005-08-28 14:52:14 +00:00
|
|
|
snprintf(temp, PATH_MAX, "%s/etc/golded.inc", getenv("MBSE_ROOT"));
|
2005-08-10 18:57:22 +00:00
|
|
|
if ((fp = fopen(temp, "w")) != NULL) {
|
|
|
|
fprintf(fp, "; GoldED.inc -- Automatic created by mbsetup %s -- Do not edit!\n\n", VERSION);
|
|
|
|
fprintf(fp, "; Basic information.\n;\n");
|
|
|
|
if (strlen(CFG.sysop_name) && CFG.akavalid[0] && CFG.aka[0].zone) {
|
|
|
|
fprintf(fp, "USERNAME %s\n\n", CFG.sysop_name);
|
|
|
|
fprintf(fp, "ADDRESS %s\n", aka2str(CFG.aka[0]));
|
|
|
|
for (i = 1; i < 40; i++)
|
|
|
|
if (CFG.akavalid[i])
|
|
|
|
fprintf(fp, "AKA %s\n", aka2str(CFG.aka[i]));
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
|
|
|
|
gold_akamatch(fp);
|
|
|
|
fprintf(fp, "; JAM MessageBase Setup\n;\n");
|
|
|
|
fprintf(fp, "JAMPATH %s/tmp/\n", getenv("MBSE_ROOT"));
|
|
|
|
fprintf(fp, "JAMHARDDELETE NO\n\n");
|
|
|
|
|
|
|
|
fprintf(fp, "; Semaphore files\n;\n");
|
|
|
|
fprintf(fp, "SEMAPHORE NETSCAN %s/var/sema/mailout\n", getenv("MBSE_ROOT"));
|
|
|
|
fprintf(fp, "SEMAPHORE ECHOSCAN %s/var/sema/mailout\n\n", getenv("MBSE_ROOT"));
|
|
|
|
|
|
|
|
gold_areas(fp);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
Syslog('+', "Created new %s", temp);
|
|
|
|
} else {
|
|
|
|
WriteError("$Could not create %s", temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 05:46:24 +00:00
|
|
|
void die(int onsig)
|
|
|
|
{
|
2002-08-05 13:30:44 +00:00
|
|
|
/*
|
|
|
|
* First check if there is a child running, if so, kill it.
|
|
|
|
*/
|
|
|
|
if (e_pid) {
|
|
|
|
if ((kill(e_pid, SIGTERM)) == 0)
|
|
|
|
Syslog('+', "SIGTERM to pid %d succeeded", e_pid);
|
|
|
|
else {
|
|
|
|
if ((kill(e_pid, SIGKILL)) == 0)
|
|
|
|
Syslog('+', "SIGKILL to pid %d succeeded", e_pid);
|
|
|
|
else
|
|
|
|
WriteError("Failed to kill pid %d", e_pid);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-08-05 13:30:44 +00:00
|
|
|
* In case the child had the tty in raw mode, reset the tty.
|
2001-08-17 05:46:24 +00:00
|
|
|
*/
|
2004-03-02 20:47:23 +00:00
|
|
|
execute_pth((char *)"stty", (char *)"sane", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-10-20 20:58:55 +00:00
|
|
|
if (onsig != MBERR_NO_PROGLOCK)
|
2002-09-24 19:54:42 +00:00
|
|
|
CloseDupes();
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
/*
|
|
|
|
* Check for locked and open message base.
|
|
|
|
*/
|
|
|
|
if (MsgBase.Locked)
|
|
|
|
Msg_UnLock();
|
|
|
|
if (MsgBase.Open)
|
|
|
|
Msg_Close();
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
signal(onsig, SIG_IGN);
|
2003-12-04 22:07:33 +00:00
|
|
|
deinitnl();
|
2002-08-05 13:30:44 +00:00
|
|
|
|
|
|
|
if (!do_quiet) {
|
|
|
|
show_log = TRUE;
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_colour(CYAN, BLACK);
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
if (onsig) {
|
|
|
|
if (onsig <= NSIG)
|
|
|
|
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
|
|
|
|
else
|
|
|
|
WriteError("Terminated with error %d", onsig);
|
2005-08-10 18:57:22 +00:00
|
|
|
} else {
|
|
|
|
if (areas_changed)
|
|
|
|
editor_configs();
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (echo_imp + net_imp + net_out + echo_out)
|
|
|
|
CreateSema((char *)"msglink");
|
|
|
|
|
2002-08-28 20:34:50 +00:00
|
|
|
if ((echo_out + net_out + tic_out) || flushed)
|
2002-08-05 13:30:44 +00:00
|
|
|
CreateSema((char *)"scanout");
|
|
|
|
|
|
|
|
if (tic_imp)
|
|
|
|
CreateSema((char *)"reqindex");
|
|
|
|
|
2004-07-23 21:24:09 +00:00
|
|
|
if (net_in + net_imp + net_out + net_bad + net_msgs)
|
|
|
|
Syslog('+', "Netmail [%4d] import [%4d] out [%4d] bad [%4d] msgs [%4d]", net_in, net_imp, net_out, net_bad, net_msgs);
|
2002-08-05 13:30:44 +00:00
|
|
|
if (email_in + email_imp + email_out + email_bad)
|
|
|
|
Syslog('+', "Email [%4d] import [%4d] out [%4d] bad [%4d]", email_in, email_imp, email_out, email_bad);
|
|
|
|
if (echo_in + echo_imp + echo_out + echo_bad + echo_dupe)
|
|
|
|
Syslog('+', "Echomail [%4d] import [%4d] out [%4d] bad [%4d] dupe [%4d]", echo_in, echo_imp, echo_out, echo_bad, echo_dupe);
|
|
|
|
if (news_in + news_imp + news_out + news_bad + news_dupe)
|
|
|
|
Syslog('+', "News [%4d] import [%4d] out [%4d] bad [%4d] dupe [%4d]", news_in, news_imp, news_out, news_bad, news_dupe);
|
|
|
|
if (tic_in + tic_imp + tic_out + tic_bad + tic_dup)
|
|
|
|
Syslog('+', "TICfiles [%4d] import [%4d] out [%4d] bad [%4d] dupe [%4d]", tic_in, tic_imp, tic_out, tic_bad, tic_dup);
|
|
|
|
if (Magics + Hatched)
|
|
|
|
Syslog('+', " Magics [%4d] hatch [%4d]", Magics, Hatched);
|
|
|
|
if (notify + areamgr + filemgr)
|
|
|
|
Syslog('+', "Notify msgs [%4d] AreaMgr [%4d] FileMgr [%4d]", notify, areamgr, filemgr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There should be no locks anymore, but in case of a crash try to unlock
|
2002-09-24 19:54:42 +00:00
|
|
|
* all possible directories. Only if onsig <> 110, this was a lock error
|
|
|
|
* and there should be no lock. We prevent removing the lock of another
|
|
|
|
* mbfido this way.
|
2002-08-05 13:30:44 +00:00
|
|
|
*/
|
2002-10-20 20:58:55 +00:00
|
|
|
if (onsig != MBERR_NO_PROGLOCK) {
|
2002-09-24 19:54:42 +00:00
|
|
|
ulockdir(CFG.inbound);
|
|
|
|
ulockdir(CFG.pinbound);
|
|
|
|
ulockdir(CFG.out_queue);
|
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
|
|
|
|
t_end = time(NULL);
|
|
|
|
Syslog(' ', "MBFIDO finished in %s", t_elapsed(t_start, t_end));
|
|
|
|
|
|
|
|
if (!do_quiet)
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_colour(LIGHTGRAY, BLACK);
|
2002-08-05 13:30:44 +00:00
|
|
|
ExitClient(onsig);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2004-08-07 12:16:09 +00:00
|
|
|
int i, x, Loop, envrecip_count = 0;
|
2002-08-05 13:30:44 +00:00
|
|
|
char *p, *cmd, *temp, Options[81];
|
|
|
|
struct passwd *pw;
|
|
|
|
struct tm *t;
|
|
|
|
fa_list **envrecip, *envrecip_start = NULL;
|
|
|
|
faddr *taddr = NULL;
|
|
|
|
FILE *ofp;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
/*
|
|
|
|
* The next trick is to supply a fake environment variable
|
|
|
|
* MBSE_ROOT in case we are started from UUCP or the MTA.
|
|
|
|
* this will setup the variable so InitConfig() will work.
|
|
|
|
* The /etc/passwd must point to the correct homedirectory.
|
|
|
|
* Some programs can't set uid to mbse, so mbfido is installed
|
|
|
|
* setuid mbse.
|
|
|
|
*/
|
|
|
|
if (getenv("MBSE_ROOT") == NULL) {
|
|
|
|
pw = getpwuid(getuid());
|
|
|
|
if (strcmp(pw->pw_name, "mbse")) {
|
|
|
|
/*
|
|
|
|
* We are not running as user mbse.
|
|
|
|
*/
|
|
|
|
pw = getpwnam("mbse");
|
|
|
|
if (setuid(pw->pw_uid)) {
|
|
|
|
printf("Fatal error: can't set uid to user mbse\n");
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
envptr = xstrcpy((char *)"MBSE_ROOT=");
|
|
|
|
envptr = xstrcat(envptr, pw->pw_dir);
|
|
|
|
putenv(envptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
InitConfig();
|
|
|
|
memset(&Options, 0, sizeof(Options));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize global variables, data records.
|
|
|
|
*/
|
|
|
|
InitNode();
|
|
|
|
InitMsgs();
|
|
|
|
InitTic();
|
|
|
|
InitUser();
|
|
|
|
InitFidonet();
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_TermInit(1, 80, 25);
|
2002-08-05 13:30:44 +00:00
|
|
|
t_start = time(NULL);
|
|
|
|
t = localtime(&t_start);
|
|
|
|
Diw = t->tm_wday;
|
|
|
|
Miy = t->tm_mon;
|
|
|
|
umask(002);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Catch all the signals we can, and ignore the rest.
|
|
|
|
*/
|
|
|
|
for(i = 0; i < NSIG; i++) {
|
|
|
|
|
2003-12-04 22:07:33 +00:00
|
|
|
if ((i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
|
2002-08-05 13:30:44 +00:00
|
|
|
signal(i, (void (*))die);
|
2004-04-09 18:31:22 +00:00
|
|
|
else if (i == SIGCHLD)
|
|
|
|
signal(i, SIG_DFL);
|
2003-12-04 22:07:33 +00:00
|
|
|
else if ((i != SIGKILL) && (i != SIGSTOP))
|
2002-08-05 13:30:44 +00:00
|
|
|
signal(i, SIG_IGN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((p = strrchr(argv[0], '/')))
|
|
|
|
p++;
|
|
|
|
else
|
|
|
|
p = argv[0];
|
|
|
|
if (!strcmp(p, "mbmail")) {
|
|
|
|
do_quiet = TRUE;
|
|
|
|
do_mail = TRUE;
|
|
|
|
cmd = xstrcpy((char *)"Cmd: mbmail");
|
|
|
|
} else if (!strcmp(p, "mbnews")) {
|
|
|
|
do_quiet = TRUE;
|
|
|
|
do_uucp = TRUE;
|
|
|
|
cmd = xstrcpy((char *)"Cmd: mbnews");
|
|
|
|
} else {
|
|
|
|
if (argc < 2)
|
|
|
|
Help();
|
|
|
|
cmd = xstrcpy((char *)"Cmd: mbfido");
|
|
|
|
}
|
|
|
|
|
|
|
|
envrecip = &envrecip_start;
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
cmd = xstrcat(cmd, (char *)" ");
|
|
|
|
cmd = xstrcat(cmd, argv[i]);
|
|
|
|
|
2005-07-03 16:16:17 +00:00
|
|
|
if ((strncmp(tl(argv[i]), "ne", 2) == 0) && !do_mail)
|
2002-08-05 13:30:44 +00:00
|
|
|
do_news = TRUE;
|
2005-07-03 16:16:17 +00:00
|
|
|
else if ((strncmp(tl(argv[i]), "no", 2) == 0) && !do_mail) {
|
2002-08-05 13:30:44 +00:00
|
|
|
do_notify = TRUE;
|
|
|
|
if (((i + 1) < argc) &&
|
2001-08-17 05:46:24 +00:00
|
|
|
((strchr(argv[i + 1], ':') != NULL) ||
|
|
|
|
(atoi(argv[i + 1])) ||
|
|
|
|
(strncmp(argv[i + 1], "*", 1) == 0))) {
|
2005-08-28 14:52:14 +00:00
|
|
|
snprintf(Options, 81, "%s", argv[i + 1]);
|
2001-08-17 05:46:24 +00:00
|
|
|
i++;
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-03 16:16:17 +00:00
|
|
|
else if ((strncmp(tl(argv[i]), "r", 1) == 0) && !do_mail)
|
2002-08-05 13:30:44 +00:00
|
|
|
do_roll = TRUE;
|
2005-07-03 16:16:17 +00:00
|
|
|
else if ((strncmp(tl(argv[i]), "a", 1) == 0) && !do_mail)
|
2002-08-05 13:30:44 +00:00
|
|
|
do_areas = TRUE;
|
2005-07-03 16:16:17 +00:00
|
|
|
else if ((strncmp(tl(argv[i]), "s", 1) == 0) && !do_mail)
|
2002-08-05 13:30:44 +00:00
|
|
|
do_scan = TRUE;
|
2005-07-03 16:16:17 +00:00
|
|
|
else if ((strncmp(tl(argv[i]), "ta", 2) == 0) && !do_mail)
|
2002-08-05 13:30:44 +00:00
|
|
|
do_tags = TRUE;
|
2005-07-03 16:16:17 +00:00
|
|
|
else if ((strncmp(tl(argv[i]), "ti", 2) == 0) && !do_mail)
|
2002-08-05 13:30:44 +00:00
|
|
|
do_tic = TRUE;
|
2005-07-03 16:16:17 +00:00
|
|
|
else if ((strncmp(tl(argv[i]), "te", 2) == 0) && !do_mail) {
|
2002-08-05 13:30:44 +00:00
|
|
|
do_test = TRUE;
|
|
|
|
if ((i + 1) < argc) {
|
|
|
|
if ((taddr = parsefaddr(argv[i + 1])) == NULL) {
|
|
|
|
Help();
|
2001-08-25 19:53:11 +00:00
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
i++;
|
|
|
|
cmd = xstrcat(cmd, (char *)" ");
|
|
|
|
cmd = xstrcat(cmd, argv[i]);
|
|
|
|
}
|
2005-07-03 16:16:17 +00:00
|
|
|
} else if ((strncmp(tl(argv[i]), "to", 2) == 0) && !do_mail)
|
2002-08-05 13:30:44 +00:00
|
|
|
do_toss = TRUE;
|
2005-07-03 16:16:17 +00:00
|
|
|
else if ((strncmp(tl(argv[i]), "u", 1) == 0) && !do_mail)
|
2002-08-05 13:30:44 +00:00
|
|
|
do_uucp = TRUE;
|
2005-07-03 16:16:17 +00:00
|
|
|
else if ((strncmp(tl(argv[i]), "m", 1) == 0) && !do_mail)
|
2002-08-05 13:30:44 +00:00
|
|
|
do_mail = TRUE;
|
2005-07-03 16:16:17 +00:00
|
|
|
else if ((strncmp(tl(argv[i]), "w", 1) == 0) && !do_mail)
|
2002-08-05 13:30:44 +00:00
|
|
|
do_stat = TRUE;
|
|
|
|
else if (strncmp(tl(argv[i]), "-f", 2) == 0)
|
|
|
|
do_full = TRUE;
|
|
|
|
else if (strncmp(tl(argv[i]), "-l", 2) == 0)
|
|
|
|
do_learn = TRUE;
|
|
|
|
else if (strncmp(tl(argv[i]), "-noc", 4) == 0)
|
|
|
|
check_crc = FALSE;
|
|
|
|
else if (strncmp(tl(argv[i]), "-nod", 4) == 0)
|
|
|
|
check_dupe = FALSE;
|
|
|
|
else if (strncmp(tl(argv[i]), "-q", 2) == 0)
|
|
|
|
do_quiet = TRUE;
|
|
|
|
else if (strncmp(tl(argv[i]), "-a", 2) == 0)
|
2005-08-26 18:26:38 +00:00
|
|
|
do_obs_a = TRUE;
|
2002-08-05 13:30:44 +00:00
|
|
|
else if (strncmp(tl(argv[i]), "-unp", 4) == 0)
|
|
|
|
do_unprot = TRUE;
|
|
|
|
else if (strncmp(tl(argv[i]), "-uns", 4) == 0)
|
|
|
|
do_unsec = TRUE;
|
|
|
|
else if (do_mail) {
|
|
|
|
/*
|
|
|
|
* Possible recipient address(es).
|
|
|
|
*/
|
|
|
|
if ((taddr = parsefaddr(argv[i]))) {
|
|
|
|
(*envrecip) = (fa_list*)malloc(sizeof(fa_list));
|
|
|
|
(*envrecip)->next = NULL;
|
|
|
|
(*envrecip)->addr = taddr;
|
|
|
|
envrecip = &((*envrecip)->next);
|
|
|
|
envrecip_count++;
|
|
|
|
} else {
|
2005-07-03 16:16:17 +00:00
|
|
|
cmd = xstrcat(cmd, (char *)" <- unparsable recipient! ");
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2004-08-12 12:50:52 +00:00
|
|
|
if ((!do_areas) && (!do_toss) && (!do_scan) && (!do_tic) && (!do_notify) && (!do_roll) &&
|
|
|
|
(!do_tags) && (!do_stat) && (!do_test) && (!do_news) && (!do_uucp) && (!do_mail))
|
|
|
|
Help();
|
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
ProgName();
|
|
|
|
pw = getpwuid(getuid());
|
2003-09-09 19:39:51 +00:00
|
|
|
InitClient(pw->pw_name, (char *)"mbfido", CFG.location, CFG.logfile,
|
|
|
|
CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
Syslog(' ', " ");
|
|
|
|
Syslog(' ', "MBFIDO v%s", VERSION);
|
|
|
|
Syslog(' ', cmd);
|
|
|
|
free(cmd);
|
2005-08-26 18:26:38 +00:00
|
|
|
if (do_obs_a)
|
|
|
|
WriteError("The -a option is obsolete, adjust your setup");
|
2001-12-23 20:17:39 +00:00
|
|
|
|
2002-09-24 19:54:42 +00:00
|
|
|
/*
|
2002-10-20 20:58:55 +00:00
|
|
|
* Not yet locked, if anything goes wrong, exit with die(MBERR_NO_PROGLOCK)
|
2002-09-24 19:54:42 +00:00
|
|
|
*/
|
2004-03-21 12:55:45 +00:00
|
|
|
if (enoughspace(CFG.freespace) == 0)
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_DISK_FULL);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
if (do_mail) {
|
|
|
|
/*
|
|
|
|
* Try to get a lock for a long time, another mbfido may be legally
|
|
|
|
* running since mbmail is started by the MTA instead of by mbtask.
|
|
|
|
* The timeout is 10 minutes. If mbmail times out, the MTA will
|
|
|
|
* bounce the message. What happens during the time we wait is
|
|
|
|
* unknown, will the MTA be patient enough?
|
|
|
|
*/
|
|
|
|
i = 30;
|
|
|
|
while (TRUE) {
|
|
|
|
if (do_unprot) {
|
|
|
|
if (lockdir(CFG.inbound))
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (lockdir(CFG.pinbound))
|
2001-11-14 19:50:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
i--;
|
|
|
|
if (! i) {
|
|
|
|
WriteError("Lock timeout, aborting");
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_NO_PROGLOCK);
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
|
|
|
sleep(20);
|
|
|
|
Nopper();
|
2001-11-14 19:50:27 +00:00
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Started under control of mbtask, that means if there is a lock then
|
|
|
|
* there is something wrong; abort.
|
|
|
|
*/
|
|
|
|
if (do_unprot) {
|
|
|
|
if (! lockdir(CFG.inbound))
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_NO_PROGLOCK);
|
2002-08-05 13:30:44 +00:00
|
|
|
} else {
|
|
|
|
if (! lockdir(CFG.pinbound))
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_NO_PROGLOCK);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
|
|
|
|
2002-09-24 19:54:42 +00:00
|
|
|
/*
|
|
|
|
* Locking succeeded, no more abort alowed with die(110)
|
|
|
|
*/
|
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
if (initnl())
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_INIT_ERROR);
|
2002-08-05 13:30:44 +00:00
|
|
|
if (!do_mail && !do_uucp)
|
|
|
|
Rollover();
|
|
|
|
if (!do_quiet)
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read alias file
|
|
|
|
*/
|
|
|
|
cmd = calloc(PATH_MAX, sizeof(char));
|
2005-08-28 14:52:14 +00:00
|
|
|
snprintf(cmd, PATH_MAX, "%s/etc/aliases", getenv("MBSE_ROOT"));
|
2002-08-05 13:30:44 +00:00
|
|
|
if ((do_news || do_scan || do_toss || do_mail) && file_exist(cmd, R_OK) == 0)
|
|
|
|
readalias(cmd);
|
|
|
|
free(cmd);
|
|
|
|
|
|
|
|
if (do_mail) {
|
|
|
|
if (!envrecip_count) {
|
|
|
|
WriteError("No valid receipients specified, aborting");
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_NO_RECIPIENTS);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
|
|
|
|
umask(066);
|
|
|
|
if ((ofp = tmpfile()) == NULL) {
|
|
|
|
WriteError("$Can't open tmpfile for RFC message");
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_INIT_ERROR);
|
2002-08-03 19:52:57 +00:00
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
temp = calloc(10240, sizeof(char));
|
|
|
|
while (fgets(temp, 10240, stdin))
|
|
|
|
fprintf(ofp, temp);
|
|
|
|
free(temp);
|
|
|
|
|
|
|
|
for (envrecip = &envrecip_start; *envrecip; envrecip = &((*envrecip)->next)) {
|
|
|
|
Syslog('+', "Message to: %s", ascfnode((*envrecip)->addr, 0x7f));
|
|
|
|
rfc2ftn(ofp, (*envrecip)->addr);
|
2002-06-29 12:56:11 +00:00
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
|
|
|
|
fclose(ofp);
|
|
|
|
flush_queue();
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_OK);
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
|
|
|
|
2002-09-24 19:54:42 +00:00
|
|
|
InitDupes();
|
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
if (do_notify)
|
|
|
|
if (Notify(Options)) {
|
|
|
|
do_flush = TRUE;
|
|
|
|
}
|
2004-07-24 15:32:30 +00:00
|
|
|
if (do_tic || do_toss)
|
|
|
|
toss_msgs();
|
2002-08-05 13:30:44 +00:00
|
|
|
if (do_tic) {
|
|
|
|
if (IsSema((char *)"mailin"))
|
|
|
|
RemoveSema((char *)"mailin");
|
|
|
|
/*
|
|
|
|
* Hatch new files and process .tic files
|
|
|
|
* until nothing left to do.
|
|
|
|
*/
|
|
|
|
Loop = TRUE;
|
|
|
|
do {
|
2004-07-23 21:24:09 +00:00
|
|
|
toss_msgs();
|
2002-08-05 13:30:44 +00:00
|
|
|
Hatch();
|
|
|
|
switch (Tic()) {
|
2002-10-20 20:58:55 +00:00
|
|
|
case -1: die(MBERR_OK);
|
2002-08-05 13:30:44 +00:00
|
|
|
break;
|
|
|
|
case 0: Loop = FALSE;
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
} while (Loop);
|
|
|
|
}
|
|
|
|
if (do_news) {
|
|
|
|
ScanNews();
|
|
|
|
if (IsSema((char *)"newnews"))
|
|
|
|
RemoveSema((char *)"newnews");
|
|
|
|
}
|
2004-07-23 21:24:09 +00:00
|
|
|
if (do_scan) {
|
|
|
|
toss_msgs();
|
2002-08-05 13:30:44 +00:00
|
|
|
ScanMail(do_full);
|
2004-07-23 21:24:09 +00:00
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
if (do_toss) {
|
|
|
|
if (IsSema((char *)"mailin"))
|
|
|
|
RemoveSema((char *)"mailin");
|
2004-07-23 21:24:09 +00:00
|
|
|
toss_msgs();
|
2002-08-05 13:30:44 +00:00
|
|
|
if (TossMail() == FALSE)
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_OK);
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
|
|
|
if (do_tic || do_toss) {
|
|
|
|
/*
|
|
|
|
* Do inbound direcory sessions
|
|
|
|
*/
|
2002-11-11 12:56:19 +00:00
|
|
|
if (dirinbound()) {
|
|
|
|
if (do_tic) {
|
|
|
|
/*
|
|
|
|
* Hatch new files and process .tic files
|
|
|
|
* until nothing left to do.
|
|
|
|
*/
|
|
|
|
Loop = TRUE;
|
|
|
|
do {
|
2004-07-23 21:24:09 +00:00
|
|
|
toss_msgs();
|
2002-11-11 12:56:19 +00:00
|
|
|
Hatch();
|
|
|
|
switch (Tic()) {
|
|
|
|
case -1: die(MBERR_OK);
|
|
|
|
break;
|
|
|
|
case 0: Loop = FALSE;
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
} while (Loop);
|
|
|
|
}
|
|
|
|
if (do_toss) {
|
2004-07-23 21:24:09 +00:00
|
|
|
toss_msgs();
|
2002-11-11 12:56:19 +00:00
|
|
|
TossMail();
|
|
|
|
}
|
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
|
|
|
if (!do_uucp)
|
|
|
|
newspost();
|
|
|
|
if (do_test) {
|
|
|
|
if (taddr == NULL)
|
|
|
|
Help();
|
|
|
|
TestTracker(taddr);
|
|
|
|
tidy_faddr(taddr);
|
|
|
|
}
|
|
|
|
if (do_tags)
|
|
|
|
MakeTags();
|
|
|
|
if (do_stat)
|
|
|
|
MakeStat();
|
|
|
|
if (do_uucp)
|
|
|
|
NewsUUCP();
|
2004-08-07 12:16:09 +00:00
|
|
|
if (do_areas) {
|
|
|
|
if (!do_quiet) {
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_colour(LIGHTGREEN, BLACK);
|
2004-08-07 12:16:09 +00:00
|
|
|
printf("Are you sure to process all area lists [y/N] ");
|
|
|
|
fflush(stdout);
|
2004-11-03 20:48:45 +00:00
|
|
|
x = mbse_Getone();
|
2004-08-07 12:16:09 +00:00
|
|
|
printf("\r \r");
|
|
|
|
fflush(stdout);
|
|
|
|
if (toupper(x) != 'Y')
|
|
|
|
die(MBERR_OK);
|
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
Areas();
|
2004-08-07 12:16:09 +00:00
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
if (do_flush)
|
|
|
|
flush_queue();
|
|
|
|
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_OK);
|
2002-08-05 13:30:44 +00:00
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Toss Fidonet mail
|
|
|
|
*/
|
|
|
|
int TossMail(void)
|
|
|
|
{
|
2002-08-05 13:30:44 +00:00
|
|
|
char *inbound, *fname;
|
|
|
|
DIR *dp;
|
|
|
|
struct dirent *de;
|
|
|
|
struct stat sbuf;
|
|
|
|
int files = 0, files_ok = 0, rc = 0, maxrc = 0;
|
|
|
|
fd_list *fdl = NULL;
|
|
|
|
|
|
|
|
if (do_unprot)
|
|
|
|
inbound = xstrcpy(CFG.inbound);
|
|
|
|
else
|
|
|
|
inbound = xstrcpy(CFG.pinbound);
|
|
|
|
|
|
|
|
Syslog('+', "Pass: toss netmail (%s)", inbound);
|
|
|
|
|
|
|
|
if (chdir(inbound) == -1) {
|
|
|
|
WriteError("$Can't chdir(%s)", inbound);
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_INIT_ERROR);
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First toss any netmail packets.
|
|
|
|
*/
|
|
|
|
maxrc = rc = TossPkts();
|
|
|
|
chdir(inbound);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the directory for ARCmail archives. The archive extension
|
|
|
|
* numbering doesn't matter, as long as there is something, so
|
|
|
|
* all kind of ARCmail naming schemes are recognized.
|
|
|
|
*/
|
|
|
|
if ((dp = opendir(inbound)) == NULL) {
|
|
|
|
WriteError("$Can't opendir(%s)", inbound);
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_INIT_ERROR);
|
2002-08-05 13:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Syslog('+', "Pass: toss ARCmail (%s)", inbound);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add all ARCmail filenames to the memory array.
|
|
|
|
*/
|
|
|
|
sync();
|
|
|
|
while ((de=readdir(dp)))
|
|
|
|
if ((strlen(de->d_name) == 12) && ((strncasecmp(de->d_name+8,".su",3) == 0) ||
|
|
|
|
(strncasecmp(de->d_name+8,".mo",3) == 0) || (strncasecmp(de->d_name+8,".tu",3) == 0) ||
|
|
|
|
(strncasecmp(de->d_name+8,".we",3) == 0) || (strncasecmp(de->d_name+8,".th",3) == 0) ||
|
|
|
|
(strncasecmp(de->d_name+8,".fr",3) == 0) || (strncasecmp(de->d_name+8,".sa",3) == 0))) {
|
|
|
|
stat(de->d_name, &sbuf);
|
|
|
|
fill_fdlist(&fdl, de->d_name, sbuf.st_mtime);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
closedir(dp);
|
|
|
|
sort_fdlist(&fdl);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
/*
|
|
|
|
* Now process the archives, the oldest first.
|
|
|
|
*/
|
|
|
|
while ((fname = pull_fdlist(&fdl)) != NULL) {
|
|
|
|
files++;
|
|
|
|
IsDoing("Unpack arcmail");
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
if (IsSema((char *)"upsalarm")) {
|
|
|
|
Syslog('+', "Detected upsalarm semafore, aborting toss");
|
|
|
|
break;
|
|
|
|
}
|
2004-03-20 23:00:22 +00:00
|
|
|
if (enoughspace(CFG.freespace) == 0) {
|
|
|
|
Syslog('+', "Low diskspace, aborting toss");
|
2002-10-20 20:58:55 +00:00
|
|
|
rc = MBERR_DISK_FULL;
|
2002-08-05 13:30:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
if (checkspace(inbound, fname, UNPACK_FACTOR))
|
|
|
|
if ((rc = unpack(fname)) == 0) {
|
|
|
|
files_ok++;
|
|
|
|
rc = TossPkts();
|
|
|
|
chdir(inbound);
|
|
|
|
} else
|
|
|
|
WriteError("Error unpacking file %s", fname);
|
|
|
|
else
|
|
|
|
Syslog('!', "Insufficient space to unpack file %s", fname);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
if (rc > maxrc)
|
|
|
|
maxrc = rc;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
free(inbound);
|
|
|
|
if ((files || packets) && ((files_ok != files) || (packets_ok != packets)))
|
|
|
|
Syslog('!', "Processed %d of %d files, %d of %d packets, rc=%d", files_ok, files, packets_ok, packets, maxrc);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
return TRUE;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Toss all packets currently in the inbound. Tossing is sorted by
|
|
|
|
* age of the files.
|
|
|
|
*/
|
|
|
|
int TossPkts(void)
|
|
|
|
{
|
2002-08-05 13:30:44 +00:00
|
|
|
char *inbound = NULL, *fname;
|
|
|
|
DIR *dp;
|
|
|
|
struct dirent *de;
|
|
|
|
struct stat sbuf;
|
|
|
|
int rc = 0, maxrc = 0;
|
|
|
|
fd_list *fdl = NULL;
|
|
|
|
|
|
|
|
IsDoing("Tossing mail");
|
|
|
|
|
|
|
|
if (do_unprot)
|
|
|
|
inbound = xstrcpy(CFG.inbound);
|
|
|
|
else
|
|
|
|
inbound = xstrcpy(CFG.pinbound);
|
|
|
|
|
|
|
|
if ((dp = opendir(inbound)) == NULL) {
|
|
|
|
WriteError("$Can't opendir(%s)", inbound);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read all .pkt filenames, get the timestamp and add them
|
|
|
|
* to the memory array for later sort on filedate.
|
|
|
|
*/
|
|
|
|
while ((de = readdir(dp)))
|
|
|
|
if ((strlen(de->d_name) == 12) && (strncasecmp(de->d_name+8,".pkt",4) == 0)) {
|
|
|
|
stat(de->d_name, &sbuf);
|
|
|
|
fill_fdlist(&fdl, de->d_name, sbuf.st_mtime);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
closedir(dp);
|
|
|
|
sort_fdlist(&fdl);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
/*
|
|
|
|
* Get the filenames, the oldest first until nothing left.
|
|
|
|
*/
|
|
|
|
while ((fname = pull_fdlist(&fdl)) != NULL) {
|
|
|
|
|
2004-03-20 23:00:22 +00:00
|
|
|
if (enoughspace(CFG.freespace) == 0) {
|
|
|
|
Syslog('+', "Low diskspace, abort tossing packet");
|
2002-08-05 13:30:44 +00:00
|
|
|
return FALSE;
|
2004-03-20 23:00:22 +00:00
|
|
|
}
|
2002-08-05 13:30:44 +00:00
|
|
|
packets++;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
/*
|
2002-08-05 13:30:44 +00:00
|
|
|
* See if "pktdate" from Tobias Ernst (or another preprocessor) is installed.
|
2001-08-17 05:46:24 +00:00
|
|
|
*/
|
2002-08-05 13:30:44 +00:00
|
|
|
if (strlen(CFG.pktdate)) {
|
2004-03-02 20:47:23 +00:00
|
|
|
rc = execute_str(CFG.pktdate, fname, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
2002-08-05 13:30:44 +00:00
|
|
|
if (rc)
|
|
|
|
Syslog('+', "%s preprocessing rc=%d", fname, rc);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
2002-08-05 13:30:44 +00:00
|
|
|
if ((rc = toss(fname)) == 0)
|
|
|
|
packets_ok++;
|
|
|
|
else
|
|
|
|
WriteError("Error tossing packet %s", fname);
|
|
|
|
if (rc > maxrc)
|
|
|
|
maxrc = rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(inbound);
|
|
|
|
do_flush = TRUE;
|
|
|
|
return maxrc;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Toss one packet
|
|
|
|
*/
|
|
|
|
int toss(char *fn)
|
|
|
|
{
|
2002-08-05 13:30:44 +00:00
|
|
|
int rc = 0, ld;
|
|
|
|
char newname[16];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock the packet
|
|
|
|
*/
|
|
|
|
if ((ld = f_lock(fn)) == -1)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
rc = TossPkt(fn);
|
|
|
|
if (rc == 0) {
|
|
|
|
unlink(fn);
|
|
|
|
} else {
|
|
|
|
strncpy(newname,fn,sizeof(newname)-1);
|
|
|
|
strcpy(newname+8,".bad");
|
|
|
|
rename(fn,newname);
|
|
|
|
}
|
|
|
|
|
|
|
|
funlock(ld);
|
|
|
|
return rc;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|