~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to clamdscan/proto.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
/* must be first because it may define _XOPEN_SOURCE */
26
26
#include "shared/fdpassing.h"
27
27
#include <stdio.h>
 
28
#ifdef HAVE_UNISTD_H
28
29
#include <unistd.h>
 
30
#endif
29
31
#include <string.h>
30
32
#include <errno.h>
31
33
#include <stdlib.h>
33
35
#include <sys/stat.h>
34
36
#include <fcntl.h>
35
37
#include <sys/types.h>
36
 
#include <sys/socket.h>
 
38
#ifdef HAVE_SYS_SELECT_H
37
39
#include <sys/select.h>
 
40
#endif
 
41
#ifndef _WIN32
38
42
#include <arpa/inet.h>
 
43
#include <sys/socket.h>
 
44
#endif
39
45
 
40
46
#include "libclamav/others.h"
41
47
#include "shared/actions.h"
62
68
    }
63
69
 
64
70
    if(connect(sockd, (struct sockaddr *)mainsa, mainsasz) < 0) {
65
 
        close(sockd);
 
71
        closesocket(sockd);
66
72
        logg("!Can't connect to clamd: %s\n", strerror(errno));
67
73
        return -1;
68
74
    }
160
166
    unsigned long int todo = maxstream;
161
167
 
162
168
    if(filename) {
163
 
        if((fd = open(filename, O_RDONLY))<0) {
 
169
        if((fd = open(filename, O_RDONLY | O_BINARY))<0) {
164
170
            logg("~%s: Access denied. ERROR\n", filename);
165
171
            return 0;
166
172
        }
241
247
/* Sends a proper scan request to clamd and parses its replies
242
248
 * This is used only in non IDSESSION mode
243
249
 * Returns the number of infected files or -1 on error */
244
 
int dsresult(int sockd, int scantype, const char *filename, int *printok, int *files, int *errors) {
 
250
int dsresult(int sockd, int scantype, const char *filename, int *printok, int *errors) {
245
251
    int infected = 0, len, beenthere = 0;
246
252
    char *bol, *eol;
247
253
    struct RCVLN rcv;
282
288
    while((len = recvln(&rcv, &bol, &eol))) {
283
289
        if(len == -1) return -1;
284
290
        beenthere = 1;
285
 
        if(files)
286
 
            (*files)++;
287
291
        if(!filename) logg("~%s\n", bol);
288
292
        if(len > 7) {
289
293
            char *colon = strrchr(bol, ':');
345
349
    int sockd, ret;
346
350
    const char *f = filename;
347
351
 
 
352
    c->files++;
348
353
    switch(reason) {
349
354
    case error_stat:
350
355
        logg("!Can't access file %s\n", path);
373
378
 
374
379
    if((sockd = dconnect()) < 0) {
375
380
        if(filename) free(filename);
 
381
        c->errors++;
376
382
        return CL_EOPEN;
377
383
    }
378
 
    ret = dsresult(sockd, c->scantype, f, &c->printok, &c->files, &c->errors);
 
384
    ret = dsresult(sockd, c->scantype, f, &c->printok, &c->errors);
379
385
    if(filename) free(filename);
380
 
    close(sockd);
381
 
    if(ret < 0) return CL_EOPEN;
 
386
    closesocket(sockd);
 
387
    if(ret < 0) {
 
388
        c->errors++;
 
389
        return CL_EOPEN;
 
390
    }
382
391
    c->infected += ret;
383
392
    if(reason == visit_directory_toplev)
384
393
        return CL_BREAK;
387
396
 
388
397
/* Non-IDSESSION handler
389
398
 * Returns non zero for serious errors, zero otherwise */
390
 
int serial_client_scan(char *file, int scantype, int *infected, int maxlevel, int flags) {
 
399
int serial_client_scan(char *file, int scantype, int *infected, int *err, int maxlevel, int flags) {
391
400
    struct cli_ftw_cbdata data;
392
401
    struct client_serial_data cdata;
393
402
    int ftw;
401
410
 
402
411
    ftw = cli_ftw(file, flags, maxlevel ? maxlevel : INT_MAX, serial_callback, &data, NULL);
403
412
    *infected += cdata.infected;
 
413
    *err += cdata.errors;
404
414
 
405
 
    if((cdata.errors < cdata.files) && (ftw == CL_SUCCESS || ftw == CL_BREAK)) {
 
415
    if(!cdata.errors && (ftw == CL_SUCCESS || ftw == CL_BREAK)) {
406
416
        if(cdata.printok)
407
417
            logg("~%s: OK\n", file);
408
418
        return 0;
409
419
    } else if(!cdata.files) {
410
420
        logg("~%s: No files scanned\n", file);
 
421
        return 0;
411
422
    }
412
423
    return 1;
413
424
}
490
501
    struct SCANID *cid;
491
502
    int res;
492
503
 
 
504
    c->files++;
493
505
    switch(reason) {
494
506
    case error_stat:
495
507
        logg("!Can't access file %s\n", path);
546
558
    cid->file = filename;
547
559
    cid->next = c->ids;
548
560
    c->ids = cid;
549
 
    c->files++;
550
561
 
551
562
    switch(c->scantype) {
552
563
#ifdef HAVE_FD_PASSING
572
583
 
573
584
/* IDSESSION handler
574
585
 * Returns non zero for serious errors, zero otherwise */
575
 
int parallel_client_scan(char *file, int scantype, int *infected, int maxlevel, int flags) {
 
586
int parallel_client_scan(char *file, int scantype, int *infected, int *err, int maxlevel, int flags) {
576
587
    struct cli_ftw_cbdata data;
577
588
    struct client_parallel_data cdata;
578
589
    int ftw;
581
592
        return 1;
582
593
 
583
594
    if(sendln(cdata.sockd, "zIDSESSION", 11)) {
584
 
        close(cdata.sockd);
 
595
        closesocket(cdata.sockd);
585
596
        return 1;
586
597
    }
587
598
 
597
608
    ftw = cli_ftw(file, flags, maxlevel ? maxlevel : INT_MAX, parallel_callback, &data, NULL);
598
609
 
599
610
    if(ftw != CL_SUCCESS) {
 
611
        *err += cdata.errors;
600
612
        *infected += cdata.infected;
601
 
        close(cdata.sockd);
 
613
        closesocket(cdata.sockd);
602
614
        return 1;
603
615
    }
604
616
 
605
617
    sendln(cdata.sockd, "zEND", 5);
606
618
    while(cdata.ids && !dspresult(&cdata));
607
 
    close(cdata.sockd);
 
619
    closesocket(cdata.sockd);
608
620
 
609
621
    *infected += cdata.infected;
 
622
    *err += cdata.errors;
610
623
 
611
624
    if(cdata.ids) {
612
625
        logg("!Clamd closed the connection before scanning all files.\n");
613
626
        return 1;
614
627
    }
615
 
    if(cdata.errors == cdata.files)
 
628
    if(cdata.errors)
616
629
        return 1;
 
630
 
 
631
    if(!cdata.files)
 
632
        return 0;
 
633
 
617
634
    if(cdata.printok)
618
635
        logg("~%s: OK\n", file);
619
636
    return 0;