summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorRichard Basch <probe@mit.edu>1996-01-22 04:52:28 +0000
committerRichard Basch <probe@mit.edu>1996-01-22 04:52:28 +0000
commitb1e0369e1b9516117d24a7c90fafe69048f36660 (patch)
tree8f5ca99cde63c4eb13ae4a55fe074203bd1a324c /src/lib
parent99deb652aed6395120f957f211dbd604e4aa8774 (diff)
Fixed three problems in the database rename function:
1. Added a missing call to krb5_dbm_db_end_update to ensure the lock file timestamp is updated. 2. Corrected the test for a valid lock file handle to be >=0 not non-zero. 3. Use the lock file of the target name, since the source will shortly disappear and another process may already be checking for the lock file of the target. (For example, a kdb5_edit db load will use a temporary name and rename the db to the proper name when it is done, and krb5kdc will be testing for the target lock file.) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7351 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/kdb/kdb_dbm.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/lib/kdb/kdb_dbm.c b/src/lib/kdb/kdb_dbm.c
index 888f70395..989a19ba1 100644
--- a/src/lib/kdb/kdb_dbm.c
+++ b/src/lib/kdb/kdb_dbm.c
@@ -886,11 +886,11 @@ krb5_dbm_db_rename(context, from, to)
context->db_context = (void *) NULL;
if (!(retval = k5dbm_init_context(context))) {
/*
- * Set the name of our temporary database context to the source
+ * Set the name of our temporary database context to the target
* database. We need to do this so that the database calls do the
* operations to the right lock file.
*/
- retval = krb5_dbm_db_set_name(context, from);
+ retval = krb5_dbm_db_set_name(context, to);
db_ctx = (krb5_db_context *) context->db_context;
if ((db_ctx->db_lf_name = gen_dbsuffix(db_ctx->db_name,
KDBM_LOCK_EXT(db_ctx)))) {
@@ -952,11 +952,14 @@ krb5_dbm_db_rename(context, from, to)
(fromdir && todir && (rename (fromdir, todir) == 0))) &&
((!frompag && !topag) ||
(frompag && topag && (rename (frompag, topag) == 0)))) {
- if (fromok && took)
- (void) rename(fromok, took);
- retval = 0;
- } else
- retval = errno;
+ /* We only need to unlink the source lock file */
+ (void) unlink(fromok);
+ retval = krb5_dbm_db_end_update(context);
+ } else {
+ (void) krb5_dbm_db_end_update(context);
+ retval = errno;
+ }
+
errout:
if (fromok)
@@ -973,16 +976,17 @@ errout:
free_dbsuffix (fromdir);
if (context->db_context) {
- if (db_ctx->db_lf_file) {
+ if (db_ctx->db_lf_file >= 0) {
krb5_dbm_db_unlock(context);
close(db_ctx->db_lf_file);
}
k5dbm_clear_context((krb5_db_context *) context->db_context);
free (context->db_context);
}
+
context->db_context = s_context;
+ (void) krb5_dbm_db_unlock(context); /* unlock saved context db */
- (void) krb5_dbm_db_unlock(context); /* unlock database */
return retval;
}