~ubuntu-branches/ubuntu/raring/clamav/raring

« back to all changes in this revision

Viewing changes to clamdscan/client.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2008-09-05 17:25:34 UTC
  • mfrom: (0.35.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080905172534-yi3f8fkye1o7u1r3
* New upstream version (closes: #497662, #497773)
  - lots of new options for clamd.conf
  - fixes CVEs CVE-2008-3912, CVE-2008-3913, CVE-2008-3914, and
    CVE-2008-1389
* No longer supports --unzip option, so typo is gone (closes: #496276)
* Translations:
  - sv (thanks Martin Bagge <brother@bsnet.se>) (closes: #491760)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <sys/types.h>
27
27
#include <sys/stat.h>
28
28
#include <sys/socket.h>
 
29
#ifdef HAVE_SYS_LIMITS_H
 
30
#include <sys/limits.h>
 
31
#endif
29
32
#include <sys/un.h>
30
33
#include <netinet/in.h>
31
34
#include <arpa/inet.h>
45
48
#include "misc.h"
46
49
#include "str.h"
47
50
#include "client.h"
 
51
#include "clamd_fdscan.h"
48
52
 
49
53
#ifdef PF_INET
50
54
# define SOCKET_INET    PF_INET
230
234
    return infected;
231
235
}
232
236
 
 
237
#ifndef PATH_MAX
 
238
#define PATH_MAX 1024
 
239
#endif
 
240
 
233
241
static char *abpath(const char *filename)
234
242
{
235
243
        struct stat foo;
236
 
        char *fullpath, cwd[200];
 
244
        char *fullpath, cwd[PATH_MAX + 1];
237
245
 
238
246
    if(stat(filename, &foo) == -1) {
239
247
        logg("^Can't access file %s\n", filename);
240
248
        perror(filename);
241
249
        return NULL;
242
250
    } else {
243
 
        fullpath = malloc(200 + strlen(filename) + 10);
244
 
#ifdef C_CYGWIN
245
 
        sprintf(fullpath, "%s", filename);
246
 
#else
247
 
        if(!getcwd(cwd, 200)) {
 
251
        fullpath = malloc(PATH_MAX + strlen(filename) + 10);
 
252
        if(!getcwd(cwd, PATH_MAX)) {
248
253
            logg("^Can't get absolute pathname of current working directory.\n");
249
254
            return NULL;
250
255
        }
251
256
        sprintf(fullpath, "%s/%s", cwd, filename);
252
 
#endif
253
257
    }
254
258
 
255
259
    return fullpath;
256
260
}
257
261
 
258
 
static int dconnect(const struct optstruct *opt)
 
262
static int dconnect(const struct optstruct *opt, int *is_unix)
259
263
{
260
264
        struct sockaddr_un server;
261
265
        struct sockaddr_in server2;
265
269
        const char *clamav_conf = opt_arg(opt, "config-file");
266
270
        int sockd;
267
271
 
268
 
 
 
272
    if(is_unix)
 
273
            *is_unix = 0;
269
274
    if(!clamav_conf)
270
275
        clamav_conf = DEFAULT_CFG;
271
276
 
300
305
            freecfg(copt);
301
306
            return -1;
302
307
        }
303
 
 
 
308
        if(is_unix)
 
309
                *is_unix = 1;
304
310
    } else if((cpt = cfgopt(copt, "TCPSocket"))->enabled) {
305
311
 
306
312
        if((sockd = socket(SOCKET_INET, SOCK_STREAM, 0)) < 0) {
349
355
        int bread, sockd;
350
356
 
351
357
 
352
 
    if((sockd = dconnect(opt)) < 0)
 
358
    if((sockd = dconnect(opt, NULL)) < 0)
353
359
        return 2;
354
360
 
355
361
    if(write(sockd, "VERSION", 7) <= 0) {
368
374
 
369
375
int client(const struct optstruct *opt, int *infected)
370
376
{
371
 
        char cwd[200], *fullpath;
 
377
        char cwd[PATH_MAX+1], *fullpath;
372
378
        int sockd, ret, errors = 0;
373
379
        struct stat sb;
374
380
        const char *scantype = "CONTSCAN";
382
388
    /* parse argument list */
383
389
    if(opt->filename == NULL || strlen(opt->filename) == 0) {
384
390
        /* scan current directory */
385
 
        if(!getcwd(cwd, 200)) {
 
391
        if(!getcwd(cwd, PATH_MAX)) {
386
392
            logg("^Can't get absolute pathname of current working directory.\n");
387
393
            return 2;
388
394
        }
389
395
 
390
 
        if((sockd = dconnect(opt)) < 0)
 
396
        if((sockd = dconnect(opt, NULL)) < 0)
391
397
            return 2;
392
398
 
393
399
        if((ret = dsfile(sockd, scantype, cwd, opt)) >= 0)
398
404
        close(sockd);
399
405
 
400
406
    } else if(!strcmp(opt->filename, "-")) { /* scan data from stdin */
401
 
        if((sockd = dconnect(opt)) < 0)
 
407
        int is_unix;
 
408
        if((sockd = dconnect(opt, &is_unix)) < 0)
402
409
            return 2;
403
410
 
404
 
        if((ret = dsstream(sockd, opt)) >= 0)
 
411
        if(opt_check(opt,"fdpass")) {
 
412
#ifndef HAVE_FD_PASSING
 
413
                logg("^File descriptor pass support not compiled in, falling back to stream scan\n");
 
414
                ret = dsstream(sockd, opt);
 
415
#else
 
416
                if(!is_unix) {
 
417
                        logg("^File descriptor passing can only work on local (unix) sockets! Falling back to stream scan\n");
 
418
                        /* fall back to stream */
 
419
                        ret = dsstream(sockd, opt);
 
420
                } else {
 
421
                        char buff[4096];
 
422
                        memset(buff, 0, sizeof(buff));
 
423
                        ret = clamd_fdscan(sockd, 0, buff, sizeof(buff));
 
424
                        logg("fd: %s%s",buff, ret == 1 ? " FOUND" : ret == -1 ? " ERROR" : "OK");
 
425
                }
 
426
#endif
 
427
        } else
 
428
                ret = dsstream(sockd, opt);
 
429
        if(ret >= 0)
405
430
            *infected += ret;
406
431
        else
407
432
            errors++;
432
457
                switch(sb.st_mode & S_IFMT) {
433
458
                    case S_IFREG:
434
459
                    case S_IFDIR:
435
 
                        if((sockd = dconnect(opt)) < 0)
 
460
                        if((sockd = dconnect(opt, NULL)) < 0)
436
461
                            return 2;
437
462
 
438
463
                        if((ret = dsfile(sockd, scantype, fullpath, opt)) >= 0)