metze/heimdal/wip.git
4 years agotgs-rep: always return canonical realm lorikeet-heimdal-metze-20200327104420
Isaac Boukris [Wed, 31 Oct 2018 19:46:45 +0000 (21:46 +0200)]
tgs-rep: always return canonical realm

even if canonicalize falg is not set, same as Windows.

Regression introduced by upstream commit:
378f34b4be9865ed3949918fba8d2dd877b395c0

Signed-off-by: Isaac Boukris <iboukris@gmail.com>
(cherry picked from Samba commit a9e6119ca0c2a78ef314c3162122539ee834aa04)

4 years agokdc: Provide flag to hint to KDC that this is a FAST key lookup
Andrew Bartlett [Thu, 20 Sep 2018 23:36:18 +0000 (16:36 -0700)]
kdc: Provide flag to hint to KDC that this is a FAST key lookup

For Samba the fast key is not stored in the replicated DB, so
this helps Samba find it in the Samba hdb module.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
4 years agoTODO: auth: For NTLM and KDC authentication, log the authentication duration
Andrew Bartlett [Wed, 5 Sep 2018 05:41:57 +0000 (17:41 +1200)]
TODO: auth: For NTLM and KDC authentication, log the authentication duration

This is not a general purpose profiling solution, but these JSON logs are already being
generated and stored, so this is worth adding.

Some administrators are very keen to know how long authentication
takes, particularly due to long replication transactions in other
processes.

This complements a similar patch set to log the transaction duration.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
(Simlar to Samba commit 1bb2a1c6b3eaccf114ac3f3b5b51f57828a04996)
[metze@samba.org: improved for upstream heimdal]
Signed-off-by: Stefan Metzmacher <metze@samba.org>
4 years agolib/krb5 correctly follow KRB5_KDC_ERR_WRONG_REALM client referrals
Stefan Metzmacher [Wed, 5 Sep 2018 05:35:47 +0000 (17:35 +1200)]
lib/krb5 correctly follow KRB5_KDC_ERR_WRONG_REALM client referrals

An AS-REQ with an enterprise principal will always directed to a kdc of the local
(default) realm. The KDC directs the client into the direction of the
final realm. See rfc6806.txt.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from Samba commit fca11edc0b476f5b87b3301da32fd0409d9590c7)

4 years agoTODO CHECK heimdal: Fix loss of information in _gsskrb5_canon_name() from call to...
Andrew Bartlett [Tue, 26 Sep 2017 03:34:38 +0000 (16:34 +1300)]
TODO CHECK heimdal: Fix loss of information in _gsskrb5_canon_name() from call to krb5_sname_to_principal()

This would discard the realm the client specified.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
4 years agoheimdal: Honour KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME in parse_name_canon_rules()
Andrew Bartlett [Tue, 26 Sep 2017 02:11:53 +0000 (15:11 +1300)]
heimdal: Honour KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME in parse_name_canon_rules()

This is called from gsskrb5_set_dns_canonicalize() and krb5_set_dns_canonicalize_hostname()
and is used by Samba to ensure that the AD DC sees the name as specified by the client.

We allow the krb5.conf to override, if specifically configured.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
4 years agoTODO: heimdal: Pass extra information to hdb_auth_status() to log success and failures
Andrew Bartlett [Tue, 21 Feb 2017 01:07:54 +0000 (14:07 +1300)]
TODO: heimdal: Pass extra information to hdb_auth_status() to log success and failures

We now pass on the original client name and the client address to allow
consistent audit logging in Samba across multiple protocols.

We use config->db[0] to find the first database to record incorrect
users.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
(Similar to Samba commit f498ba77df2313e78863e5f2706840c43e232a96)
[metze@samba.org: improved for heimdal upstream]
Signed-off-by: Stefan Metzmacher <metze@samba.org>
4 years agoChange KDC to respect HDB server name type if f.canonicalize is set
Andrew Bartlett [Wed, 5 Sep 2018 02:50:00 +0000 (14:50 +1200)]
Change KDC to respect HDB server name type if f.canonicalize is set

This changes behaviour flagged as being for Java 1.6.  My hope is that this does not
set f.canonicalize

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
4 years agoExport krb5_init_creds_* functions
Andreas Schneider [Wed, 5 Sep 2018 02:49:57 +0000 (14:49 +1200)]
Export krb5_init_creds_* functions

The function krb5_get_init_creds_opt_get_error() is deprecated and
krb5_init_creds_init() and krb5_init_creds_get_error() should be used
now.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from Samba commit e4f82de7716e91a1c512a8c37ca768b591029a4a)

4 years agolib/krb5 correctly follow KRB5_KDC_ERR_WRONG_REALM client referrals
Stefan Metzmacher [Wed, 5 Sep 2018 02:49:54 +0000 (14:49 +1200)]
lib/krb5 correctly follow KRB5_KDC_ERR_WRONG_REALM client referrals

An AS-REQ with an enterprise principal will always directed to a kdc of the local
(default) realm. The KDC directs the client into the direction of the
final realm. See rfc6806.txt.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from Samba commit fca11edc0b476f5b87b3301da32fd0409d9590c7)

4 years agoheimdal: Match windows and return KRB5KDC_ERR_CLIENT_REVOKED when the account is...
Andrew Bartlett [Mon, 25 Nov 2013 01:13:02 +0000 (14:13 +1300)]
heimdal: Match windows and return KRB5KDC_ERR_CLIENT_REVOKED when the account is locked out

Change-Id: I3c306d1516aa569549f5f024fe1fff2d4f2abefc
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
(cherry picked from Samba commit 580a705b83014e94556b9d5a8877406816e02190)

4 years agoHEIMDAL:kdc: make it possible to disable the principal based referral detection
Stefan Metzmacher [Sun, 29 Jan 2017 16:19:14 +0000 (17:19 +0100)]
HEIMDAL:kdc: make it possible to disable the principal based referral detection

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12554

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
4 years agolib/krb5: windows KDCs always return the canoncalized server principal
Stefan Metzmacher [Mon, 25 Jul 2011 07:23:52 +0000 (09:23 +0200)]
lib/krb5: windows KDCs always return the canoncalized server principal

Is there a better way to handle this?

metze

4 years agoHACK: Netbios Domain as Realm
Stefan Metzmacher [Fri, 22 Aug 2008 09:45:26 +0000 (11:45 +0200)]
HACK: Netbios Domain as Realm

This is really a ugly hack, to support using the Netbios Domain Name
as realm against windows KDC's, they always return the full realm
based on the DNS Name.

metze

4 years agokdc: use the correct kvno number for PKINIT in the AS-REP
Stefan Metzmacher [Wed, 14 Sep 2016 22:07:27 +0000 (00:07 +0200)]
kdc: use the correct kvno number for PKINIT in the AS-REP

Signed-off-by: Stefan Metzmacher <metze@samba.org>
4 years agokdc: add krb5plugin_windc_pac_pk_generate() hook
Stefan Metzmacher [Wed, 18 May 2016 15:07:42 +0000 (17:07 +0200)]
kdc: add krb5plugin_windc_pac_pk_generate() hook

This allows PAC_CRENDENTIAL_INFO to be added to the PAC
when using PKINIT. In that case PAC_CRENDENTIAL_INFO contains
an encrypted PAC_CRENDENTIAL_DATA.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11441

Signed-off-by: Stefan Metzmacher <metze@samba.org>
(similar to Samba commit 0022ea9efb0e7809fa2d060b294320eb0479cdd2)

4 years agoAlign locked out account behaviour with Windows
Gary Lockyer [Wed, 20 Sep 2017 03:35:10 +0000 (15:35 +1200)]
Align locked out account behaviour with Windows

Windows does not check the password on an account that has been locked.

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
4 years agoFix size types
Andreas Schneider [Wed, 5 Sep 2018 02:49:59 +0000 (14:49 +1200)]
Fix size types

Upstream pull request:
https://github.com/heimdal/heimdal/pull/354

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(parts of cherry picked Samba commit 72979d1d60ca2eab1e7903c2e77b8cca69667691)

4 years agolorikeet-heimdal: modernize URLs in helper scripts
Andrew Bartlett [Mon, 10 Sep 2018 21:13:07 +0000 (16:13 -0500)]
lorikeet-heimdal: modernize URLs in helper scripts

We have moved some repos and have https these days

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
4 years agolorikeet-heimdal: import-lorikeet: Use --no-verify when importing heimdal
Andrew Bartlett [Mon, 10 Sep 2018 21:05:40 +0000 (16:05 -0500)]
lorikeet-heimdal: import-lorikeet: Use --no-verify when importing heimdal

This allows us to import byte-for-byte files even if they have whitespace "errors".

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
4 years agolorikeet-heimdal: apply_heimdal: Try harder to apply patches from Samba
Andrew Bartlett [Wed, 5 Sep 2018 02:04:44 +0000 (14:04 +1200)]
lorikeet-heimdal: apply_heimdal: Try harder to apply patches from Samba

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
4 years agolorikeet-heimdal: apply_heimdal: Only show the Heimdal part of the patch to cherry...
Andrew Bartlett [Wed, 5 Sep 2018 01:57:35 +0000 (13:57 +1200)]
lorikeet-heimdal: apply_heimdal: Only show the Heimdal part of the patch to cherry-pick

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
4 years agolorikeet-heimdal: Include Samba commit in cherry-picked patches
Andrew Bartlett [Wed, 5 Sep 2018 01:45:04 +0000 (13:45 +1200)]
lorikeet-heimdal: Include Samba commit in cherry-picked patches

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
4 years agolorikeet-heimdal: improve apply_heimdal.sh
Andrew Bartlett [Fri, 21 Feb 2014 02:58:20 +0000 (15:58 +1300)]
lorikeet-heimdal: improve apply_heimdal.sh

4 years agolorikeet-heimdal: specify hash to heimdal import, rather than using the date
Andrew Bartlett [Wed, 19 Feb 2014 09:06:57 +0000 (22:06 +1300)]
lorikeet-heimdal: specify hash to heimdal import, rather than using the date

4 years agolorikeet-heimdal: remove obsolete script for importing from svn.
Jelmer Vernooij [Tue, 21 Dec 2010 14:17:30 +0000 (15:17 +0100)]
lorikeet-heimdal: remove obsolete script for importing from svn.

4 years agolorikeet-heimdal: add IMPORT-HEIMDAL.sh
Stefan Metzmacher [Fri, 22 Aug 2008 09:57:36 +0000 (11:57 +0200)]
lorikeet-heimdal: add IMPORT-HEIMDAL.sh

I think this can be removed...

metze

4 years agolorikeet-heimdal: rebase-lorikeet: Explicitly use bash.
Jelmer Vernooij [Fri, 26 Oct 2012 14:34:47 +0000 (06:34 -0800)]
lorikeet-heimdal: rebase-lorikeet: Explicitly use bash.

Standard sh doesn't have pushd/popd.

4 years agolorikeet-heimdal: Add a new script to help merging patches from Samba4 to heimdal
Andrew Tridgell [Wed, 1 Dec 2010 02:00:08 +0000 (13:00 +1100)]
lorikeet-heimdal: Add a new script to help merging patches from Samba4 to heimdal

4 years agolorikeet-heimdal: improve import-lorikeet.sh for the toplevel build
Stefan Metzmacher [Thu, 14 Jul 2011 14:24:37 +0000 (16:24 +0200)]
lorikeet-heimdal: improve import-lorikeet.sh for the toplevel build

metze

4 years agolorikeet-heimdal: Improve the heimdal import scripts
Andrew Bartlett [Tue, 30 Nov 2010 23:54:49 +0000 (10:54 +1100)]
lorikeet-heimdal: Improve the heimdal import scripts

4 years agolorikeet-heimdal: add scipts to rebase and import the latest version into samba4
Stefan Metzmacher [Fri, 27 Mar 2009 06:31:11 +0000 (07:31 +0100)]
lorikeet-heimdal: add scipts to rebase and import the latest version into samba4

If you use this scripts, read them! :-)

metze

4 years agolorikeet-heimdal: add wrap_ex_ntlm.diff from abartlet
Stefan Metzmacher [Fri, 22 Aug 2008 09:58:18 +0000 (11:58 +0200)]
lorikeet-heimdal: add wrap_ex_ntlm.diff from abartlet

metze

4 years agolorikeet-heimdal: add HEIMDAL-LICENCE.txt
Stefan Metzmacher [Fri, 22 Aug 2008 09:57:06 +0000 (11:57 +0200)]
lorikeet-heimdal: add HEIMDAL-LICENCE.txt

metze

4 years agolorikeet-heimdal: camellia-ntt GPLv2+ license
Stefan Metzmacher [Fri, 22 Aug 2008 09:43:50 +0000 (11:43 +0200)]
lorikeet-heimdal: camellia-ntt GPLv2+ license

metze

4 years agolorikeet-heimdal: autogen.sh modifications
Stefan Metzmacher [Fri, 22 Aug 2008 09:42:21 +0000 (11:42 +0200)]
lorikeet-heimdal: autogen.sh modifications

metze

4 years agoExpand tokens in gss cred store "ccache" value
Nicolas Williams [Wed, 18 Mar 2020 18:37:13 +0000 (13:37 -0500)]
Expand tokens in gss cred store "ccache" value

This is needed so that sshd and such can get make practical use of the
"ccache" key in GSS cred stores.

This commit only changes the store path, not the acquisition path.

4 years agoList FILE collection even when KRB5CCNAME is a sub
Nicolas Williams [Wed, 18 Mar 2020 05:43:01 +0000 (00:43 -0500)]
List FILE collection even when KRB5CCNAME is a sub

Setting KRB5CCNAME=/tmp/krb5cc_${UID}+${princ} should not prevent
listing the FILE collection.

4 years agohcrypto: Fix Makefile build race
Nicolas Williams [Wed, 18 Mar 2020 00:46:37 +0000 (19:46 -0500)]
hcrypto: Fix Makefile build race

4 years agokrb5: Use sqlite3_close(), not v2
Nicolas Williams [Wed, 18 Mar 2020 00:45:51 +0000 (19:45 -0500)]
krb5: Use sqlite3_close(), not v2

4 years agokrb5: Fix kinit harder
Nicolas Williams [Sat, 14 Mar 2020 02:36:00 +0000 (21:36 -0500)]
krb5: Fix kinit harder

The previous fixes for using `krb5_cc_default_for()` weren't quite
correct.

4 years agokrb5: Allow rename of empty FILE ccaches
Nicolas Williams [Sat, 14 Mar 2020 16:25:46 +0000 (11:25 -0500)]
krb5: Allow rename of empty FILE ccaches

4 years agogss: Sometimes set KRB5CCNAME when not overwriting
Nicolas Williams [Fri, 13 Mar 2020 23:43:00 +0000 (18:43 -0500)]
gss: Sometimes set KRB5CCNAME when not overwriting

4 years agogss: Fix default cache preference
Nicolas Williams [Fri, 13 Mar 2020 23:14:17 +0000 (18:14 -0500)]
gss: Fix default cache preference

4 years agoFix Appveyor Windows build
Nicolas Williams [Fri, 13 Mar 2020 03:58:13 +0000 (22:58 -0500)]
Fix Appveyor Windows build

4 years agogss: Prefer the default ccache when user_realm
Nicolas Williams [Thu, 12 Mar 2020 22:58:53 +0000 (17:58 -0500)]
gss: Prefer the default ccache when user_realm

gss_store_cred_into*() will now switch the new cred cache to be the
primary/default cred cache when

 - the caller requested it and,
 - if the caller passed in a user name, the creds' principal is the best
   principal for the named user.

A principal is the best principal for a user when the principal has just
one component, the component is the user's username, and the realm is
the configured user_realm.

4 years agokinit: Prefer the default ccache when user_realm
Nicolas Williams [Thu, 12 Mar 2020 22:57:16 +0000 (17:57 -0500)]
kinit: Prefer the default ccache when user_realm

If using the new --cache-default-for option, use the real default if the
principal is the best principal for the user.

A principal is the best principal for a user when the principal has just
one component, the component is the user's username, and the realm is
the configured user_realm.

4 years agokinit: Add --cache-default-for flag (fix check-cc)
Nicolas Williams [Thu, 12 Mar 2020 16:46:47 +0000 (11:46 -0500)]
kinit: Add --cache-default-for flag (fix check-cc)

4 years agoFix warnings (some bugs, some spurious)
Nicolas Williams [Thu, 12 Mar 2020 05:42:33 +0000 (00:42 -0500)]
Fix warnings (some bugs, some spurious)

Many spurious VC warnings not quieted though.

4 years agokrb5: Make FILE ccache type a collection type!
Nicolas Williams [Wed, 11 Mar 2020 18:42:30 +0000 (13:42 -0500)]
krb5: Make FILE ccache type a collection type!

4 years agokrb5: Restore FILE as the default ccache type
Nicolas Williams [Wed, 11 Mar 2020 18:42:03 +0000 (13:42 -0500)]
krb5: Restore FILE as the default ccache type

4 years agogsskrb5: Add unique ccache k/v for cred store
Nicolas Williams [Wed, 11 Mar 2020 18:40:35 +0000 (13:40 -0500)]
gsskrb5: Add unique ccache k/v for cred store

This will allow sshd and such to be configured to request unique ccache
names.

4 years agokrb5: Add krb5_set_config() for test_cc
Nicolas Williams [Wed, 11 Mar 2020 18:40:02 +0000 (13:40 -0500)]
krb5: Add krb5_set_config() for test_cc

4 years agoRevert cccol changes to kinit
Nicolas Williams [Thu, 12 Mar 2020 15:57:25 +0000 (10:57 -0500)]
Revert cccol changes to kinit

4 years agokdc: kx509.c fix build failures
Jeffrey Altman [Sun, 8 Mar 2020 14:28:37 +0000 (10:28 -0400)]
kdc: kx509.c fix build failures

bcb5ed28fbe25d3b207d17ddd2f420f938a4ef03 ("kdc/kx509.c: clean up
krb5_get_error_message strings used for mk_error_resp") introduced a
build failure.  'context' is not a local variable but a field in the
kx509_req_context.

Change-Id: I38a8a9b1a19c3370dfc039d6e09445425936c32b

4 years agokdc/kx509.c: clean up krb5_get_error_message strings used for mk_error_resp
Daria Phoebe Brashear [Fri, 10 Jan 2020 18:12:57 +0000 (13:12 -0500)]
kdc/kx509.c: clean up krb5_get_error_message strings used for mk_error_resp

mk_error_response expects the strings it builds will need to be freed but
not those passed in; krb5_get_error_message generates a string which needs to
be freed. keep track of and free those strings.

4 years agolib/base log_file should free filename in all cases
Daria Phoebe Brashear [Thu, 5 Mar 2020 23:58:41 +0000 (18:58 -0500)]
lib/base log_file should free filename in all cases

once we've used the filename we built, free it before exit

4 years agohdb: don't use lock_file name after free in open_lock_file
Daria Phoebe Brashear [Mon, 13 Jan 2020 04:53:02 +0000 (23:53 -0500)]
hdb: don't use lock_file name after free in open_lock_file

4 years agolib/kadm5 kadm5_c_randkey_principal allow keyblock cleanup on error
Daria Phoebe Brashear [Fri, 10 Jan 2020 18:08:43 +0000 (13:08 -0500)]
lib/kadm5 kadm5_c_randkey_principal allow keyblock cleanup on error

the code to perform cleanup is present but an overzealous goto out
precludes it from being called. break from our for loop in event of error
and allow cleanup to take place

4 years agokrb5_mk_ncred: clean enc_krb_cred_part before use
Daria Phoebe Brashear [Fri, 10 Jan 2020 17:58:09 +0000 (12:58 -0500)]
krb5_mk_ncred: clean enc_krb_cred_part before use

the early exit case can try to free enc_krb_cred_part, which will be
stack garbage. clear it before it's used.

4 years agokdc kx509: avoid double free of cprinc and s in check_authz
Daria Phoebe Brashear [Fri, 10 Jan 2020 17:51:20 +0000 (12:51 -0500)]
kdc kx509: avoid double free of cprinc and s in check_authz

on error from der_parse_heim_old we early exit via out, which frees
s and cprinc; we should not do so a second time unless we explicitly
NULL the pointers but there is no value in doing so.

4 years agokrb5: Init mutex of anon MEMORY ccaches
Nicolas Williams [Wed, 4 Mar 2020 20:11:42 +0000 (14:11 -0600)]
krb5: Init mutex of anon MEMORY ccaches

4 years agokrb5: Improve cccol sub naming; add gss_store_cred_into2()
Nicolas Williams [Thu, 23 Jan 2020 01:18:14 +0000 (19:18 -0600)]
krb5: Improve cccol sub naming; add gss_store_cred_into2()

 - Formalize the TYPE:collection_name:subsidiary_name naming scheme for
   ccaches in ccache collections
    - KEYRING: ccaches are weird because they have one more optional field: the
      "anchor", so rather than just assume a naming convention everywhere, we
      add new functions as well
 - Add krb5_cc_{resolve,default}_sub() that allows one to specify a
   "subsidiary" ccache name in a collection separately from the
   collection name
 - Add krb5_cc_{resolve,default}_for() which take a principal name,
   unparse it, and use it as the subsidiary ccache name (with colons
   replaced)
 - Make kinit use the new interfaces
 - Add missing DIR ccache iteration functionality
 - Revamps test_cc
 - Add krb5_cc_get_collection() and krb5_cc_get_subsidiary()
 - Bump the ccops SPI version number
 - Add gss_store_cred_into2()
 - Make MEMORY:anonymous not linked into the global MEMORY ccache
   collection, and uses this for delegated cred handles

TBD:

 - Split this up into a krb5 change and gss mech_krb5 change?
 - Add krb5_cc_init_and_store() utility, per Greg's suggestion?

4 years agoroken: Add mkdtemp()
Nicolas Williams [Fri, 24 Jan 2020 06:24:52 +0000 (00:24 -0600)]
roken: Add mkdtemp()

4 years agoroken: Add base32
Nicolas Williams [Tue, 14 Jan 2020 01:46:13 +0000 (19:46 -0600)]
roken: Add base32

4 years agoappveyor: Minor improvements for debugging
Nicolas Williams [Mon, 2 Mar 2020 16:52:39 +0000 (10:52 -0600)]
appveyor: Minor improvements for debugging

4 years agohdb: Fix memory leak in hdb_generate_key_set()
Nicolas Williams [Sun, 1 Mar 2020 03:32:26 +0000 (21:32 -0600)]
hdb: Fix memory leak in hdb_generate_key_set()

4 years agoMove some infra bits of lib/krb5/ to lib/base/ (2)
Nicolas Williams [Tue, 25 Feb 2020 00:50:01 +0000 (18:50 -0600)]
Move some infra bits of lib/krb5/ to lib/base/ (2)

This is the second of two commits in a series that must be picked together.

This series of two commits moves parts of lib/krb5/ infrastructure
functionality to lib/base/, leaving behind wrappers.

Some parts of libkrb5 are entirely generic or easily made so, and could
be useful in various parts of Heimdal that are not specific to the krb5
API, such as:

 - lib/gssapi/  (especially since the integration of NegoEx)
 - lib/hx509/
 - bx509d       (which should really move out of kdc/)

For the above we need to move these bits of lib/krb5/:

 - lib/krb5/config_file.c   (all of it, leaving forwardings behind)
 - lib/krb5/config_reg.c    (all of it)
 - lib/krb5/plugin.c        (all of it, leaving forwardings behind)
 - lib/krb5/log.c           (all of it, ditto)
 - lib/krb5/heim_err.et     (all of it)

And because of those two, these too must also move:

 - lib/krb5/expand_path.c   (all of it, leaving forwardings behind)
 - lib/krb5/warn.c          (just the warning functions, ditto)

The changes to the moved files are mostly quite straightforward and are
best reviewed with --word-diff=color.

We're also creating a heim_context and a heim API to go with it.  But
it's as thin as possible, with as little state as necessary to enable
this move.  Functions for dealing with error messages use callbacks.

Moving plugin.c does have one knock-on effect on all users of the old
krb5 plugin API (which remains), which is that a global search and
replace of struct krb5_plugin_data to struct heim_plugin_data was
needed, though the layout and size of that structure doesn't change, so
the ABI doesn't either.

As well, we now build lib/vers/ and lib/com_err/ before lib/base/ so as
to be able to move lib/krb5/heim_err.et to lib/base/ so that we can make
use of HEIM_ERR_* in lib/base/, specifically in the files that moved.

Once this is all done we'll be able to use config files and plugins in
lib/hx509/, we'll be able to move bx509d out of kdc/, and so on.

Most if not all of the new functions in lib/base/ are Heimdal-private,
thus calling conventions for them are not declared.

Status:

 - builds and passes CIs (Travis, Appveyor)
 - ran make check-valgrind and no new leaks or other memory errors
 - ready for review

HOW TO REVIEW:

     $ # Review file moves:
     $ git log --stat -n1 HEAD^
     $
     $ # Review changes to moved files using --word-diff=color
     $ git log -p -b -w --word-diff=color HEAD^..HEAD   \
               lib/base/config_file.c                   \
               lib/base/config_reg.c                    \
               lib/base/expand_path.c                   \
               lib/base/warn.c                          \
               lib/krb5/config_file.c                   \
               lib/krb5/config_reg.c                    \
               lib/krb5/expand_path.c                   \
               lib/krb5/warn.c
     $
     $ # Review the whole thing, possibly adding -b and/or -w, and
     $ # maybe --word-diff=color:
     $ git log -p origin/master..HEAD
     $ git log -p -b -w origin/master..HEAD
     $ git log -p -b -w --word-diff=color origin/master..HEAD

TBD (future commits):

 - make lib/gssapi use the new heimbase functions
 - move kx509/bx509d common code to lib/hx509/ or other approp. location
 - move bx509d out of kdc/

4 years agoMove some infra bits of lib/krb5/ to lib/base/ (1)
Nicolas Williams [Wed, 26 Feb 2020 05:25:51 +0000 (23:25 -0600)]
Move some infra bits of lib/krb5/ to lib/base/ (1)

This is the first of two commits in a series that must be picked
together.

This series of two commits moves parts of lib/krb5/ infrastructure
functionality to lib/base/, leaving behind wrappers.

This commit only renames files to enable git log/diff/blame to follow
the renames: to help future code archeology, and to make reviewing these
two commits easier.

The next commit in this series ensures that the moved files have the
correct content (i.e., defining heim APIs instead of krb5 APIs), and
will create files in lib/krb5 with the same names and krb5 API wrappers
around the new heim API functions.

The next commit also explains the motivation, which, briefly, is to:

 - remove krb5 API usage from lib/gssapi/,
 - enable the use of configuration and plugins in lib/hx509/
   (as well as lib/gssapi/ and future projects),

and

 - enable the further disentanglement of bx509d from kdc/.

4 years agogss: initialize mech output parameters in mechglue
Luke Howard [Mon, 2 Mar 2020 06:10:11 +0000 (17:10 +1100)]
gss: initialize mech output parameters in mechglue

Initialize mechanism output parameters before calling mechanism
GSS_Accept_sec_context(), to behave robustly with poorly implemented mechanisms
that may return before initializing them.

4 years agogss: plug leak in test_negoex_mech
Luke Howard [Mon, 2 Mar 2020 06:15:33 +0000 (17:15 +1100)]
gss: plug leak in test_negoex_mech

test_negoex_mech should free the result of calling decode_GSSAPIContextToken()

4 years agogss: initialize output params in test_negoex_mech
Luke Howard [Mon, 2 Mar 2020 06:08:31 +0000 (17:08 +1100)]
gss: initialize output params in test_negoex_mech

test_negoex_mech, being a simple test mechanism ported from MIT that was not
designed to be particularly robust, failed to initialize various output
parameters such as the source name. On Heimdal this triggered an invalid read
because the mechglue did not initialize those variables before calling the
mechanism. This commit fixes this.

4 years agotgs-req: strip forwardable and proxiable if the server is disallowed
Isaac Boukris [Sat, 18 Jan 2020 13:47:02 +0000 (14:47 +0100)]
tgs-req: strip forwardable and proxiable if the server is disallowed

4 years agogss: add mechanism-force-mechListMIC hook to SPNEGO
Luke Howard [Tue, 4 Feb 2020 05:39:34 +0000 (16:39 +1100)]
gss: add mechanism-force-mechListMIC hook to SPNEGO

NTLM erroneously requires a mechListMIC at the SPNEGO layer if an internal MIC
in the NTLM protocol was used. Add a private interface between SPNEGO and the
Samba NTLM mechanism to allow the mechanism to signal that a mechListMIC is
required even if it otherwise would not be.

This interface is the same as that supported by MIT.

Note that only the Samba NTLM mechanism currently implements this feature, it
is not implemented by the Heimdal NTLM mechanism (which does not support NTLM
authenticate message MICs).

4 years agogss: don't explicitly reorder krb5 to front of spnego
Luke Howard [Sun, 29 Dec 2019 09:45:03 +0000 (20:45 +1100)]
gss: don't explicitly reorder krb5 to front of spnego

Previously krb5 was tried explicitly, but now the internal mech list is
reordered so that krb5 is first, this should no longer be required. This
permits an application to specify another mechanism as preferred over krb5
using gss_set_neg_mechs().

4 years agogss: harmonize negState with RFC 4178
Luke Howard [Tue, 14 Jan 2020 02:06:51 +0000 (13:06 +1100)]
gss: harmonize negState with RFC 4178

RFC 4178 4.2.2 uses the field name negState rather than negResult in
NegTokenResp, to denote the negotiation state. Harmonize with this, also
replacing the underscores in accept-completed and accepet-incomplete to match
the RFC.

4 years agogss: harmonize SPNEGO with [MS-SPNG]
Luke Howard [Wed, 1 Jan 2020 00:25:16 +0000 (11:25 +1100)]
gss: harmonize SPNEGO with [MS-SPNG]

In [MS-SPNG], the Microsoft extension is defined as NegTokenInit2 rather than
NegTokenInitWin. Harmonize with the specification.

4 years agogss: don't generate mechListMIC in SPNEGO if it is safe to omit it
Luke Howard [Wed, 1 Jan 2020 11:32:46 +0000 (22:32 +1100)]
gss: don't generate mechListMIC in SPNEGO if it is safe to omit it

4 years agogss: port NegoEx implementation from MIT
Luke Howard [Mon, 30 Dec 2019 02:34:10 +0000 (13:34 +1100)]
gss: port NegoEx implementation from MIT

An implementation of draft-zhu-negoex-04 for MIT Kerberos was developed in
2011. This has been recently integrated, with many fixes from Greg Hudson. This
commit ports it to Heimdal. The implementation has been interoperability tested
with MIT Kerberos and Windows, using the GSS EAP mechanism developed as part of
the Moonshot project.

The SPNEGO code was also updated to import the state machine from Apple which
improves mechListMIC processing and avoids discarding initial context tokens
generated during mechanism probing, that can be used for optimistic tokens.

Finally, to aid in testing, the GSS-API mechanism glue configuration file can
be changed using the environment variable GSS_MECH_CONFIG. This environment
variable name, along with the format of the configuration file, is compatible
with MIT (although it would be difficult for a single mechanism binary to
support both implementations).

4 years agogss: remove SPNEGO name wrappers
Luke Howard [Thu, 2 Jan 2020 05:30:42 +0000 (16:30 +1100)]
gss: remove SPNEGO name wrappers

Wrapping GSS names at the SPNEGO level serves no purpose; remove it and return
mechglue names directly. This required a small change to the NTLM mechanism to
allow NULL names to be passed to its release name function.

4 years agogss: add some missing GM_USE_MG_CRED checks
Luke Howard [Sat, 28 Dec 2019 05:35:04 +0000 (16:35 +1100)]
gss: add some missing GM_USE_MG_CRED checks

GM_USE_MG_CRED allows a mechanism glue credential to be used by a mechanism
without additional wrapping. Although no extant mechanisms use this flag, the
flag had sporadic support in the mechanism glue already. In the interest of
consistency, add missing GM_USE_MG_CRED checks. If this functionality is not
desired, then all checks should be removed.

4 years agogss: make krb5 default GSS mech earlier in path
Luke Howard [Thu, 26 Dec 2019 13:15:13 +0000 (00:15 +1100)]
gss: make krb5 default GSS mech earlier in path

Defensively default to GSS_KRB5_MECHANISM on all calls to
gss_init_sec_context() if mech_type is GSS_C_NO_OID (rather than only on the
first call).

4 years agogss: expose gss_destroy_cred()
Luke Howard [Sat, 28 Dec 2019 13:15:49 +0000 (00:15 +1100)]
gss: expose gss_destroy_cred()

Build and export gss_destroy_cred(). This permanently destroys the credential,
rather than releasing a handle to it.

4 years agogss: merge Apple name helper APIs
Luke Howard [Sat, 28 Dec 2019 05:34:35 +0000 (16:34 +1100)]
gss: merge Apple name helper APIs

Add helper APIs to the mechanism glue from the Apple implementation.
gss_mg_export_name() can be used by a mechanism to create an exported name
(this is used by the future SAnon implementation). _gss_mech_import_name()
allows the mechanism to pass in a list of parsing functions for specific name
tiypes. This commit only adds support to the mechanism glue itself.

4 years agogss: merge enhanced Apple mechglue logging
Luke Howard [Sat, 28 Dec 2019 05:45:47 +0000 (16:45 +1100)]
gss: merge enhanced Apple mechglue logging

Add _gss_mg_log() and friends for logging from within the mechanism glue and
SPNEGO. These APIs wrap around the libkrb5 logging APIs.

4 years agogss: use tail queue instead of singly linked list in mechglue
Luke Howard [Sat, 28 Dec 2019 05:30:55 +0000 (16:30 +1100)]
gss: use tail queue instead of singly linked list in mechglue

The GSS mechglue uses singly linked lists for mechanisms and mechanism objects,
to which new entries are inserted at the head. This breaks ordering of
mechanisms specified in OID sets and in /etc/gss/mech, as they will be back to
front. Use a tail queue instead so that new entries are inserted at the end.

4 years agobase: make heimqueue.h a shared header
Luke Howard [Thu, 26 Dec 2019 10:41:29 +0000 (21:41 +1100)]
base: make heimqueue.h a shared header

Share heimqueue.h between base and asn1, to avoid duplication of code.

4 years agogss: mechanism optional interfaces
Luke Howard [Sat, 28 Dec 2019 13:17:26 +0000 (00:17 +1100)]
gss: mechanism optional interfaces

Make mechanism interfaces that are optional in usage, optional in
implementation, i.e. do not require them to be present when dynamically loading
a mechanism. In order to aid minimal mechanism implementation, more of these
should likely be made optional (this will require an additional check in the
mechglue to return GSS_S_UNAVAILABLE if the function pointer is NULL). This is
left as a future exercise.

4 years agogss: use _gss_ntlm_set_keys() in gss_init_sec_context()
Luke Howard [Fri, 27 Dec 2019 12:11:00 +0000 (23:11 +1100)]
gss: use _gss_ntlm_set_keys() in gss_init_sec_context()

DRY: use the _gss_ntlm_set_keys() helper function to initialize the key state
for both initiator and acceptor.

4 years agogss: don't provide domain to nsi_probe() in NTLM
Luke Howard [Fri, 27 Dec 2019 09:47:24 +0000 (20:47 +1100)]
gss: don't provide domain to nsi_probe() in NTLM

_gss_ntlm_accept_sec_context() does not provide the acceptor domain to
nsi_probe(); for consistency, _gss_ntlm_acquire_cred_from() should do that
same. Providing the acceptor domain was breaking tests.

Note that the Heimdal NTLM implementation is old and has few consumers (Apple
and Samba use their own implementations). Arguably we should merge the Apple
implementation or remove it.

4 years agogss: NTLM nsi_probe returns a krb5, not gss error
Luke Howard [Fri, 27 Dec 2019 09:31:45 +0000 (20:31 +1100)]
gss: NTLM nsi_probe returns a krb5, not gss error

The nsi_probe() error code was treated as a GSS error code, rather than a krb5
error. Return a GSS error code, setting the krb5 error in minor_status.

4 years agogss: register GSS_KRB5_S error table
Luke Howard [Sun, 29 Dec 2019 06:44:26 +0000 (17:44 +1100)]
gss: register GSS_KRB5_S error table

The Kerberos GSS mechanism specific error table in gkrb5_err.et was never
registered with libkrb5, so the messages corresponding to those errors would
never be available. Register them with the thread local context used by the
krb5 mechanism.

4 years agoWindows: Fix type cast warning.
Rod Widdowson [Wed, 29 Jan 2020 10:31:15 +0000 (10:31 +0000)]
Windows: Fix type cast warning.

Since at least SDK V6.1 HCRYPTPROV has been specified as ULONG_PTR
this means that comparing or setting one with NULL causes a cast
warning.

Use an explicit cast from zero to that type.

4 years agoUpdate README.md
Jeffrey Altman [Fri, 10 Jan 2020 20:00:16 +0000 (15:00 -0500)]
Update README.md

4 years agobx509: Add /, /health for load balancer checking
Nicolas Williams [Fri, 10 Jan 2020 17:39:56 +0000 (11:39 -0600)]
bx509: Add /, /health for load balancer checking

A HEAD or GET of / or /health will now produce a 200 instead of a 404.

Ideally we should add configuration arguments that would allow /health
to get a token, make a CSR, and test the /bx509 (and/or /bnegotiate)
functionality, that way we'd have a real health check.  For now we defer
that work, as external health monitoring can be done using a simple
script anyways.

4 years agobx509: Do not clobber library error info
Nicolas Williams [Fri, 10 Jan 2020 17:34:33 +0000 (11:34 -0600)]
bx509: Do not clobber library error info

4 years agokdc: add test_token_validator -a option
Nicolas Williams [Fri, 10 Jan 2020 17:32:59 +0000 (11:32 -0600)]
kdc: add test_token_validator -a option

4 years agokdc: implement test_kdc_ca -a option
Nicolas Williams [Fri, 10 Jan 2020 17:30:56 +0000 (11:30 -0600)]
kdc: implement test_kdc_ca -a option

4 years agobx509: Fix CSR authorizer IPC plugin bug
Nicolas Williams [Fri, 10 Jan 2020 17:29:21 +0000 (11:29 -0600)]
bx509: Fix CSR authorizer IPC plugin bug

When marking SANs authorized, mark the SAN, not some EKU, authorized!

4 years agoAdd bx509d.8 man page
Nicolas Williams [Fri, 3 Jan 2020 06:12:43 +0000 (00:12 -0600)]
Add bx509d.8 man page