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);
((!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);