#define KDB_DB2_DATABASE_NAME "database_name"
-static char *gen_dbsuffix(char *, char *);
-
static krb5_error_code krb5_db2_db_start_update(krb5_context);
static krb5_error_code krb5_db2_db_end_update(krb5_context);
krb5_error_code krb5_db2_db_lock(krb5_context, int);
-static krb5_error_code krb5_db2_db_set_hashfirst(krb5_context, int);
-
/*
* Locking:
*
/*
* Routines to deal with context.
*/
-#define k5db2_inited(c) (c && c->dal_handle \
- && c->dal_handle->db_context \
+#define k5db2_inited(c) (c->dal_handle->db_context \
&& ((krb5_db2_context *) c->dal_handle->db_context)->db_inited)
static krb5_error_code
}
}
-static krb5_error_code
-krb5_db2_db_set_hashfirst(krb5_context context, int hashfirst)
-{
- krb5_db2_context *dbc;
- kdb5_dal_handle *dal_handle;
-
- if (k5db2_inited(context))
- return KRB5_KDB_DBNOTINITED;
- dal_handle = context->dal_handle;
- dbc = (krb5_db2_context *) dal_handle->db_context;
- dbc->hashfirst = hashfirst;
- return 0;
-}
-
/*
* initialization for data base routines.
*/
char *filename = NULL;
krb5_db2_context *db_ctx;
krb5_error_code retval;
- kdb5_dal_handle *dal_handle;
char policy_db_name[1024], policy_lock_name[1024];
if (k5db2_inited(context))
if ((retval = k5db2_init_context(context)))
return (retval);
- dal_handle = context->dal_handle;
- db_ctx = dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
db_ctx->db = NULL;
if (!(filename = gen_dbsuffix(db_ctx->db_name, db_ctx->tempdb
{
krb5_error_code retval = 0;
krb5_db2_context *db_ctx;
- kdb5_dal_handle *dal_handle;
-
- dal_handle = context->dal_handle;
- if (dal_handle == NULL) {
- return 0;
- }
-
- db_ctx = (krb5_db2_context *) dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
if (k5db2_inited(context)) {
if (close(db_ctx->db_lf_file))
retval = errno;
}
k5db2_clear_context(db_ctx);
- /* free(dal_handle->db_context); */
- dal_handle->db_context = NULL;
+ free(context->dal_handle->db_context);
+ context->dal_handle->db_context = NULL;
}
return retval;
}
krb5_db2_db_set_mkey(krb5_context context, krb5_keyblock *key)
{
krb5_db2_context *db_ctx;
- kdb5_dal_handle *dal_handle;
if (!k5db2_inited(context))
return (KRB5_KDB_DBNOTINITED);
- dal_handle = context->dal_handle;
- db_ctx = dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
db_ctx->db_master_key = key;
return 0;
}
krb5_db2_db_get_mkey(krb5_context context, krb5_keyblock **key)
{
krb5_db2_context *db_ctx;
- kdb5_dal_handle *dal_handle;
if (!k5db2_inited(context))
return (KRB5_KDB_DBNOTINITED);
- dal_handle = context->dal_handle;
- db_ctx = dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
*key = db_ctx->db_master_key;
return 0;
krb5_db2_db_set_mkey_list(krb5_context context, krb5_keylist_node *key_list)
{
krb5_db2_context *db_ctx;
- kdb5_dal_handle *dal_handle;
if (!k5db2_inited(context))
return (KRB5_KDB_DBNOTINITED);
- dal_handle = context->dal_handle;
- db_ctx = dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
db_ctx->db_master_key_list = key_list;
return 0;
}
krb5_db2_db_get_mkey_list(krb5_context context, krb5_keylist_node **key_list)
{
krb5_db2_context *db_ctx;
- kdb5_dal_handle *dal_handle;
if (!k5db2_inited(context))
return (KRB5_KDB_DBNOTINITED);
- dal_handle = context->dal_handle;
- db_ctx = dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
*key_list = db_ctx->db_master_key_list;
return 0;
krb5_db2_db_get_age(krb5_context context, char *db_name, time_t *age)
{
krb5_db2_context *db_ctx;
- kdb5_dal_handle *dal_handle;
struct stat st;
if (!k5db2_inited(context))
return (KRB5_KDB_DBNOTINITED);
- dal_handle = context->dal_handle;
- db_ctx = (krb5_db2_context *) dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
if (fstat(db_ctx->db_lf_file, &st) < 0)
*age = -1;
{
krb5_error_code retval;
krb5_db2_context *db_ctx;
- kdb5_dal_handle *dal_handle;
struct stat st;
time_t now;
struct utimbuf utbuf;
return (KRB5_KDB_DBNOTINITED);
retval = 0;
- dal_handle = context->dal_handle;
- db_ctx = dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
now = time((time_t *) NULL);
if (fstat(db_ctx->db_lf_file, &st) == 0) {
if (st.st_mtime >= now) {
DB *db;
krb5_error_code retval;
time_t mod_time;
- kdb5_dal_handle *dal_handle;
int mode, gotlock, tries;
switch (in_mode) {
if (!k5db2_inited(context))
return KRB5_KDB_DBNOTINITED;
- dal_handle = context->dal_handle;
- db_ctx = (krb5_db2_context *) dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
if (db_ctx->db_locks_held && (db_ctx->db_lock_mode >= mode)) {
/* No need to upgrade lock, just return */
db_ctx->db_locks_held++;
krb5_db2_db_unlock(krb5_context context)
{
krb5_db2_context *db_ctx;
- kdb5_dal_handle *dal_handle;
DB *db;
krb5_error_code retval;
if (!k5db2_inited(context))
return KRB5_KDB_DBNOTINITED;
- dal_handle = context->dal_handle;
- db_ctx = (krb5_db2_context *) dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
if ((retval = osa_adb_release_lock(db_ctx->policy_db))) {
return retval;
char policy_db_name[1024], policy_lock_name[1024];
tmpcontext = 0;
- if (!context->dal_handle
- || !context->dal_handle->db_context) {
+ if (!context->dal_handle->db_context) {
tmpcontext = 1;
if ((retval1 = k5db2_init_context(context)))
return (retval1);
retval2 = destroy_file_suffix(dbname, KDB2_LOCK_EXT);
if (tmpcontext) {
- k5db2_clear_context((krb5_db2_context *) context->dal_handle->db_context);
+ k5db2_clear_context(context->dal_handle->db_context);
free(context->dal_handle->db_context);
context->dal_handle->db_context = NULL;
}
DBT key, contents;
krb5_data keydata, contdata;
int trynum, dbret;
- kdb5_dal_handle *dal_handle;
*more = FALSE;
*nentries = 0;
if (!k5db2_inited(context))
return KRB5_KDB_DBNOTINITED;
- dal_handle = context->dal_handle;
- db_ctx = (krb5_db2_context *) dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
for (trynum = 0; trynum < KRB5_DB2_MAX_RETRY; trynum++) {
if ((retval = krb5_db2_db_lock(context, KRB5_LOCKMODE_SHARED))) {
krb5_data contdata, keydata;
krb5_error_code retval;
krb5_db2_context *db_ctx;
- kdb5_dal_handle *dal_handle;
krb5_clear_error_message (context);
if (db_args) {
if (!k5db2_inited(context))
return KRB5_KDB_DBNOTINITED;
- dal_handle = context->dal_handle;
- db_ctx = (krb5_db2_context *) dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
if ((retval = krb5_db2_db_lock(context, KRB5_LOCKMODE_EXCLUSIVE)))
return retval;
DBT key, contents;
krb5_data keydata, contdata;
int i, dbret;
- kdb5_dal_handle *dal_handle;
if (!k5db2_inited(context))
return KRB5_KDB_DBNOTINITED;
- dal_handle = context->dal_handle;
- db_ctx = (krb5_db2_context *) dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
if ((retval = krb5_db2_db_lock(context, KRB5_LOCKMODE_EXCLUSIVE)))
return (retval);
krb5_data contdata;
krb5_db_entry entries;
krb5_error_code retval;
- kdb5_dal_handle *dal_handle;
int dbret;
void *cookie;
if (!k5db2_inited(context))
return KRB5_KDB_DBNOTINITED;
- dal_handle = context->dal_handle;
- db_ctx = (krb5_db2_context *) dal_handle->db_context;
+ db_ctx = context->dal_handle->db_context;
retval = krb5_db2_db_lock(context, KRB5_LOCKMODE_SHARED);
if (retval)
{
krb5_boolean old;
krb5_db2_context *db_ctx;
- kdb5_dal_handle *dal_handle;
- dal_handle = context->dal_handle;
+ db_ctx = context->dal_handle->db_context;
old = mode;
- if (dal_handle && (db_ctx = (krb5_db2_context *) dal_handle->db_context)) {
+ if (db_ctx) {
old = db_ctx->db_nb_locks;
db_ctx->db_nb_locks = mode;
}
}
krb5_error_code
-krb5_db2_set_master_key_ext(krb5_context kcontext,
+krb5_db2_set_master_key_ext(krb5_context context,
char *pwd, krb5_keyblock * key)
{
- return krb5_db2_db_set_mkey(kcontext, key);
+ return krb5_db2_db_set_mkey(context, key);
}
void *
-krb5_db2_alloc(krb5_context kcontext, void *ptr, size_t size)
+krb5_db2_alloc(krb5_context context, void *ptr, size_t size)
{
return realloc(ptr, size);
}
void
-krb5_db2_free(krb5_context kcontext, void *ptr)
+krb5_db2_free(krb5_context context, void *ptr)
{
free(ptr);
}
/* policy functions */
krb5_error_code
-krb5_db2_create_policy(krb5_context kcontext, osa_policy_ent_t policy)
+krb5_db2_create_policy(krb5_context context, osa_policy_ent_t policy)
{
- kdb5_dal_handle *dal_handle;
- krb5_db2_context *dbc;
-
- dal_handle = kcontext->dal_handle;
- dbc = (krb5_db2_context *) dal_handle->db_context;
+ krb5_db2_context *dbc = context->dal_handle->db_context;
return osa_adb_create_policy(dbc->policy_db, policy);
}
krb5_error_code
-krb5_db2_get_policy(krb5_context kcontext,
+krb5_db2_get_policy(krb5_context context,
char *name, osa_policy_ent_t * policy, int *cnt)
{
- kdb5_dal_handle *dal_handle;
- krb5_db2_context *dbc;
-
- dal_handle = kcontext->dal_handle;
- dbc = (krb5_db2_context *) dal_handle->db_context;
+ krb5_db2_context *dbc = context->dal_handle->db_context;
return osa_adb_get_policy(dbc->policy_db, name, policy, cnt);
}
krb5_error_code
-krb5_db2_put_policy(krb5_context kcontext, osa_policy_ent_t policy)
+krb5_db2_put_policy(krb5_context context, osa_policy_ent_t policy)
{
- kdb5_dal_handle *dal_handle;
- krb5_db2_context *dbc;
-
- dal_handle = kcontext->dal_handle;
- dbc = (krb5_db2_context *) dal_handle->db_context;
+ krb5_db2_context *dbc = context->dal_handle->db_context;
return osa_adb_put_policy(dbc->policy_db, policy);
}
krb5_error_code
-krb5_db2_iter_policy(krb5_context kcontext,
+krb5_db2_iter_policy(krb5_context context,
char *match_entry,
osa_adb_iter_policy_func func, void *data)
{
- kdb5_dal_handle *dal_handle;
- krb5_db2_context *dbc;
-
- dal_handle = kcontext->dal_handle;
- dbc = (krb5_db2_context *) dal_handle->db_context;
+ krb5_db2_context *dbc = context->dal_handle->db_context;
return osa_adb_iter_policy(dbc->policy_db, func, data);
}
krb5_error_code
-krb5_db2_delete_policy(krb5_context kcontext, char *policy)
+krb5_db2_delete_policy(krb5_context context, char *policy)
{
- kdb5_dal_handle *dal_handle;
- krb5_db2_context *dbc;
-
- dal_handle = kcontext->dal_handle;
- dbc = (krb5_db2_context *) dal_handle->db_context;
+ krb5_db2_context *dbc = context->dal_handle->db_context;
return osa_adb_destroy_policy(dbc->policy_db, policy);
}
void
-krb5_db2_free_policy(krb5_context kcontext, osa_policy_ent_t entry)
+krb5_db2_free_policy(krb5_context context, osa_policy_ent_t entry)
{
osa_free_policy_ent(entry);
}
/* */
krb5_error_code
-krb5_db2_promote_db(krb5_context kcontext, char *conf_section, char **db_args)
+krb5_db2_promote_db(krb5_context context, char *conf_section, char **db_args)
{
krb5_error_code status = 0;
char *db_name = NULL;
char *temp_db_name = NULL;
char **db_argp;
int merge_nra = 0;
+ krb5_db2_context *db_ctx = context->dal_handle->db_context;
- krb5_clear_error_message (kcontext);
+ krb5_clear_error_message (context);
- {
- kdb5_dal_handle *dal_handle = kcontext->dal_handle;
- krb5_db2_context *db_ctx = dal_handle->db_context;
- db_name = strdup(db_ctx->db_name);
- if (db_name == NULL) {
- status = ENOMEM;
- goto clean_n_exit;
- }
+ db_name = strdup(db_ctx->db_name);
+ if (db_name == NULL) {
+ status = ENOMEM;
+ goto clean_n_exit;
}
- assert(kcontext->dal_handle != NULL);
temp_db_name = gen_dbsuffix(db_name, "~");
if (temp_db_name == NULL) {
status = ENOMEM;
}
}
- status = krb5_db2_db_rename (kcontext, temp_db_name, db_name, merge_nra);
+ status = krb5_db2_db_rename (context, temp_db_name, db_name, merge_nra);
if (status)
goto clean_n_exit;
clean_n_exit:
- if (db_name)
- free(db_name);
- if (temp_db_name)
- free(temp_db_name);
+ free(db_name);
+ free(temp_db_name);
return status;
}
* fail_auth_count, and any negative TL data values.
*/
static krb5_error_code
-krb5_db2_merge_principal(krb5_context kcontext,
+krb5_db2_merge_principal(krb5_context context,
krb5_db_entry *src,
krb5_db_entry *dst,
int *changed)
* Note: src_db is locked on success.
*/
static krb5_error_code
-krb5_db2_begin_nra_merge(krb5_context kcontext,
+krb5_db2_begin_nra_merge(krb5_context context,
krb5_db2_context *src_db,
krb5_db2_context *dst_db)
{
krb5_error_code retval;
- kdb5_dal_handle *dal_handle = kcontext->dal_handle;
+ kdb5_dal_handle *dal_handle = context->dal_handle;
struct nra_context nra;
- nra.kcontext = kcontext;
+ nra.kcontext = context;
nra.db_context = dst_db;
assert(dal_handle->db_context == dst_db);
dal_handle->db_context = src_db;
- retval = krb5_db2_db_lock(kcontext, KRB5_LOCKMODE_EXCLUSIVE);
+ retval = krb5_db2_db_lock(context, KRB5_LOCKMODE_EXCLUSIVE);
if (retval) {
dal_handle->db_context = dst_db;
return retval;
}
- retval = krb5_db2_db_iterate_ext(kcontext,
+ retval = krb5_db2_db_iterate_ext(context,
krb5_db2_merge_nra_iterator,
&nra,
0,
0);
if (retval != 0)
- (void) krb5_db2_db_unlock(kcontext);
+ (void) krb5_db2_db_unlock(context);
dal_handle->db_context = dst_db;
* src_db.
*/
static krb5_error_code
-krb5_db2_end_nra_merge(krb5_context kcontext,
+krb5_db2_end_nra_merge(krb5_context context,
krb5_db2_context *src_db,
krb5_db2_context *dst_db)
{
krb5_error_code retval;
- kdb5_dal_handle *dal_handle = kcontext->dal_handle;
+ kdb5_dal_handle *dal_handle = context->dal_handle;
dal_handle->db_context = src_db;
- retval = krb5_db2_db_unlock(kcontext);
+ retval = krb5_db2_db_unlock(context);
dal_handle->db_context = dst_db;
return retval;