]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Simplify EFTYPE checking in db2 KDB module
authorGreg Hudson <ghudson@mit.edu>
Mon, 28 Mar 2016 17:29:26 +0000 (13:29 -0400)
committerGreg Hudson <ghudson@mit.edu>
Fri, 29 Apr 2016 23:05:10 +0000 (19:05 -0400)
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().

ticket: 8378

src/plugins/kdb/db2/adb_openclose.c
src/plugins/kdb/db2/kdb_db2.c
src/plugins/kdb/db2/policy_db.h

index 9bad905055d33ab77816790730f863d5642c0516..d9d4cee3ec6937f6695ddf62fb3c8d76f823cf99 100644 (file)
@@ -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;
index 1b7bc16f5d9a025595a9e9ad76b17397718e43d8..2e27aac4110b5acac232f74bf6faaecb2b7dc002 100644 (file)
@@ -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. */
index 87429b94d415330660fa3b03cbee3d865ffcd9d9..62d11464c9d2db0439d1215deefeed617169164f 100644 (file)
 #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