Skip to content

Commit

Permalink
Add regex support for OnAccessExcludePath
Browse files Browse the repository at this point in the history
  • Loading branch information
b1tg committed Jul 22, 2024
1 parent 06a9bb1 commit 686a888
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
14 changes: 14 additions & 0 deletions clamonacc/inotif/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions clamonacc/inotif/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 21 additions & 9 deletions clamonacc/inotif/inotif.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
// common
#include "optparser.h"
#include "output.h"

#include "misc.h"
// clamd
#include "server.h"
#include "clamd_others.h"
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 686a888

Please sign in to comment.