From: Greg Hudson Date: Mon, 28 Mar 2016 17:29:26 +0000 (-0400) Subject: Simplify EFTYPE checking in db2 KDB module X-Git-Tag: krb5-1.15-beta1~206 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b572a01b6295fd816a5785a4cd0f5243a360caba;p=thirdparty%2Fkrb5.git 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(). ticket: 8378 --- diff --git a/src/plugins/kdb/db2/adb_openclose.c b/src/plugins/kdb/db2/adb_openclose.c index 9bad905055..d9d4cee3ec 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 1b7bc16f5d..2e27aac411 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 87429b94d4..62d11464c9 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 +/* 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