summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2004-03-11 17:29:51 +0000
committerBob Beck <beck@cvs.openbsd.org>2004-03-11 17:29:51 +0000
commita19d357bdbc334be82384a27fc1b8412605482a7 (patch)
tree422d11abba23ade1c9788d8ca8be05359a75f0f9 /libexec
parent82275da0b8d88ff3d0c7857a568455186ddb4fa7 (diff)
Call db-sync() after each db modification since they aren't all that
frequent in the scheme of things and this avoids the possibility of database corruption. Run here for a week. ok millert@ deraadt@
Diffstat (limited to 'libexec')
-rw-r--r--libexec/spamd/grey.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/libexec/spamd/grey.c b/libexec/spamd/grey.c
index 4eadb77f092..dc59b09292c 100644
--- a/libexec/spamd/grey.c
+++ b/libexec/spamd/grey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grey.c,v 1.9 2004/03/10 00:33:56 deraadt Exp $ */
+/* $OpenBSD: grey.c,v 1.10 2004/03/11 17:29:50 beck Exp $ */
/*
* Copyright (c) 2004 Bob Beck. All rights reserved.
@@ -196,11 +196,11 @@ greyscan(char *dbname)
"deleting %s from %s", a, dbname);
}
if (db->del(db, &dbk, 0)) {
- db->sync(db, 0);
db->close(db);
db = NULL;
return(-1);
}
+ db->sync(db, 0);
} else if (gd.pass <= now) {
int tuple = 0;
char *cp;
@@ -217,11 +217,15 @@ greyscan(char *dbname)
tuple = 1;
*cp = '\0';
}
- if ((addwhiteaddr(a) == -1) && db->del(db, &dbk, 0))
+ if ((addwhiteaddr(a) == -1) && db->del(db, &dbk, 0)) {
+ db->sync(db, 0);
goto bad;
+ }
if (tuple) {
- if (db->del(db, &dbk, 0))
+ if (db->del(db, &dbk, 0)) {
+ db->sync(db, 0);
goto bad;
+ }
/* re-add entry, keyed only by ip */
memset(&dbk, 0, sizeof(dbk));
dbk.size = strlen(a);
@@ -230,10 +234,14 @@ greyscan(char *dbname)
gd.expire = now + whiteexp;
dbd.size = sizeof(gd);
dbd.data = &gd;
- if (db->put(db, &dbk, &dbd, 0))
+ if (db->put(db, &dbk, &dbd, 0)) {
+ db->sync(db, 0);
goto bad;
+ }
+ db->sync(db, 0);
syslog_r(LOG_DEBUG, &sdata,
"whitelisting %s in %s", a, dbname);
+
}
if (debug)
fprintf(stderr, "whitelisted %s\n", a);
@@ -294,6 +302,7 @@ greyupdate(char *dbname, char *ip, char *from, char *to)
dbd.size = sizeof(gd);
dbd.data = &gd;
r = db->put(db, &dbk, &dbd, 0);
+ db->sync(db, 0);
if (r)
goto bad;
if (debug)
@@ -303,6 +312,7 @@ greyupdate(char *dbname, char *ip, char *from, char *to)
if (dbd.size != sizeof(gd)) {
/* whatever this is, it doesn't belong */
db->del(db, &dbk, 0);
+ db->sync(db, 0);
goto bad;
}
memcpy(&gd, dbd.data, sizeof(gd));
@@ -316,6 +326,7 @@ greyupdate(char *dbname, char *ip, char *from, char *to)
dbd.size = sizeof(gd);
dbd.data = &gd;
r = db->put(db, &dbk, &dbd, 0);
+ db->sync(db, 0);
if (r)
goto bad;
if (debug)