From 686a88822d418e50e304bb9fa3e35b8919aea707 Mon Sep 17 00:00:00 2001 From: b1tg Date: Tue, 23 Jul 2024 04:46:07 +0800 Subject: [PATCH] Add regex support for OnAccessExcludePath --- clamonacc/inotif/hash.c | 14 ++++++++++++++ clamonacc/inotif/hash.h | 4 ++++ clamonacc/inotif/inotif.c | 30 +++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/clamonacc/inotif/hash.c b/clamonacc/inotif/hash.c index 5b6c9381b5..90091cec88 100644 --- a/clamonacc/inotif/hash.c +++ b/clamonacc/inotif/hash.c @@ -142,6 +142,8 @@ int onas_ht_init(struct onas_ht **ht, uint32_t size) **ht = (struct onas_ht){ .htable = NULL, .size = size, + .head = NULL, + .tail = NULL, .nbckts = 0, }; @@ -260,6 +262,18 @@ int onas_ht_insert(struct onas_ht *ht, struct onas_element *elem) bckt = ht->htable[idx]; } + if (ht->nbckts == 0) { + ht->head = bckt; + ht->tail = bckt; + bckt->prev = NULL; + bckt->next = NULL; + } else { + struct onas_bucket *ht_tail = ht->tail; + ht_tail->next = bckt; + bckt->prev = ht_tail; + bckt->next = NULL; + ht->tail = bckt; + } bsize = bckt->size; ret = onas_bucket_insert(bckt, elem); diff --git a/clamonacc/inotif/hash.h b/clamonacc/inotif/hash.h index a8e8f2d0f8..cc1491e5d0 100644 --- a/clamonacc/inotif/hash.h +++ b/clamonacc/inotif/hash.h @@ -45,11 +45,15 @@ struct onas_bucket { struct onas_element *head; struct onas_element *tail; + struct onas_bucket *next; + struct onas_bucket *prev; }; struct onas_ht { struct onas_bucket **htable; + struct onas_bucket *head; + struct onas_bucket *tail; /* Must be a sufficiently high power of two--will not grow. */ uint32_t size; diff --git a/clamonacc/inotif/inotif.c b/clamonacc/inotif/inotif.c index 74654b19a0..8aec36adf4 100644 --- a/clamonacc/inotif/inotif.c +++ b/clamonacc/inotif/inotif.c @@ -49,7 +49,7 @@ // common #include "optparser.h" #include "output.h" - +#include "misc.h" // clamd #include "server.h" #include "clamd_others.h" @@ -531,15 +531,27 @@ void *onas_ddd_th(void *arg) /* Remove provided paths recursively. */ if ((pt = optget(ctx->clamdopts, "OnAccessExcludePath"))->enabled) { while (pt) { - size_t ptlen = strlen(pt->strarg); - if (onas_ht_get(ddd_ht, pt->strarg, ptlen, NULL) == CL_SUCCESS) { - if (onas_ht_rm_hierarchy(ddd_ht, pt->strarg, ptlen, 0)) { - logg(LOGG_ERROR, "ClamInotif: can't exclude '%s'\n", pt->strarg); - return NULL; - } else - logg(LOGG_INFO, "ClamInotif: excluding '%s' (and all sub-directories)\n", pt->strarg); + struct onas_bucket *ob = ddd_ht->head; + while (ob != NULL) { + struct onas_element *oe = ob->head; + while (oe != NULL) { + if (match_regex(oe->key, pt->strarg)) { + if (onas_ht_get(ddd_ht, oe->key, oe->klen, NULL) == CL_SUCCESS) { + char *oe_key = cli_safer_strdup(oe->key); + if (onas_ht_rm_hierarchy(ddd_ht, oe->key, oe->klen, 0)) { + logg(LOGG_ERROR, "ClamInotif: can't exclude '%s'\n", oe_key); + free(oe_key); + return NULL; + } else { + logg(LOGG_INFO, "ClamInotif: excluding '%s' (and all sub-directories)\n", oe_key); + free(oe_key); + } + } + } + oe = oe->next; + } + ob = ob->next; } - pt = (struct optstruct *)pt->nextarg; } }