git-svn: trunk@2172
Tomasz Kojm authored on 2006/08/04 06:33:37... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
/* |
2 | 2 |
* Compilation: gcc -Wall ex1.c -o ex1 -lclamav |
3 | 3 |
* |
4 |
- * Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net> |
|
4 |
+ * Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
5 | 5 |
* |
6 | 6 |
* This program is free software; you can redistribute it and/or modify |
7 | 7 |
* it under the terms of the GNU General Public License as published by |
... | ... |
@@ -28,13 +28,21 @@ |
28 | 28 |
#include <fcntl.h> |
29 | 29 |
#include <clamav.h> |
30 | 30 |
|
31 |
+/* |
|
32 |
+ * Exit codes: |
|
33 |
+ * 0: clean |
|
34 |
+ * 1: infected |
|
35 |
+ * 2: error |
|
36 |
+ */ |
|
37 |
+ |
|
31 | 38 |
int main(int argc, char **argv) |
32 | 39 |
{ |
33 |
- int fd, ret, no = 0; |
|
40 |
+ int fd, ret; |
|
34 | 41 |
unsigned long int size = 0; |
42 |
+ unsigned int sigs = 0; |
|
35 | 43 |
long double mb; |
36 | 44 |
const char *virname; |
37 |
- struct cl_node *root = NULL; |
|
45 |
+ struct cl_engine *engine = NULL; |
|
38 | 46 |
struct cl_limits limits; |
39 | 47 |
|
40 | 48 |
|
... | ... |
@@ -49,19 +57,18 @@ int main(int argc, char **argv) |
49 | 49 |
} |
50 | 50 |
|
51 | 51 |
/* load all available databases from default directory */ |
52 |
- |
|
53 |
- if((ret = cl_loaddbdir(cl_retdbdir(), &root, &no))) { |
|
54 |
- printf("cl_loaddbdir: %s\n", cl_perror(ret)); |
|
52 |
+ if((ret = cl_load(cl_retdbdir(), &engine, &sigs, CL_DB_STDOPT))) { |
|
53 |
+ printf("cl_loaddbdir: %s\n", cl_strerror(ret)); |
|
55 | 54 |
close(fd); |
56 | 55 |
exit(2); |
57 | 56 |
} |
58 | 57 |
|
59 |
- printf("Loaded %d signatures.\n", no); |
|
58 |
+ printf("Loaded %d signatures.\n", sigs); |
|
60 | 59 |
|
61 | 60 |
/* build engine */ |
62 |
- if((ret = cl_build(root))) { |
|
61 |
+ if((ret = cl_build(engine))) { |
|
63 | 62 |
printf("Database initialization error: %s\n", cl_strerror(ret));; |
64 |
- cl_free(root); |
|
63 |
+ cl_free(engine); |
|
65 | 64 |
close(fd); |
66 | 65 |
exit(2); |
67 | 66 |
} |
... | ... |
@@ -69,24 +76,33 @@ int main(int argc, char **argv) |
69 | 69 |
/* set up archive limits */ |
70 | 70 |
memset(&limits, 0, sizeof(struct cl_limits)); |
71 | 71 |
limits.maxfiles = 1000; /* max files */ |
72 |
- limits.maxfilesize = 10 * 1048576; /* maximal archived file size == 10 Mb */ |
|
73 |
- limits.maxreclevel = 5; /* maximal recursion level */ |
|
74 |
- limits.maxratio = 200; /* maximal compression ratio */ |
|
75 |
- limits.archivememlim = 0; /* disable memory limit for bzip2 scanner */ |
|
72 |
+ limits.maxfilesize = 10 * 1048576; /* maximum size of archived/compressed |
|
73 |
+ * file (files exceeding this limit |
|
74 |
+ * will be ignored) |
|
75 |
+ */ |
|
76 |
+ limits.maxreclevel = 5; /* maximum recursion level */ |
|
77 |
+ limits.maxratio = 200; /* maximum compression ratio */ |
|
76 | 78 |
|
77 |
- /* scan descriptor */ |
|
78 |
- if((ret = cl_scandesc(fd, &virname, &size, root, &limits, CL_SCAN_STDOPT)) == CL_VIRUS) |
|
79 |
+ /* scan file descriptor */ |
|
80 |
+ if((ret = cl_scandesc(fd, &virname, &size, engine, &limits, CL_SCAN_STDOPT)) == CL_VIRUS) { |
|
79 | 81 |
printf("Virus detected: %s\n", virname); |
80 |
- else { |
|
81 |
- printf("No virus detected.\n"); |
|
82 |
- if(ret != CL_CLEAN) |
|
83 |
- printf("Error: %s\n", cl_perror(ret)); |
|
82 |
+ } else { |
|
83 |
+ if(ret == CL_CLEAN) { |
|
84 |
+ printf("No virus detected.\n"); |
|
85 |
+ } else { |
|
86 |
+ printf("Error: %s\n", cl_strerror(ret)); |
|
87 |
+ cl_free(engine); |
|
88 |
+ exit(2); |
|
89 |
+ } |
|
84 | 90 |
} |
85 | 91 |
close(fd); |
86 | 92 |
|
93 |
+ /* calculate size of scanned data */ |
|
87 | 94 |
mb = size * (CL_COUNT_PRECISION / 1024) / 1024.0; |
88 |
- printf("Data scanned: %2.2Lf Mb\n", mb); |
|
95 |
+ printf("Data scanned: %2.2Lf MB\n", mb); |
|
96 |
+ |
|
97 |
+ /* free memory */ |
|
98 |
+ cl_free(engine); |
|
89 | 99 |
|
90 |
- cl_free(root); |
|
91 | 100 |
exit(ret == CL_VIRUS ? 1 : 0); |
92 | 101 |
} |