git-svn-id: file:///var/lib/svn/clamav-devel/branches/clamd-proto@4719 77e5149b-7576-45b1-b177-96237e5ba77b
aCaB authored on 2009/02/10 01:23:38... | ... |
@@ -266,7 +266,7 @@ int client(const struct optstruct *opts, int *infected) |
266 | 266 |
|
267 | 267 |
scandash = (opts->filename && opts->filename[0] && !strcmp(opts->filename[0], "-") && !opts->filename[1]); |
268 | 268 |
remote = isremote(opts); |
269 |
- // remote = 1; /* FIXME : get rid of me */ |
|
269 |
+ /* remote = 1; */ |
|
270 | 270 |
#ifdef HAVE_FD_PASSING |
271 | 271 |
if(!remote && optget(clamdopts, "LocalSocket")->enabled && (optget(opts, "fdpass")->enabled || scandash)) { |
272 | 272 |
scantype = FILDES; |
... | ... |
@@ -280,7 +280,7 @@ int client(const struct optstruct *opts, int *infected) |
280 | 280 |
else scantype = CONT; |
281 | 281 |
|
282 | 282 |
maxrec = optget(clamdopts, "MaxDirectoryRecursion")->numarg; |
283 |
- maxstream = optget(clamdopts, "StreamMaxLength")->numarg; /* FIXME: propagate */ |
|
283 |
+ maxstream = optget(clamdopts, "StreamMaxLength")->numarg; |
|
284 | 284 |
optfree(clamdopts); |
285 | 285 |
|
286 | 286 |
if(!mainsa) { |
... | ... |
@@ -150,7 +150,7 @@ int recvln(struct RCVLN *s, char **rbol, char **reol) { |
150 | 150 |
static int send_stream(int sockd, const char *filename) { |
151 | 151 |
uint32_t buf[BUFSIZ/sizeof(uint32_t)]; |
152 | 152 |
int fd, len; |
153 |
- unsigned int todo = maxstream; |
|
153 |
+ unsigned long int todo = maxstream; |
|
154 | 154 |
|
155 | 155 |
if(filename) { |
156 | 156 |
if((fd = open(filename, O_RDONLY))<0) { |
... | ... |
@@ -164,8 +164,7 @@ static int send_stream(int sockd, const char *filename) { |
164 | 164 |
while((len = read(fd, &buf[2], sizeof(buf) - 2*sizeof(uint32_t))) > 0) { |
165 | 165 |
if((unsigned int)len > todo) len = todo; |
166 | 166 |
buf[0] = htonl(len); |
167 |
- buf[1] = 0xdeadbeef; |
|
168 |
- if(sendln(sockd, (const char *)buf, len+2*sizeof(uint32_t))) { /* FIXME: need to handle limits */ |
|
167 |
+ if(sendln(sockd, (const char *)buf, len+sizeof(uint32_t))) { |
|
169 | 168 |
logg("!Can't write to the socket.\n"); |
170 | 169 |
close(fd); |
171 | 170 |
return 1; |
... | ... |
@@ -181,9 +180,8 @@ static int send_stream(int sockd, const char *filename) { |
181 | 181 |
logg("!Failed to read from %s.\n", filename); |
182 | 182 |
return 1; |
183 | 183 |
} |
184 |
- buf[0] = 0; |
|
185 |
- buf[1] = 0xdeadbeef; |
|
186 |
- sendln(sockd, (const char*)buf, 8); |
|
184 |
+ *buf=0; |
|
185 |
+ sendln(sockd, (const char *)buf, 4); |
|
187 | 186 |
return 0; |
188 | 187 |
} |
189 | 188 |
|
... | ... |
@@ -314,7 +312,8 @@ struct client_serial_data { |
314 | 314 |
int spam; |
315 | 315 |
}; |
316 | 316 |
|
317 |
-/* FTW callback for scanning in non IDSESSION mode */ |
|
317 |
+/* FTW callback for scanning in non IDSESSION mode |
|
318 |
+ * Returns SUCCESS or BREAK on success, CL_EXXX on error */ |
|
318 | 319 |
static int serial_callback(struct stat *sb, char *filename, const char *path, enum cli_ftw_reason reason, struct cli_ftw_cbdata *data) { |
319 | 320 |
struct client_serial_data *c = (struct client_serial_data *)data->data; |
320 | 321 |
int sockd, ret; |
... | ... |
@@ -359,10 +358,11 @@ static int serial_callback(struct stat *sb, char *filename, const char *path, en |
359 | 359 |
} |
360 | 360 |
|
361 | 361 |
/* Non-IDSESSION handler |
362 |
- * FIXME: returns what ? */ |
|
362 |
+ * Returns non zero for serious errors, zero otherwise */ |
|
363 | 363 |
int serial_client_scan(const char *file, int scantype, int *infected, int *errors, int maxlevel) { |
364 | 364 |
struct cli_ftw_cbdata data; |
365 | 365 |
struct client_serial_data cdata; |
366 |
+ int ftw; |
|
366 | 367 |
|
367 | 368 |
cdata.infected = 0; |
368 | 369 |
cdata.errors = 0; |
... | ... |
@@ -370,14 +370,16 @@ int serial_client_scan(const char *file, int scantype, int *infected, int *error |
370 | 370 |
cdata.spam = 0; |
371 | 371 |
data.data = &cdata; |
372 | 372 |
|
373 |
- cli_ftw(file, CLI_FTW_STD, maxlevel ? maxlevel : INT_MAX, serial_callback, &data); |
|
374 |
- /* FIXME: return SUCCESS or BREAK is ok, anything else is bad */ |
|
375 |
- if(!printinfected && !cdata.infected && (!cdata.errors || cdata.spam)) |
|
376 |
- logg("~%s: OK\n", file); |
|
377 |
- |
|
373 |
+ ftw = cli_ftw(file, CLI_FTW_STD, maxlevel ? maxlevel : INT_MAX, serial_callback, &data); |
|
378 | 374 |
*infected += cdata.infected; |
379 | 375 |
*errors += cdata.errors; |
380 |
- return 0; |
|
376 |
+ |
|
377 |
+ if(ftw == CL_SUCCESS || ftw == CL_BREAK) { |
|
378 |
+ if(!printinfected && !cdata.infected && (!cdata.errors || cdata.spam)) |
|
379 |
+ logg("~%s: OK\n", file); |
|
380 |
+ return 0; |
|
381 |
+ } |
|
382 |
+ return 1; |
|
381 | 383 |
} |
382 | 384 |
|
383 | 385 |
/* Used in IDSESSION mode */ |
... | ... |
@@ -425,7 +427,7 @@ int dspresult(struct client_parallel_data *c) { |
425 | 425 |
if(!id) { |
426 | 426 |
c->errors++; |
427 | 427 |
logg("!Bogus session id from clamd\n"); |
428 |
- return 1; /* this is an hard failure */ |
|
428 |
+ return 1; |
|
429 | 429 |
} |
430 | 430 |
filename = (*id)->file; |
431 | 431 |
if(len > 7) { |
... | ... |
@@ -452,7 +454,8 @@ int dspresult(struct client_parallel_data *c) { |
452 | 452 |
return 0; |
453 | 453 |
} |
454 | 454 |
|
455 |
-/* FTW callback for scanning in IDSESSION mode */ |
|
455 |
+/* FTW callback for scanning in IDSESSION mode |
|
456 |
+ * Returns SUCCESS or BREAK on success, CL_EXXX on error */ |
|
456 | 457 |
static int parallel_callback(struct stat *sb, char *filename, const char *path, enum cli_ftw_reason reason, struct cli_ftw_cbdata *data) { |
457 | 458 |
struct client_parallel_data *c = (struct client_parallel_data *)data->data; |
458 | 459 |
struct SCANID **id = &c->ids, *cid; |
... | ... |
@@ -492,7 +495,7 @@ static int parallel_callback(struct stat *sb, char *filename, const char *path, |
492 | 492 |
c->errors++; |
493 | 493 |
free(filename); |
494 | 494 |
logg("!select failed during session\n"); |
495 |
- return CL_BREAK; /* this is an hard failure */ |
|
495 |
+ return CL_BREAK; |
|
496 | 496 |
} |
497 | 497 |
if(FD_ISSET(c->sockd, &rfds)) { |
498 | 498 |
if(dspresult(c)) { |
... | ... |
@@ -506,6 +509,11 @@ static int parallel_callback(struct stat *sb, char *filename, const char *path, |
506 | 506 |
while (*id) |
507 | 507 |
id = &((*id)->next); |
508 | 508 |
cid = (struct SCANID *)malloc(sizeof(struct SCANID)); |
509 |
+ if(!cid) { |
|
510 |
+ free(filename); |
|
511 |
+ logg("!Failed to allocate scanid entry\n"); |
|
512 |
+ return CL_BREAK; |
|
513 |
+ } |
|
509 | 514 |
*id = cid; |
510 | 515 |
cid->id = ++c->lastid; |
511 | 516 |
cid->file = filename; |
... | ... |
@@ -513,21 +521,23 @@ static int parallel_callback(struct stat *sb, char *filename, const char *path, |
513 | 513 |
|
514 | 514 |
switch(c->scantype) { |
515 | 515 |
case FILDES: |
516 |
- send_fdpass(c->sockd, filename); /* FIXME: check return */ |
|
516 |
+ if(send_fdpass(c->sockd, filename)) |
|
517 |
+ return CL_BREAK; |
|
517 | 518 |
break; |
518 | 519 |
case STREAM: |
519 |
- send_stream(c->sockd, filename); /* FIXME: check return */ |
|
520 |
+ if(send_stream(c->sockd, filename)) |
|
521 |
+ return CL_BREAK; |
|
520 | 522 |
break; |
521 | 523 |
} |
522 |
- |
|
523 | 524 |
return CL_SUCCESS; |
524 | 525 |
} |
525 | 526 |
|
526 | 527 |
/* Non-IDSESSION handler |
527 |
- * FIXME: returns what ? */ |
|
528 |
+ * Returns non zero for serious errors, zero otherwise */ |
|
528 | 529 |
int parallel_client_scan(const char *file, int scantype, int *infected, int *errors, int maxlevel) { |
529 | 530 |
struct cli_ftw_cbdata data; |
530 | 531 |
struct client_parallel_data cdata; |
532 |
+ int ftw; |
|
531 | 533 |
|
532 | 534 |
if((cdata.sockd = dconnect()) < 0) |
533 | 535 |
return 1; |
... | ... |
@@ -545,8 +555,14 @@ int parallel_client_scan(const char *file, int scantype, int *infected, int *err |
545 | 545 |
cdata.ids = NULL; |
546 | 546 |
data.data = &cdata; |
547 | 547 |
|
548 |
- cli_ftw(file, CLI_FTW_STD, maxlevel ? maxlevel : INT_MAX, parallel_callback, &data); |
|
549 |
- /* FIXME: check return */ |
|
548 |
+ ftw = cli_ftw(file, CLI_FTW_STD, maxlevel ? maxlevel : INT_MAX, parallel_callback, &data); |
|
549 |
+ *infected += cdata.infected; |
|
550 |
+ *errors += cdata.errors; |
|
551 |
+ |
|
552 |
+ if(ftw != CL_SUCCESS && ftw != CL_BREAK) { |
|
553 |
+ close(cdata.sockd); |
|
554 |
+ return 1; |
|
555 |
+ } |
|
550 | 556 |
|
551 | 557 |
sendln(cdata.sockd, "zEND", 5); |
552 | 558 |
while(cdata.ids && !dspresult(&cdata)); |
... | ... |
@@ -554,12 +570,9 @@ int parallel_client_scan(const char *file, int scantype, int *infected, int *err |
554 | 554 |
|
555 | 555 |
if(cdata.ids) { |
556 | 556 |
logg("!Clamd closed connection before scanning all files.\n"); |
557 |
- } else { |
|
558 |
- if(!printinfected && !cdata.infected && (!cdata.errors || cdata.spam)) |
|
559 |
- logg("~%s: OK\n", file); |
|
557 |
+ return 1; |
|
560 | 558 |
} |
561 |
- |
|
562 |
- *infected += cdata.infected; |
|
563 |
- *errors += cdata.errors; |
|
564 |
- return (!!cdata.ids); |
|
559 |
+ if(!printinfected && !cdata.infected && (!cdata.errors || cdata.spam)) |
|
560 |
+ logg("~%s: OK\n", file); |
|
561 |
+ return 0; |
|
565 | 562 |
} |