From f813822cdd6603b52392d58ca665cd5a9b1931e1 Mon Sep 17 00:00:00 2001 From: Johan Danielsson Date: Sat, 9 Aug 1997 20:34:15 +0000 Subject: [PATCH] +DB_rename . git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@2861 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/hdb/db.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/hdb/db.c b/lib/hdb/db.c index d8023cb5f..8d79fe893 100644 --- a/lib/hdb/db.c +++ b/lib/hdb/db.c @@ -145,7 +145,6 @@ DB_delete(krb5_context context, HDB *db, hdb_entry *entry) static krb5_error_code DB_seq(krb5_context context, HDB *db, hdb_entry *entry, int flag) - { DB *d = (DB*)db->db; DBT key, value; @@ -214,6 +213,25 @@ DB__get(krb5_context context, HDB *db, krb5_data key, krb5_data *reply) return 0; } +static krb5_error_code +DB_rename(krb5_context context, HDB *db, const char *new_name) +{ + int ret; + char *old, *new; + + asprintf(&old, "%s.db", db->name); + asprintf(&new, "%s.db", new_name); + ret = rename(old, new); + free(old); + free(new); + if(ret) + return errno; + + free(db->name); + db->name = strdup(new_name); + return 0; +} + krb5_error_code hdb_db_open(krb5_context context, HDB **db, const char *filename, int flags, mode_t mode) @@ -227,6 +245,7 @@ hdb_db_open(krb5_context context, HDB **db, return errno; *db = malloc(sizeof(**db)); (*db)->db = d; + (*db)->name = strdup(filename); (*db)->close = DB_close; (*db)->fetch = DB_fetch; (*db)->store = DB_store; @@ -235,6 +254,7 @@ hdb_db_open(krb5_context context, HDB **db, (*db)->nextkey= DB_nextkey; (*db)->lock = DB_lock; (*db)->unlock = DB_unlock; + (*db)->rename = DB_rename; return 0; }