From: Barry Jaspan Date: Tue, 8 Oct 1996 17:35:30 +0000 (+0000) Subject: * adb_openclose.c, adb_policy.c: implement database renaming; X-Git-Tag: krb5-1.0-freeze1~274 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fdf24445c7cba76d439d29bf6ddefd8864f4bf60;p=krb5.git * adb_openclose.c, adb_policy.c: implement database renaming; also, only create a db lockfile after the database has been successfully created [krb5-admin/62] git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@9148 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/kadm5/srv/ChangeLog b/src/lib/kadm5/srv/ChangeLog index 6bf776389..3bd2f388f 100644 --- a/src/lib/kadm5/srv/ChangeLog +++ b/src/lib/kadm5/srv/ChangeLog @@ -1,3 +1,9 @@ +Tue Oct 8 13:33:48 1996 Barry Jaspan + + * adb_openclose.c, adb_policy.c: implement database renaming; + also, only create a db lockfile after the database has been + successfully created [krb5-admin/62] + Fri Oct 4 08:40:21 1996 Ezra Peisach * svr_principal.c (kadm5_get_principal): Do not assume malloc(0) diff --git a/src/lib/kadm5/srv/adb_openclose.c b/src/lib/kadm5/srv/adb_openclose.c index 627a6b410..0417be53b 100644 --- a/src/lib/kadm5/srv/adb_openclose.c +++ b/src/lib/kadm5/srv/adb_openclose.c @@ -28,11 +28,6 @@ osa_adb_ret_t osa_adb_create_db(char *filename, char *lockfilename, DB *db; HASHINFO info; - lf = fopen(lockfilename, "w+"); - if (lf == NULL) - return errno; - (void) fclose(lf); - memset(&info, 0, sizeof(info)); info.hash = NULL; info.bsize = 256; @@ -44,6 +39,13 @@ osa_adb_ret_t osa_adb_create_db(char *filename, char *lockfilename, return errno; if (db->close(db) < 0) return errno; + + /* only create the lock file if we successfully created the db */ + lf = fopen(lockfilename, "w+"); + if (lf == NULL) + return errno; + (void) fclose(lf); + return OSA_ADB_OK; } @@ -57,6 +59,48 @@ osa_adb_ret_t osa_adb_destroy_db(char *filename, char *lockfilename, return OSA_ADB_OK; } +osa_adb_ret_t osa_adb_rename_db(char *filefrom, char *lockfrom, + char *fileto, char *lockto, int magic) +{ + osa_adb_db_t fromdb, todb; + osa_adb_ret_t ret; + + if (ret = osa_adb_init_db(&fromdb, filefrom, lockfrom, magic)) + return ret; + if (ret = osa_adb_init_db(&todb, fileto, lockto, magic)) { + (void) osa_adb_fini_db(fromdb, magic); + return ret; + } + if (ret = osa_adb_get_lock(fromdb, OSA_ADB_PERMANENT)) { + (void) osa_adb_fini_db(fromdb, magic); + (void) osa_adb_fini_db(todb, magic); + return ret; + } + if (ret = osa_adb_get_lock(todb, OSA_ADB_PERMANENT)) { + (void) osa_adb_fini_db(fromdb, magic); + (void) osa_adb_fini_db(todb, magic); + return ret; + } + if (rename(filefrom, fileto) < 0) { + (void) osa_adb_fini_db(fromdb, magic); + (void) osa_adb_fini_db(todb, magic); + return errno; + } + /* + * Do not release the lock on fromdb because it is being renamed + * out of existence; no one can ever use it again. + */ + if (ret = osa_adb_release_lock(todb)) { + (void) osa_adb_fini_db(fromdb, magic); + (void) osa_adb_fini_db(todb, magic); + return ret; + } + + (void) osa_adb_fini_db(fromdb, magic); + (void) osa_adb_fini_db(todb, magic); + return 0; +} + osa_adb_ret_t osa_adb_init_db(osa_adb_db_t *dbp, char *filename, char *lockfilename, int magic) { diff --git a/src/lib/kadm5/srv/adb_policy.c b/src/lib/kadm5/srv/adb_policy.c index ff0117bac..5ee70fafd 100644 --- a/src/lib/kadm5/srv/adb_policy.c +++ b/src/lib/kadm5/srv/adb_policy.c @@ -62,6 +62,16 @@ osa_adb_ret_t osa_adb_close_policy(osa_adb_princ_t db) return osa_adb_fini_db(db, OSA_ADB_POLICY_DB_MAGIC); } +osa_adb_ret_t osa_adb_rename_policy(kadm5_config_params *fromparams, + kadm5_config_params *toparams) +{ + return osa_adb_rename_db(fromparams->admin_dbname, + fromparams->admin_lockfile, + toparams->admin_dbname, + toparams->admin_lockfile, + OSA_ADB_POLICY_DB_MAGIC); +} + /* * Function: osa_adb_create_policy *