From a3d6fdd5355d366f3d23915cecc10c6f039daa44 Mon Sep 17 00:00:00 2001 From: Aaron Haslett Date: Tue, 1 May 2018 11:10:24 +1200 Subject: [PATCH] auth: keytab invalidation test chgtdcpass should add a new DC password and delete the old ones but the bug exposed by this test causes the tool to remove only a single record from the old entries, leaving the old passwords functional. Since the tool is used by administrators who may have disclosed their domain join password and want to invalidate it, this is a security concern. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13415 Signed-off-by: Aaron Haslett Reviewed-by: Andrew Bartlett Reviewed-by: Andreas Schneider --- selftest/knownfail.d/keytab | 1 + selftest/tests.py | 2 + source4/auth/tests/kerberos.c | 107 ++++++++++++++++++++++++++++++++++ source4/auth/wscript_build | 6 ++ 4 files changed, 116 insertions(+) create mode 100644 selftest/knownfail.d/keytab create mode 100644 source4/auth/tests/kerberos.c diff --git a/selftest/knownfail.d/keytab b/selftest/knownfail.d/keytab new file mode 100644 index 00000000000..6777d98ff28 --- /dev/null +++ b/selftest/knownfail.d/keytab @@ -0,0 +1 @@ +^samba.unittests.kerberos.test_krb5_remove_obsolete_keytab_entries_many diff --git a/selftest/tests.py b/selftest/tests.py index 185ad37fd4a..f354bb57ef5 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -187,5 +187,7 @@ plantestsuite("samba.unittests.tldap", "none", [os.path.join(bindir(), "default/source3/test_tldap")]) plantestsuite("samba.unittests.rfc1738", "none", [os.path.join(bindir(), "default/lib/util/test_rfc1738")]) +plantestsuite("samba.unittests.kerberos", "none", + [os.path.join(bindir(), "test_kerberos")]) plantestsuite("samba.unittests.ms_fnmatch", "none", [os.path.join(bindir(), "default/lib/util/test_ms_fnmatch")]) diff --git a/source4/auth/tests/kerberos.c b/source4/auth/tests/kerberos.c new file mode 100644 index 00000000000..703c8067908 --- /dev/null +++ b/source4/auth/tests/kerberos.c @@ -0,0 +1,107 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "includes.h" +#include "system/kerberos.h" +#include "auth/kerberos/kerberos.h" +#include "auth/credentials/credentials.h" +#include "auth/credentials/credentials_proto.h" +#include "auth/credentials/credentials_krb5.h" +#include "auth/kerberos/kerberos_credentials.h" +#include "auth/kerberos/kerberos_util.h" + +static void internal_obsolete_keytab_test(int num_principals, int num_kvnos, + krb5_kvno kvno, const char *kt_name) +{ + krb5_context krb5_ctx; + krb5_keytab keytab; + krb5_keytab_entry kt_entry; + krb5_kt_cursor cursor; + krb5_error_code code; + + int i,j; + char princ_name[6] = "user0"; + char expect_princ_name[23] = "user0@samba.example.com"; + bool found_previous; + const char *error_str; + + TALLOC_CTX *tmp_ctx = talloc_new(NULL); + krb5_principal *principals = talloc_zero_array(tmp_ctx, + krb5_principal, + num_principals); + krb5_init_context(&krb5_ctx); + krb5_kt_resolve(krb5_ctx, kt_name, &keytab); + ZERO_STRUCT(kt_entry); + + for(i=0; i