Commit Graph

253 Commits

Author SHA1 Message Date
Stefan Metzmacher
baf1930b6a kdc: don't fail salt_fastuser_crypto with r->req.req_body.cname == NULL for TGS-REQ 2024-01-09 16:06:06 -06:00
Joseph Sutton
fbe89adf27 kdc: Fix spelling of error and log messages
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00
Joseph Sutton
da9cad2047 kdc: Overwrite ‘error_code’ only if we have an actual error
‘r->error_code’ might have been set earlier, and we don’t want to
overwrite it with a successful error code.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-06-20 18:02:15 -05:00
Joseph Sutton
243207f10a kdc: Ensure that we emit a non-zero error code
If ‘r->error_code’ was zero, we would turn it into an ERR_GENERIC error
and return that to the client. Now we return the actual error code
instead.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-06-20 18:02:15 -05:00
Joseph Sutton
d83802e2d4 kdc: Fix log message typo 2023-06-20 18:02:15 -05:00
Joseph Sutton
cf6b216868 kdc: Have caller pass HDB_F_FOR_TGS_REQ into _kdc_fast_check_armor_pac()
We shall soon want to use this function for AS-REQs as well as TGS-REQs.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-06-13 17:41:21 -05:00
Nicolas Williams
6cf01fea19 kdc: Quiet warnings re: debug logging 2023-01-04 01:36:02 -06:00
Nicolas Williams
ea39bc5a6b kdc: Fix #1059 2023-01-04 01:36:01 -06:00
Nicolas Williams
be0d4036a9 kdc: Quiet set-but-not-use variable warning 2023-01-04 01:36:01 -06:00
Stefan Metzmacher
c4216b17a8 kdc: add enable_fast option (enabled by default)
This makes it possible to disable fast if needed,
which is very good for regression tests.
Samba disables this in a few test environments with this
option.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-09-25 21:13:01 +10:00
Luke Howard
df655cecd1 kdc: allow audit plugins to influence return code
Honor the return code of _kdc_audit_request(), propagating if non-zero. Note
that this is principally intended to allow the audit plugin to return
HDB_ERR_NOT_FOUND_HERE, which influences whether the KDC sends an error reply
or not. If the audit plugin also wishes to rewrite r->error_code, it must do so
separately.

Closes: #964
2022-03-03 10:10:37 +11:00
Stefan Metzmacher
8495f63bc3 kdc: provide kdc_request_get_explicit_armor_{clientdb,client,pac}()
_kdc_fast_check_armor_pac() already checks the PAC of the armor,
but it should also remember it if it's an TGS-REQ with explicit armor.

This will allow the kdc pac hooks to generate a compound identity PAC
with PAC_TYPE_DEVICE_INFO.

Signed-off-by: Stefan Metzmacher <metze@samba.org>

Closes: #967
2022-03-03 10:10:29 +11:00
Stefan Metzmacher
11d8a053f5 kdc-plugin: also pass astgs_request_t to the pac related functions
This is more consistent and allows the pac hooks to be more flexible.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-03-03 09:58:48 +11:00
Luke Howard
ed4fe65794 base: change ret fieldname to error_code in request struct 2022-01-20 17:23:24 +11:00
Nicolas Williams
b349b4add0 kdc: Fix recent dangling ptr; move more into r
As we move more and more state into astgs_request_t we need to be
careful not to leave locals and function arguments aliasing objects from
the astgs_request_t.
2022-01-18 15:32:05 -06:00
Nicolas Williams
fcba7a9fd1 kdc: Check errors from krb5_auth_con_getauthenticator() 2022-01-18 00:32:51 -06:00
Luke Howard
94ed961d02 kdc: make auditing API public
Samba plugins will need to use auditing API without including krb5-private.h,
so make the auditing APIs public.
2022-01-18 16:09:50 +11:00
Nicolas Williams
04b07ff8b6 kdc: Quiet a coverity warning (TGS) 2022-01-17 11:05:05 -06:00
Luke Howard
0e8c4ccc6e hdb: eliminate hdb_entry_ex
Remove hdb_entry_ex and revert to the original design of hdb_entry (except with
an additional context member in hdb_entry which is managed by the free_entry
method in HDB).
2022-01-15 18:54:57 +11:00
Luke Howard
c5551775e2 hdb: decorate HDB_entry with context member
Decorate HDB_entry with context and move free_entry callback into HDB structure
itself. Requires updating hdb_free_entry() signature to include HDB parameter.
A follow-up commit will consolidate hdb_entry_ex (which has a single hdb_entry
member) into hdb_entry.
2022-01-15 18:54:57 +11:00
Luke Howard
10fc7730d0 kdc: send request, not TGS, server name in TGS errors
Return the request server principal name in TGS errors rather than the TGS
server name.
2022-01-10 15:29:49 +11:00
Luke Howard
40e4a4df09 kdc: use astgs_request_t for client/server name (TGS)
Store the client and server principal name from the TGT and request
(respectively) in the astgs_request_t rather than using local variables.
2022-01-10 15:29:49 +11:00
Luke Howard
0287558838 kdc: move Services for User implementation out of krb5tgs.c
Move the Services for User (SFU/S4U) implementation -- protocol transition and
constrained delegation -- into its own compilation unit, with an interface that
only takes an astgs_request_t, so it can be easily factored out into a plugin
module in the future.

This refactoring is also careful to update all client names in the request
structure after the SFU/S4U validation has successfully completed.
2022-01-05 13:01:06 +11:00
Luke Howard
b27026996a base: s/addkv_{bool,number,object}/setkv
Now heim_audit_addkv() correctly supports multiple values, the other functions
that (by design) replace existing values with a single value should use the
heim_audit_setkv prefix.

A subsequent commit could add variants that support multiple values for
non-string types.
2022-01-04 09:07:10 +11:00
Luke Howard
a4c6b81ce9 kdc: add audit plugin API to windc API
Allow the windc plugin to also implement an audit callback. As part of this
change, both the HDB and windc audit function signatures are changed to return
void.
2022-01-03 16:17:01 +11:00
Luke Howard
98070b5eaa Revert "heimdal: handle referrals for 3 part DRSUAPI SPNs"
Active Directory/Samba-specific referral policy should be implemented by a
windc plugin, not in the main KDC code. It looks like it probably isn't
necessary at all if Samba wishes to bypass Heimdal's referral handling.

This reverts commit 6f0cafa6cf.
2022-01-03 16:17:01 +11:00
Luke Howard
3fa47f5a1a kdc: add referral_policy callback to windc plugin
Add a referral policy hook to the TGS as a more elegant way of resolving
referral detection for Samba). The hook can either rewrite the server_princ in
the request, or it can return an error to disable built-in referral processing.
2022-01-03 16:17:01 +11:00
Luke Howard
a9c6bc2bf2 kdc: audit "yes" boolean values as booleans
Audit boolean values that were logged as "yes" as boolean values; this will
change audit log values to "true" instead, so this patch may be omitted.
2022-01-02 15:25:52 +11:00
Luke Howard
93c8d57091 kdc: call HDB audit function in both AS and TGS
Call the HDB audit method, if present, in both AS and TGS, immediately prior to
generating an error response to send to the clinet.
2022-01-02 15:25:52 +11:00
Luke Howard
1e1c5dbbfc kdc: make error code available to audit function
Set r->ret in the request before calling the HDB audit method.
2022-01-02 15:25:52 +11:00
Luke Howard
cc0874d410 kdc: preserve value types in auditing
Preserve integer/boolean audit values as their native types; convert to strings
when logging only. This commit goes some way towards unifying the two auditing
APIs.
2022-01-02 15:25:52 +11:00
Nicolas Williams
fb3ea5b943 kdc: Add ret to common svc req elements
We're logging SUCCESS even when the KDC sends error replies.  That's
because we're returning success to process_request() even when we send
errors to clients.  The error we want to send to the client, and that we
succeed or fail to send it, are different statuses.

Also, further move things into `r` and out of function arguments.
2021-12-27 10:16:58 +11:00
Nicolas Williams
eeba89a1af kdc: Stop confusing the compiler 2021-12-23 21:06:38 -06:00
Luke Howard
f49e99e15f kdc: remove e_text argument to _kdc_encode_reply()
e_text is part of astgs_request_t, so it doesn't need to be an explicit
argument to _kdc_encode_reply()
2021-12-23 17:49:36 -06:00
Luke Howard
b6be850e0d kdc: remove outpadata from astgs_request_t
Remove the outpadata field from astgs_request_t, because it's not something we
wish to expose publically (yet it is something that Samba needs in the
client_access plugin API, to add Windows error information).

Instead, allocate rep->padata at the start of AS/TGS request handling, and
ensure it is valid for the lifetime of the request until it is encoded (at
which point it will be freed and set to NULL if zero length, to avoid sending a
zero length METHOD-DATA to the client).

(The previous approach of setting rep->padata to point to &r->outpadata was
fragile, because it required clearing the pointer before freeing the KDC-REP.)
2021-12-23 17:49:36 -06:00
Luke Howard
64dad876a4 kdc: simplify client_access windc plugin API
Make client_access plugin API take a single argument, astgs_request_t. Note: in
order to avoid making r->outpadata public (it's an internal buffer), but allow
Samba to modify the reply pa data, some pointer magic is required.
2021-12-23 17:49:36 -06:00
Luke Howard
e81bcb71f3 kdc: add finalize_reply API to windc plugin
Allow a windc plugin to finalize the KDC reply (including the encrypted ticket
and reply parts) before encoding for transmission.
2021-12-23 17:49:36 -06:00
Luke Howard
805ea5e0a0 kdc: use rep/et/ek fields in astgs_request_t
Use rep/et/ek fields in astgs_request_t that were previously present but not
globally used.
2021-12-23 17:49:36 -06:00
Luke Howard
2e8b172f38 kdc: move PAC into astgs_request_t structure 2021-12-23 17:49:36 -06:00
Luke Howard
5b7cf5d56f kdc: centralize include PAC logic
Add a helper function that returns TRUE if a PAC should be included in ticket
authorization data, that can be called from both AS and TGS paths.

Per [MS-KILE] 3.3.5.3, PACs are always included for TGTs; for service
tickets, policy is governed by whether the client explicitly requested
a PAC be omitted when requesting a TGT, or if the no-auth-data-reqd
flag is set on the service principal entry.
2021-12-23 13:52:15 +11:00
Luke Howard
317df4dbd4 kdc: remove pac_attributes_present field
Remove the unwieldy pac_attributes_present field from the request structure.

Instead, if PAC attributes are not present in the TGT, the default is to assume
they were set to KRB5_PAC_WAS_GIVEN_IMPLICITLY.
2021-12-23 13:26:40 +11:00
Luke Howard
f18c9e06a8 kdc: honor PAC_ATTRIBUTES in presented TGT
PACs are included when issuing TGTs, if there is no PAC_ATTRIBUTES buffer
(legacy behavior) or if the attributes buffer indicates the AS client requested
one.
2021-12-22 17:13:13 +11:00
Luke Howard
b4f3617964 kdc: don't add PAC_ATTRIBUTES PAC buffer for service tickets
Only include the PAC_ATTRIBUTES PAC info buffer if we are issuing a TGT, as its
contents are not relevant to application services. (The buffer contains a bit
indicating whether the client explicitly or implicitly requested a PAC.)
2021-12-22 16:38:52 +11:00
Luke Howard
f7964251ff kdc: support for PAC_ATTRIBUTES_INFO
Add PAC_ATTRIBUTES_INFO to the PAC. This info buffer indicates whether the user
explicitly requested a PAC be present or absent.

Note: this changes the windc plugin ABI.
2021-12-22 10:36:26 +11:00
Luke Howard
e50033aec2 kdc: add canonical principal name to authz data
Use the UPN_DNS_INFO buffer of the PAC to include the canonical principal name.

Arguably we should use AD-LOGIN-ALIAS as defined in RFC6806, but we may not
always know all the principal's aliases, and this approach allows us to share
application service logic with Windows.
2021-12-22 10:36:26 +11:00
Luke Howard
a3392b099e kdc: allow cross-realm FAST armor TGT
08e0305b introduced a patch to validate armor ticket PACs, but required that
the armor client principal was in the local realm (as it did not allow
_kdc_db_fetch() to fail).

Allow cross-realm FAST armor clients by using the same logic to look up the
client principal as the TGS itself does, i.e. use db_fetch_client() which
handles the case where the client is not local to the KDC.

Note: the armor PAC is only required to be validated when issuing a final,
non-referral service ticket, as this is the only point upon which device claims
should be inserted (according to my understanding).

Closes: #901
2021-12-18 15:09:38 +11:00
Luke Howard
e7588952ce kdc: add auth data type for synthetic principals
Add a new authorization data type to indicate a synthetic principal was used,
to allow synthetic clients acquired outside of PKINIT (e.g. with GSS-API
pre-authentication) to use the TGS.

Note: we continue to honor KRB5_AUTHDATA_INITIAL_VERIFIED_CAS to indicate that
it is OK for the client to be synthetic, even though it is only an indication
that the client *may* have been synthetic.
2021-12-18 15:09:38 +11:00
Nicolas Williams
27d6526e3a kdc: Check unparse_flags() result differently 2021-12-18 11:34:12 +11:00
Luke Howard
fc76c83ab1 Revert "tgs-rep: always return canonical realm when force_canonicalize set"
This reverts commit 6f81e4c93b.

This patch may have originated in Samba from before force_canonicalize was
supported. Because the server_principal argument to tgs_make_reply() is
canonicalized prior to calling (if the server entry has force_canonicalize
set), honoring it again in tgs_make_reply() is superfluous.
2021-12-18 11:32:49 +11:00
Isaac Boukris
6f81e4c93b tgs-rep: always return canonical realm when force_canonicalize set
This allows Samba to have a behaviour where
even if canonicalize flag is not set, the canonical realm
is returned, allowing a HDB module to require behaviour
that is the same as Windows.

Regression (for a HDB module wanting AD behaviour) was
introduced by commit:
378f34b4be

Signed-off-by: Isaac Boukris <iboukris@gmail.com>

[abartlet@samba.org Similar to Samba commit a9e6119ca0c2a78ef314c3162122539ee834aa04
 but made conditional on server->entry.flags.force_canonicalize to
 allow upstream submission]
2021-12-17 13:28:59 +11:00