summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorRichard Basch <probe@mit.edu>1996-01-31 00:22:23 +0000
committerRichard Basch <probe@mit.edu>1996-01-31 00:22:23 +0000
commit02ae2af7f92d06426591c66792c880d358b5fda0 (patch)
tree9f55c4934d4a90b2bb18b6da08e3998df8fc2192 /src/lib
parentd86be61b478d175e1548bab6a69ceb2c2465db2c (diff)
downloadkrb5-02ae2af7f92d06426591c66792c880d358b5fda0.tar.gz
krb5-02ae2af7f92d06426591c66792c880d358b5fda0.tar.xz
krb5-02ae2af7f92d06426591c66792c880d358b5fda0.zip
Several changes to the db rename feature.
Renaming locks the target lock file. If the target lock file doesn't exist, create it. Check the return value of krb5_dbm_db_set_name and set the context accordingly if the target didn't exist. Only unlink the source lock file if one could be computed. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7418 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/kdb/kdb_dbm.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/lib/kdb/kdb_dbm.c b/src/lib/kdb/kdb_dbm.c
index 1d61c622f..b80a0a65c 100644
--- a/src/lib/kdb/kdb_dbm.c
+++ b/src/lib/kdb/kdb_dbm.c
@@ -886,31 +886,36 @@ 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 target
- * database. We need to do this so that the database calls do the
- * operations to the right lock file.
+ * Set the database to the target, so that other processes sharing
+ * the target will stop their activity, and notice the new database.
*/
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)))) {
- if ((db_ctx->db_lf_file = open(db_ctx->db_lf_name,
- O_RDWR|O_EXCL|O_CREAT, 0600)) >= 0){
- db_ctx->db_inited = 1;
- if ((retval = krb5_dbm_db_get_age(context,
- NULL,
- &db_ctx->db_lf_time)))
- goto errout;
- }
- else {
- retval = errno;
+ if (retval) {
+ if (retval == ENOENT)
+ db_ctx->db_name = strdup(to);
+ else
goto errout;
- }
}
- else {
+
+ db_ctx = (krb5_db_context *) context->db_context;
+ db_ctx->db_lf_name = gen_dbsuffix(db_ctx->db_name,
+ KDBM_LOCK_EXT(db_ctx));
+ if (db_ctx->db_lf_name == (char *)NULL) {
retval = ENOMEM;
goto errout;
}
+
+ db_ctx->db_lf_file = open(db_ctx->db_lf_name, O_RDWR|O_CREAT, 0600);
+ if (db_ctx->db_lf_file < 0) {
+ retval = errno;
+ goto errout;
+ }
+
+ db_ctx->db_inited = 1;
+
+ retval = krb5_dbm_db_get_age(context, NULL, &db_ctx->db_lf_time);
+ if (retval)
+ goto errout;
}
else
return(retval);
@@ -953,7 +958,8 @@ krb5_dbm_db_rename(context, from, to)
((!frompag && !topag) ||
(frompag && topag && (rename (frompag, topag) == 0)))) {
/* We only need to unlink the source lock file */
- (void) unlink(fromok);
+ if (fromok)
+ (void) unlink(fromok);
retval = krb5_dbm_db_end_update(context);
} else {
(void) krb5_dbm_db_end_update(context);