krb5 commit [krb5-1.14]: Simplify EFTYPE checking in db2 KDB module

Tom Yu tlyu at mit.edu
Wed Jul 6 14:23:03 EDT 2016


https://github.com/krb5/krb5/commit/0b7c9417ab0f95b380dba3fd53432b68f4daf737
commit 0b7c9417ab0f95b380dba3fd53432b68f4daf737
Author: Greg Hudson <ghudson at mit.edu>
Date:   Mon Mar 28 13:29:26 2016 -0400

    Simplify EFTYPE checking in db2 KDB module
    
    Create a new macro IS_EFTYPE in policy_db.h, and use it to avoid
    preprocessor conditionals in open_db() and osa_adb_open_and_lock().
    
    (cherry picked from commit b572a01b6295fd816a5785a4cd0f5243a360caba)
    
    ticket: 8378
    version_fixed: 1.14.3

 src/plugins/kdb/db2/adb_openclose.c |    8 ++------
 src/plugins/kdb/db2/kdb_db2.c       |    7 +------
 src/plugins/kdb/db2/policy_db.h     |    8 ++++++++
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/plugins/kdb/db2/adb_openclose.c b/src/plugins/kdb/db2/adb_openclose.c
index 9bad905..d9d4cee 100644
--- a/src/plugins/kdb/db2/adb_openclose.c
+++ b/src/plugins/kdb/db2/adb_openclose.c
@@ -324,15 +324,11 @@ osa_adb_open_and_lock(osa_adb_princ_t db, int locktype)
     db->db = dbopen(db->filename, O_RDWR, 0600, DB_BTREE, &db->btinfo);
     if (db->db != NULL)
         goto open_ok;
-    switch (errno) {
-#ifdef EFTYPE
-    case EFTYPE:
-#endif
-    case EINVAL:
+    if (IS_EFTYPE(errno)) {
         db->db = dbopen(db->filename, O_RDWR, 0600, DB_HASH, &db->info);
         if (db->db != NULL)
             goto open_ok;
-    default:
+    } else {
         (void) osa_adb_release_lock(db);
         if (errno == EINVAL)
             return OSA_ADB_BAD_DB;
diff --git a/src/plugins/kdb/db2/kdb_db2.c b/src/plugins/kdb/db2/kdb_db2.c
index 1b7bc16..2e27aac 100644
--- a/src/plugins/kdb/db2/kdb_db2.c
+++ b/src/plugins/kdb/db2/kdb_db2.c
@@ -372,18 +372,13 @@ open_db(krb5_db2_context *dbc, int flags, int mode)
         goto done;
 
     /* If that was wrong, retry with the other type. */
-    switch (errno) {
-#ifdef EFTYPE
-    case EFTYPE:
-#endif
-    case EINVAL:
+    if (IS_EFTYPE(errno)) {
         db = dbopen(fname, flags, mode,
                     dbc->hashfirst ? DB_BTREE : DB_HASH,
                     dbc->hashfirst ? (void *) &bti : (void *) &hashi);
         /* If that worked, update our guess for next time. */
         if (db != NULL)
             dbc->hashfirst = !dbc->hashfirst;
-        break;
     }
 
     /* Don't try unlocked iteration with a hash database. */
diff --git a/src/plugins/kdb/db2/policy_db.h b/src/plugins/kdb/db2/policy_db.h
index 87429b9..62d1146 100644
--- a/src/plugins/kdb/db2/policy_db.h
+++ b/src/plugins/kdb/db2/policy_db.h
@@ -34,6 +34,14 @@
 #include "adb_err.h"
 #include <com_err.h>
 
+/* DB2 uses EFTYPE to indicate a database file of the wrong format, and falls
+ * back to EINVAL if the platform does not define EFTYPE. */
+#ifdef EFTYPE
+#define IS_EFTYPE(e) ((e) == EFTYPE || (e) == EINVAL)
+#else
+#define IS_EFTYPE(e) ((e) == EINVAL)
+#endif
+
 typedef long            osa_adb_ret_t;
 
 #define OSA_ADB_POLICY_DB_MAGIC 0x12345A00


More information about the cvs-krb5 mailing list