Switched to virus scanner from library

This commit is contained in:
Michiel Broek 2008-02-17 17:50:13 +00:00
parent 5890ef471c
commit e9dbd74830
7 changed files with 42 additions and 280 deletions

View File

@ -11,6 +11,10 @@ v0.95.1 07-Jan-2008
mbfido:
Changed error message on the news gate.
Switched to virus scanner from library.
mbfile:
Switched to virus scanner from library.
mbsebbs:
Added MIB counters.

View File

@ -13,7 +13,7 @@ SRCS = addbbs.c backalias.c flock.c hatch.c mbdiff.c mgrutil.c qualify.c \
mbmsg.c newspost.c postemail.c scan.c toberep.c atoul.c filemgr.c \
hash.c mbaff.c mbseq.c notify.c postnetmail.c scannews.c tosspkt.c \
mbfkill.c mbfutil.c mbfindex.c mbfcheck.c mbfpack.c mbflist.c mbfadopt.c \
mbfimport.c mbfsort.c virscan.c mbftoberep.c mbfmove.c mbfdel.c bounce.c \
mbfimport.c mbfsort.c mbftoberep.c mbfmove.c mbfdel.c bounce.c \
createm.c createf.c msgflags.c dirsession.c queue.c dirlock.c msg.c orphans.c
HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h qualify.h \
postnetmail.h scannews.h tosspkt.h addpkt.h bwrite.h forward.h \
@ -24,9 +24,9 @@ HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h qualify.h \
grlist.h maketags.h mbmsg.h newspost.h postecho.h rollover.h tic.h mbfrearc.h \
atoul.h filemgr.h hash.h mbaff.h mbseq.h notify.h postemail.h scan.h toberep.h \
mbfkill.h mbfutil.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfadopt.h \
mbfimport.h mbfsort.h virscan.h mbftoberep.h mbfmove.h mbfdel.h bounce.h \
mbfimport.h mbfsort.h mbftoberep.h mbfmove.h mbfdel.h bounce.h \
createm.h createf.h msgflags.h dirsession.h queue.h dirlock.h msg.h orphans.h
MBFIDO_OBJS = flock.o tosspkt.o mbfido.o hatch.o maketags.o virscan.o tracker.o \
MBFIDO_OBJS = flock.o tosspkt.o mbfido.o hatch.o maketags.o tracker.o \
makestat.o scannews.o lhash.o bounce.o unpack.o tic.o ptic.o \
utic.o mover.o hash.o mkftnhdr.o addbbs.o magic.o fsort.o toberep.o \
ftn2rfc.o atoul.o ping.o forward.o sendmail.o scan.o addpkt.o \
@ -39,7 +39,7 @@ MBAFF_OBJS = announce.o fflist.o filefind.o grlist.o mbaff.o msgutil.o toberep.o
MBINDEX_OBJS = mbindex.o
MBDIFF_OBJS = mbdiff.o
MBFILE_OBJS = mbfile.o mbfkill.o mbfutil.o mbfindex.o mbfcheck.o mbfpack.o mbflist.o mbfadopt.o \
mbfimport.o virscan.o mbftoberep.o mbfmove.o mbfdel.o mbfsort.o mbfrearc.o
mbfimport.o mbftoberep.o mbfmove.o mbfdel.o mbfsort.o mbfrearc.o
MBMSG_OBJS = post.o mbmsg.o
MBFIDO_LIBS = ../lib/libmbse.a ../lib/libmsgbase.a ../lib/libdbase.a ../lib/libdiesel.a ../lib/libmbinet.a ../lib/libnodelist.a
MBSEQ_LIBS = ../lib/libmbse.a ../lib/libdbase.a
@ -131,7 +131,7 @@ hatch.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h utic.h roll
mbdiff.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbdiff.h
mgrutil.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h ../lib/diesel.h sendmail.h rollover.h addpkt.h createm.h createf.h mgrutil.h
qualify.o: ../config.h ../lib/mbselib.h qualify.h
ptic.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h unpack.h mover.h toberep.h orphans.h tic.h utic.h magic.h forward.h rollover.h ptic.h magic.h createf.h virscan.h qualify.h addbbs.h
ptic.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h unpack.h mover.h toberep.h orphans.h tic.h utic.h magic.h forward.h rollover.h ptic.h magic.h createf.h qualify.h addbbs.h
sendmail.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h addpkt.h rollover.h sendmail.h
tracker.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/nodelist.h ../lib/mbsedb.h tracker.h
addpkt.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h addpkt.h
@ -187,10 +187,9 @@ mbfindex.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h ../lib/d
mbfcheck.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbfutil.h mbfcheck.h
mbfpack.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbfutil.h mbfpack.h
mbflist.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbfutil.h mbflist.h
mbfadopt.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h virscan.h mbfutil.h mbflist.h
mbfimport.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h virscan.h mbfutil.h mbfimport.h
mbfadopt.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbfutil.h mbflist.h
mbfimport.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbfutil.h mbfimport.h
mbfsort.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbfutil.h mbfsort.h
virscan.o: ../config.h ../lib/mbselib.h virscan.h
mbftoberep.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbfutil.h mbftoberep.h
mbfmove.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbfutil.h mbfmove.h
mbfdel.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbfutil.h mbfmove.h

View File

@ -4,7 +4,7 @@
* Purpose: File Database Maintenance - Adopt file
*
*****************************************************************************
* Copyright (C) 1997-2006
* Copyright (C) 1997-2008
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@ -32,7 +32,6 @@
#include "../lib/mbselib.h"
#include "../lib/users.h"
#include "../lib/mbsedb.h"
#include "virscan.h"
#include "mbfutil.h"
#include "mbflist.h"
@ -50,7 +49,7 @@ void AdoptFile(int Area, char *File, char *Description)
char Desc[256], TDesc[256];
int IsArchive = FALSE, MustRearc = FALSE, UnPacked = FALSE;
int IsVirus = FALSE, File_Id = FALSE;
int i, j, k, lines = 0, File_id_cnt = 0, rc;
int i, j, k, lines = 0, File_id_cnt = 0;
struct FILE_record f_db;
Syslog('f', "Adopt(%d, %s, %s)", Area, MBSE_SS(File), MBSE_SS(Description));
@ -86,59 +85,27 @@ void AdoptFile(int Area, char *File, char *Description)
}
snprintf(temp, PATH_MAX, "%s/%s", pwd, File);
if ((unarc = unpacker(File)) == NULL) {
Syslog('+', "No known archive: %s", File);
snprintf(temp2, PATH_MAX, "%s/tmp/arc%d/%s", getenv("MBSE_ROOT"), (int)getpid(), File);
if ((rc = file_cp(temp, temp2))) {
WriteError("Can't copy file to %s, %s", temp2, strerror(rc));
if (!do_quiet)
printf("\nCan't copy file to %s, %s\n", temp2, strerror(rc));
die(MBERR_INIT_ERROR);
} else {
if (do_novir == FALSE) {
if (!do_quiet) {
printf("Virscan \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
IsVirus = VirScan(tmpdir);
} else {
IsVirus = FALSE;
IsVirus = VirScanFile(temp);
}
if (IsVirus) {
clean_tmpwork();
chdir(pwd);
WriteError("Virus found");
if (!do_quiet)
printf("\nVirus found\n");
die(MBERR_VIRUS_FOUND);
}
}
} else {
if ((unarc = unpacker(File))) {
IsArchive = TRUE;
if (strlen(area.Archiver) && (strcmp(unarc, area.Archiver) == 0))
MustRearc = TRUE;
UnPacked = UnpackFile(temp);
if (!UnPacked)
die(MBERR_INIT_ERROR);
if (do_novir == FALSE) {
if (!do_quiet) {
printf("Virscan \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
IsVirus = VirScan(tmpdir);
} else {
IsVirus = FALSE;
}
if (IsVirus) {
clean_tmpwork();
chdir(pwd);
WriteError("Virus found");
if (!do_quiet)
printf("\nVirus found\n");
die(MBERR_VIRUS_FOUND);
}
}
if (!do_quiet) {

View File

@ -4,7 +4,7 @@
* Purpose: File Database Maintenance - Import files with files.bbs
*
*****************************************************************************
* Copyright (C) 1997-2007
* Copyright (C) 1997-2008
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@ -32,7 +32,6 @@
#include "../lib/mbselib.h"
#include "../lib/users.h"
#include "../lib/mbsedb.h"
#include "virscan.h"
#include "mbfutil.h"
#include "mbfimport.h"
@ -84,56 +83,20 @@ void test_file(char *dirpath, char *search, char *result)
*/
int flush_file(char *source, char *dest, char *lname, struct FILE_record f_db, int Area)
{
int Doit, rc;
char *temp2, *unarc, *tmpdir;
int Doit = TRUE, rc = 0;
Syslog('f', "flush_file(%s, %s, %s, %d)", source, dest, lname, Area);
temp2 = calloc(PATH_MAX, sizeof(char));
tmpdir = calloc(PATH_MAX, sizeof(char));
snprintf(tmpdir, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid());
Doit = TRUE;
if ((unarc = unpacker(source)) == NULL) {
Syslog('+', "Unknown archive format %s", source);
snprintf(temp2, PATH_MAX, "%s/%s", tmpdir, f_db.Name);
if ((rc = file_cp(source, temp2))) {
WriteError("1 Can't copy file to %s, %s", temp2, strerror(rc));
if (!do_quiet)
printf("Can't copy file to %s, %s\n", temp2, strerror(rc));
Doit = FALSE;
} else {
if (do_novir == FALSE) {
if (!do_quiet) {
printf("Virscan \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
if (VirScan(tmpdir)) {
Doit = FALSE;
}
}
}
} else {
if (!do_quiet) {
printf("Unpacking \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
if (UnpackFile(source)) {
if (do_novir == FALSE) {
if (!do_quiet) {
printf("Virscan \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
if (VirScan(tmpdir)) {
Doit = FALSE;
}
}
} else {
if (VirScanFile(source)) {
Doit = FALSE;
}
}
rc = 0;
if (Doit) {
if (!do_quiet) {
printf("Adding \b\b\b\b\b\b\b\b\b\b");
@ -150,8 +113,6 @@ int flush_file(char *source, char *dest, char *lname, struct FILE_record f_db, i
}
}
free(temp2);
free(tmpdir);
return rc;
}

View File

@ -4,7 +4,7 @@
* Purpose ...............: Process 1 .tic file
*
*****************************************************************************
* Copyright (C) 1997-2007
* Copyright (C) 1997-2008
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@ -44,7 +44,6 @@
#include "ptic.h"
#include "magic.h"
#include "createf.h"
#include "virscan.h"
#include "qualify.h"
#include "addbbs.h"
@ -339,7 +338,7 @@ int ProcessTic(fa_list **sbl, orphans **opl)
* Check if this is an archive, and if so, which compression method
* is used for this file.
*/
if (strlen(tic.Convert) || tic.VirScan || tic.FileId || tic.ConvertAll || strlen(tic.Banner)) {
if (strlen(tic.Convert) || tic.FileId || tic.ConvertAll || strlen(tic.Banner)) {
/*
* Create tmp workdir
*/
@ -373,7 +372,7 @@ int ProcessTic(fa_list **sbl, orphans **opl)
}
}
if ((tic.VirScan || MustRearc) && IsArchive) {
if (MustRearc && IsArchive) {
snprintf(temp2, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid());
if (!checkspace(temp2, TIC.TicIn.File, UNPACK_FACTOR)) {
@ -420,42 +419,19 @@ int ProcessTic(fa_list **sbl, orphans **opl)
}
}
if (tic.VirScan && !UnPacked) {
/*
* Copy file to tempdir and run scanner over the file
* whatever that is. This should catch single files
* with worms or other macro viri
* Scan file for viri.
*/
snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File);
snprintf(temp2, PATH_MAX, "%s/tmp/arc%d/%s", getenv("MBSE_ROOT"), (int)getpid(), TIC.TicIn.File);
if ((rc = file_cp(temp1, temp2))) {
WriteError("Can't copy %s to %s: %s", temp1, temp2, strerror(rc));
free(Temp);
tidy_qualify(&qal);
clean_tmpwork();
return 1;
}
snprintf(temp2, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid());
if (chdir(temp2) != 0) {
WriteError("$Can't change to %s", temp2);
free(Temp);
tidy_qualify(&qal);
clean_tmpwork();
return 1;
}
}
if (tic.VirScan) {
snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File);
if (!do_quiet) {
printf("Virscan \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
if (VirScan(NULL)) {
clean_tmpwork();
if (VirScanFile(temp1)) {
chdir(TIC.Inbound);
Bad((char *)"Possible virus found!");
free(Temp);

View File

@ -1,136 +0,0 @@
/*****************************************************************************
*
* $Id$
* Purpose ...............: Scan for virusses
*
*****************************************************************************
* Copyright (C) 1997-2007
*
* 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
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*****************************************************************************/
#include "../config.h"
#include "../lib/mbselib.h"
#include "virscan.h"
extern pid_t mypid;
/*
* Check for known viri, optional in a defined path.
*/
int VirScan(char *path)
{
char *pwd, *temp, *stdlog, *errlog, buf[256];
FILE *fp, *lp;
int vrc, rc = FALSE, has_scan = FALSE;
temp = calloc(PATH_MAX, sizeof(char));
stdlog = calloc(PATH_MAX, sizeof(char));
errlog = calloc(PATH_MAX, sizeof(char));
snprintf(temp, PATH_MAX, "%s/etc/virscan.data", getenv("MBSE_ROOT"));
snprintf(stdlog, PATH_MAX, "%s/tmp/stdlog%d", getenv("MBSE_ROOT"), mypid);
snprintf(errlog, PATH_MAX, "%s/tmp/errlog%d", getenv("MBSE_ROOT"), mypid);
if ((fp = fopen(temp, "r")) == NULL) {
WriteError("No virus scanners defined");
free(temp);
free(stdlog);
free(errlog);
return FALSE;
}
fread(&virscanhdr, sizeof(virscanhdr), 1, fp);
while (fread(&virscan, virscanhdr.recsize, 1, fp) == 1) {
if (virscan.available) {
if (file_exist(virscan.scanner, X_OK) == 0) {
has_scan = TRUE;
} else {
Syslog('+', "Warning: virusscanner %s marked active but not present", virscan.comment);
}
}
}
if (!has_scan) {
Syslog('+', "No active virus scanners, skipping scan");
fclose(fp);
free(temp);
free(stdlog);
free(errlog);
return FALSE;
}
pwd = calloc(PATH_MAX, sizeof(char));
getcwd(pwd, PATH_MAX);
if (path) {
chdir(path);
Syslog('+', "Start virusscan in %s", path);
} else {
Syslog('+', "Start virusscan in %s", pwd);
}
fseek(fp, virscanhdr.hdrsize, SEEK_SET);
while (fread(&virscan, virscanhdr.recsize, 1, fp) == 1) {
if (virscan.available && (file_exist(virscan.scanner, X_OK) ==0)) {
Altime(3600);
vrc = execute_str(virscan.scanner, virscan.options, (char *)NULL, (char *)"/dev/null", stdlog, errlog);
if (file_size(stdlog)) {
if ((lp = fopen(stdlog, "r"))) {
while (fgets(buf, sizeof(buf) -1, lp)) {
Striplf(buf);
Syslog('+', "stdout: \"%s\"", printable(buf, 0));
}
fclose(lp);
}
}
if (file_size(errlog)) {
if ((lp = fopen(errlog, "r"))) {
while (fgets(buf, sizeof(buf) -1, lp)) {
Striplf(buf);
Syslog('+', "stderr: \"%s\"", printable(buf, 0));
}
fclose(lp);
}
}
unlink(stdlog);
unlink(errlog);
if (vrc != virscan.error) {
Syslog('!', "Virus found by %s", virscan.comment);
rc = TRUE;
}
Altime(0);
Nopper();
}
}
fclose(fp);
if (path)
chdir(pwd);
free(pwd);
free(temp);
free(stdlog);
free(errlog);
return rc;
}

View File

@ -1,9 +0,0 @@
/* $Id$ */
#ifndef _VIRSCAN_H
#define _VIRSCAN_H
int VirScan(char *);
#endif