From cfae6dac9696fbc30720b16891b006ae77d5dcec 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 | 15 +++++++++++++++ clamonacc/inotif/hash.h | 4 ++++ clamonacc/inotif/inotif.c | 31 ++++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/clamonacc/inotif/hash.c b/clamonacc/inotif/hash.c index 5b6c9381b5..7f84a75138 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,19 @@ int onas_ht_insert(struct onas_ht *ht, struct onas_element *elem) bckt = ht->htable[idx]; } + /* Init activated buckets */ + 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..4d1ade79ea 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; /* Next activated bucket */ + struct onas_bucket *prev; /* Prev activated bucket */ }; struct onas_ht { struct onas_bucket **htable; + struct onas_bucket *head; /* Activated buckets head */ + struct onas_bucket *tail; /* Activated buckets 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 9795db4fb2..ca7db761c9 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,28 @@ 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; + /* Iterate through the activated buckets to find matched paths */ + 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; } }