From 71461cc249f1ad760260bf790a05abb1011f4499 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Sat, 2 Feb 1991 01:34:20 +0000 Subject: [PATCH] Added kdb_db_destroy() function git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1647 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/kdb/kdb_dbm.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/lib/kdb/kdb_dbm.c b/src/lib/kdb/kdb_dbm.c index ff448b3c3..291670220 100644 --- a/src/lib/kdb/kdb_dbm.c +++ b/src/lib/kdb/kdb_dbm.c @@ -20,6 +20,7 @@ static char rcsid_krb_dbm_c[] = #include #include #include +#include #define KRB5_DBM_MAX_RETRY 5 @@ -644,6 +645,66 @@ char *db_name; return retval; } +/* + * Destroy the database. Zero's out all of the files, just to be sure. + */ +krb5_error_code +destroy_file_suffix(dbname, suffix) + char *dbname; + char *suffix; +{ + char *filename; + struct stat statb; + int nb,fd,i; + char buf[BUFSIZ]; + + filename = gen_dbsuffix(dbname, suffix); + if (stat(filename, &statb)) { + free(filename); + if (errno == ENOENT) + return(0); + else + return(errno); + } + if ((fd = open(filename, O_RDWR, 0)) < 0) { + free(filename); + return(errno); + } + i = 0; + while (i < statb.st_size) { + nb = write(fd, buf, BUFSIZ); + if (nb < 0) { + free(filename); + return(errno); + } + i += nb; + } + fsync(fd); + close(fd); + + if (unlink(filename)) { + free(filename); + return(errno); + } + free(filename); + return(0); +} + +krb5_error_code +krb5_dbm_db_destroy(dbname) + char *dbname; +{ + krb5_error_code retval; + + if (retval = destroy_file_suffix(dbname, ".pag")) + return(retval); + if (retval = destroy_file_suffix(dbname, ".dir")) + return(retval); + if (retval = destroy_file_suffix(dbname, ".ok")) + return(retval); + return(0); +} + /* * "Atomically" rename the database in a way that locks out read * access in the middle of the rename. -- 2.26.2