git-svn-id: file:///var/lib/svn/clamav-devel/branches/clamd-proto@4701 77e5149b-7576-45b1-b177-96237e5ba77b

aCaB authored on 2009/02/08 23:43:17
Showing 2 changed files
... ...
@@ -64,13 +64,12 @@
64 64
 #endif
65 65
 
66 66
 int notremoved = 0, notmoved = 0;
67
-int printinfected = 0;
68
-
69 67
 struct sockaddr *mainsa = NULL;
70 68
 int mainsasz;
71 69
 static struct sockaddr_un nixsock;
72 70
 static struct sockaddr_in tcpsock;
73 71
 
72
+/* OnInfected action handlers/wrappers */
74 73
 void (*action)(const char *) = NULL;
75 74
 static char *actarget;
76 75
 static void move_infected(const char *filename, int move);
... ...
@@ -89,6 +88,7 @@ static void action_remove(const char *filename) {
89 89
     }
90 90
 }
91 91
 
92
+/* Inits the OnInfected action */
92 93
 void actsetup(const struct optstruct *opts) {
93 94
     if(optget(opts, "move")->enabled) {
94 95
 	actarget = optget(opts, "move")->strarg;
... ...
@@ -101,6 +101,8 @@ void actsetup(const struct optstruct *opts) {
101 101
     }
102 102
 }
103 103
 
104
+/* Inits the communication layer
105
+ * Returns 0 if clamd is local, non zero if clamd is remote */
104 106
 static int isremote(const struct optstruct *opts) {
105 107
     int s, ret;
106 108
     const struct optstruct *opt;
... ...
@@ -155,6 +157,9 @@ static int isremote(const struct optstruct *opts) {
155 155
 }
156 156
 
157 157
 
158
+/* Turns a relative path into an absolute one
159
+ * Returns a pointer to the path (which must be 
160
+ * freed by the caller) or NULL on error */
158 161
 static char *makeabs(const char *basepath) {
159 162
     int namelen;
160 163
     char *ret;
... ...
@@ -178,22 +183,20 @@ static char *makeabs(const char *basepath) {
178 178
     return ret;
179 179
 }
180 180
 
181
-
182
-
181
+/* Recursively scans a path with the given scantype
182
+ * Returns non zero for serious errors, zero otherwise */
183 183
 static int client_scan(const char *file, int scantype, int *infected, int *errors, int maxlevel, int session) {
184 184
     int ret;
185 185
     char *fullpath = makeabs(file);
186 186
 
187
-    if(!fullpath) {
188
-	(*errors)++;
189
-	return 1;
190
-    }
187
+    if(!fullpath)
188
+	return 0;
191 189
     if (!session)
192 190
 	ret = serial_client_scan(fullpath, scantype, infected, errors, maxlevel);
193 191
     else
194 192
 	ret = parallel_client_scan(fullpath, scantype, infected, errors, maxlevel);
195 193
     free(fullpath);
196
-    return 0;
194
+    return ret;
197 195
 }
198 196
 
199 197
 int get_clamd_version(const struct optstruct *opts)
... ...
@@ -38,6 +38,7 @@
38 38
 
39 39
 extern struct sockaddr *mainsa;
40 40
 extern int mainsasz;
41
+int printinfected;
41 42
 extern void (*action)(const char *);
42 43
 
43 44
 static const char *scancmd[] = { "CONTSCAN", "MULTISCAN" };
... ...
@@ -332,7 +333,7 @@ static int serial_callback(struct stat *sb, char *filename, const char *path, en
332 332
 
333 333
     if((sockd = dconnect()) < 0) {
334 334
 	free(filename);
335
-	return CL_BREAK;
335
+	return CL_EIO;
336 336
     }
337 337
     if((ret = dsresult(sockd, c->scantype, f)) >= 0)
338 338
 	c->infected += ret;
... ...
@@ -358,8 +359,9 @@ int serial_client_scan(const char *file, int scantype, int *infected, int *error
358 358
     data.data = &cdata;
359 359
 
360 360
     cli_ftw(file, CLI_FTW_STD, maxlevel ? maxlevel : INT_MAX, serial_callback, &data);
361
-    /* FIXME: care about return ? */
362
-    if(!cdata.infected && (!cdata.errors || cdata.spam)) logg("~%s: OK\n", file);
361
+    /* FIXME: return SUCCESS or BREAK is ok, anything else is bad */
362
+    if(!printinfected && !cdata.infected && (!cdata.errors || cdata.spam))
363
+	logg("~%s: OK\n", file);
363 364
 
364 365
     *infected += cdata.infected;
365 366
     *errors += cdata.errors;
... ...
@@ -445,7 +447,7 @@ static int parallel_callback(struct stat *sb, char *filename, const char *path,
445 445
 
446 446
     switch(reason) {
447 447
     case error_stat:
448
-	logg("^Can't access file %s\n", filename);
448
+	logg("^Can't access file %s\n", path);
449 449
 	return CL_SUCCESS;
450 450
     case error_mem:
451 451
 	logg("^Memory allocation failed in ftw\n");
... ...
@@ -454,7 +456,7 @@ static int parallel_callback(struct stat *sb, char *filename, const char *path,
454 454
 	logg("^Directory recursion limit reached\n");
455 455
 	return CL_SUCCESS;
456 456
     case warning_skipped_special:
457
-	logg("~%s: Not supported file type. ERROR\n", filename);
457
+	logg("~%s: Not supported file type. ERROR\n", path);
458 458
 	c->errors++;
459 459
 	return CL_SUCCESS;
460 460
     case visit_directory_toplev:
... ...
@@ -491,7 +493,7 @@ static int parallel_callback(struct stat *sb, char *filename, const char *path,
491 491
 
492 492
     while (*id)
493 493
 	id = &((*id)->next);
494
-    cid = (struct SCANID *)malloc(sizeof(struct SCANID *));
494
+    cid = (struct SCANID *)malloc(sizeof(struct SCANID));
495 495
     *id = cid;
496 496
     cid->id = ++c->lastid;
497 497
     cid->file = filename;
... ...
@@ -541,7 +543,8 @@ int parallel_client_scan(const char *file, int scantype, int *infected, int *err
541 541
     sendln(cdata.sockd, "zEND", 5);
542 542
     close(cdata.sockd);
543 543
 
544
-    if(!cdata.infected && (!cdata.errors || cdata.spam)) logg("~%s: OK\n", file);
544
+    if(!printinfected && !cdata.infected && (!cdata.errors || cdata.spam))
545
+	logg("~%s: OK\n", file);
545 546
 
546 547
     *infected += cdata.infected;
547 548
     *errors += cdata.errors;