git-svn: trunk@4909
aCaB authored on 2009/03/08 00:32:16... | ... |
@@ -74,7 +74,6 @@ static struct sockaddr_in tcpsock; |
74 | 74 |
static int isremote(const struct optstruct *opts) { |
75 | 75 |
int s, ret; |
76 | 76 |
const struct optstruct *opt; |
77 |
- struct hostent *he; |
|
78 | 77 |
struct optstruct *clamdopts; |
79 | 78 |
const char *clamd_conf = optget(opts, "config-file")->strarg; |
80 | 79 |
static struct sockaddr_in testsock; |
... | ... |
@@ -257,7 +256,7 @@ int client(const struct optstruct *opts, int *infected) |
257 | 257 |
struct stat sb; |
258 | 258 |
fstat(0, &sb); |
259 | 259 |
if((sb.st_mode & S_IFMT) != S_IFREG) scantype = STREAM; |
260 |
- if((sockd = dconnect()) >= 0 && (ret = dsresult(sockd, scantype, NULL)) >= 0) |
|
260 |
+ if((sockd = dconnect()) >= 0 && (ret = dsresult(sockd, scantype, NULL, &ret)) >= 0) |
|
261 | 261 |
*infected = ret; |
262 | 262 |
else |
263 | 263 |
errors = 1; |
... | ... |
@@ -238,7 +238,7 @@ static int send_fdpass(int sockd, const char *filename) { |
238 | 238 |
/* Sends a proper scan request to clamd and parses its replies |
239 | 239 |
* This is used only in non IDSESSION mode |
240 | 240 |
* Returns the number of infected files or -1 on error */ |
241 |
-int dsresult(int sockd, int scantype, const char *filename) { |
|
241 |
+int dsresult(int sockd, int scantype, const char *filename, int *printok) { |
|
242 | 242 |
int infected = 0, len, beenthere = 0; |
243 | 243 |
char *bol, *eol; |
244 | 244 |
struct RCVLN rcv; |
... | ... |
@@ -268,7 +268,10 @@ int dsresult(int sockd, int scantype, const char *filename) { |
268 | 268 |
#endif |
269 | 269 |
} |
270 | 270 |
|
271 |
- if(len <=0) return len; |
|
271 |
+ if(len <=0) { |
|
272 |
+ *printok = 0; |
|
273 |
+ return len; |
|
274 |
+ } |
|
272 | 275 |
|
273 | 276 |
while((len = recvln(&rcv, &bol, &eol))) { |
274 | 277 |
if(len == -1) return -1; |
... | ... |
@@ -280,6 +283,7 @@ int dsresult(int sockd, int scantype, const char *filename) { |
280 | 280 |
logg("Failed to parse reply\n"); |
281 | 281 |
return -1; |
282 | 282 |
} else if(!memcmp(eol - 7, " FOUND", 6)) { |
283 |
+ *printok = 0; |
|
283 | 284 |
infected++; |
284 | 285 |
if(filename) { |
285 | 286 |
if(scantype >= STREAM) { |
... | ... |
@@ -293,6 +297,7 @@ int dsresult(int sockd, int scantype, const char *filename) { |
293 | 293 |
} |
294 | 294 |
} |
295 | 295 |
} else if(!memcmp(eol-7, " ERROR", 6)) { |
296 |
+ *printok = 0; |
|
296 | 297 |
if(filename) { |
297 | 298 |
if(scantype >= STREAM) |
298 | 299 |
logg("~%s%s\n", filename, colon); |
... | ... |
@@ -315,6 +320,7 @@ int dsresult(int sockd, int scantype, const char *filename) { |
315 | 315 |
struct client_serial_data { |
316 | 316 |
int infected; |
317 | 317 |
int scantype; |
318 |
+ int printok; |
|
318 | 319 |
}; |
319 | 320 |
|
320 | 321 |
/* FTW callback for scanning in non IDSESSION mode |
... | ... |
@@ -351,7 +357,7 @@ static int serial_callback(struct stat *sb, char *filename, const char *path, en |
351 | 351 |
if(filename) free(filename); |
352 | 352 |
return CL_EOPEN; |
353 | 353 |
} |
354 |
- ret = dsresult(sockd, c->scantype, f); |
|
354 |
+ ret = dsresult(sockd, c->scantype, f, &c->printok); |
|
355 | 355 |
if(filename) free(filename); |
356 | 356 |
close(sockd); |
357 | 357 |
if(ret < 0) return CL_EOPEN; |
... | ... |
@@ -369,6 +375,7 @@ int serial_client_scan(char *file, int scantype, int *infected, int maxlevel, in |
369 | 369 |
int ftw; |
370 | 370 |
|
371 | 371 |
cdata.infected = 0; |
372 |
+ cdata.printok = printinfected^1; |
|
372 | 373 |
cdata.scantype = scantype; |
373 | 374 |
data.data = &cdata; |
374 | 375 |
|
... | ... |
@@ -376,7 +383,7 @@ int serial_client_scan(char *file, int scantype, int *infected, int maxlevel, in |
376 | 376 |
*infected += cdata.infected; |
377 | 377 |
|
378 | 378 |
if(ftw == CL_SUCCESS || ftw == CL_BREAK) { |
379 |
- if(!printinfected && !cdata.infected) |
|
379 |
+ if(cdata.printok) |
|
380 | 380 |
logg("~%s: OK\n", file); |
381 | 381 |
return 0; |
382 | 382 |
} |
... | ... |
@@ -389,6 +396,7 @@ struct client_parallel_data { |
389 | 389 |
int scantype; |
390 | 390 |
int sockd; |
391 | 391 |
int lastid; |
392 |
+ int printok; |
|
392 | 393 |
struct SCANID { |
393 | 394 |
unsigned int id; |
394 | 395 |
const char *file; |
... | ... |
@@ -433,9 +441,11 @@ static int dspresult(struct client_parallel_data *c) { |
433 | 433 |
return 1; |
434 | 434 |
} else if(!memcmp(eol - 7, " FOUND", 6)) { |
435 | 435 |
c->infected++; |
436 |
+ c->printok = 0; |
|
436 | 437 |
logg("~%s%s\n", filename, colon); |
437 | 438 |
if(action) action(filename); |
438 | 439 |
} else if(!memcmp(eol-7, " ERROR", 6)) { |
440 |
+ c->printok = 0; |
|
439 | 441 |
logg("~%s%s\n", filename, colon); |
440 | 442 |
} |
441 | 443 |
} |
... | ... |
@@ -501,7 +511,7 @@ static int parallel_callback(struct stat *sb, char *filename, const char *path, |
501 | 501 |
cid = (struct SCANID *)malloc(sizeof(struct SCANID)); |
502 | 502 |
if(!cid) { |
503 | 503 |
free(filename); |
504 |
- logg("!Failed to allocate scanid entry: %x\n", strerror(errno)); |
|
504 |
+ logg("!Failed to allocate scanid entry: %s\n", strerror(errno)); |
|
505 | 505 |
return CL_BREAK; |
506 | 506 |
} |
507 | 507 |
cid->id = ++c->lastid; |
... | ... |
@@ -520,6 +530,7 @@ static int parallel_callback(struct stat *sb, char *filename, const char *path, |
520 | 520 |
break; |
521 | 521 |
} |
522 | 522 |
if(res <= 0) { |
523 |
+ c->printok = 0; |
|
523 | 524 |
c->ids = cid->next; |
524 | 525 |
c->lastid--; |
525 | 526 |
free(cid); |
... | ... |
@@ -548,6 +559,7 @@ int parallel_client_scan(char *file, int scantype, int *infected, int maxlevel, |
548 | 548 |
cdata.scantype = scantype; |
549 | 549 |
cdata.lastid = 0; |
550 | 550 |
cdata.ids = NULL; |
551 |
+ cdata.printok = printinfected^1; |
|
551 | 552 |
data.data = &cdata; |
552 | 553 |
|
553 | 554 |
ftw = cli_ftw(file, flags, maxlevel ? maxlevel : INT_MAX, parallel_callback, &data); |
... | ... |
@@ -568,7 +580,7 @@ int parallel_client_scan(char *file, int scantype, int *infected, int maxlevel, |
568 | 568 |
logg("!Clamd closed the connection before scanning all files.\n"); |
569 | 569 |
return 1; |
570 | 570 |
} |
571 |
- if(!printinfected && !cdata.infected) |
|
571 |
+ if(cdata.printok) |
|
572 | 572 |
logg("~%s: OK\n", file); |
573 | 573 |
return 0; |
574 | 574 |
} |
... | ... |
@@ -36,5 +36,5 @@ void recvlninit(struct RCVLN *s, int sockd); |
36 | 36 |
int recvln(struct RCVLN *s, char **rbol, char **reol); |
37 | 37 |
int serial_client_scan(char *file, int scantype, int *infected, int maxlevel, int flags); |
38 | 38 |
int parallel_client_scan(char *file, int scantype, int *infected, int maxlevel, int flags); |
39 |
-int dsresult(int sockd, int scantype, const char *filename); |
|
39 |
+int dsresult(int sockd, int scantype, const char *filename, int *spam); |
|
40 | 40 |
#endif |