clamdscan/clamdscan.c
b151ef55
 /*
2bc31f05
  *  Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net>
b151ef55
  *
  *  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
30738099
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  *  MA 02110-1301, USA.
b151ef55
  */
 
8b242bb9
 #if HAVE_CONFIG_H
 #include "clamav-config.h"
 #endif
 
b151ef55
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/time.h>
 #include <time.h>
df52b7aa
 #include <signal.h>
b151ef55
 
 #include "options.h"
 #include "others.h"
 #include "shared.h"
 #include "defaults.h"
e8217f5a
 #include "client.h"
36f2038b
 #include "output.h"
e441c102
 #include "misc.h"
b151ef55
 
2bc31f05
 #include "clamscan_opt.h"
 
b151ef55
 void help(void);
 
9b0efa74
 short printinfected = 0;
 
b77a9c76
 extern int notremoved, notmoved;
 
2bc31f05
 int main(int argc, char **argv)
b151ef55
 {
df52b7aa
 	int ds, dms, ret, infected;
b151ef55
 	struct timeval t1, t2;
 	struct timezone tz;
 	time_t starttime;
2bc31f05
 	struct optstruct *opt;
 	char *clamdscan_accepted[] = { "help", "version", "verbose", "quiet",
 				  "stdout", "log", "move", "remove",
 				  "config-file", "no-summary",
 				  "disable-summary", NULL };
b151ef55
 
 
2bc31f05
     opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, clamdscan_accepted);
     if(!opt) {
 	mprintf("!Can't parse the command line\n");
 	return 2;
     }
b151ef55
 
2bc31f05
     if(opt_check(opt, "verbose")) {
36f2038b
 	mprintf_verbose = 1;
 	logg_verbose = 1;
     }
b151ef55
 
2bc31f05
     if(opt_check(opt, "quiet"))
7fbb6473
 	mprintf_quiet = 1;
b151ef55
 
2bc31f05
     if(opt_check(opt, "stdout"))
7fbb6473
 	mprintf_stdout = 1;
b151ef55
 
2bc31f05
     if(opt_check(opt, "version")) {
e441c102
 	print_version();
2bc31f05
 	opt_free(opt);
7fbb6473
 	exit(0);
b151ef55
     }
 
2bc31f05
     if(opt_check(opt, "help")) {
 	opt_free(opt);
b151ef55
     	help();
     }
 
2bc31f05
     if(opt_check(opt, "infected"))
7fbb6473
 	printinfected = 1;
b151ef55
 
     /* initialize logger */
 
2bc31f05
     if(opt_check(opt, "log")) {
 	logg_file = opt_arg(opt, "log");
b151ef55
 	if(logg("--------------------------------------\n")) {
 	    mprintf("!Problem with internal logger.\n");
2bc31f05
 	    opt_free(opt);
7fbb6473
 	    exit(2);
b151ef55
 	}
     } else 
36f2038b
 	logg_file = NULL;
b151ef55
 
 
     time(&starttime);
     /* ctime() does \n, but I need it once more */
 
     gettimeofday(&t1, &tz);
df52b7aa
 
     ret = client(opt, &infected);
b151ef55
 
2bc31f05
     /* TODO: Implement STATUS in clamd */
     if(!opt_check(opt, "disable-summary") && !opt_check(opt, "no-summary")) {
b151ef55
 	gettimeofday(&t2, &tz);
 	ds = t2.tv_sec - t1.tv_sec;
 	dms = t2.tv_usec - t1.tv_usec;
 	ds -= (dms < 0) ? (1):(0);
 	dms += (dms < 0) ? (1000000):(0);
f1c4563e
 	logg("\n----------- SCAN SUMMARY -----------\n");
 	logg("Infected files: %d\n", infected);
b77a9c76
 	if(notremoved) {
f1c4563e
 	    logg("Not removed: %d\n", notremoved);
b77a9c76
 	}
 	if(notmoved) {
f1c4563e
 	    logg("Not moved: %d\n", notmoved);
b77a9c76
 	}
f1c4563e
 	logg("Time: %d.%3.3d sec (%d m %d s)\n", ds, dms/1000, ds/60, ds%60);
b151ef55
     }
 
2bc31f05
     opt_free(opt);
7fbb6473
     exit(ret);
b151ef55
 }
 
 void help(void)
 {
 
     mprintf_stdout = 1;
 
     mprintf("\n");
8ef2ff6f
     mprintf("                       ClamAV Daemon Client "VERSION"\n");
     mprintf("     (C) 2002 - 2005 ClamAV Team - http://www.clamav.net/team.html\n\n");
a0faaedf
 
     mprintf("    --help              -h             Show help\n");
     mprintf("    --version           -V             Print version number and exit\n");
     mprintf("    --verbose           -v             Be verbose\n");
     mprintf("    --quiet                            Be quiet, only output error messages\n");
     mprintf("    --stdout                           Write to stdout instead of stderr\n");
     mprintf("                                       (this help is always written to stdout)\n");
     mprintf("    --log=FILE          -l FILE        Save scan report in FILE\n");
b77a9c76
     mprintf("    --remove                           Remove infected files. Be careful!\n");
     mprintf("    --move=DIRECTORY                   Move infected files into DIRECTORY\n");
a0faaedf
     mprintf("    --config-file=FILE                 Read configuration from FILE.\n");
2bc31f05
     mprintf("    --infected            -i             Only print infected files\n");
cba38bf1
     mprintf("    --no-summary                       Disable summary at end of scanning\n");
a0faaedf
     mprintf("\n");
b151ef55
 
     exit(0);
 }