svn rev #24173: trunk/src/lib/kdb/

ghudson@MIT.EDU ghudson at MIT.EDU
Sat Jul 3 15:56:17 EDT 2010


http://src.mit.edu/fisheye/changelog/krb5/?cs=24173
Commit By: ghudson
Log Message:
In kdb5.c, simplify the code for getting the profile config section.



Changed Files:
U   trunk/src/lib/kdb/kdb5.c
Modified: trunk/src/lib/kdb/kdb5.c
===================================================================
--- trunk/src/lib/kdb/kdb5.c	2010-07-03 19:25:00 UTC (rev 24172)
+++ trunk/src/lib/kdb/kdb5.c	2010-07-03 19:56:17 UTC (rev 24173)
@@ -167,40 +167,39 @@
     }
 }
 
-/* Caller must free result*/
-
-static char *
-kdb_get_conf_section(krb5_context kcontext)
+/* Set *section to the appropriate section to use for a database module's
+ * profile queries.  The caller must free the result. */
+static krb5_error_code
+get_conf_section(krb5_context context, char **section)
 {
-    krb5_error_code status = 0;
-    char   *result = NULL;
-    char   *value = NULL;
+    krb5_error_code status;
+    char *result = NULL;
+    char *value = NULL;
 
-    if (kcontext->default_realm == NULL)
-        return NULL;
-    /* The profile has to have been initialized.  If the profile was
-       not initialized, expect nothing less than a crash.  */
-    status = profile_get_string(kcontext->profile,
+    *section = NULL;
+
+    if (context->default_realm == NULL) {
+        krb5_set_error_message(context, KRB5_KDB_SERVER_INTERNAL_ERR,
+                               "No default realm set; cannot initialize KDB");
+        return KRB5_KDB_SERVER_INTERNAL_ERR;
+    }
+    status = profile_get_string(context->profile,
                                 /* realms */
                                 KDB_REALM_SECTION,
-                                kcontext->default_realm,
+                                context->default_realm,
                                 /* under the realm name, database_module */
                                 KDB_MODULE_POINTER,
                                 /* default value is the realm name itself */
-                                kcontext->default_realm,
+                                context->default_realm,
                                 &value);
-
-    if (status) {
-        /* some problem */
-        result = strdup(kcontext->default_realm);
-        /* let NULL be handled by the caller */
-    } else {
-        result = strdup(value);
-        /* free profile string */
-        profile_release_string(value);
-    }
-
-    return result;
+    if (status)
+        return status;
+    result = strdup(value);
+    profile_release_string(value);
+    if (result == NULL)
+        return ENOMEM;
+    *section = result;
+    return 0;
 }
 
 static char *
@@ -575,27 +574,18 @@
 krb5_error_code
 krb5_db_open(krb5_context kcontext, char **db_args, int mode)
 {
-    krb5_error_code status = 0;
-    char   *section = NULL;
+    krb5_error_code status;
+    char *section;
     kdb_vftabl *v;
 
-    section = kdb_get_conf_section(kcontext);
-    if (section == NULL) {
-        status = KRB5_KDB_SERVER_INTERNAL_ERR;
-        krb5_set_error_message (kcontext, status,
-                                "unable to determine configuration section for realm %s\n",
-                                kcontext->default_realm ? kcontext->default_realm : "[UNSET]");
-        goto clean_n_exit;
-    }
-
     status = get_vftabl(kcontext, &v);
     if (status)
-        goto clean_n_exit;
+        return status;
+    status = get_conf_section(kcontext, &section);
+    if (status)
+        return status;
     status = v->init_module(kcontext, section, db_args, mode);
-
-clean_n_exit:
-    if (section)
-        free(section);
+    free(section);
     return status;
 }
 
@@ -609,31 +599,20 @@
 krb5_error_code
 krb5_db_create(krb5_context kcontext, char **db_args)
 {
-    krb5_error_code status = 0;
-    char   *section = NULL;
+    krb5_error_code status;
+    char *section;
     kdb_vftabl *v;
 
-    section = kdb_get_conf_section(kcontext);
-    if (section == NULL) {
-        status = KRB5_KDB_SERVER_INTERNAL_ERR;
-        krb5_set_error_message (kcontext, status,
-                                "unable to determine configuration section for realm %s\n",
-                                kcontext->default_realm);
-        goto clean_n_exit;
-    }
-
     status = get_vftabl(kcontext, &v);
     if (status)
-        goto clean_n_exit;
-    if (v->create == NULL) {
-        status = KRB5_PLUGIN_OP_NOTSUPP;
-        goto clean_n_exit;
-    }
+        return status;
+    if (v->create == NULL)
+        return KRB5_PLUGIN_OP_NOTSUPP;
+    status = get_conf_section(kcontext, &section);
+    if (status)
+        return status;
     status = v->create(kcontext, section, db_args);
-
-clean_n_exit:
-    if (section)
-        free(section);
+    free(section);
     return status;
 }
 
@@ -659,31 +638,20 @@
 krb5_error_code
 krb5_db_destroy(krb5_context kcontext, char **db_args)
 {
-    krb5_error_code status = 0;
-    char   *section = NULL;
+    krb5_error_code status;
+    char *section;
     kdb_vftabl *v;
 
-    section = kdb_get_conf_section(kcontext);
-    if (section == NULL) {
-        status = KRB5_KDB_SERVER_INTERNAL_ERR;
-        krb5_set_error_message (kcontext, status,
-                                "unable to determine configuration section for realm %s\n",
-                                kcontext->default_realm);
-        goto clean_n_exit;
-    }
-
     status = get_vftabl(kcontext, &v);
     if (status)
-        goto clean_n_exit;
-    if (v->destroy == NULL) {
-        status = KRB5_PLUGIN_OP_NOTSUPP;
-        goto clean_n_exit;
-    }
+        return status;
+    if (v->destroy == NULL)
+        return KRB5_PLUGIN_OP_NOTSUPP;
+    status = get_conf_section(kcontext, &section);
+    if (status)
+        return status;
     status = v->destroy(kcontext, section, db_args);
-
-clean_n_exit:
-    if (section)
-        free(section);
+    free(section);
     return status;
 }
 
@@ -2248,8 +2216,8 @@
 krb5_error_code
 krb5_db_promote(krb5_context kcontext, char **db_args)
 {
-    krb5_error_code status = 0;
-    char *section = NULL;
+    krb5_error_code status;
+    char *section;
     kdb_vftabl *v;
 
     status = get_vftabl(kcontext, &v);
@@ -2257,16 +2225,9 @@
         return status;
     if (v->promote_db == NULL)
         return KRB5_PLUGIN_OP_NOTSUPP;
-
-    section = kdb_get_conf_section(kcontext);
-    if (section == NULL) {
-        status = KRB5_KDB_SERVER_INTERNAL_ERR;
-        krb5_set_error_message(kcontext, status, "Unable to determine "
-                               "configuration section for realm %s\n",
-                               kcontext->default_realm);
+    status = get_conf_section(kcontext, &section);
+    if (status)
         return status;
-    }
-
     status = v->promote_db(kcontext, section, db_args);
     free(section);
     return status;




More information about the cvs-krb5 mailing list