From 5086353ebad66d430aac40efff9778f0a0d2ce7c Mon Sep 17 00:00:00 2001 From: Alexey Tikhonov Date: Oct 21 2019 09:27:06 +0000 Subject: util/sss_krb5.c: elimination of unreachable code It was wrong to check `kt_err` after ``` if (!principal_found) { ... goto done; } ``` since getting to this point of code would mean `kt_err` equals to 0 and thus statement inside `if (kt_err != 0) ...` was unreachable. Moreover it was logical error to do `goto done;` inside this statement without setting `kerr`. Reviewed-by: Sumit Bose --- diff --git a/src/util/sss_krb5.c b/src/util/sss_krb5.c index c0cc28a..0086fca 100644 --- a/src/util/sss_krb5.c +++ b/src/util/sss_krb5.c @@ -395,16 +395,16 @@ krb5_error_code find_principal_in_keytab(krb5_context ctx, } if (!principal_found) { - kerr = KRB5_KT_NOTFOUND; - DEBUG(SSSDBG_TRACE_FUNC, - "No principal matching %s@%s found in keytab.\n", - pattern_primary, pattern_realm); - goto done; - } - - /* check if we got any errors from krb5_kt_next_entry */ - if (kt_err != 0 && kt_err != KRB5_KT_END) { - DEBUG(SSSDBG_CRIT_FAILURE, "Error while reading keytab.\n"); + /* If principal was not found then 'kt_err' was set */ + if (kt_err != KRB5_KT_END) { + kerr = kt_err; + DEBUG(SSSDBG_CRIT_FAILURE, "Error while reading keytab.\n"); + } else { + kerr = KRB5_KT_NOTFOUND; + DEBUG(SSSDBG_TRACE_FUNC, + "No principal matching %s@%s found in keytab.\n", + pattern_primary, pattern_realm); + } goto done; } @@ -413,7 +413,6 @@ krb5_error_code find_principal_in_keytab(krb5_context ctx, DEBUG(SSSDBG_CRIT_FAILURE, "krb5_copy_principal failed.\n"); goto done; } - kerr = 0; done: