~yolanda.robla/ubuntu/saucy/clamav/dep-8-tests

« back to all changes in this revision

Viewing changes to libclamav/others_common.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2009-11-02 23:27:19 UTC
  • mfrom: (0.35.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091102232719-61ay35095dhbuxfm
Tags: 0.95.3+dfsg-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop build-dep on electric-fence (in Universe)
  - Build-dep on libltdl3-dev instead of libltdl-dev for updating earlier
    releases more easily
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
496
496
    return CL_SUCCESS;
497
497
}
498
498
 
499
 
static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data);
500
 
static int handle_entry(struct dirent_data *entry, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data)
 
499
static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data, cli_ftw_pathchk pathchk);
 
500
static int handle_entry(struct dirent_data *entry, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data, cli_ftw_pathchk pathchk)
501
501
{
502
502
    if (!entry->is_dir) {
503
503
        return callback(entry->statbuf, entry->filename, entry->filename, visit_file, data);
504
504
    } else {
505
 
        return cli_ftw_dir(entry->dirname, flags, maxdepth, callback, data);
 
505
        return cli_ftw_dir(entry->dirname, flags, maxdepth, callback, data, pathchk);
506
506
    }
507
507
}
508
508
 
509
 
int cli_ftw(char *path, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data)
 
509
int cli_ftw(char *path, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data, cli_ftw_pathchk pathchk)
510
510
{
511
511
    struct stat statbuf;
512
512
    enum filetype ft = ft_unknown;
513
513
    struct dirent_data entry;
514
514
    int stated = 0;
515
 
 
516
515
    int ret;
517
516
 
518
 
    if ((flags & CLI_FTW_TRIM_SLASHES) && path[0] && path[1]) {
 
517
    if (((flags & CLI_FTW_TRIM_SLASHES) || pathchk) && path[0] && path[1]) {
519
518
        char *pathend;
520
519
        /* trim slashes so that dir and dir/ behave the same when
521
520
         * they are symlinks, and we are not following symlinks */
524
523
        while (pathend > path && pathend[-1] == '/') --pathend;
525
524
        *pathend = '\0';
526
525
    }
 
526
    if(pathchk && pathchk(path, data) == 1)
 
527
        return CL_SUCCESS;
527
528
    ret = handle_filetype(path, flags, &statbuf, &stated, &ft, callback, data);
528
529
    if (ret != CL_SUCCESS)
529
530
        return ret;
538
539
        if (ret != CL_SUCCESS)
539
540
            return ret;
540
541
    }
541
 
    return handle_entry(&entry, flags, maxdepth, callback, data);
 
542
    return handle_entry(&entry, flags, maxdepth, callback, data, pathchk);
542
543
}
543
544
 
544
 
static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data)
 
545
static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data, cli_ftw_pathchk pathchk)
545
546
{
546
547
    DIR *dd;
547
548
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
617
618
            else
618
619
                sprintf(fname, "%s/%s", dirname, dent->d_name);
619
620
 
 
621
            if(pathchk && pathchk(fname, data) == 1) {
 
622
                free(fname);
 
623
                continue;
 
624
            }
 
625
 
620
626
            ret = handle_filetype(fname, flags, &statbuf, &stated, &ft, callback, data);
621
627
            if (ret != CL_SUCCESS) {
622
628
                free(fname);
674
680
            qsort(entries, entries_cnt, sizeof(*entries), ftw_compare);
675
681
            for (i = 0; i < entries_cnt; i++) {
676
682
                struct dirent_data *entry = &entries[i];
677
 
                ret = handle_entry(entry, flags, maxdepth-1, callback, data);
 
683
                ret = handle_entry(entry, flags, maxdepth-1, callback, data, pathchk);
678
684
                if (entry->is_dir)
679
685
                    free(entry->filename);
680
686
                if (entry->statbuf)
682
688
                if (ret != CL_SUCCESS)
683
689
                    break;
684
690
            }
 
691
            for (i++;i<entries_cnt;i++) {
 
692
                struct dirent_data *entry = &entries[i];
 
693
                free(entry->filename);
 
694
            }
685
695
            free(entries);
686
696
        }
687
697
    } else {
739
749
    if(name_salt[0] == 16) { /* minimizes re-seeding after the first call to cli_gentemp() */
740
750
            struct timeval tv;
741
751
        gettimeofday(&tv, (struct timezone *) 0);
742
 
        srand(tv.tv_usec+clock());
 
752
        srand(tv.tv_usec+clock()+rand());
743
753
    }
744
754
 
745
755
    return 1 + (unsigned int) (max * (rand() / (1.0 + RAND_MAX)));