~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to sigtool/vba.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:
17
17
 *  MA 02110-1301, USA.
18
18
 */
19
19
 
 
20
#if HAVE_CONFIG_H
 
21
#include "clamav-config.h"
 
22
#endif
 
23
 
20
24
#include <stdio.h>
21
25
#include <string.h>
22
26
#include <stdlib.h>
29
33
 
30
34
#include "libclamav/clamav.h"
31
35
#include "libclamav/vba_extract.h"
32
 
#include "libclamav/others.h"
33
36
#include "libclamav/cltypes.h"
34
37
#include "libclamav/ole2_extract.h"
35
 
 
36
 
#ifndef O_BINARY
37
 
#define O_BINARY        0
38
 
#endif
 
38
#include "shared/output.h"
39
39
 
40
40
typedef struct mac_token_tag
41
41
{
50
50
 
51
51
} mac_token2_t;
52
52
 
 
53
cli_ctx *convenience_ctx(int fd) {
 
54
    cli_ctx *ctx;
 
55
    if(!(ctx = malloc(sizeof(*ctx))) ||
 
56
       !(ctx->engine = cl_engine_new()) ||
 
57
       !(ctx->fmap = cli_malloc(sizeof(struct F_MAP *))) ||
 
58
       !(*ctx->fmap = fmap(fd, 0, 0))) {
 
59
        printf("malloc failed\n");
 
60
        return NULL; /* and leak */
 
61
    }
 
62
    return ctx;
 
63
}
 
64
 
 
65
void destroy_ctx(cli_ctx *ctx) {
 
66
    close((*(ctx->fmap))->fd);
 
67
    funmap(*(ctx->fmap));
 
68
    free(ctx->fmap);
 
69
    cl_engine_free((struct cl_engine *)ctx->engine);
 
70
    free(ctx);
 
71
}
 
72
 
53
73
int sigtool_vba_scandir(const char *dirname, int hex_output, struct uniq *U);
54
74
 
55
75
static char *get_unicode_name (char *name, int size)
966
986
    const char *tmpdir;
967
987
    char *dir;
968
988
    int ret = CL_CLEAN, desc;
 
989
    cli_ctx *ctx;
969
990
 
970
991
 
971
992
    if ((dd = opendir (dirname)) != NULL) {
974
995
                if (strcmp (dent->d_name, ".") && strcmp (dent->d_name, "..")) {
975
996
                    /* build the full name */
976
997
                    fname = (char *) cli_calloc (strlen (dirname) + strlen (dent->d_name) + 2, sizeof (char));
977
 
                    sprintf (fname, "%s/%s", dirname, dent->d_name);
 
998
                    sprintf (fname, "%s"PATHSEP"%s", dirname, dent->d_name);
978
999
 
979
1000
                    /* stat the file */
980
1001
                    if (lstat (fname, &statbuf) != -1) {
987
1008
                        } else {
988
1009
                            if (S_ISREG (statbuf.st_mode)) {
989
1010
                                struct uniq *vba = NULL;
990
 
                                tmpdir = getenv ("TMPDIR");
991
 
 
992
 
                                if (tmpdir == NULL)
993
 
#ifdef P_tmpdir
994
 
                                    tmpdir = P_tmpdir;
995
 
#else
996
 
                                    tmpdir = "/tmp";
997
 
#endif
 
1011
                                tmpdir = cli_gettmpdir();
998
1012
 
999
1013
                                /* generate the temporary directory */
1000
1014
                                dir = cli_gentemp (tmpdir);
1003
1017
                                    closedir (dd);
1004
1018
                                    return -1;
1005
1019
                                }
 
1020
 
1006
1021
                                if (mkdir (dir, 0700)) {
1007
1022
                                    printf ("Can't create temporary directory %s\n", dir);
1008
1023
                                    closedir (dd);
1010
1025
                                    return CL_ETMPDIR;
1011
1026
                                }
1012
1027
 
1013
 
                                if ((desc = open (fname, O_RDONLY)) == -1) {
 
1028
                                if ((desc = open (fname, O_RDONLY|O_BINARY)) == -1) {
1014
1029
                                    printf ("Can't open file %s\n", fname);
1015
1030
                                    closedir (dd);
1016
1031
                                    free(dir);
1017
1032
                                    return 1;
1018
1033
                                }
1019
1034
 
1020
 
                                if ((ret = cli_ole2_extract (desc, dir, NULL, &vba))) {
 
1035
                                if(!(ctx = convenience_ctx(desc))) {
 
1036
                                    close(desc);
 
1037
                                    closedir(dd);
 
1038
                                    free(dir);
 
1039
                                    return 1;
 
1040
                                }
 
1041
                                if ((ret = cli_ole2_extract (dir, ctx, &vba))) {
1021
1042
                                    printf ("ERROR %s\n", cl_strerror (ret));
 
1043
                                    destroy_ctx(ctx);
1022
1044
                                    cli_rmdirs (dir);
1023
1045
                                    free (dir);
1024
 
                                    close(desc);
1025
1046
                                    closedir (dd);
1026
1047
                                    return ret;
1027
1048
                                }
1028
 
                                close(desc);
1029
1049
 
1030
1050
                                if(vba)
1031
1051
                                    sigtool_vba_scandir (dir, hex_output, vba);
1032
 
 
 
1052
                                destroy_ctx(ctx);
1033
1053
                                cli_rmdirs (dir);
1034
1054
                                free (dir);
1035
1055
                            }
1041
1061
            }
1042
1062
        }
1043
1063
    } else {
1044
 
        cli_errmsg ("Can't open directory %s.\n", dirname);
 
1064
        logg("!Can't open directory %s.\n", dirname);
1045
1065
        return CL_EOPEN;
1046
1066
    }
1047
1067
 
1066
1086
 
1067
1087
        for(i = 0; i < vba_project->count; i++) {
1068
1088
            for(j = 0; j < vba_project->colls[i]; j++) {
1069
 
                snprintf(vbaname, 1024, "%s/%s_%u", vba_project->dir, vba_project->name[i], j);
 
1089
                snprintf(vbaname, 1024, "%s"PATHSEP"%s_%u", vba_project->dir, vba_project->name[i], j);
1070
1090
                vbaname[sizeof(vbaname)-1] = '\0';
1071
1091
                fd = open(vbaname, O_RDONLY|O_BINARY);
1072
1092
                if(fd == -1) continue;
1092
1112
 
1093
1113
    if((hashcnt = uniq_get(U, "powerpoint document", 19, &hash))) {
1094
1114
        while(hashcnt--) {
1095
 
            snprintf(vbaname, 1024, "%s/%s_%u", dirname, hash, hashcnt);
 
1115
            snprintf(vbaname, 1024, "%s"PATHSEP"%s_%u", dirname, hash, hashcnt);
1096
1116
            vbaname[sizeof(vbaname)-1] = '\0';
1097
1117
            fd = open(vbaname, O_RDONLY|O_BINARY);
1098
1118
            if (fd == -1) continue;
1108
1128
 
1109
1129
    if ((hashcnt = uniq_get(U, "worddocument", 12, &hash))) {
1110
1130
        while(hashcnt--) {
1111
 
            snprintf(vbaname, sizeof(vbaname), "%s/%s_%u", dirname, hash, hashcnt);
 
1131
            snprintf(vbaname, sizeof(vbaname), "%s"PATHSEP"%s_%u", dirname, hash, hashcnt);
1112
1132
            vbaname[sizeof(vbaname)-1] = '\0';
1113
1133
            fd = open(vbaname, O_RDONLY|O_BINARY);
1114
1134
            if (fd == -1) continue;
1146
1166
                if (strcmp (dent->d_name, ".") && strcmp (dent->d_name, "..")) {
1147
1167
                    /* build the full name */
1148
1168
                    fullname = calloc (strlen (dirname) + strlen (dent->d_name) + 2, sizeof (char));
1149
 
                    sprintf (fullname, "%s/%s", dirname, dent->d_name);
 
1169
                    sprintf (fullname, "%s"PATHSEP"%s", dirname, dent->d_name);
1150
1170
 
1151
1171
                    /* stat the file */
1152
1172
                    if (lstat (fullname, &statbuf) != -1) {
1158
1178
            }
1159
1179
        }
1160
1180
    } else {
1161
 
        cli_errmsg ("ScanDir -> Can't open directory %s.\n", dirname);
 
1181
        logg("!ScanDir -> Can't open directory %s.\n", dirname);
1162
1182
        return CL_EOPEN;
1163
1183
    }
1164
1184