2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 #pragma ident "%Z%%M% %I% %E% SMI"
8 * Copyright 2006 by the Massachusetts Institute of Technology.
11 * Export of this software from the United States of America may
12 * require a specific license from the United States Government.
13 * It is the responsibility of any person or organization contemplating
14 * export to obtain such a license before exporting.
16 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
17 * distribute this software and its documentation for any purpose and
18 * without fee is hereby granted, provided that the above copyright
19 * notice appear in all copies and that both that copyright notice and
20 * this permission notice appear in supporting documentation, and that
21 * the name of M.I.T. not be used in advertising or publicity pertaining
22 * to distribution of the software without specific, written prior
23 * permission. Furthermore if you modify this software you must label
24 * your software as modified software and not distribute it in such a
25 * fashion that it might be confused with the original M.I.T. software.
26 * M.I.T. makes no representations about the suitability of
27 * this software for any purpose. It is provided "as is" without express
28 * or implied warranty.
32 * This code was based on code donated to MIT by Novell for
33 * distribution under the MIT license.
46 #include "k5-platform.h"
49 /* Currently DB2 policy related errors are exported from DAL. But
50 other databases should set_err function to return string. */
56 #define KRB5_TL_DB_ARGS 0x7fff
59 * internal static variable
62 static k5_mutex_t db_lock
= K5_MUTEX_PARTIAL_INITIALIZER
;
64 #ifdef _KDB5_STATIC_LINK
65 #undef _KDB5_DYNAMIC_LINK
67 #undef _KDB5_DYNAMIC_LINK
68 /* to avoid redefinition problem */
69 #define _KDB5_DYNAMIC_LINK
72 static db_library lib_list
;
78 MAKE_INIT_FUNCTION(kdb_init_lock_list
);
79 MAKE_FINI_FUNCTION(kdb_fini_lock_list
);
82 kdb_init_lock_list(void)
84 return k5_mutex_finish_init(&db_lock
);
91 err
= CALL_INIT_FUNCTION (kdb_init_lock_list
);
94 return k5_mutex_lock(&db_lock
);
98 kdb_fini_lock_list(void)
100 if (INITIALIZER_RAN(kdb_init_lock_list
))
101 k5_mutex_destroy(&db_lock
);
107 return k5_mutex_unlock(&db_lock
);
110 #define kdb_init_lib_lock(a) 0
111 #define kdb_destroy_lib_lock(a) (void)0
112 #define kdb_lock_lib_lock(a, b) 0
113 #define kdb_unlock_lib_lock(a, b) (void)0
115 /* Caller must free result*/
118 kdb_get_conf_section(krb5_context kcontext
)
120 krb5_error_code status
= 0;
124 if (kcontext
->default_realm
== NULL
)
126 /* The profile has to have been initialized. If the profile was
127 not initialized, expect nothing less than a crash. */
128 status
= profile_get_string(kcontext
->profile
,
131 kcontext
->default_realm
,
132 /* under the realm name, database_module */
134 /* default value is the realm name itself */
135 kcontext
->default_realm
,
140 result
= strdup(kcontext
->default_realm
);
141 /* let NULL be handled by the caller */
143 result
= strdup(value
);
144 /* free profile string */
145 profile_release_string(value
);
152 kdb_get_library_name(krb5_context kcontext
)
154 krb5_error_code status
= 0;
159 status
= profile_get_string(kcontext
->profile
,
162 kcontext
->default_realm
,
163 /* under the realm name, database_module */
165 /* default value is the realm name itself */
166 kcontext
->default_realm
,
172 #define DB2_NAME "db2"
173 /* we got the module section. Get the library name from the module */
174 status
= profile_get_string(kcontext
->profile
, KDB_MODULE_SECTION
, value
,
184 result
= strdup(lib
);
187 /* free profile string */
188 profile_release_string(value
);
192 /* free profile string */
193 profile_release_string(lib
);
199 kdb_setup_opt_functions(db_library lib
)
201 if (lib
->vftabl
.set_master_key
== NULL
) {
202 lib
->vftabl
.set_master_key
= kdb_def_set_mkey
;
205 if (lib
->vftabl
.get_master_key
== NULL
) {
206 lib
->vftabl
.get_master_key
= kdb_def_get_mkey
;
209 if (lib
->vftabl
.fetch_master_key
== NULL
) {
210 lib
->vftabl
.fetch_master_key
= krb5_db_def_fetch_mkey
;
213 if (lib
->vftabl
.verify_master_key
== NULL
) {
214 lib
->vftabl
.verify_master_key
= krb5_def_verify_master_key
;
217 if (lib
->vftabl
.dbe_search_enctype
== NULL
) {
218 lib
->vftabl
.dbe_search_enctype
= krb5_dbe_def_search_enctype
;
221 if (lib
->vftabl
.db_change_pwd
== NULL
) {
222 lib
->vftabl
.db_change_pwd
= krb5_dbe_def_cpw
;
225 if (lib
->vftabl
.store_master_key
== NULL
) {
226 lib
->vftabl
.store_master_key
= krb5_def_store_mkey
;
229 if (lib
->vftabl
.promote_db
== NULL
) {
230 lib
->vftabl
.promote_db
= krb5_def_promote_db
;
234 static int kdb_db2_pol_err_loaded
= 0;
235 #ifdef _KDB5_STATIC_LINK
236 #define DEF_SYMBOL(a) extern kdb_vftabl krb5_db_vftabl_ ## a
237 #define GET_SYMBOL(a) (krb5_db_vftabl_ ## a)
238 static krb5_error_code
239 kdb_load_library(krb5_context kcontext
, char *lib_name
, db_library
* lib
)
241 krb5_error_code status
;
242 void *vftabl_addr
= NULL
;
243 char buf
[KRB5_MAX_ERR_STR
];
245 if (!strcmp("kdb_db2", lib_name
) && (kdb_db2_pol_err_loaded
== 0)) {
246 initialize_adb_error_table();
247 kdb_db2_pol_err_loaded
= 1;
250 *lib
= calloc((size_t) 1, sizeof(**lib
));
256 status
= kdb_init_lib_lock(*lib
);
261 strcpy((*lib
)->name
, lib_name
);
263 #if !defined(KDB5_USE_LIB_KDB_DB2) && !defined(KDB5_USE_LIB_TEST)
264 #error No database module defined
267 #ifdef KDB5_USE_LIB_KDB_DB2
268 if (strcmp(lib_name
, "kdb_db2") == 0) {
270 vftabl_addr
= (void *) &GET_SYMBOL(kdb_db2
);
273 #ifdef KDB5_USE_LIB_TEST
274 if (strcmp(lib_name
, "test") == 0) {
276 vftabl_addr
= (void *) &GET_SYMBOL(test
);
280 snprintf(buf
, sizeof(buf
), gettext("Program not built to support %s database type\n"),
282 status
= KRB5_KDB_DBTYPE_NOSUP
;
283 krb5_db_set_err(kcontext
, krb5_err_have_str
, status
, buf
);
287 memcpy(&(*lib
)->vftabl
, vftabl_addr
, sizeof(kdb_vftabl
));
289 kdb_setup_opt_functions(*lib
);
291 if ((status
= (*lib
)->vftabl
.init_library())) {
292 /* ERROR. library not initialized cleanly */
293 snprintf(buf
, sizeof(buf
), gettext("%s library initialization failed, error code %ld\n"),
295 status
= KRB5_KDB_DBTYPE_INIT
;
296 krb5_db_set_err(kcontext
, krb5_err_have_str
, status
, buf
);
302 free(*lib
), *lib
= NULL
;
307 #else /* KDB5_STATIC_LINK*/
309 static char *db_dl_location
[] = DEFAULT_KDB_LIB_PATH
;
310 #define db_dl_n_locations (sizeof(db_dl_location) / sizeof(db_dl_location[0]))
312 static krb5_error_code
313 kdb_load_library(krb5_context kcontext
, char *lib_name
, db_library
* lib
)
315 krb5_error_code status
= 0;
317 void **vftabl_addrs
= NULL
;
318 /* N.B.: If this is "const" but not "static", the Solaris 10
319 native compiler has trouble building the library because of
320 absolute relocations needed in read-only section ".rodata".
321 When it's static, it goes into ".picdata", which is
323 static const char *const dbpath_names
[] = {
324 KDB_MODULE_SECTION
, "db_module_dir", NULL
,
326 const char *filebases
[2];
327 char **profpath
= NULL
;
330 filebases
[0] = lib_name
;
333 if (!strcmp(DB2_NAME
, lib_name
) && (kdb_db2_pol_err_loaded
== 0)) {
334 initialize_adb_error_table();
335 kdb_db2_pol_err_loaded
= 1;
338 *lib
= calloc((size_t) 1, sizeof(**lib
));
344 status
= kdb_init_lib_lock(*lib
);
349 strcpy((*lib
)->name
, lib_name
);
351 /* Fetch the list of directories specified in the config
353 status
= profile_get_values(kcontext
->profile
, dbpath_names
, &profpath
);
354 if (status
!= 0 && status
!= PROF_NO_RELATION
)
358 while (profpath
[ndx
] != NULL
)
361 path
= calloc(ndx
+ db_dl_n_locations
, sizeof (char *));
367 memcpy(path
, profpath
, ndx
* sizeof(profpath
[0]));
368 memcpy(path
+ ndx
, db_dl_location
, db_dl_n_locations
* sizeof(char *));
371 if ((status
= krb5int_open_plugin_dirs ((const char **) path
,
373 &(*lib
)->dl_dir_handle
, &kcontext
->err
))) {
374 const char *err_str
= krb5_get_error_message(kcontext
, status
);
375 status
= KRB5_KDB_DBTYPE_NOTFOUND
;
376 krb5_set_error_message (kcontext
, status
,
377 gettext("Unable to find requested database type: %s"), err_str
);
378 krb5_free_error_message (kcontext
, err_str
);
382 if ((status
= krb5int_get_plugin_dir_data (&(*lib
)->dl_dir_handle
, "kdb_function_table",
383 &vftabl_addrs
, &kcontext
->err
))) {
384 const char *err_str
= krb5_get_error_message(kcontext
, status
);
385 status
= KRB5_KDB_DBTYPE_INIT
;
386 krb5_set_error_message (kcontext
, status
,
387 gettext("plugin symbol 'kdb_function_table' lookup failed: %s"), err_str
);
388 krb5_free_error_message (kcontext
, err_str
);
392 if (vftabl_addrs
[0] == NULL
) {
394 status
= KRB5_KDB_DBTYPE_NOTFOUND
;
395 krb5_set_error_message (kcontext
, status
,
396 gettext("Unable to load requested database module '%s': plugin symbol 'kdb_function_table' not found"),
401 memcpy(&(*lib
)->vftabl
, vftabl_addrs
[0], sizeof(kdb_vftabl
));
402 kdb_setup_opt_functions(*lib
);
404 if ((status
= (*lib
)->vftabl
.init_library())) {
405 /* ERROR. library not initialized cleanly */
410 if (vftabl_addrs
!= NULL
) { krb5int_free_plugin_dir_data (vftabl_addrs
); }
411 /* Both of these DTRT with NULL. */
412 profile_free_list(profpath
);
416 kdb_destroy_lib_lock(*lib
);
417 if (PLUGIN_DIR_OPEN((&(*lib
)->dl_dir_handle
))) {
418 krb5int_close_plugin_dirs (&(*lib
)->dl_dir_handle
);
427 #endif /* end of _KDB5_STATIC_LINK */
429 static krb5_error_code
430 kdb_find_library(krb5_context kcontext
, char *lib_name
, db_library
* lib
)
432 /* lock here so that no two threads try to do the same at the same time */
433 krb5_error_code status
= 0;
435 db_library curr_elt
, prev_elt
= NULL
;
437 if ((status
= kdb_lock_list()) != 0) {
443 while (curr_elt
!= NULL
) {
444 if (strcmp(lib_name
, curr_elt
->name
) == 0) {
449 curr_elt
= curr_elt
->next
;
452 /* module not found. create and add to list */
453 status
= kdb_load_library(kcontext
, lib_name
, lib
);
459 /* prev_elt points to the last element in the list */
460 prev_elt
->next
= *lib
;
461 (*lib
)->prev
= prev_elt
;
468 (*lib
)->reference_cnt
++;
472 (void)kdb_unlock_list();
478 static krb5_error_code
479 kdb_free_library(db_library lib
)
481 krb5_error_code status
= 0;
484 if ((status
= kdb_lock_list()) != 0) {
489 lib
->reference_cnt
--;
491 if (lib
->reference_cnt
== 0) {
492 status
= lib
->vftabl
.fini_library();
497 /* close the library */
498 if (PLUGIN_DIR_OPEN((&lib
->dl_dir_handle
))) {
499 krb5int_close_plugin_dirs (&lib
->dl_dir_handle
);
502 kdb_destroy_lib_lock(lib
);
504 if (lib
->prev
== NULL
) {
505 /* first element in the list */
506 lib_list
= lib
->next
;
508 lib
->prev
->next
= lib
->next
;
512 lib
->next
->prev
= lib
->prev
;
519 (void)kdb_unlock_list();
525 static krb5_error_code
526 kdb_setup_lib_handle(krb5_context kcontext
)
528 char *library
= NULL
;
529 krb5_error_code status
= 0;
530 db_library lib
= NULL
;
531 kdb5_dal_handle
*dal_handle
= NULL
;
533 dal_handle
= calloc((size_t) 1, sizeof(kdb5_dal_handle
));
534 if (dal_handle
== NULL
) {
539 library
= kdb_get_library_name(kcontext
);
540 if (library
== NULL
) {
541 status
= KRB5_KDB_DBTYPE_NOTFOUND
;
545 status
= kdb_find_library(kcontext
, library
, &lib
);
550 dal_handle
->lib_handle
= lib
;
551 kcontext
->db_context
= (void *) dal_handle
;
559 (void)kdb_free_library(lib
);
566 static krb5_error_code
567 kdb_free_lib_handle(krb5_context kcontext
)
569 krb5_error_code status
= 0;
572 kdb_free_library(((kdb5_dal_handle
*) kcontext
->db_context
)->
578 free(kcontext
->db_context
);
579 kcontext
->db_context
= NULL
;
586 get_errmsg (krb5_context kcontext
, krb5_error_code err_code
)
588 kdb5_dal_handle
*dal_handle
;
592 assert(kcontext
!= NULL
);
593 /* Must be called with dal_handle->lib_handle locked! */
594 assert(kcontext
->db_context
!= NULL
);
595 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
596 if (dal_handle
->lib_handle
->vftabl
.errcode_2_string
== NULL
)
598 e
= dal_handle
->lib_handle
->vftabl
.errcode_2_string(kcontext
, err_code
);
600 krb5_set_error_message(kcontext
, err_code
, "%s", e
);
601 if (dal_handle
->lib_handle
->vftabl
.release_errcode_string
)
602 dal_handle
->lib_handle
->vftabl
.release_errcode_string(kcontext
, e
);
606 * External functions... DAL API
609 krb5_db_open(krb5_context kcontext
, char **db_args
, int mode
)
611 krb5_error_code status
= 0;
612 char *section
= NULL
;
613 kdb5_dal_handle
*dal_handle
;
615 section
= kdb_get_conf_section(kcontext
);
616 if (section
== NULL
) {
617 status
= KRB5_KDB_SERVER_INTERNAL_ERR
;
618 krb5_set_error_message (kcontext
, status
,
619 gettext("unable to determine configuration section for realm %s\n"),
620 kcontext
->default_realm
? kcontext
->default_realm
: "[UNSET]");
624 if (kcontext
->db_context
== NULL
) {
625 status
= kdb_setup_lib_handle(kcontext
);
631 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
632 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
634 /* Solaris Kerberos */
635 kdb_free_lib_handle(kcontext
);
640 dal_handle
->lib_handle
->vftabl
.init_module(kcontext
, section
, db_args
,
642 get_errmsg(kcontext
, status
);
644 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
646 /* Solaris Kerberos */
648 kdb_free_lib_handle(kcontext
);
657 krb5_db_inited(krb5_context kcontext
)
659 return !(kcontext
&& kcontext
->db_context
&&
660 ((kdb5_dal_handle
*) kcontext
->db_context
)->db_context
);
664 krb5_db_create(krb5_context kcontext
, char **db_args
)
666 krb5_error_code status
= 0;
667 char *section
= NULL
;
668 kdb5_dal_handle
*dal_handle
;
670 section
= kdb_get_conf_section(kcontext
);
671 if (section
== NULL
) {
672 status
= KRB5_KDB_SERVER_INTERNAL_ERR
;
673 krb5_set_error_message (kcontext
, status
,
674 gettext("unable to determine configuration section for realm %s\n"),
675 kcontext
->default_realm
);
679 if (kcontext
->db_context
== NULL
) {
680 status
= kdb_setup_lib_handle(kcontext
);
686 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
687 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
693 dal_handle
->lib_handle
->vftabl
.db_create(kcontext
, section
, db_args
);
694 get_errmsg(kcontext
, status
);
696 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
705 krb5_db_fini(krb5_context kcontext
)
707 krb5_error_code status
= 0;
708 kdb5_dal_handle
*dal_handle
;
710 if (kcontext
->db_context
== NULL
) {
711 /* module not loaded. So nothing to be done */
715 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
716 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
721 status
= dal_handle
->lib_handle
->vftabl
.fini_module(kcontext
);
722 get_errmsg(kcontext
, status
);
724 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
730 status
= kdb_free_lib_handle(kcontext
);
737 krb5_db_destroy(krb5_context kcontext
, char **db_args
)
739 krb5_error_code status
= 0;
740 char *section
= NULL
;
741 kdb5_dal_handle
*dal_handle
;
743 section
= kdb_get_conf_section(kcontext
);
744 if (section
== NULL
) {
745 status
= KRB5_KDB_SERVER_INTERNAL_ERR
;
746 krb5_set_error_message (kcontext
, status
,
747 gettext("unable to determine configuration section for realm %s\n"),
748 kcontext
->default_realm
);
752 if (kcontext
->db_context
== NULL
) {
753 status
= kdb_setup_lib_handle(kcontext
);
759 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
760 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
766 dal_handle
->lib_handle
->vftabl
.db_destroy(kcontext
, section
, db_args
);
767 get_errmsg(kcontext
, status
);
768 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
777 krb5_db_get_age(krb5_context kcontext
, char *db_name
, time_t * t
)
779 krb5_error_code status
= 0;
780 kdb5_dal_handle
*dal_handle
;
782 if (kcontext
->db_context
== NULL
) {
783 status
= kdb_setup_lib_handle(kcontext
);
789 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
790 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
795 status
= dal_handle
->lib_handle
->vftabl
.db_get_age(kcontext
, db_name
, t
);
796 get_errmsg(kcontext
, status
);
797 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
804 krb5_db_set_option(krb5_context kcontext
, int option
, void *value
)
806 krb5_error_code status
= 0;
807 kdb5_dal_handle
*dal_handle
;
809 if (kcontext
->db_context
== NULL
) {
810 status
= kdb_setup_lib_handle(kcontext
);
816 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
817 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
823 dal_handle
->lib_handle
->vftabl
.db_set_option(kcontext
, option
, value
);
824 get_errmsg(kcontext
, status
);
825 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
832 krb5_db_lock(krb5_context kcontext
, int lock_mode
)
834 krb5_error_code status
= 0;
835 kdb5_dal_handle
*dal_handle
;
837 if (kcontext
->db_context
== NULL
) {
838 status
= kdb_setup_lib_handle(kcontext
);
844 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
845 /* acquire an exclusive lock, ensures no other thread uses this context */
846 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, TRUE
);
851 status
= dal_handle
->lib_handle
->vftabl
.db_lock(kcontext
, lock_mode
);
852 get_errmsg(kcontext
, status
);
854 /* exclusive lock is still held, so no other thread could use this context */
855 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
862 krb5_db_unlock(krb5_context kcontext
)
864 krb5_error_code status
= 0;
865 kdb5_dal_handle
*dal_handle
;
867 if (kcontext
->db_context
== NULL
) {
868 status
= kdb_setup_lib_handle(kcontext
);
874 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
875 /* normal lock acquired and exclusive lock released */
876 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
881 status
= dal_handle
->lib_handle
->vftabl
.db_unlock(kcontext
);
882 get_errmsg(kcontext
, status
);
884 kdb_unlock_lib_lock(dal_handle
->lib_handle
, TRUE
);
891 krb5_db_get_principal(krb5_context kcontext
,
892 krb5_const_principal search_for
,
893 krb5_db_entry
* entries
,
894 int *nentries
, krb5_boolean
* more
)
896 krb5_error_code status
= 0;
897 kdb5_dal_handle
*dal_handle
;
899 if (kcontext
->db_context
== NULL
) {
900 status
= kdb_setup_lib_handle(kcontext
);
906 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
907 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
913 dal_handle
->lib_handle
->vftabl
.db_get_principal(kcontext
, search_for
,
916 get_errmsg(kcontext
, status
);
917 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
924 krb5_db_get_principal_nolock(krb5_context kcontext
,
925 krb5_const_principal search_for
,
926 krb5_db_entry
* entries
,
927 int *nentries
, krb5_boolean
* more
)
929 krb5_error_code status
= 0;
930 kdb5_dal_handle
*dal_handle
;
932 if (kcontext
->db_context
== NULL
) {
933 status
= kdb_setup_lib_handle(kcontext
);
939 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
940 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
946 dal_handle
->lib_handle
->vftabl
.db_get_principal_nolock(kcontext
,
950 get_errmsg(kcontext
, status
);
951 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
958 krb5_db_free_principal(krb5_context kcontext
, krb5_db_entry
* entry
, int count
)
960 krb5_error_code status
= 0;
961 kdb5_dal_handle
*dal_handle
;
963 if (kcontext
->db_context
== NULL
) {
964 status
= kdb_setup_lib_handle(kcontext
);
970 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
971 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
977 dal_handle
->lib_handle
->vftabl
.db_free_principal(kcontext
, entry
,
979 get_errmsg(kcontext
, status
);
980 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
987 krb5_db_put_principal(krb5_context kcontext
,
988 krb5_db_entry
* entries
, int *nentries
)
990 krb5_error_code status
= 0;
991 kdb5_dal_handle
*dal_handle
;
992 char **db_args
= NULL
;
993 krb5_tl_data
*prev
, *curr
, *next
;
994 int db_args_size
= 0;
996 if (kcontext
->db_context
== NULL
) {
997 status
= kdb_setup_lib_handle(kcontext
);
1003 /* Giving db_args as part of tl data causes, db2 to store the
1004 tl_data as such. To prevent this, tl_data is collated and
1005 passed as a sepearte argument. Currently supports only one
1006 principal. but passing it as a seperate argument makes it
1007 difficult for kadmin remote to pass arguments to server. */
1008 prev
= NULL
, curr
= entries
->tl_data
;
1010 if (curr
->tl_data_type
== KRB5_TL_DB_ARGS
) {
1012 /* Since this is expected to be NULL terminated string and
1013 this could come from any client, do a check before
1014 passing it to db. */
1015 if (((char *) curr
->tl_data_contents
)[curr
->tl_data_length
- 1] !=
1017 /* not null terminated. Dangerous input */
1023 t
= realloc(db_args
, sizeof(char *) * (db_args_size
+ 1)); /* 1 for NULL */
1030 db_args
[db_args_size
- 1] = (char *) curr
->tl_data_contents
;
1031 db_args
[db_args_size
] = NULL
;
1033 next
= curr
->tl_data_next
;
1035 /* current node is the first in the linked list. remove it */
1036 entries
->tl_data
= curr
->tl_data_next
;
1038 prev
->tl_data_next
= curr
->tl_data_next
;
1040 entries
->n_tl_data
--;
1041 krb5_db_free(kcontext
, curr
);
1043 /* previous does not change */
1047 curr
= curr
->tl_data_next
;
1051 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1052 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1057 status
= dal_handle
->lib_handle
->vftabl
.db_put_principal(kcontext
, entries
,
1060 get_errmsg(kcontext
, status
);
1061 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1064 while (db_args_size
) {
1065 if (db_args
[db_args_size
- 1])
1066 krb5_db_free(kcontext
, db_args
[db_args_size
- 1]);
1078 krb5_db_delete_principal(krb5_context kcontext
,
1079 krb5_principal search_for
, int *nentries
)
1081 krb5_error_code status
= 0;
1082 kdb5_dal_handle
*dal_handle
;
1084 if (kcontext
->db_context
== NULL
) {
1085 status
= kdb_setup_lib_handle(kcontext
);
1091 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1092 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1098 dal_handle
->lib_handle
->vftabl
.db_delete_principal(kcontext
,
1101 get_errmsg(kcontext
, status
);
1102 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1109 krb5_db_iterate(krb5_context kcontext
,
1111 int (*func
) (krb5_pointer
, krb5_db_entry
*),
1112 krb5_pointer func_arg
,
1113 /* Solaris Kerberos: adding support for db_args */
1116 krb5_error_code status
= 0;
1117 kdb5_dal_handle
*dal_handle
;
1119 if (kcontext
->db_context
== NULL
) {
1120 status
= kdb_setup_lib_handle(kcontext
);
1126 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1127 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1132 /* Solaris Kerberos: adding support for db_args */
1133 status
= dal_handle
->lib_handle
->vftabl
.db_iterate(kcontext
,
1137 get_errmsg(kcontext
, status
);
1138 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1145 krb5_supported_realms(krb5_context kcontext
, char **realms
)
1147 krb5_error_code status
= 0;
1148 kdb5_dal_handle
*dal_handle
;
1150 if (kcontext
->db_context
== NULL
) {
1151 status
= kdb_setup_lib_handle(kcontext
);
1157 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1158 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1164 dal_handle
->lib_handle
->vftabl
.db_supported_realms(kcontext
, realms
);
1165 get_errmsg(kcontext
, status
);
1166 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1173 krb5_free_supported_realms(krb5_context kcontext
, char **realms
)
1175 krb5_error_code status
= 0;
1176 kdb5_dal_handle
*dal_handle
;
1178 if (kcontext
->db_context
== NULL
) {
1179 status
= kdb_setup_lib_handle(kcontext
);
1185 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1186 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1192 dal_handle
->lib_handle
->vftabl
.db_free_supported_realms(kcontext
,
1194 get_errmsg(kcontext
, status
);
1195 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1202 krb5_db_set_master_key_ext(krb5_context kcontext
,
1203 char *pwd
, krb5_keyblock
* key
)
1205 krb5_error_code status
= 0;
1206 kdb5_dal_handle
*dal_handle
;
1208 if (kcontext
->db_context
== NULL
) {
1209 status
= kdb_setup_lib_handle(kcontext
);
1215 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1216 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1221 status
= dal_handle
->lib_handle
->vftabl
.set_master_key(kcontext
, pwd
, key
);
1222 get_errmsg(kcontext
, status
);
1224 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1231 krb5_db_set_mkey(krb5_context context
, krb5_keyblock
* key
)
1233 return krb5_db_set_master_key_ext(context
, NULL
, key
);
1237 krb5_db_get_mkey(krb5_context kcontext
, krb5_keyblock
** key
)
1239 krb5_error_code status
= 0;
1240 kdb5_dal_handle
*dal_handle
;
1242 if (kcontext
->db_context
== NULL
) {
1243 status
= kdb_setup_lib_handle(kcontext
);
1249 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1250 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1255 /* Lets use temp key and copy it later to avoid memory problems
1256 when freed by the caller. */
1257 status
= dal_handle
->lib_handle
->vftabl
.get_master_key(kcontext
, key
);
1258 get_errmsg(kcontext
, status
);
1259 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1266 krb5_db_store_master_key(krb5_context kcontext
,
1268 krb5_principal mname
,
1269 krb5_keyblock
* key
, char *master_pwd
)
1271 krb5_error_code status
= 0;
1272 kdb5_dal_handle
*dal_handle
;
1274 if (kcontext
->db_context
== NULL
) {
1275 status
= kdb_setup_lib_handle(kcontext
);
1281 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1282 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1287 status
= dal_handle
->lib_handle
->vftabl
.store_master_key(kcontext
,
1291 get_errmsg(kcontext
, status
);
1292 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1298 char *krb5_mkey_pwd_prompt1
= KRB5_KDC_MKEY_1
;
1299 char *krb5_mkey_pwd_prompt2
= KRB5_KDC_MKEY_2
;
1302 krb5_db_fetch_mkey(krb5_context context
,
1303 krb5_principal mname
,
1305 krb5_boolean fromkeyboard
,
1307 char *db_args
, krb5_data
* salt
, krb5_keyblock
* key
)
1309 krb5_error_code retval
;
1310 char password
[BUFSIZ
];
1312 unsigned int size
= sizeof(password
);
1314 krb5_keyblock tmp_key
;
1316 memset(&tmp_key
, 0, sizeof(tmp_key
));
1321 if ((retval
= krb5_read_password(context
, krb5_mkey_pwd_prompt1
,
1322 twice
? krb5_mkey_pwd_prompt2
: 0,
1323 password
, &size
))) {
1327 pwd
.data
= password
;
1330 retval
= krb5_principal2salt(context
, mname
, &scratch
);
1335 krb5_c_string_to_key(context
, etype
, &pwd
, salt
? salt
: &scratch
,
1339 krb5_xfree(scratch
.data
);
1340 memset(password
, 0, sizeof(password
)); /* erase it */
1343 kdb5_dal_handle
*dal_handle
;
1345 if (context
->db_context
== NULL
) {
1346 retval
= kdb_setup_lib_handle(context
);
1352 dal_handle
= (kdb5_dal_handle
*) context
->db_context
;
1353 retval
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1357 #if 0 /************** Begin IFDEF'ed OUT *******************************/
1359 tmp_key
.enctype
= key
->enctype
;
1361 /* Solaris Kerberos: need to use etype */
1362 tmp_key
.enctype
= etype
;
1363 #endif /**************** END IFDEF'ed OUT *******************************/
1364 retval
= dal_handle
->lib_handle
->vftabl
.fetch_master_key(context
,
1369 get_errmsg(context
, retval
);
1370 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1376 key
->contents
= malloc(tmp_key
.length
);
1377 if (key
->contents
== NULL
) {
1382 key
->magic
= tmp_key
.magic
;
1383 key
->enctype
= tmp_key
.enctype
;
1384 key
->length
= tmp_key
.length
;
1385 memcpy(key
->contents
, tmp_key
.contents
, tmp_key
.length
);
1389 if (tmp_key
.contents
) {
1390 memset(tmp_key
.contents
, 0, tmp_key
.length
);
1391 krb5_db_free(context
, tmp_key
.contents
);
1397 krb5_db_verify_master_key(krb5_context kcontext
,
1398 krb5_principal mprinc
, krb5_keyblock
* mkey
)
1400 krb5_error_code status
= 0;
1401 kdb5_dal_handle
*dal_handle
;
1403 if (kcontext
->db_context
== NULL
) {
1404 status
= kdb_setup_lib_handle(kcontext
);
1410 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1411 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1416 status
= dal_handle
->lib_handle
->vftabl
.verify_master_key(kcontext
,
1418 get_errmsg(kcontext
, status
);
1419 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1426 krb5_db_alloc(krb5_context kcontext
, void *ptr
, size_t size
)
1428 krb5_error_code status
;
1429 kdb5_dal_handle
*dal_handle
;
1430 void *new_ptr
= NULL
;
1432 if (kcontext
->db_context
== NULL
) {
1433 status
= kdb_setup_lib_handle(kcontext
);
1439 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1441 new_ptr
= dal_handle
->lib_handle
->vftabl
.db_alloc(kcontext
, ptr
, size
);
1448 krb5_db_free(krb5_context kcontext
, void *ptr
)
1450 krb5_error_code status
;
1451 kdb5_dal_handle
*dal_handle
;
1453 if (kcontext
->db_context
== NULL
) {
1454 status
= kdb_setup_lib_handle(kcontext
);
1460 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1462 dal_handle
->lib_handle
->vftabl
.db_free(kcontext
, ptr
);
1468 /* has to be modified */
1471 krb5_dbe_find_enctype(krb5_context kcontext
,
1472 krb5_db_entry
* dbentp
,
1475 krb5_int32 kvno
, krb5_key_data
** kdatap
)
1477 krb5_int32 start
= 0;
1478 return krb5_dbe_search_enctype(kcontext
, dbentp
, &start
, ktype
, stype
,
1483 krb5_dbe_search_enctype(krb5_context kcontext
,
1484 krb5_db_entry
* dbentp
,
1488 krb5_int32 kvno
, krb5_key_data
** kdatap
)
1490 krb5_error_code status
= 0;
1491 kdb5_dal_handle
*dal_handle
;
1493 if (kcontext
->db_context
== NULL
) {
1494 status
= kdb_setup_lib_handle(kcontext
);
1500 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1501 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1506 status
= dal_handle
->lib_handle
->vftabl
.dbe_search_enctype(kcontext
,
1512 get_errmsg(kcontext
, status
);
1513 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1519 #define REALM_SEP_STRING "@"
1522 krb5_db_setup_mkey_name(krb5_context context
,
1523 const char *keyname
,
1525 char **fullname
, krb5_principal
* principal
)
1527 krb5_error_code retval
;
1529 size_t rlen
= strlen(realm
);
1533 keyname
= KRB5_KDB_M_NAME
; /* XXX external? */
1535 keylen
= strlen(keyname
);
1537 fname
= malloc(keylen
+ rlen
+ strlen(REALM_SEP_STRING
) + 1);
1541 strcpy(fname
, keyname
);
1542 (void)strcat(fname
, REALM_SEP_STRING
);
1543 (void)strcat(fname
, realm
);
1545 if ((retval
= krb5_parse_name(context
, fname
, principal
)))
1555 krb5_dbe_lookup_last_pwd_change(context
, entry
, stamp
)
1556 krb5_context context
;
1557 krb5_db_entry
*entry
;
1558 krb5_timestamp
*stamp
;
1560 krb5_tl_data tl_data
;
1561 krb5_error_code code
;
1564 tl_data
.tl_data_type
= KRB5_TL_LAST_PWD_CHANGE
;
1566 if ((code
= krb5_dbe_lookup_tl_data(context
, entry
, &tl_data
)))
1569 if (tl_data
.tl_data_length
!= 4) {
1574 krb5_kdb_decode_int32(tl_data
.tl_data_contents
, tmp
);
1576 *stamp
= (krb5_timestamp
) tmp
;
1583 krb5_dbe_lookup_tl_data(context
, entry
, ret_tl_data
)
1584 krb5_context context
;
1585 krb5_db_entry
*entry
;
1586 krb5_tl_data
*ret_tl_data
;
1588 krb5_tl_data
*tl_data
;
1590 for (tl_data
= entry
->tl_data
; tl_data
; tl_data
= tl_data
->tl_data_next
) {
1591 if (tl_data
->tl_data_type
== ret_tl_data
->tl_data_type
) {
1592 *ret_tl_data
= *tl_data
;
1597 /* if the requested record isn't found, return zero bytes.
1598 * if it ever means something to have a zero-length tl_data,
1599 * this code and its callers will have to be changed */
1601 ret_tl_data
->tl_data_length
= 0;
1602 ret_tl_data
->tl_data_contents
= NULL
;
1607 krb5_dbe_create_key_data(context
, entry
)
1608 krb5_context context
;
1609 krb5_db_entry
*entry
;
1611 if ((entry
->key_data
=
1612 (krb5_key_data
*) krb5_db_alloc(context
, entry
->key_data
,
1613 (sizeof(krb5_key_data
) *
1614 (entry
->n_key_data
+ 1)))) == NULL
)
1617 memset(entry
->key_data
+ entry
->n_key_data
, 0, sizeof(krb5_key_data
));
1618 entry
->n_key_data
++;
1624 krb5_dbe_update_mod_princ_data(context
, entry
, mod_date
, mod_princ
)
1625 krb5_context context
;
1626 krb5_db_entry
*entry
;
1627 krb5_timestamp mod_date
;
1628 krb5_const_principal mod_princ
;
1630 krb5_tl_data tl_data
;
1632 krb5_error_code retval
= 0;
1633 krb5_octet
*nextloc
= 0;
1634 char *unparse_mod_princ
= 0;
1635 unsigned int unparse_mod_princ_size
;
1637 if ((retval
= krb5_unparse_name(context
, mod_princ
, &unparse_mod_princ
)))
1640 unparse_mod_princ_size
= strlen(unparse_mod_princ
) + 1;
1642 if ((nextloc
= (krb5_octet
*) malloc(unparse_mod_princ_size
+ 4))
1644 free(unparse_mod_princ
);
1648 tl_data
.tl_data_type
= KRB5_TL_MOD_PRINC
;
1649 tl_data
.tl_data_length
= unparse_mod_princ_size
+ 4;
1650 tl_data
.tl_data_contents
= nextloc
;
1653 krb5_kdb_encode_int32(mod_date
, nextloc
);
1656 memcpy(nextloc
+ 4, unparse_mod_princ
, unparse_mod_princ_size
);
1658 retval
= krb5_dbe_update_tl_data(context
, entry
, &tl_data
);
1660 free(unparse_mod_princ
);
1667 krb5_dbe_lookup_mod_princ_data(context
, entry
, mod_time
, mod_princ
)
1668 krb5_context context
;
1669 krb5_db_entry
*entry
;
1670 krb5_timestamp
*mod_time
;
1671 krb5_principal
*mod_princ
;
1673 krb5_tl_data tl_data
;
1674 krb5_error_code code
;
1676 tl_data
.tl_data_type
= KRB5_TL_MOD_PRINC
;
1678 if ((code
= krb5_dbe_lookup_tl_data(context
, entry
, &tl_data
)))
1681 if ((tl_data
.tl_data_length
< 5) ||
1682 (tl_data
.tl_data_contents
[tl_data
.tl_data_length
- 1] != '\0'))
1683 return (KRB5_KDB_TRUNCATED_RECORD
);
1686 krb5_kdb_decode_int32(tl_data
.tl_data_contents
, *mod_time
);
1689 if ((code
= krb5_parse_name(context
,
1690 (const char *) (tl_data
.tl_data_contents
+ 4),
1698 krb5_dbe_update_last_pwd_change(context
, entry
, stamp
)
1699 krb5_context context
;
1700 krb5_db_entry
*entry
;
1701 krb5_timestamp stamp
;
1703 krb5_tl_data tl_data
;
1704 krb5_octet buf
[4]; /* this is the encoded size of an int32 */
1706 tl_data
.tl_data_type
= KRB5_TL_LAST_PWD_CHANGE
;
1707 tl_data
.tl_data_length
= sizeof(buf
);
1708 krb5_kdb_encode_int32((krb5_int32
) stamp
, buf
);
1709 tl_data
.tl_data_contents
= buf
;
1711 return (krb5_dbe_update_tl_data(context
, entry
, &tl_data
));
1715 krb5_dbe_update_tl_data(context
, entry
, new_tl_data
)
1716 krb5_context context
;
1717 krb5_db_entry
*entry
;
1718 krb5_tl_data
*new_tl_data
;
1720 krb5_tl_data
*tl_data
= NULL
;
1723 /* copy the new data first, so we can fail cleanly if malloc()
1726 (krb5_octet
*) krb5_db_alloc(context
, NULL
,
1727 new_tl_data
->tl_data_length
)) == NULL
)
1730 /* Find an existing entry of the specified type and point at
1731 * it, or NULL if not found */
1733 if (new_tl_data
->tl_data_type
!= KRB5_TL_DB_ARGS
) { /* db_args can be multiple */
1734 for (tl_data
= entry
->tl_data
; tl_data
;
1735 tl_data
= tl_data
->tl_data_next
)
1736 if (tl_data
->tl_data_type
== new_tl_data
->tl_data_type
)
1740 /* if necessary, chain a new record in the beginning and point at it */
1744 (krb5_tl_data
*) krb5_db_alloc(context
, NULL
,
1745 sizeof(krb5_tl_data
)))
1750 memset(tl_data
, 0, sizeof(krb5_tl_data
));
1751 tl_data
->tl_data_next
= entry
->tl_data
;
1752 entry
->tl_data
= tl_data
;
1756 /* fill in the record */
1758 if (tl_data
->tl_data_contents
)
1759 krb5_db_free(context
, tl_data
->tl_data_contents
);
1761 tl_data
->tl_data_type
= new_tl_data
->tl_data_type
;
1762 tl_data
->tl_data_length
= new_tl_data
->tl_data_length
;
1763 tl_data
->tl_data_contents
= tmp
;
1764 memcpy(tmp
, new_tl_data
->tl_data_contents
, tl_data
->tl_data_length
);
1769 /* change password functions */
1771 krb5_dbe_cpw(krb5_context kcontext
,
1772 krb5_keyblock
* master_key
,
1773 krb5_key_salt_tuple
* ks_tuple
,
1776 int new_kvno
, krb5_boolean keepold
, krb5_db_entry
* db_entry
)
1778 krb5_error_code status
= 0;
1779 kdb5_dal_handle
*dal_handle
;
1781 if (kcontext
->db_context
== NULL
) {
1782 status
= kdb_setup_lib_handle(kcontext
);
1788 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1789 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1794 status
= dal_handle
->lib_handle
->vftabl
.db_change_pwd(kcontext
,
1801 get_errmsg(kcontext
, status
);
1802 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1808 /* policy management functions */
1810 krb5_db_create_policy(krb5_context kcontext
, osa_policy_ent_t policy
)
1812 krb5_error_code status
= 0;
1813 kdb5_dal_handle
*dal_handle
;
1815 if (kcontext
->db_context
== NULL
) {
1816 status
= kdb_setup_lib_handle(kcontext
);
1822 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1823 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1828 status
= dal_handle
->lib_handle
->vftabl
.db_create_policy(kcontext
, policy
);
1829 get_errmsg(kcontext
, status
);
1830 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1837 krb5_db_get_policy(krb5_context kcontext
, char *name
,
1838 osa_policy_ent_t
* policy
, int *cnt
)
1840 krb5_error_code status
= 0;
1841 kdb5_dal_handle
*dal_handle
;
1843 if (kcontext
->db_context
== NULL
) {
1844 status
= kdb_setup_lib_handle(kcontext
);
1850 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1851 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1857 dal_handle
->lib_handle
->vftabl
.db_get_policy(kcontext
, name
, policy
,
1859 get_errmsg(kcontext
, status
);
1860 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1867 krb5_db_put_policy(krb5_context kcontext
, osa_policy_ent_t policy
)
1869 krb5_error_code status
= 0;
1870 kdb5_dal_handle
*dal_handle
;
1872 if (kcontext
->db_context
== NULL
) {
1873 status
= kdb_setup_lib_handle(kcontext
);
1879 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1880 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1885 status
= dal_handle
->lib_handle
->vftabl
.db_put_policy(kcontext
, policy
);
1886 get_errmsg(kcontext
, status
);
1887 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1894 krb5_db_iter_policy(krb5_context kcontext
, char *match_entry
,
1895 osa_adb_iter_policy_func func
, void *data
)
1897 krb5_error_code status
= 0;
1898 kdb5_dal_handle
*dal_handle
;
1900 if (kcontext
->db_context
== NULL
) {
1901 status
= kdb_setup_lib_handle(kcontext
);
1907 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1908 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1914 dal_handle
->lib_handle
->vftabl
.db_iter_policy(kcontext
, match_entry
,
1916 get_errmsg(kcontext
, status
);
1917 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1924 krb5_db_delete_policy(krb5_context kcontext
, char *policy
)
1926 krb5_error_code status
= 0;
1927 kdb5_dal_handle
*dal_handle
;
1929 if (kcontext
->db_context
== NULL
) {
1930 status
= kdb_setup_lib_handle(kcontext
);
1936 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1937 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1942 status
= dal_handle
->lib_handle
->vftabl
.db_delete_policy(kcontext
, policy
);
1943 get_errmsg(kcontext
, status
);
1944 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1951 krb5_db_free_policy(krb5_context kcontext
, osa_policy_ent_t policy
)
1953 krb5_error_code status
= 0;
1954 kdb5_dal_handle
*dal_handle
;
1956 if (kcontext
->db_context
== NULL
) {
1957 status
= kdb_setup_lib_handle(kcontext
);
1963 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
1964 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1969 dal_handle
->lib_handle
->vftabl
.db_free_policy(kcontext
, policy
);
1970 get_errmsg(kcontext
, status
);
1971 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
1978 krb5_db_promote(krb5_context kcontext
, char **db_args
)
1980 krb5_error_code status
= 0;
1981 char *section
= NULL
;
1982 kdb5_dal_handle
*dal_handle
;
1984 section
= kdb_get_conf_section(kcontext
);
1985 if (section
== NULL
) {
1986 status
= KRB5_KDB_SERVER_INTERNAL_ERR
;
1987 krb5_set_error_message (kcontext
, status
,
1988 gettext("unable to determine configuration section for realm %s\n"),
1989 kcontext
->default_realm
);
1993 if (kcontext
->db_context
== NULL
) {
1994 status
= kdb_setup_lib_handle(kcontext
);
2000 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
2001 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
2007 dal_handle
->lib_handle
->vftabl
.promote_db(kcontext
, section
, db_args
);
2008 get_errmsg(kcontext
, status
);
2009 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);
2018 * Solaris Kerberos: support for iprop
2020 * Not all KDB plugins support iprop.
2022 * sets iprop_supported to 1 if iprop supportd, 0 otherwise.
2025 krb5_db_supports_iprop(krb5_context kcontext
, int *iprop_supported
)
2027 krb5_error_code status
= 0;
2028 kdb5_dal_handle
*dal_handle
;
2030 if (kcontext
->db_context
== NULL
) {
2031 status
= kdb_setup_lib_handle(kcontext
);
2037 dal_handle
= (kdb5_dal_handle
*) kcontext
->db_context
;
2038 status
= kdb_lock_lib_lock(dal_handle
->lib_handle
, FALSE
);
2043 *iprop_supported
= dal_handle
->lib_handle
->vftabl
.iprop_supported
;
2044 kdb_unlock_lib_lock(dal_handle
->lib_handle
, FALSE
);