]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Correctly get default realm in kdb5.c
authorGreg Hudson <ghudson@mit.edu>
Mon, 10 Feb 2014 20:26:34 +0000 (15:26 -0500)
committerGreg Hudson <ghudson@mit.edu>
Wed, 12 Feb 2014 01:06:16 +0000 (20:06 -0500)
Call krb5_get_default_realm instead of directly accessing
context->default_realm, to remove the requirement that
krb5_get_default_realm or krb5_set_default_realm be used before
krb5_db_open.

src/lib/kdb/kdb5.c
src/tests/kdbtest.c

index ca2040d3bc9c70a10d3651bd0191d73afcae4bb9..0af6a75f2fb9e876b6e68fd4eb20a0039094f216 100644 (file)
@@ -212,12 +212,12 @@ static krb5_error_code
 get_conf_section(krb5_context context, char **section)
 {
     krb5_error_code status;
-    char *result = NULL;
-    char *value = NULL;
+    char *result = NULL, *value = NULL, *defrealm;
 
     *section = NULL;
 
-    if (context->default_realm == NULL) {
+    status = krb5_get_default_realm(context, &defrealm);
+    if (status) {
         krb5_set_error_message(context, KRB5_KDB_SERVER_INTERNAL_ERR,
                                _("No default realm set; cannot initialize "
                                  "KDB"));
@@ -226,12 +226,13 @@ get_conf_section(krb5_context context, char **section)
     status = profile_get_string(context->profile,
                                 /* realms */
                                 KDB_REALM_SECTION,
-                                context->default_realm,
+                                defrealm,
                                 /* under the realm name, database_module */
                                 KDB_MODULE_POINTER,
                                 /* default value is the realm name itself */
-                                context->default_realm,
+                                defrealm,
                                 &value);
+    krb5_free_default_realm(context, defrealm);
     if (status)
         return status;
     result = strdup(value);
@@ -246,18 +247,19 @@ static char *
 kdb_get_library_name(krb5_context kcontext)
 {
     krb5_error_code status = 0;
-    char   *result = NULL;
-    char   *value = NULL;
-    char   *lib = NULL;
+    char *result = NULL, *value = NULL, *lib = NULL, *defrealm = NULL;
 
+    status = krb5_get_default_realm(kcontext, &defrealm);
+    if (status)
+        goto clean_n_exit;
     status = profile_get_string(kcontext->profile,
                                 /* realms */
                                 KDB_REALM_SECTION,
-                                kcontext->default_realm,
+                                defrealm,
                                 /* under the realm name, database_module */
                                 KDB_MODULE_POINTER,
                                 /* default value is the realm name itself */
-                                kcontext->default_realm,
+                                defrealm,
                                 &value);
     if (status)
         goto clean_n_exit;
@@ -276,6 +278,7 @@ kdb_get_library_name(krb5_context kcontext)
 
     result = strdup(lib);
 clean_n_exit:
+    krb5_free_default_realm(kcontext, defrealm);
     profile_release_string(value);
     profile_release_string(lib);
     return result;
index 93de07be87509b10320034a8d398f9bd9d2b5d94..64f28bbca18fb85c08f106446720e8b675555cf4 100644 (file)
@@ -276,14 +276,10 @@ main()
     osa_policy_ent_t pol;
     krb5_pa_data **e_data;
     const char *status;
-    char *defrealm;
     int count;
 
     CHECK(krb5_init_context_profile(NULL, KRB5_INIT_CONTEXT_KDC, &ctx));
 
-    /* Currently necessary for krb5_db_open to work. */
-    CHECK(krb5_get_default_realm(ctx, &defrealm));
-
     /* If we can, revert to requiring all entries match sample_princ in
      * iter_princ_handler */
     CHECK_COND(krb5_db_inited(ctx) != 0);
@@ -401,7 +397,6 @@ main()
     /* It might be nice to exercise krb5_db_destroy here, but the LDAP module
      * doesn't support it. */
 
-    krb5_free_default_realm(ctx, defrealm);
     krb5_free_context(ctx);
     return 0;
 }