bmf

bmf (Bayesian Mail Filter) 0.9.4 fork + patches
git clone git://git.codemadness.org/bmf
Log | Files | Refs | README | LICENSE

commit 4c3c79f49125ef555fba1df7f6cbab2c7b26ea00
parent ea2535f01b1fb73863f7104b0e21719b577620c1
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sat, 27 Oct 2018 19:14:50 +0200

initial unveil(2) support + some code-cleanup and remove unused functions

Diffstat:
bmf.c | 14++++++--------
config.h | 3++-
dbh.h | 2--
dbtext.c | 33+++++++++++++++++++--------------
dbtext.h | 4----
filt.c | 3+--
vec.c | 11+++++++----
7 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/bmf.c b/bmf.c @@ -75,7 +75,6 @@ version(void) int main(int argc, char **argv) { - int ch; dbfmt_t dbfmt = db_text; char *dbname = NULL; bool_t rdonly; @@ -83,18 +82,17 @@ main(int argc, char **argv) mbox_t mboxtype = detect; bool_t do_passthru = false; dbh_t *pdb; - dbt_t *pblist; - dbt_t *pglist; - dbt_t *ptable; + dbt_t *pblist, *pglist, *ptable; vec_t mlist; stats_t stats; lex_t lex; tok_t tok; bool_t is_spam = false; + int ch; int fd = STDIN_FILENO; - if (pledge("stdio rpath wpath cpath flock", NULL) == -1) + if (pledge("stdio rpath wpath cpath flock unveil", NULL) == -1) err(1, "pledge"); srand(time(NULL)); @@ -110,14 +108,14 @@ main(int argc, char **argv) break; case 'V': version(); - break; /* notreached */ + break; /* NOTREACHED */ case 'd': free(dbname); dbname = strdup(optarg); break; case 'h': usage(); - break; /* notreached */ + break; /* NOTREACHED */ case 'k': stats.keepers = atoi(optarg); break; @@ -141,7 +139,7 @@ main(int argc, char **argv) break; case 't': mode = mode_test; - if (pledge("stdio rpath cpath flock", NULL) == -1) + if (pledge("stdio rpath cpath flock unveil", NULL) == -1) err(1, "pledge"); break; case 'v': diff --git a/config.h b/config.h @@ -29,9 +29,10 @@ #include <time.h> #include <unistd.h> -/* pledge(2) */ +/* pledge(2) and unveil(2) */ #ifndef __OpenBSD__ #define pledge(a,b) 0 +#define unveil(a,b) 0 #endif #include <sys/file.h> diff --git a/dbh.h b/dbh.h @@ -27,8 +27,6 @@ struct _dbt { bool_t(*close) (dbt_t *); bool_t(*mergeclose) (dbt_t *, vec_t *); bool_t(*unmergeclose) (dbt_t *, vec_t *); - bool_t(*import) (dbt_t *, cpchar); - bool_t(*export) (dbt_t *, cpchar); uint(*getmsgcount) (dbt_t *); uint(*getcount) (dbt_t *, str_t *); }; diff --git a/dbtext.c b/dbtext.c @@ -76,6 +76,7 @@ dbtext_db_open(cpchar dbhost, cpchar dbname, cpchar dbuser, cpchar dbpass) if ((pthis->dir = malloc(dirlen)) == NULL) goto bail; + /* NOTE: no truncation possible */ snprintf(pthis->dir, dirlen, "%s/.bmf", phome); } @@ -89,6 +90,24 @@ dbtext_db_open(cpchar dbhost, cpchar dbname, cpchar dbuser, cpchar dbpass) goto bail; } + /* unveil(2), TODO: rework later */ + /* TODO: permission depending on mode */ + char listpath[PATH_MAX]; + snprintf(listpath, sizeof(listpath), "%s/%s", pthis->dir, "goodlist"); + if (unveil(listpath, "rw") == -1) { + perror("unveil()"); + exit(2); + } + snprintf(listpath, sizeof(listpath), "%s/%s", pthis->dir, "spamlist"); + if (unveil(listpath, "rw") == -1) { + perror("unveil()"); + exit(2); + } + if (unveil(NULL, NULL) == -1) { + perror("unveil()"); + exit(2); + } + return (dbh_t *)pthis; bail: @@ -136,8 +155,6 @@ dbtext_db_opentable(dbhtext_t * pthis, cpchar table, bool_t rdonly) ptable->close = dbtext_table_close; ptable->mergeclose = dbtext_table_mergeclose; ptable->unmergeclose = dbtext_table_unmergeclose; - ptable->import = dbtext_table_import; - ptable->export = dbtext_table_export; ptable->getmsgcount = dbtext_table_getmsgcount; ptable->getcount = dbtext_table_getcount; ptable->fd = -1; @@ -442,18 +459,6 @@ dbtext_table_unmergeclose(dbttext_t * pthis, vec_t * pmsg) return dbtext_table_close(pthis); } -bool_t -dbtext_table_import(dbttext_t * pthis, cpchar filename) -{ - return false; -} - -bool_t -dbtext_table_export(dbttext_t * pthis, cpchar filename) -{ - return false; -} - uint dbtext_table_getmsgcount(dbttext_t * pthis) { diff --git a/dbtext.h b/dbtext.h @@ -16,8 +16,6 @@ struct _dbttext bool_t (*close)(dbttext_t*); bool_t (*mergeclose)(dbttext_t*,vec_t*); bool_t (*unmergeclose)(dbttext_t*,vec_t*); - bool_t (*import)(dbttext_t*,cpchar); - bool_t (*export)(dbttext_t*,cpchar); uint (*getmsgcount)(dbttext_t*); uint (*getcount)(dbttext_t*,str_t*); @@ -45,8 +43,6 @@ dbt_t* dbtext_db_opentable( dbhtext_t* pthis, cpchar table, bool_t rdonly ); bool_t dbtext_table_close( dbttext_t* pthis ); bool_t dbtext_table_mergeclose( dbttext_t* pthis, vec_t* pmsg ); bool_t dbtext_table_unmergeclose( dbttext_t* pthis, vec_t* pmsg ); -bool_t dbtext_table_import( dbttext_t* pthis, cpchar filename ); -bool_t dbtext_table_export( dbttext_t* pthis, cpchar filename ); uint dbtext_table_getmsgcount( dbttext_t* pthis ); uint dbtext_table_getcount( dbttext_t* pthis, str_t* pword ); diff --git a/filt.c b/filt.c @@ -65,8 +65,7 @@ bayesfilt(dbt_t * pglist, dbt_t * pblist, vec_t * pmlist, stats_t * pstats) #endif - discrim_t *pp; - discrim_t *hit; + discrim_t *pp, *hit; for (pp = pstats->extrema; pp < pstats->extrema + pstats->keepers; pp++) { pp->key.p = NULL; diff --git a/vec.c b/vec.c @@ -34,22 +34,25 @@ vec_create(vec_t * pthis) void vec_destroy(vec_t * pthis) { + pthis->nitems = 0; free(pthis->pitems); + pthis->pitems = NULL; } static void vec_setsize(vec_t * pthis, uint nsize) { - if (nsize > pthis->nalloc) { - uint nnewalloc; - str_t *pnewitems; - uint n; + uint nnewalloc; + str_t *pnewitems; + uint n; + if (nsize > pthis->nalloc) { nnewalloc = pthis->nalloc * 2; if (nnewalloc < nsize) nnewalloc = nsize; pnewitems = (str_t *) realloc(pthis->pitems, nnewalloc * sizeof(str_t)); if (pnewitems == NULL) { + perror("realloc()"); exit(2); } for (n = pthis->nitems; n < nsize; n++) {