/* * Copyright (C) 2006 Tony Sin(x) '76 * All rights reserved. * */ /* * GNU GENERAL PUBLIC LICENSE * Version 2, June 1991 * * Copyright (C) 1989, 1991 Free Software Foundation, Inc. * 675 Mass Ave, Cambridge, MA 02139, USA * Everyone is permitted to copy and distribute verbatim copies * of this license document, but changing it is not allowed. * * This program 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 of the License, or * (at your option) any later version. * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifdef HAVE_CONFIG_H #ifndef __main_config_h__ #define __main_config_h__ #include "../config.h" #endif #include #include #include #include #include #include #include #include #include #include #ifdef TIME_WITH_SYS_TIME #include #include #else #ifdef HAVE_SYS_TIME_H #include #else #include #endif #endif #endif #include "clam.h" #include "courier.h" #include "message.h" #include "quarantine.h" #include "util.h" #include "exception.h" #include "cmdfifo.h" int main() { FILE *fp; struct stat temp_stat; char *buf, c; cQuarantine *quarantine = NULL; cMessage *message = NULL; cClamAv *clam = NULL; cCourierTask *courierTask = NULL; cCmdFifo *cmdFifo; sigset_t mask; int err, fifoId; struct timespec dummy_wait; openlog(PACKAGE,0,LOG_MAIL); umask(0); if (sigemptyset(&mask) == -1) throw cException(PACKAGE_NAME,"main","sigemptyset, update won't be available",errno); if (sigaddset(&mask,SIGUSR1) == -1) throw cException(PACKAGE_NAME,"main","sigaddset(USR1), update won't be available",errno); if (sigaddset(&mask,SIGUSR2) == -1) throw cException(PACKAGE_NAME,"main","sigaddset(USR2), update won't be available",errno); if ((err = pthread_sigmask(SIG_BLOCK,&mask,NULL))) throw cException(PACKAGE_NAME,"main","pthread_sigmask, update won't be available",err); buf = new char[BUF_LEN]; try { if ((fp = fopen(QUARANTINE_FILE,"rt")) == NULL) throw cException(); if (fgets(buf,BUF_LEN,fp) == NULL) throw cException(PACKAGE_NAME,"main","fgets",ferror(fp)); purgeEscapeChars(buf); if (!stat(BZ2_FILE,&temp_stat)) quarantine = new cQuarantine(buf,_c_bzip2); else if (!stat(GZ_FILE,&temp_stat)) quarantine = new cQuarantine(buf,_c_gzip); else quarantine = new cQuarantine(buf); fclose(fp); } catch (cException c_e) { if (strlen(c_e.str) > 0) syslog(LOG_ERR,"%s",c_e.str); } try { if (stat(MESSAGE_FILE,&temp_stat) == -1) throw cException(); message = new cMessage(MESSAGE_FILE); } catch (cException c_e) { } clam = new cClamAv; courierTask = new cCourierTask; cmdFifo = new cCmdFifo; sprintf(buf,"%s Copyright 2006 BeCrux",PACKAGE_STRING); syslog(LOG_INFO,"%s",buf); delete [] buf; try { if (read(STDIN_FILENO,&c,sizeof(c)) == -1) throw cException(PACKAGE_NAME,"main","read",errno); } catch (cException c_e) { if (strlen(c_e.str) > 0) syslog(LOG_ERR,"%s",c_e.str); } if ((fifoId = open(CLAMCOUR_CMD_FIFO,O_WRONLY)) != -1) { write(fifoId,"quitFIFO",strlen("quitFIFO")); #ifdef HAVE_FDATASYNC fdatasync(fifoId); #else #ifdef HAVE_FSYNC fsync(fifoId); #endif #endif close(fifoId); dummy_wait.tv_sec = 0; dummy_wait.tv_nsec = (1000000000L / TICK_LEN) * 5; nanosleep(&dummy_wait,NULL); } if (courierTask != NULL) delete courierTask; if (clam != NULL) delete clam; if (message != NULL) delete message; if (quarantine != NULL) delete quarantine; closelog(); return 0; }