Skip to content

Commit cfae6da

Browse files
b1tgval-ms
authored andcommitted
Add regex support for OnAccessExcludePath
1 parent 801a0ef commit cfae6da

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

clamonacc/inotif/hash.c

+15
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ int onas_ht_init(struct onas_ht **ht, uint32_t size)
142142
**ht = (struct onas_ht){
143143
.htable = NULL,
144144
.size = size,
145+
.head = NULL,
146+
.tail = NULL,
145147
.nbckts = 0,
146148
};
147149

@@ -260,6 +262,19 @@ int onas_ht_insert(struct onas_ht *ht, struct onas_element *elem)
260262
bckt = ht->htable[idx];
261263
}
262264

265+
/* Init activated buckets */
266+
if (ht->nbckts == 0) {
267+
ht->head = bckt;
268+
ht->tail = bckt;
269+
bckt->prev = NULL;
270+
bckt->next = NULL;
271+
} else {
272+
struct onas_bucket *ht_tail = ht->tail;
273+
ht_tail->next = bckt;
274+
bckt->prev = ht_tail;
275+
bckt->next = NULL;
276+
ht->tail = bckt;
277+
}
263278
bsize = bckt->size;
264279
ret = onas_bucket_insert(bckt, elem);
265280

clamonacc/inotif/hash.h

+4
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ struct onas_bucket {
4545

4646
struct onas_element *head;
4747
struct onas_element *tail;
48+
struct onas_bucket *next; /* Next activated bucket */
49+
struct onas_bucket *prev; /* Prev activated bucket */
4850
};
4951

5052
struct onas_ht {
5153

5254
struct onas_bucket **htable;
55+
struct onas_bucket *head; /* Activated buckets head */
56+
struct onas_bucket *tail; /* Activated buckets tail */
5357

5458
/* Must be a sufficiently high power of two--will not grow. */
5559
uint32_t size;

clamonacc/inotif/inotif.c

+22-9
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
// common
5050
#include "optparser.h"
5151
#include "output.h"
52-
52+
#include "misc.h"
5353
// clamd
5454
#include "server.h"
5555
#include "clamd_others.h"
@@ -531,15 +531,28 @@ void *onas_ddd_th(void *arg)
531531
/* Remove provided paths recursively. */
532532
if ((pt = optget(ctx->clamdopts, "OnAccessExcludePath"))->enabled) {
533533
while (pt) {
534-
size_t ptlen = strlen(pt->strarg);
535-
if (onas_ht_get(ddd_ht, pt->strarg, ptlen, NULL) == CL_SUCCESS) {
536-
if (onas_ht_rm_hierarchy(ddd_ht, pt->strarg, ptlen, 0)) {
537-
logg(LOGG_ERROR, "ClamInotif: can't exclude '%s'\n", pt->strarg);
538-
return NULL;
539-
} else
540-
logg(LOGG_INFO, "ClamInotif: excluding '%s' (and all sub-directories)\n", pt->strarg);
534+
struct onas_bucket *ob = ddd_ht->head;
535+
/* Iterate through the activated buckets to find matched paths */
536+
while (ob != NULL) {
537+
struct onas_element *oe = ob->head;
538+
while (oe != NULL) {
539+
if (match_regex(oe->key, pt->strarg)) {
540+
if (onas_ht_get(ddd_ht, oe->key, oe->klen, NULL) == CL_SUCCESS) {
541+
char *oe_key = cli_safer_strdup(oe->key);
542+
if (onas_ht_rm_hierarchy(ddd_ht, oe->key, oe->klen, 0)) {
543+
logg(LOGG_ERROR, "ClamInotif: can't exclude '%s'\n", oe_key);
544+
free(oe_key);
545+
return NULL;
546+
} else {
547+
logg(LOGG_INFO, "ClamInotif: excluding '%s' (and all sub-directories)\n", oe_key);
548+
free(oe_key);
549+
}
550+
}
551+
}
552+
oe = oe->next;
553+
}
554+
ob = ob->next;
541555
}
542-
543556
pt = (struct optstruct *)pt->nextarg;
544557
}
545558
}

0 commit comments

Comments
 (0)