summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2012-06-02 13:54:12 -0400
committerGreg Hudson <ghudson@mit.edu>2012-06-02 14:08:08 -0400
commita5c693ee32900b252490a75b18ed40088eb6fec0 (patch)
tree5650e88339ab206932719e71df25872f7b81d3fb /src/lib/krb5
parent5befd068e13d671490e6b0ac868d1cd23ffa9496 (diff)
downloadkrb5-a5c693ee32900b252490a75b18ed40088eb6fec0.tar.gz
krb5-a5c693ee32900b252490a75b18ed40088eb6fec0.tar.xz
krb5-a5c693ee32900b252490a75b18ed40088eb6fec0.zip
Tighten up error checking in t_keytab.c
When checking for specific error codes, using CHECK() meant that we wouldn't properly fail if we got error code 0. Define and use a CHECK_ERR() to test for a specific error code, and define CHECK() in terms of it.
Diffstat (limited to 'src/lib/krb5')
-rw-r--r--src/lib/krb5/keytab/t_keytab.c45
1 files changed, 16 insertions, 29 deletions
diff --git a/src/lib/krb5/keytab/t_keytab.c b/src/lib/krb5/keytab/t_keytab.c
index 6e8707649..6b64d52f4 100644
--- a/src/lib/krb5/keytab/t_keytab.c
+++ b/src/lib/krb5/keytab/t_keytab.c
@@ -40,13 +40,14 @@ extern const krb5_kt_ops krb5_ktf_writable_ops;
#define KRB5_OK 0
-#define CHECK(kret,msg) \
- if (kret != KRB5_OK) { \
+#define CHECK_ERR(kret,err,msg) \
+ if (kret != err) { \
com_err(msg, kret, ""); \
fflush(stderr); \
exit(1); \
} else if(debug) printf("%s went ok\n", msg);
+#define CHECK(kret,msg) CHECK_ERR(kret, 0, msg)
#define CHECK_STR(str,msg) \
if (str == 0) { \
@@ -66,9 +67,7 @@ test_misc(krb5_context context)
fprintf(stderr, "Testing miscellaneous error conditions\n");
kret = krb5_kt_resolve(context, "unknown_method_ep:/tmp/name", &ktid);
- if (kret != KRB5_KT_UNKNOWN_TYPE) {
- CHECK(kret, "resolve unknown type");
- }
+ CHECK_ERR(kret, KRB5_KT_UNKNOWN_TYPE, "resolve unknown type");
/* Test length limits on krb5_kt_default_name */
kret = krb5_kt_default_name(context, defname, sizeof(defname));
@@ -82,9 +81,7 @@ test_misc(krb5_context context)
}
kret = krb5_kt_default_name(context, name, strlen(defname));
free(name);
- if (kret != KRB5_CONFIG_NOTENUFSPACE) {
- CHECK(kret, "krb5_kt_default_name limited");
- }
+ CHECK_ERR(kret, KRB5_CONFIG_NOTENUFSPACE, "krb5_kt_default_name limited");
}
static void
@@ -117,25 +114,22 @@ kt_test(krb5_context context, const char *name)
*/
p = malloc(strlen(buf));
kret = krb5_kt_get_name(context, kt, p, 1);
- if(kret != KRB5_KT_NAME_TOOLONG) {
- CHECK(kret, "get_name - size 1");
- }
+ CHECK_ERR(kret, KRB5_KT_NAME_TOOLONG, "get_name - size 1");
kret = krb5_kt_get_name(context, kt, p, strlen(buf));
- if(kret != KRB5_KT_NAME_TOOLONG) {
- CHECK(kret, "get_name");
- }
+ CHECK_ERR(kret, KRB5_KT_NAME_TOOLONG, "get_name");
free(p);
/* Try to lookup unknown principal - when keytab does not exist*/
kret = krb5_parse_name(context, "test/test2@TEST.MIT.EDU", &princ);
CHECK(kret, "parsing principal");
-
+ /* This will return ENOENT for FILE because the file doesn't exist,
+ * so accept that or KRB5_KT_NOTFOUND. */
kret = krb5_kt_get_entry(context, kt, princ, 0, 0, &kent);
- if((kret != KRB5_KT_NOTFOUND) && (kret != ENOENT)) {
- CHECK(kret, "Getting non-existant entry");
+ if (kret != ENOENT) {
+ CHECK_ERR(kret, KRB5_KT_NOTFOUND, "Getting non-existent entry");
}
@@ -199,9 +193,7 @@ kt_test(krb5_context context, const char *name)
cnt++;
krb5_free_keytab_entry_contents(context, &kent);
}
- if (kret != KRB5_KT_END) {
- CHECK(kret, "getting next entry");
- }
+ CHECK_ERR(kret, KRB5_KT_END, "getting next entry");
if(cnt != 3) {
fprintf(stderr, "Mismatch in number of entries in keytab");
@@ -219,9 +211,7 @@ kt_test(krb5_context context, const char *name)
kret = krb5_kt_get_entry(context, kt, princ, 0, 0, &kent);
- if((kret != KRB5_KT_NOTFOUND)) {
- CHECK(kret, "Getting non-existant entry");
- }
+ CHECK_ERR(kret, KRB5_KT_NOTFOUND, "Getting non-existant entry");
krb5_free_principal(context, princ);
@@ -339,9 +329,8 @@ kt_test(krb5_context context, const char *name)
/* Try to lookup specified enctype and kvno - that does not exist*/
kret = krb5_kt_get_entry(context, kt, princ, 3, 1, &kent);
- if(kret != KRB5_KT_KVNONOTFOUND) {
- CHECK(kret, "looking up specific principal, kvno, enctype");
- }
+ CHECK_ERR(kret, KRB5_KT_KVNONOTFOUND,
+ "looking up specific principal, kvno, enctype");
krb5_free_principal(context, princ);
@@ -436,9 +425,7 @@ main(void)
/* All keytab types are registered by default -- test for
redundant error */
kret = krb5_kt_register(context, &krb5_ktf_writable_ops);
- if(kret && kret != KRB5_KT_TYPE_EXISTS) {
- CHECK(kret, "register ktf_writable");
- }
+ CHECK_ERR(kret, KRB5_KT_TYPE_EXISTS, "register ktf_writable");
test_misc(context);
do_test(context, "WRFILE:", FALSE);