-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathextensions.c
More file actions
118 lines (101 loc) · 2.61 KB
/
Copy pathextensions.c
File metadata and controls
118 lines (101 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
ClamAV Live Scan
mad.coder@mail.com
https://github.com/madcoder42/clamAVLiveScan
Copyright 2017 madcoder42
This file is part of ClamAV Live Scan.
ClamAV Live Scan is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ClamAV Live Scan is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ClamAV Live Scan. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common.h"
void loadAllExtensions()
{
char ext[16];
int len;
char *s = (char *)SCANEXTENSIONS;
char *tmp = NULL;
while((tmp = strchr(s, ';')) != NULL) {
len = (tmp - s);
if (len < 15) {
memset(ext, 0, 16);
ext[0] = '.';
memcpy(ext + 1, s, len);
addAnExtensions(ext);
}
s = tmp + 1;
}
if (s != NULL && (len = strlen(s)) < 15) {
memset(ext, 0, 16);
ext[0] = '.';
memcpy(ext + 1, s, len);
addAnExtensions(ext);
}
return;
}
/******************************************************************************/
void addAnExtensions(char *ext)
{
struct sEXTENSIONS *n = NULL;
if ((n = (struct sEXTENSIONS *)malloc(sizeof(struct sEXTENSIONS))) == NULL) {
return;
}
if ((n->ext = (char *)calloc((strlen(ext) + 1), sizeof(char))) == NULL) {
free(n);
return;
}
strcpy(n->ext, ext);
n->next = NULL;
if (PARAMS.extHead == NULL) {
PARAMS.extHead = n;
} else {
PARAMS.extLast->next = n;
}
PARAMS.extLast = n;
return;
}
/******************************************************************************/
short int isValidExtension(char *path)
{
struct sEXTENSIONS *n = NULL;
char *ext = NULL;
int len;
if ((ext = strrchr(path, '.')) == NULL) {
return RET_E;
}
len = strlen(ext);
if (len == 0 || len > 15) {
return RET_E;
}
n = PARAMS.extHead;
while(n != NULL) {
if (strcasecmp(ext, n->ext) == 0) {
return RET_O;
}
n = n->next;
}
return RET_E;
}
/******************************************************************************/
void delAllExtensions()
{
struct sEXTENSIONS *n = NULL;
struct sEXTENSIONS *nNext = NULL;
n = PARAMS.extHead;
while(n != NULL) {
nNext = n->next;
free(n->ext);
free(n);
n = nNext;
}
PARAMS.extHead = NULL;
PARAMS.extLast = NULL;
return;
}