/* default value is the realm name itself */
kcontext->default_realm,
&value);
- if (status) {
+ if (status)
goto clean_n_exit;
- }
#define DB2_NAME "db2"
/* we got the module section. Get the library name from the module */
}
result = strdup(lib);
- clean_n_exit:
- if (value) {
- /* free profile string */
- profile_release_string(value);
- }
-
- if (lib) {
- /* free profile string */
- profile_release_string(lib);
- }
+clean_n_exit:
+ profile_release_string(value);
+ profile_release_string(lib);
return result;
}
static void
kdb_setup_opt_functions(db_library lib)
{
- if (lib->vftabl.set_master_key == NULL) {
+ if (lib->vftabl.set_master_key == NULL)
lib->vftabl.set_master_key = kdb_def_set_mkey;
- }
-
- if (lib->vftabl.set_master_key_list == NULL) {
+ if (lib->vftabl.set_master_key_list == NULL)
lib->vftabl.set_master_key_list = kdb_def_set_mkey_list;
- }
-
- if (lib->vftabl.get_master_key == NULL) {
+ if (lib->vftabl.get_master_key == NULL)
lib->vftabl.get_master_key = kdb_def_get_mkey;
- }
-
- if (lib->vftabl.get_master_key_list == NULL) {
+ if (lib->vftabl.get_master_key_list == NULL)
lib->vftabl.get_master_key_list = kdb_def_get_mkey_list;
- }
-
- if (lib->vftabl.fetch_master_key == NULL) {
+ if (lib->vftabl.fetch_master_key == NULL)
lib->vftabl.fetch_master_key = krb5_db_def_fetch_mkey;
- }
-
- if (lib->vftabl.verify_master_key == NULL) {
+ if (lib->vftabl.verify_master_key == NULL)
lib->vftabl.verify_master_key = krb5_def_verify_master_key;
- }
-
- if (lib->vftabl.fetch_master_key_list == NULL) {
+ if (lib->vftabl.fetch_master_key_list == NULL)
lib->vftabl.fetch_master_key_list = krb5_def_fetch_mkey_list;
- }
-
- if (lib->vftabl.store_master_key_list == NULL) {
+ if (lib->vftabl.store_master_key_list == NULL)
lib->vftabl.store_master_key_list = krb5_def_store_mkey_list;
- }
-
- if (lib->vftabl.dbe_search_enctype == NULL) {
+ if (lib->vftabl.dbe_search_enctype == NULL)
lib->vftabl.dbe_search_enctype = krb5_dbe_def_search_enctype;
- }
-
- if (lib->vftabl.db_change_pwd == NULL) {
+ if (lib->vftabl.db_change_pwd == NULL)
lib->vftabl.db_change_pwd = krb5_dbe_def_cpw;
- }
-
- if (lib->vftabl.store_master_key == NULL) {
+ if (lib->vftabl.store_master_key == NULL)
lib->vftabl.store_master_key = krb5_def_store_mkey;
- }
-
- if (lib->vftabl.promote_db == NULL) {
+ if (lib->vftabl.promote_db == NULL)
lib->vftabl.promote_db = krb5_def_promote_db;
- }
-
- if (lib->vftabl.dbekd_decrypt_key_data == NULL) {
+ if (lib->vftabl.dbekd_decrypt_key_data == NULL)
lib->vftabl.dbekd_decrypt_key_data = krb5_dbekd_def_decrypt_key_data;
- }
-
- if (lib->vftabl.dbekd_encrypt_key_data == NULL) {
+ if (lib->vftabl.dbekd_encrypt_key_data == NULL)
lib->vftabl.dbekd_encrypt_key_data = krb5_dbekd_def_encrypt_key_data;
- }
}
#ifdef STATIC_PLUGINS
filebases[1] = NULL;
*lib = calloc((size_t) 1, sizeof(**lib));
- if (*lib == NULL) {
- status = ENOMEM;
- goto clean_n_exit;
- }
+ if (*lib == NULL)
+ return ENOMEM;
strlcpy((*lib)->name, lib_name, sizeof((*lib)->name));
memcpy(&(*lib)->vftabl, vftabl_addrs[0], sizeof(kdb_vftabl));
kdb_setup_opt_functions(*lib);
- if ((status = (*lib)->vftabl.init_library())) {
- /* ERROR. library not initialized cleanly */
+ if ((status = (*lib)->vftabl.init_library()))
goto clean_n_exit;
- }
clean_n_exit:
- if (vftabl_addrs != NULL) { krb5int_free_plugin_dir_data (vftabl_addrs); }
+ krb5int_free_plugin_dir_data(vftabl_addrs);
/* Both of these DTRT with NULL. */
profile_free_list(profpath);
free(path);
- if (status) {
- if (*lib) {
- if (PLUGIN_DIR_OPEN((&(*lib)->dl_dir_handle))) {
- krb5int_close_plugin_dirs (&(*lib)->dl_dir_handle);
- }
- free(*lib);
- *lib = NULL;
- }
+ if (status && *lib) {
+ if (PLUGIN_DIR_OPEN((&(*lib)->dl_dir_handle)))
+ krb5int_close_plugin_dirs (&(*lib)->dl_dir_handle);
+ free(*lib);
+ *lib = NULL;
}
return status;
}
kdb_db2_pol_err_loaded = 1;
}
- if ((status = kdb_lock_list()) != 0) {
+ if ((status = kdb_lock_list()) != 0)
goto clean_n_exit;
- }
locked = 1;
curr_elt = lib_list;
/* module not found. create and add to list */
status = kdb_load_library(kcontext, lib_name, lib);
- if (status) {
+ if (status)
goto clean_n_exit;
- }
if (prev_elt) {
/* prev_elt points to the last element in the list */
lib_list = *lib;
}
- clean_n_exit:
- if (*lib) {
+clean_n_exit:
+ if (*lib)
(*lib)->reference_cnt++;
- }
- if (locked) {
+ if (locked)
kdb_unlock_list();
- }
return status;
}
krb5_error_code status = 0;
int locked = 0;
- if ((status = kdb_lock_list()) != 0) {
+ if ((status = kdb_lock_list()) != 0)
goto clean_n_exit;
- }
locked = 1;
lib->reference_cnt--;
if (lib->reference_cnt == 0) {
status = lib->vftabl.fini_library();
- if (status) {
+ if (status)
goto clean_n_exit;
- }
/* close the library */
- if (PLUGIN_DIR_OPEN((&lib->dl_dir_handle))) {
+ if (PLUGIN_DIR_OPEN((&lib->dl_dir_handle)))
krb5int_close_plugin_dirs (&lib->dl_dir_handle);
- }
- if (lib->prev == NULL) {
- /* first element in the list */
- lib_list = lib->next;
- } else {
+ if (lib->prev == NULL)
+ lib_list = lib->next; /* first element in the list */
+ else
lib->prev->next = lib->next;
- }
- if (lib->next) {
+ if (lib->next)
lib->next->prev = lib->prev;
- }
free(lib);
}
- clean_n_exit:
- if (locked) {
+clean_n_exit:
+ if (locked)
kdb_unlock_list();
- }
return status;
}
}
status = kdb_find_library(kcontext, library, &lib);
- if (status) {
+ if (status)
goto clean_n_exit;
- }
dal_handle->lib_handle = lib;
kcontext->dal_handle = dal_handle;
- clean_n_exit:
+clean_n_exit:
free(library);
if (status) {
free(dal_handle);
- if (lib) {
+ if (lib)
kdb_free_library(lib);
- }
}
return status;
krb5_error_code status = 0;
status = kdb_free_library(kcontext->dal_handle->lib_handle);
- if (status) {
- goto clean_n_exit;
- }
+ if (status)
+ return status;
free(kcontext->dal_handle);
kcontext->dal_handle = NULL;
-
- clean_n_exit:
- return status;
+ return 0;
}
static void
-get_errmsg (krb5_context kcontext, krb5_error_code err_code)
+get_errmsg(krb5_context kcontext, krb5_error_code err_code)
{
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
const char *e;
+
if (err_code == 0)
return;
- assert(kcontext != NULL);
- /* Must be called with dal_handle->lib_handle locked! */
- assert(kcontext->dal_handle != NULL);
- dal_handle = kcontext->dal_handle;
- if (dal_handle->lib_handle->vftabl.errcode_2_string == NULL)
+ assert(kcontext != NULL && kcontext->dal_handle != NULL);
+ v = &kcontext->dal_handle->lib_handle->vftabl;
+ if (v->errcode_2_string == NULL)
return;
- e = dal_handle->lib_handle->vftabl.errcode_2_string(kcontext, err_code);
+ e = v->errcode_2_string(kcontext, err_code);
assert (e != NULL);
krb5_set_error_message(kcontext, err_code, "%s", e);
- if (dal_handle->lib_handle->vftabl.release_errcode_string)
- dal_handle->lib_handle->vftabl.release_errcode_string(kcontext, e);
+ if (v->release_errcode_string)
+ v->release_errcode_string(kcontext, e);
+}
+
+static krb5_error_code
+get_vftabl(krb5_context kcontext, kdb_vftabl **vftabl_ptr)
+{
+ krb5_error_code status;
+
+ *vftabl_ptr = NULL;
+ if (kcontext->dal_handle == NULL) {
+ status = krb5_db_setup_lib_handle(kcontext);
+ if (status)
+ return status;
+ }
+ *vftabl_ptr = &kcontext->dal_handle->lib_handle->vftabl;
+ return 0;
}
/*
{
krb5_error_code status = 0;
char *section = NULL;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
section = kdb_get_conf_section(kcontext);
if (section == NULL) {
goto clean_n_exit;
}
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
-
- status =
- dal_handle->lib_handle->vftabl.init_module(kcontext, section, db_args,
- mode);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ goto clean_n_exit;
+ status = v->init_module(kcontext, section, db_args, mode);
get_errmsg(kcontext, status);
- clean_n_exit:
+clean_n_exit:
if (section)
free(section);
return status;
{
krb5_error_code status = 0;
char *section = NULL;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
section = kdb_get_conf_section(kcontext);
if (section == NULL) {
goto clean_n_exit;
}
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.db_create(kcontext, section, db_args);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ goto clean_n_exit;
+ status = v->db_create(kcontext, section, db_args);
get_errmsg(kcontext, status);
- clean_n_exit:
+clean_n_exit:
if (section)
free(section);
return status;
krb5_db_fini(krb5_context kcontext)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- /* module not loaded. So nothing to be done */
- goto clean_n_exit;
- }
+ /* Do nothing if module was never loaded. */
+ if (kcontext->dal_handle == NULL)
+ return 0;
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.fini_module(kcontext);
+ v = &kcontext->dal_handle->lib_handle->vftabl;
+ status = v->fini_module(kcontext);
get_errmsg(kcontext, status);
- if (status) {
- goto clean_n_exit;
- }
-
- status = kdb_free_lib_handle(kcontext);
+ if (status)
+ return status;
- clean_n_exit:
- return status;
+ return kdb_free_lib_handle(kcontext);
}
krb5_error_code
{
krb5_error_code status = 0;
char *section = NULL;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
section = kdb_get_conf_section(kcontext);
if (section == NULL) {
goto clean_n_exit;
}
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.db_destroy(kcontext, section, db_args);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ goto clean_n_exit;
+ status = v->db_destroy(kcontext, section, db_args);
get_errmsg(kcontext, status);
- clean_n_exit:
+clean_n_exit:
if (section)
free(section);
return status;
krb5_db_get_age(krb5_context kcontext, char *db_name, time_t * t)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.db_get_age(kcontext, db_name, t);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_get_age(kcontext, db_name, t);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
krb5_db_set_option(krb5_context kcontext, int option, void *value)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.db_set_option(kcontext, option, value);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_set_option(kcontext, option, value);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
krb5_db_lock(krb5_context kcontext, int lock_mode)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
-
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
+ kdb_vftabl *v;
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.db_lock(kcontext, lock_mode);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_lock(kcontext, lock_mode);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
krb5_db_unlock(krb5_context kcontext)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.db_unlock(kcontext);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_unlock(kcontext);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
int *nentries, krb5_boolean * more)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.db_get_principal(kcontext, search_for, 0,
- entries, nentries,
- more);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_get_principal(kcontext, search_for, 0, entries, nentries,
+ more);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
int *nentries, krb5_boolean * more)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
-
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.db_get_principal(kcontext, search_for,
- flags,
- entries, nentries,
- more);
+ kdb_vftabl *v;
- clean_n_exit:
- return status;
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ return v->db_get_principal(kcontext, search_for, flags, entries, nentries,
+ more);
}
krb5_error_code
krb5_db_free_principal(krb5_context kcontext, krb5_db_entry * entry, int count)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
-
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
+ kdb_vftabl *v;
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.db_free_principal(kcontext, entry,
- count);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_free_principal(kcontext, entry, count);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
krb5int_put_principal_no_log(krb5_context kcontext,
krb5_db_entry *entries, int *nentries)
{
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
krb5_error_code status;
char **db_args;
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
status = extract_db_args_from_tl_data(kcontext, &entries->tl_data,
&entries->n_tl_data,
&db_args);
if (status)
return status;
- assert (kcontext->dal_handle != NULL); /* XXX */
- dal_handle = kcontext->dal_handle;
- /* XXX Locking? */
- status = dal_handle->lib_handle->vftabl.db_put_principal(kcontext, entries,
- nentries,
- db_args);
+ status = v->db_put_principal(kcontext, entries, nentries, db_args);
get_errmsg(kcontext, status);
free_db_args(kcontext, db_args);
return status;
krb5_db_entry * entries, int *nentries)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
char **db_args = NULL;
kdb_incr_update_t *upd, *fupd = 0;
char *princ_name = NULL;
log_ctx = kcontext->kdblog_context;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ goto clean_n_exit;
status = extract_db_args_from_tl_data(kcontext, &entries->tl_data,
&entries->n_tl_data,
if (status)
goto clean_n_exit;
- dal_handle = kcontext->dal_handle;
-
if (log_ctx && (log_ctx->iproprole == IPROP_MASTER)) {
if (!(upd = (kdb_incr_update_t *)
malloc(sizeof (kdb_incr_update_t)* *nentries))) {
(void) memset(upd, 0, sizeof(kdb_incr_update_t)* *nentries);
- if ((status = ulog_conv_2logentry(kcontext, entries, upd, *nentries))) {
+ if ((status = ulog_conv_2logentry(kcontext, entries, upd, *nentries)))
goto err_lock;
- }
}
status = ulog_lock(kcontext, KRB5_LOCKMODE_EXCLUSIVE);
}
}
- status = dal_handle->lib_handle->vftabl.db_put_principal(kcontext, entries,
- nentries,
- db_args);
+ status = v->db_put_principal(kcontext, entries, nentries, db_args);
get_errmsg(kcontext, status);
if (status == 0 && fupd) {
upd = fupd;
if (ulog_locked)
ulog_lock(kcontext, KRB5_LOCKMODE_UNLOCK);
- clean_n_exit:
+clean_n_exit:
free_db_args(kcontext, db_args);
if (log_ctx && (log_ctx->iproprole == IPROP_MASTER))
krb5_principal search_for,
int *nentries)
{
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
krb5_error_code status;
- assert (kcontext->dal_handle != NULL); /* XXX */
-
- dal_handle = kcontext->dal_handle;
- /* XXX Locking? */
- status = dal_handle->lib_handle->vftabl.db_delete_principal(kcontext,
- search_for,
- nentries);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_delete_principal(kcontext, search_for, nentries);
get_errmsg(kcontext, status);
return status;
}
krb5_principal search_for, int *nentries)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
kdb_incr_update_t upd;
char *princ_name = NULL;
kdb_log_context *log_ctx;
log_ctx = kcontext->kdblog_context;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
status = ulog_lock(kcontext, KRB5_LOCKMODE_EXCLUSIVE);
if (status)
return status;
free(princ_name);
}
- status = dal_handle->lib_handle->vftabl.db_delete_principal(kcontext,
- search_for,
- nentries);
+ status = v->db_delete_principal(kcontext, search_for, nentries);
get_errmsg(kcontext, status);
/*
ulog_lock(kcontext, KRB5_LOCKMODE_UNLOCK);
- clean_n_exit:
return status;
}
krb5_pointer func_arg)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.db_iterate(kcontext,
- match_entry,
- func, func_arg);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_iterate(kcontext, match_entry, func, func_arg);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
krb5_supported_realms(krb5_context kcontext, char **realms)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.db_supported_realms(kcontext, realms);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_supported_realms(kcontext, realms);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
krb5_free_supported_realms(krb5_context kcontext, char **realms)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
-
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
+ kdb_vftabl *v;
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.db_free_supported_realms(kcontext,
- realms);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_free_supported_realms(kcontext, realms);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
char *pwd, krb5_keyblock * key)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.set_master_key(kcontext, pwd, key);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->set_master_key(kcontext, pwd, key);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
krb5_keylist_node * keylist)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
-
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
+ kdb_vftabl *v;
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.set_master_key_list(kcontext, keylist);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->set_master_key_list(kcontext, keylist);
get_errmsg(kcontext, status);
-
-clean_n_exit:
return status;
}
krb5_db_get_mkey(krb5_context kcontext, krb5_keyblock ** key)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- /* Let's use temp key and copy it later to avoid memory problems
- when freed by the caller. */
- status = dal_handle->lib_handle->vftabl.get_master_key(kcontext, key);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->get_master_key(kcontext, key);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
krb5_db_get_mkey_list(krb5_context kcontext, krb5_keylist_node ** keylist)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- /* Let's use temp key and copy it later to avoid memory problems
- when freed by the caller. */
- status = dal_handle->lib_handle->vftabl.get_master_key_list(kcontext, keylist);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->get_master_key_list(kcontext, keylist);
get_errmsg(kcontext, status);
-
-clean_n_exit:
return status;
}
krb5_kvno mkvno,
krb5_keylist_node **mkey_list)
{
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
krb5_error_code status = 0;
- if (context->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(context);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = context->dal_handle;
- status = dal_handle->lib_handle->vftabl.fetch_master_key_list(context,
- mname,
- mkey,
- mkvno,
- mkey_list);
+ status = get_vftabl(context, &v);
+ if (status)
+ return status;
+ status = v->fetch_master_key_list(context, mname, mkey, mkvno, mkey_list);
get_errmsg(context, status);
-
- if (status) {
- goto clean_n_exit;
- }
-
-clean_n_exit:
return status;
}
krb5_keyblock * key, char *master_pwd)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
-
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
+ kdb_vftabl *v;
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.store_master_key(kcontext,
- keyfile,
- mname,
- kvno,
- key, master_pwd);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->store_master_key(kcontext, keyfile, mname, kvno, key,
+ master_pwd);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
char *master_pwd)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.store_master_key_list(kcontext,
- keyfile,
- mname,
- keylist,
- master_pwd);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->store_master_key_list(kcontext, keyfile, mname, keylist,
+ master_pwd);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
zap(password, sizeof(password)); /* erase it */
} else {
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
if (context->dal_handle == NULL) {
retval = krb5_db_setup_lib_handle(context);
- if (retval) {
+ if (retval)
goto clean_n_exit;
- }
}
- dal_handle = context->dal_handle;
-
/* get the enctype from the stash */
tmp_key.enctype = ENCTYPE_UNKNOWN;
- retval = dal_handle->lib_handle->vftabl.fetch_master_key(context,
- mname,
- &tmp_key,
- kvno,
- db_args);
+ v = &context->dal_handle->lib_handle->vftabl;
+ retval = v->fetch_master_key(context, mname, &tmp_key, kvno, db_args);
get_errmsg(context, retval);
- if (retval) {
+ if (retval)
goto clean_n_exit;
- }
key->contents = malloc(tmp_key.length);
if (key->contents == NULL) {
memcpy(key->contents, tmp_key.contents, tmp_key.length);
}
- clean_n_exit:
+clean_n_exit:
if (tmp_key.contents) {
zap(tmp_key.contents, tmp_key.length);
krb5_db_free(context, tmp_key.contents);
krb5_keyblock * mkey)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.verify_master_key(kcontext,
- mprinc,
- kvno,
- mkey);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->verify_master_key(kcontext, mprinc, kvno, mkey);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
* The end of the list was encountered and all entries are < now so use
* the latest entry.
*/
- if (prev_actkvno->act_time <= now) {
+ if (prev_actkvno->act_time <= now)
tmp_act_kvno = prev_actkvno->act_kvno;
- } else {
- /* XXX this shouldn't happen */
- return (KRB5_KDB_NOACTMASTERKEY);
- }
+ else
+ return KRB5_KDB_NOACTMASTERKEY; /* This shouldn't happen. */
+
}
while (cur_keyblock && cur_keyblock->kvno != tmp_act_kvno)
*act_kvno = tmp_act_kvno;
return (0);
} else {
- return (KRB5_KDB_NO_MATCHING_KEY);
+ return KRB5_KDB_NO_MATCHING_KEY;
}
}
*mkey = &cur_keyblock->keyblock;
return (0);
} else {
- return (KRB5_KDB_NO_MATCHING_KEY);
+ return KRB5_KDB_NO_MATCHING_KEY;
}
}
krb5_db_alloc(krb5_context kcontext, void *ptr, size_t size)
{
krb5_error_code status;
- kdb5_dal_handle *dal_handle;
- void *new_ptr = NULL;
-
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
-
- new_ptr = dal_handle->lib_handle->vftabl.db_alloc(kcontext, ptr, size);
+ kdb_vftabl *v;
- clean_n_exit:
- return new_ptr;
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return NULL;
+ return v->db_alloc(kcontext, ptr, size);
}
void
krb5_db_free(krb5_context kcontext, void *ptr)
{
krb5_error_code status;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
-
- dal_handle->lib_handle->vftabl.db_free(kcontext, ptr);
-
- clean_n_exit:
- return;
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return;
+ v->db_free(kcontext, ptr);
}
/* has to be modified */
krb5_int32 kvno, krb5_key_data ** kdatap)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
-
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
+ kdb_vftabl *v;
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.dbe_search_enctype(kcontext,
- dbentp,
- start,
- ktype,
- stype,
- kvno, kdatap);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->dbe_search_enctype(kcontext, dbentp, start, ktype, stype,
+ kvno, kdatap);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
}
tl_data.tl_data_contents = (krb5_octet *) malloc(tl_data.tl_data_length);
- if (tl_data.tl_data_contents == NULL) {
+ if (tl_data.tl_data_contents == NULL)
return (ENOMEM);
- }
nextloc = tl_data.tl_data_contents;
version = KRB5_TL_MKEY_AUX_VER;
const krb5_actkvno_node *cur_actkvno;
krb5_octet *tmpptr;
- if (actkvno_list == NULL) {
- return (EINVAL);
- }
+ if (actkvno_list == NULL)
+ return EINVAL;
memset(&new_tl_data, 0, sizeof(new_tl_data));
/* allocate initial KRB5_TL_ACTKVNO tl_data entry */
new_tl_data.tl_data_length = sizeof(version);
new_tl_data.tl_data_contents = (krb5_octet *) malloc(new_tl_data.tl_data_length);
if (new_tl_data.tl_data_contents == NULL)
- return (ENOMEM);
+ return ENOMEM;
/* add the current version # for the data format used for KRB5_TL_ACTKVNO */
version = KRB5_TL_ACTKVNO_VER;
tmpptr = realloc(new_tl_data.tl_data_contents, new_tl_data.tl_data_length);
if (tmpptr == NULL) {
free(new_tl_data.tl_data_contents);
- return (ENOMEM);
+ return ENOMEM;
} else {
new_tl_data.tl_data_contents = tmpptr;
}
/* If necessary, chain a new record in the beginning and point at it. */
if (!tl_data) {
- if ((tl_data =
- (krb5_tl_data *) krb5_db_alloc(context, NULL,
- sizeof(krb5_tl_data)))
- == NULL) {
+ tl_data = krb5_db_alloc(context, NULL, sizeof(krb5_tl_data));
+ if (tl_data == NULL) {
free(tmp);
return (ENOMEM);
}
int new_kvno, krb5_boolean keepold, krb5_db_entry * db_entry)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.db_change_pwd(kcontext,
- master_key,
- ks_tuple,
- ks_tuple_count,
- passwd,
- new_kvno,
- keepold, db_entry);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_change_pwd(kcontext, master_key, ks_tuple, ks_tuple_count,
+ passwd, new_kvno, keepold, db_entry);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
krb5_db_create_policy(krb5_context kcontext, osa_policy_ent_t policy)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.db_create_policy(kcontext, policy);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_create_policy(kcontext, policy);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
osa_policy_ent_t * policy, int *cnt)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.db_get_policy(kcontext, name, policy,
- cnt);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_get_policy(kcontext, name, policy, cnt);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
krb5_db_put_policy(krb5_context kcontext, osa_policy_ent_t policy)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
-
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
+ kdb_vftabl *v;
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.db_put_policy(kcontext, policy);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_put_policy(kcontext, policy);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
osa_adb_iter_policy_func func, void *data)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.db_iter_policy(kcontext, match_entry,
- func, data);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_iter_policy(kcontext, match_entry, func, data);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
krb5_db_delete_policy(krb5_context kcontext, char *policy)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
-
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
+ kdb_vftabl *v;
- dal_handle = kcontext->dal_handle;
- status = dal_handle->lib_handle->vftabl.db_delete_policy(kcontext, policy);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ status = v->db_delete_policy(kcontext, policy);
get_errmsg(kcontext, status);
-
- clean_n_exit:
return status;
}
krb5_db_free_policy(krb5_context kcontext, osa_policy_ent_t policy)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- dal_handle->lib_handle->vftabl.db_free_policy(kcontext, policy);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return;
+ v->db_free_policy(kcontext, policy);
get_errmsg(kcontext, status);
-
- clean_n_exit:
- return;
}
krb5_error_code
{
krb5_error_code status = 0;
char *section = NULL;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
section = kdb_get_conf_section(kcontext);
if (section == NULL) {
goto clean_n_exit;
}
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.promote_db(kcontext, section, db_args);
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ goto clean_n_exit;
+ status = v->promote_db(kcontext, section, db_args);
get_errmsg(kcontext, status);
- clean_n_exit:
- if (section)
- free(section);
+clean_n_exit:
+ free(section);
return status;
}
krb5_keysalt * keysalt)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
-
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.dbekd_decrypt_key_data(kcontext,
- mkey, key_data, dbkey, keysalt);
+ kdb_vftabl *v;
- clean_n_exit:
- return status;
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ return v->dbekd_decrypt_key_data(kcontext, mkey, key_data, dbkey, keysalt);
}
krb5_error_code
krb5_key_data * key_data)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
-
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
+ kdb_vftabl *v;
- dal_handle = kcontext->dal_handle;
- status =
- dal_handle->lib_handle->vftabl.dbekd_encrypt_key_data(kcontext,
- mkey, dbkey, keysalt, keyver, key_data);
-
- clean_n_exit:
- return status;
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ return v->dbekd_encrypt_key_data(kcontext, mkey, dbkey, keysalt, keyver,
+ key_data);
}
krb5_error_code
krb5_db_get_context(krb5_context context, void **db_context)
{
*db_context = KRB5_DB_GET_DB_CONTEXT(context);
- if (*db_context == NULL) {
+ if (*db_context == NULL)
return KRB5_KDB_DBNOTINITED;
- }
-
return 0;
}
krb5_data *rep)
{
krb5_error_code status = 0;
- kdb5_dal_handle *dal_handle;
+ kdb_vftabl *v;
- if (kcontext->dal_handle == NULL) {
- status = krb5_db_setup_lib_handle(kcontext);
- if (status) {
- goto clean_n_exit;
- }
- }
-
- dal_handle = kcontext->dal_handle;
- if (dal_handle->lib_handle->vftabl.db_invoke == NULL) {
- status = KRB5_KDB_DBTYPE_NOSUP;
- goto clean_n_exit;
- }
-
- status =
- dal_handle->lib_handle->vftabl.db_invoke(kcontext,
- method,
- req,
- rep);
-
- clean_n_exit:
- return status;
+ status = get_vftabl(kcontext, &v);
+ if (status)
+ return status;
+ if (v->db_invoke == NULL)
+ return KRB5_KDB_DBTYPE_NOSUP;
+ return v->db_invoke(kcontext, method, req, rep);
}
-