samba.git
2 years agos4:kdc: Pass supported enctypes to samba_kdc_set_random_keys()
Andrew Bartlett [Tue, 22 Mar 2022 20:47:53 +0000 (09:47 +1300)]
s4:kdc: Pass supported enctypes to samba_kdc_set_random_keys()

We should not supprise the callers by returning more keys than we asked to
filter by and avoids duplicating the protected_users logic within
samba_kdc_set_fixed_keys().

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agos4:kdc: Pass supported enctypes to samba_kdc_set_fixed_keys()
Andrew Bartlett [Tue, 22 Mar 2022 20:47:53 +0000 (09:47 +1300)]
s4:kdc: Pass supported enctypes to samba_kdc_set_fixed_keys()

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agos4:kdc: teach samba_kdc_message2entry_keys() to handle old and older keys too
Stefan Metzmacher [Fri, 11 Feb 2022 20:42:06 +0000 (21:42 +0100)]
s4:kdc: teach samba_kdc_message2entry_keys() to handle old and older keys too

We return the requested kvno if given, otherwise we include the
old and older keys for CLIENT|FOR_AS_REQ or SDB_F_ADMIN_DATA lookups.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: add old and older keys to sdb_entry
Stefan Metzmacher [Tue, 22 Mar 2022 23:41:13 +0000 (00:41 +0100)]
s4:kdc: add old and older keys to sdb_entry

This is the first step to return the password history
in order to avoid badPwdCount updates for failing
pre-authentication with passwords from the recent history.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: pass flags and kvno down to samba_kdc_message2entry_keys()
Stefan Metzmacher [Fri, 19 Jul 2019 11:22:48 +0000 (13:22 +0200)]
s4:kdc: pass flags and kvno down to samba_kdc_message2entry_keys()

We need a ways to ask for a specific kvno if SDB_F_KVNO_SPECIFIED
is requested. And also include the old and older keys from
the password history in the next commits.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: finally remove unused 'struct sdb_entry_ex'
Stefan Metzmacher [Wed, 23 Mar 2022 03:29:20 +0000 (04:29 +0100)]
s4:kdc: finally remove unused 'struct sdb_entry_ex'

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: avoid using sdb_entry_ex in hdb_samba4_{first,next}key()
Stefan Metzmacher [Wed, 23 Mar 2022 03:17:01 +0000 (04:17 +0100)]
s4:kdc: avoid using sdb_entry_ex in hdb_samba4_{first,next}key()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: avoid using sdb_entry_ex in hdb_samba4_fetch_kvno()
Stefan Metzmacher [Wed, 23 Mar 2022 03:17:01 +0000 (04:17 +0100)]
s4:kdc: avoid using sdb_entry_ex in hdb_samba4_fetch_kvno()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: avoid using sdb_entry_ex in netr_samlogon_generic_logon()
Stefan Metzmacher [Wed, 23 Mar 2022 03:17:01 +0000 (04:17 +0100)]
s4:kdc: avoid using sdb_entry_ex in netr_samlogon_generic_logon()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: avoid using sdb_entry_ex in mit_samba_get_{first,next}key()
Stefan Metzmacher [Wed, 23 Mar 2022 03:17:01 +0000 (04:17 +0100)]
s4:kdc: avoid using sdb_entry_ex in mit_samba_get_{first,next}key()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: avoid using sdb_entry_ex in mit_samba_get_principal()
Stefan Metzmacher [Wed, 23 Mar 2022 03:17:01 +0000 (04:17 +0100)]
s4:kdc: avoid using sdb_entry_ex in mit_samba_get_principal()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: avoid using sdb_entry_ex in samba_wdc_reget_pac()
Stefan Metzmacher [Wed, 23 Mar 2022 03:17:01 +0000 (04:17 +0100)]
s4:kdc: avoid using sdb_entry_ex in samba_wdc_reget_pac()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:libnet: avoid using sdb_entry_ex and use sdb_entry directly
Stefan Metzmacher [Wed, 23 Mar 2022 03:17:01 +0000 (04:17 +0100)]
s4:libnet: avoid using sdb_entry_ex and use sdb_entry directly

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: samba_kdc_{first,next}key() only need sdb_entry
Stefan Metzmacher [Wed, 23 Mar 2022 02:43:25 +0000 (03:43 +0100)]
s4:kdc: samba_kdc_{first,next}key() only need sdb_entry

sdb_entry_ex will be removed shortly.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: samba_kdc_fetch() only needs sdb_entry
Stefan Metzmacher [Wed, 23 Mar 2022 02:43:25 +0000 (03:43 +0100)]
s4:kdc: samba_kdc_fetch() only needs sdb_entry

sdb_entry_ex will be removed shortly.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: remove unused sdb_entry_ex_to_kdb_entry_ex()
Stefan Metzmacher [Wed, 23 Mar 2022 03:00:09 +0000 (04:00 +0100)]
s4:kdc: remove unused sdb_entry_ex_to_kdb_entry_ex()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: use sdb_entry_to_krb5_db_entry() directly
Stefan Metzmacher [Wed, 23 Mar 2022 02:57:38 +0000 (03:57 +0100)]
s4:kdc: use sdb_entry_to_krb5_db_entry() directly

We should avoid sdb_entry_ex, as it will be removed soon.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: remove unused sdb_entry_ex_to_hdb_entry_ex()
Stefan Metzmacher [Wed, 23 Mar 2022 03:00:09 +0000 (04:00 +0100)]
s4:kdc: remove unused sdb_entry_ex_to_hdb_entry_ex()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: use sdb_entry_to_hdb_entry() directly
Stefan Metzmacher [Wed, 23 Mar 2022 02:57:38 +0000 (03:57 +0100)]
s4:kdc: use sdb_entry_to_hdb_entry() directly

We should avoid sdb_entry_ex, as it will be removed soon.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: hdb_samba4_fetch_fast_cookie() don't need sdb_entry_ex
Stefan Metzmacher [Wed, 23 Mar 2022 02:52:43 +0000 (03:52 +0100)]
s4:kdc: hdb_samba4_fetch_fast_cookie() don't need sdb_entry_ex

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: samba_kdc_seq() only needs sdb_entry
Stefan Metzmacher [Wed, 23 Mar 2022 02:43:25 +0000 (03:43 +0100)]
s4:kdc: samba_kdc_seq() only needs sdb_entry

sdb_entry_ex will be removed shortly.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: samba_kdc_fetch_server() only needs sdb_entry
Stefan Metzmacher [Wed, 23 Mar 2022 02:43:25 +0000 (03:43 +0100)]
s4:kdc: samba_kdc_fetch_server() only needs sdb_entry

sdb_entry_ex will be removed shortly.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: samba_kdc_fetch_krbtgt() only needs sdb_entry
Stefan Metzmacher [Wed, 23 Mar 2022 02:43:25 +0000 (03:43 +0100)]
s4:kdc: samba_kdc_fetch_krbtgt() only needs sdb_entry

sdb_entry_ex will be removed shortly.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: samba_kdc_fetch_client() only needs sdb_entry
Stefan Metzmacher [Wed, 23 Mar 2022 02:43:25 +0000 (03:43 +0100)]
s4:kdc: samba_kdc_fetch_client() only needs sdb_entry

sdb_entry_ex will be removed shortly.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: samba_kdc_lookup_realm() only needs sdb_entry
Stefan Metzmacher [Wed, 23 Mar 2022 02:43:25 +0000 (03:43 +0100)]
s4:kdc: samba_kdc_lookup_realm() only needs sdb_entry

sdb_entry_ex will be removed shortly.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: only pass sdb_entry to samba_kdc_message2entry()
Stefan Metzmacher [Wed, 23 Mar 2022 02:36:31 +0000 (03:36 +0100)]
s4:kdc: only pass sdb_entry to samba_kdc_message2entry()

It no longer needs sdb_entry_ex.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: only pass sdb_entry to samba_kdc_trust_message2entry()
Stefan Metzmacher [Wed, 23 Mar 2022 02:36:31 +0000 (03:36 +0100)]
s4:kdc: only pass sdb_entry to samba_kdc_trust_message2entry()

It no longer needs sdb_entry_ex.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: only ZERO and free sdb_entry in samba_kdc_trust_message2entry()
Stefan Metzmacher [Wed, 23 Mar 2022 02:29:21 +0000 (03:29 +0100)]
s4:kdc: only ZERO and free sdb_entry in samba_kdc_trust_message2entry()

sdb_entry_ex only contains sdb_entry, so this is still doing
the same, but we want to remove sdb_entry_ex soon.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: s/entry_ex->entry\./entry->/g in samba_kdc_trust_message2entry()
Stefan Metzmacher [Wed, 23 Mar 2022 02:25:12 +0000 (03:25 +0100)]
s4:kdc: s/entry_ex->entry\./entry->/g in samba_kdc_trust_message2entry()

We should avoid using entry_ex->entry as sdb_entry_ex will be removed.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: only ZERO and free sdb_entry in samba_kdc_message2entry()
Stefan Metzmacher [Wed, 23 Mar 2022 02:29:21 +0000 (03:29 +0100)]
s4:kdc: only ZERO and free sdb_entry in samba_kdc_message2entry()

sdb_entry_ex only contains sdb_entry, so this is still doing
the same, but we want to remove sdb_entry_ex soon.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: s/entry_ex->entry\./entry->/g in samba_kdc_message2entry()
Stefan Metzmacher [Wed, 23 Mar 2022 02:25:12 +0000 (03:25 +0100)]
s4:kdc: s/entry_ex->entry\./entry->/g in samba_kdc_message2entry()

We should avoid using entry_ex->entry as sdb_entry_ex will be removed.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: only pass sdb_entry to samba_kdc_message2entry_keys()
Stefan Metzmacher [Wed, 23 Mar 2022 02:16:32 +0000 (03:16 +0100)]
s4:kdc: only pass sdb_entry to samba_kdc_message2entry_keys()

sdb_entry_ex will be removed as it just contains sdb_entry.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: remove unused principal argument to samba_kdc_trust_message2entry()
Stefan Metzmacher [Thu, 3 Feb 2022 13:12:02 +0000 (14:12 +0100)]
s4:kdc: remove unused principal argument to samba_kdc_trust_message2entry()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: split out a samba_kdc_fill_user_keys() helper function
Stefan Metzmacher [Fri, 11 Feb 2022 20:46:28 +0000 (21:46 +0100)]
s4:kdc: split out a samba_kdc_fill_user_keys() helper function

This will simplify further changes, e.g. asking for a specific kvno
or returning the password history in order to prevent
badPwdCount updates with passwords in the history.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: remove Primary:Kerberos usage from samba_kdc_message2entry_keys()
Stefan Metzmacher [Tue, 8 Feb 2022 13:25:53 +0000 (14:25 +0100)]
s4:kdc: remove Primary:Kerberos usage from samba_kdc_message2entry_keys()

Most likely the kerberos libraries don't support DES anymore, so
there's no point in exposing them at all.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: only pass keys to samba_kdc_set_random_keys()
Stefan Metzmacher [Tue, 22 Mar 2022 17:11:44 +0000 (18:11 +0100)]
s4:kdc: only pass keys to samba_kdc_set_random_keys()

This prepares the removal of sdb_entry_ex.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: only pass sdb_keys to samba_kdc_set_fixed_keys()
Stefan Metzmacher [Tue, 22 Mar 2022 17:09:33 +0000 (18:09 +0100)]
s4:kdc: only pass sdb_keys to samba_kdc_set_fixed_keys()

This prepares the removal of sdb_entry_ex.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: add a samba_kdc_sort_keys() function using TYPESAFE_QSORT()
Stefan Metzmacher [Tue, 8 Feb 2022 14:08:57 +0000 (15:08 +0100)]
s4:kdc: add a samba_kdc_sort_keys() function using TYPESAFE_QSORT()

This is better than calloc/free each time.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: expose a sdb_entry_free() function
Stefan Metzmacher [Tue, 22 Mar 2022 16:59:19 +0000 (17:59 +0100)]
s4:kdc: expose a sdb_entry_free() function

We'll remove sdb_entry_ex soon.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: expose sdb_entry_to_hdb_entry() function
Stefan Metzmacher [Tue, 22 Mar 2022 16:55:54 +0000 (17:55 +0100)]
s4:kdc: expose sdb_entry_to_hdb_entry() function

We'll remove sdb_entry_ex soon.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: expose a sdb_entry_to_krb5_db_entry() function
Stefan Metzmacher [Tue, 22 Mar 2022 16:55:54 +0000 (17:55 +0100)]
s4:kdc: expose a sdb_entry_to_krb5_db_entry() function

We'll remove sdb_entry_ex soon.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: let samba_kdc_entry take references to sdb_entry and kdc_entry
Stefan Metzmacher [Tue, 22 Mar 2022 16:04:22 +0000 (17:04 +0100)]
s4:kdc: let samba_kdc_entry take references to sdb_entry and kdc_entry

kdc_entry can be hdb_entry or krb5_db_entry.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: make the logic between ZERO_STRUCTP(entry_ex) and sdb_free_entry(entry_ex...
Stefan Metzmacher [Tue, 8 Feb 2022 15:50:14 +0000 (16:50 +0100)]
s4:kdc: make the logic between ZERO_STRUCTP(entry_ex) and sdb_free_entry(entry_ex) clearer

samba_kdc_[trust_]message2entry() always starts with
ZERO_STRUCTP(entry_ex) and cleans up on error with
sdb_free_entry(entry_ex), leaving a cleared structure again.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: let sdb_entry have a typed samba_kdc_entry pointer
Stefan Metzmacher [Tue, 22 Mar 2022 15:35:58 +0000 (16:35 +0100)]
s4:kdc: let sdb_entry have a typed samba_kdc_entry pointer

Both layers are owned by us so there's no need for an void
pointer.

This simplifies the code a lot and allows further cleanups.
Eventually we can remove sdb_entry_ex and only use sdb_entry,
as Heimdal also removed hdb_entry_ex.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: remove unused samba_kdc_entry->entry_ex
Stefan Metzmacher [Tue, 22 Mar 2022 15:57:57 +0000 (16:57 +0100)]
s4:kdc: remove unused samba_kdc_entry->entry_ex

It will only ever point to an sdb_entry_ex
and becomes a stale pointer fast, as
sdb_free_entry() called before any talloc_free()
can happen (with a destructor still set).

Note the talloc parent of samba_kdc_entry
is the samba_kdc_db_context longterm context.

The next commits will fill samba_kdc_entry_destructor
with logic again, but for now remove the unused code.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: split out a sdb_keys_free() helper function
Stefan Metzmacher [Fri, 11 Feb 2022 20:04:44 +0000 (21:04 +0100)]
s4:kdc: split out a sdb_keys_free() helper function

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: rename free_sdb_key() as public sdb_key_free() function
Stefan Metzmacher [Fri, 11 Feb 2022 20:04:44 +0000 (21:04 +0100)]
s4:kdc: rename free_sdb_key() as public sdb_key_free() function

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: make free_sdb_entry() static
Stefan Metzmacher [Fri, 11 Feb 2022 19:58:03 +0000 (20:58 +0100)]
s4:kdc: make free_sdb_entry() static

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: let samba_kdc_entry_destructor() call sdb_free_entry()
Stefan Metzmacher [Fri, 11 Feb 2022 19:55:25 +0000 (20:55 +0100)]
s4:kdc: let samba_kdc_entry_destructor() call sdb_free_entry()

It's basically the same as free_sdb_entry(), but the next
step will make free_sdb_entry() private.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: don't leak salt in free_sdb_key()
Stefan Metzmacher [Fri, 11 Feb 2022 20:13:24 +0000 (21:13 +0100)]
s4:kdc: don't leak salt in free_sdb_key()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: call krb5_free_keyblock_contents() in free_sdb_key()
Stefan Metzmacher [Fri, 11 Feb 2022 19:56:17 +0000 (20:56 +0100)]
s4:kdc: call krb5_free_keyblock_contents() in free_sdb_key()

This is much clearer than doing it in sdb_free_entry() already.
It also simplifies the next cleanups.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: remove unused sdb_entry_ex->free_entry()
Stefan Metzmacher [Tue, 22 Mar 2022 12:59:58 +0000 (13:59 +0100)]
s4:kdc: remove unused sdb_entry_ex->free_entry()

It seems we need to take a closer look at the
memory hierachy of the sdb_entry related code.

I'll check that during the next commits,
but for now just remove use the unused hook.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:libnet: ask for SDB_F_ADMIN_DATA in order to create a keytab entry
Stefan Metzmacher [Wed, 23 Mar 2022 01:14:46 +0000 (02:14 +0100)]
s4:libnet: ask for SDB_F_ADMIN_DATA in order to create a keytab entry

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:libnet: sdb_free_entry() already clears everything
Stefan Metzmacher [Mon, 21 Feb 2022 22:39:14 +0000 (23:39 +0100)]
s4:libnet: sdb_free_entry() already clears everything

There's no need to know about '.free_entry'.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: let sdb_free_entry clear sdb_entry_ex at the end
Stefan Metzmacher [Tue, 22 Mar 2022 12:31:31 +0000 (13:31 +0100)]
s4:kdc: let sdb_free_entry clear sdb_entry_ex at the end

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: let sdb_entry_ex_to_krb5_db_entry() initialize 'k' at the beginning
Stefan Metzmacher [Thu, 17 Feb 2022 09:59:45 +0000 (10:59 +0100)]
s4:kdc: let sdb_entry_ex_to_krb5_db_entry() initialize 'k' at the beginning

This is clearer and make further changes easier.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: let sdb_entry_to_hdb_entry() initialize *h at the beginning
Stefan Metzmacher [Thu, 17 Feb 2022 09:59:45 +0000 (10:59 +0100)]
s4:kdc: let sdb_entry_to_hdb_entry() initialize *h at the beginning

This is clearer and make further changes easier.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: remove unused mkvno from sdb_key
Stefan Metzmacher [Fri, 11 Feb 2022 20:04:57 +0000 (21:04 +0100)]
s4:kdc: remove unused mkvno from sdb_key

This is not related to the kvno of the key,
the mkvno tells the HDB layer that the keys need to
be decrypted with a master key (with the given [m]kvno).

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:kdc: strictly have 2 16-bit parts in krbtgt kvnos
Stefan Metzmacher [Wed, 16 Feb 2022 13:11:10 +0000 (14:11 +0100)]
s4:kdc: strictly have 2 16-bit parts in krbtgt kvnos

Even if the msDS-KeyVersionNumber of the main krbtgt
account if larger than 65535, we need to have
the 16 upper bits all zero in order to avoid
mixing the keys with an RODC.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agosmbd: Make an if-statement in ReadDirName() a bit more readable
Volker Lendecke [Sat, 12 Mar 2022 11:47:03 +0000 (12:47 +0100)]
smbd: Make an if-statement in ReadDirName() a bit more readable

Align to make the () structure more obvious

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed Mar 23 17:53:09 UTC 2022 on sn-devel-184

2 years agosmbclient: strequal() -> ISDOT/ISDOTDOT
Volker Lendecke [Sat, 12 Mar 2022 11:40:29 +0000 (12:40 +0100)]
smbclient: strequal() -> ISDOT/ISDOTDOT

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2 years agosmbd: Use ISDOT/ISDOTDOT in ReadDirName()
Volker Lendecke [Sat, 12 Mar 2022 11:47:54 +0000 (12:47 +0100)]
smbd: Use ISDOT/ISDOTDOT in ReadDirName()

With those macros, we check n[0] twice now, but I think the compiler
should either optimize that out or if it can't this will be in the CPU
cache, so the second check should be practially free. I can't imagine
this makes any difference but the better readability.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2 years agosmbd: Fix a misleading comment
Volker Lendecke [Sun, 13 Mar 2022 14:22:50 +0000 (15:22 +0100)]
smbd: Fix a misleading comment

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2 years agosmbd: Avoid an "else"
Volker Lendecke [Sun, 13 Mar 2022 14:58:03 +0000 (15:58 +0100)]
smbd: Avoid an "else"

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2 years agolib: Use talloc_zero, save a ZERO_STRUCT
Volker Lendecke [Mon, 21 Mar 2022 08:13:09 +0000 (09:13 +0100)]
lib: Use talloc_zero, save a ZERO_STRUCT

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2 years agolib: Add a pair of {}
Volker Lendecke [Mon, 21 Mar 2022 08:12:44 +0000 (09:12 +0100)]
lib: Add a pair of {}

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2 years agolib: Slightly simplify add_interface()
Volker Lendecke [Mon, 21 Mar 2022 08:12:02 +0000 (09:12 +0100)]
lib: Slightly simplify add_interface()

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2 years agosmbd: Make non_widelink_open() robust for non-cwd dirfsp
Volker Lendecke [Wed, 9 Mar 2022 11:58:40 +0000 (12:58 +0100)]
smbd: Make non_widelink_open() robust for non-cwd dirfsp

If you pass in dirfsp!=conn->cwd_fsp and a stream fsp, we don't chdir
to the parent pathname, and thus we also don't overwrite
fsp->base_fsp.

fsp->base_fsp!=NULL is thus the wrong condition to restore the
original base fsp name: If we open a stream with a non-cwd_fsp dirfsp,
we would overwrite fsp->base_fsp->fsp_name with NULL.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2 years agoreplace: add explicit function pointer casting from dlsym() to avoid warnings
Stefan Metzmacher [Tue, 15 Feb 2022 14:09:08 +0000 (15:09 +0100)]
replace: add explicit function pointer casting from dlsym() to avoid warnings

This avoids a lot of warnings on AIX.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Wed Mar 23 13:27:45 UTC 2022 on sn-devel-184

2 years agolib/replace: Do not typedef int bool
Andrew Bartlett [Tue, 22 Mar 2022 03:12:00 +0000 (16:12 +1300)]
lib/replace: Do not typedef int bool

We need a genuine boolean type, as otherwise expressions like

bool foo = (4 & 4);
if (foo == true) {
exit(1);
} else {
exit(2);
}

could evaluate differently on non-modern platforms, and
that would be a real pain to debug.

_Bool and bool are in C99

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Wed Mar 23 12:31:47 UTC 2022 on sn-devel-184

2 years agogitlab-ci: Drop Debian 10
Andreas Schneider [Fri, 18 Mar 2022 15:31:54 +0000 (16:31 +0100)]
gitlab-ci: Drop Debian 10

It should be enough to build on the latest Debian version. We have older
Ubuntu versions already.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agogitlab-ci: Update to openSUSE 15.3
Andreas Schneider [Fri, 18 Mar 2022 15:29:43 +0000 (16:29 +0100)]
gitlab-ci: Update to openSUSE 15.3

This drops openSUSE 15.1 and 15.2 to save some CI resources.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agogitlab-ci: Drop Fedora 34
Andreas Schneider [Fri, 18 Mar 2022 15:24:01 +0000 (16:24 +0100)]
gitlab-ci: Drop Fedora 34

It should be enough to run on the latest Fedora version. This should save us
some CI minutes. We have CentOS runners and I would prefer to add CentOS9
Stream.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agogitlab-ci: Use Ubuntu 20.04 for Coverity
Andreas Schneider [Fri, 18 Mar 2022 15:22:39 +0000 (16:22 +0100)]
gitlab-ci: Use Ubuntu 20.04 for Coverity

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agogitlab-ci: Remove unused variable for ubuntu1604
Andreas Schneider [Fri, 18 Mar 2022 15:33:00 +0000 (16:33 +0100)]
gitlab-ci: Remove unused variable for ubuntu1604

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agos3: smbd: Don't allow setting the delete on close bit on a directory if it contains...
Jeremy Allison [Mon, 21 Mar 2022 20:50:56 +0000 (13:50 -0700)]
s3: smbd: Don't allow setting the delete on close bit on a directory if it contains non-visible files and "delete veto files = no".

Remove knownfail.

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

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Mar 22 17:48:25 UTC 2022 on sn-devel-184

2 years agos3: torture: Add 2 new tests SMB2-DEL-ON-CLOSE-NONWRITE-DELETE-NO, SMB2-DEL-ON-CLOSE...
Jeremy Allison [Mon, 21 Mar 2022 20:45:25 +0000 (13:45 -0700)]
s3: torture: Add 2 new tests SMB2-DEL-ON-CLOSE-NONWRITE-DELETE-NO, SMB2-DEL-ON-CLOSE-NONWRITE-DELETE-YES.

We currently allow setting the delete on close bit for
a directory containing only explicitly hidden/vetoed files
in the case where "delete veto files = yes" *and*
"delete veto files = no". For the "delete veto files = no"
case we should be denying setting the delete on close bit
when the client tries to set it (that's the only time Windows
looks at the bit and returns an error to the user). We
already do the in the dangling symlink case, we just
missed it in the !is_visible_fsp() case.

Mark SMB2-DEL-ON-CLOSE-NONWRITE-DELETE-NO as knownfail
for now.

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

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
2 years agoWHATSNEW: Mention our matrix room as well
Andrew Bartlett [Thu, 17 Mar 2022 05:47:48 +0000 (18:47 +1300)]
WHATSNEW: Mention our matrix room as well

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Jule Anger <janger@samba.org>
Autobuild-Date(master): Mon Mar 21 13:52:06 UTC 2022 on sn-devel-184

2 years agoWHATSNEW: IRC is irc.libera.chat according to https://www.samba.org/samba/irc.html
Thomas Debesse [Tue, 15 Feb 2022 13:11:45 +0000 (14:11 +0100)]
WHATSNEW: IRC is irc.libera.chat according to https://samba.org/samba/irc.html

Signed-off-by: Thomas Debesse <dev@illwieckz.net>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agos4:rpc_server/samr: Use extended DN when searching for user
Joseph Sutton [Thu, 3 Mar 2022 01:54:00 +0000 (14:54 +1300)]
s4:rpc_server/samr: Use extended DN when searching for user

Switch to dsdb_search() for looking up the user for changing the
password, and specify that we want extended DNs. Using the SID or GUID
avoids a race condition if the DN of the user changes.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Fri Mar 18 12:45:17 UTC 2022 on sn-devel-184

2 years agosamba-tool group: Add --special parameter to add predefined special group
Joseph Sutton [Thu, 10 Feb 2022 04:14:56 +0000 (17:14 +1300)]
samba-tool group: Add --special parameter to add predefined special group

This allows default security groups that have been added since Windows
Server 2008 R2, such as Protected Users, to be created in pre-existing
domains. An error message is generated if a group already exists with
the same name, DN, or SID.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agofunctionalprep.sh: Add test for samba-tool add group --special
Joseph Sutton [Thu, 3 Mar 2022 07:59:48 +0000 (20:59 +1300)]
functionalprep.sh: Add test for samba-tool add group --special

Test that we can add the special Protected Users group, and that we get
an appropriate error message when attempting to add it a second time.

We add these tests here so that we can make use of an old provision that
does not already have the Protected Users group added.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/sam: Ensure that Protected Users group cannot be deleted
Joseph Sutton [Wed, 2 Feb 2022 02:47:05 +0000 (15:47 +1300)]
tests/sam: Ensure that Protected Users group cannot be deleted

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agos4:rpc_server/samr: Simplify lp_ctx expression
Joseph Sutton [Thu, 3 Feb 2022 02:17:40 +0000 (15:17 +1300)]
s4:rpc_server/samr: Simplify lp_ctx expression

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agos4:auth: Disable NTLM authentication for Protected Users
Joseph Sutton [Tue, 1 Feb 2022 08:08:44 +0000 (21:08 +1300)]
s4:auth: Disable NTLM authentication for Protected Users

We also move the authentication to after checking whether the user is
protected, so that if a user in the Protected Users group tries to
authenticate with a wrong password, the bag password count is not
incremented and the account is not locked out. This does not match
MS-APDS, but matches the behaviour of Windows.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agos4:kdc: Add KDC support for Protected Users group
Joseph Sutton [Wed, 2 Feb 2022 04:08:41 +0000 (17:08 +1300)]
s4:kdc: Add KDC support for Protected Users group

Accounts in the Protected Users group acting as clients lack support for
the RC4 encryption type. TGTs issued to such accounts have a lifetime
restricted to four hours, and are unable to be proxied or forwarded.

To determine at lookup time whether a client account is a member of
Protected Users, we now also create an auth_user_info_dc structure when
creating the database entry for an AS-REQ, rather than only when
creating a PAC for a TGT, or when recreating the PAC from an RODC-issued
TGT.

This means that the user's groups are now expanded even for AS-REQs that
result in an error (such as a PREAUTH_REQUIRED error), but this is
required to be able to correctly determine the account's available
encryption types, which are needed soon after fetching the user account.

Currently, the TGT lifetime may exceed four hours (for Heimdal
specifically). This may happen if PKINIT is used, and either the
pkinit_max_life_from_cert_extension option is TRUE and
pkinit_max_life_bound is greater than four hours, or
pkinit_max_life_from_cert is greater than four hours.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agos4:kdc: Add function to get user_info_dc from database
Joseph Sutton [Thu, 17 Mar 2022 22:13:40 +0000 (11:13 +1300)]
s4:kdc: Add function to get user_info_dc from database

The resulting user_info_dc is kept in the 'samba_kdc_entry' structure,
so it can be reused between calls.

This allows us to simplify samba_kdc_get_pac_blobs(), as it no longer
need to return a user_info_dc structure.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agos4:kdc: simplify samba_kdc_message2entry by using data_blob_string_const("computer")
Stefan Metzmacher [Tue, 8 Feb 2022 15:49:35 +0000 (16:49 +0100)]
s4:kdc: simplify samba_kdc_message2entry by using data_blob_string_const("computer")

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2 years agodsdb/common: Add helper function for determining if account is in Protected Users...
Joseph Sutton [Wed, 2 Feb 2022 22:11:56 +0000 (11:11 +1300)]
dsdb/common: Add helper function for determining if account is in Protected Users group

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agos4:provision_users.ldif: Add Protected Users group
Joseph Sutton [Tue, 1 Feb 2022 08:04:40 +0000 (21:04 +1300)]
s4:provision_users.ldif: Add Protected Users group

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/passwords: Test that LDAP password changes work for Protected Users
Joseph Sutton [Wed, 9 Feb 2022 00:57:47 +0000 (13:57 +1300)]
tests/passwords: Test that LDAP password changes work for Protected Users

We want to disable SAMR password changes for Protected Users, but need
to ensure that other methods of changing the password still work.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/password_lockout: Test NTLM and SAMR password changes with Protected Users
Joseph Sutton [Wed, 9 Feb 2022 00:50:10 +0000 (13:50 +1300)]
tests/password_lockout: Test NTLM and SAMR password changes with Protected Users

Test that NTLM and SAMR password changes cannot be used for Protected
Users, and that lockouts are not triggered for attempting to use them.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/krb5: Add tests for the Protected Users group
Joseph Sutton [Tue, 1 Feb 2022 08:00:16 +0000 (21:00 +1300)]
tests/krb5: Add tests for the Protected Users group

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agoauth/credentials: Add encrypt_samr_password()
Joseph Sutton [Wed, 23 Feb 2022 07:57:44 +0000 (20:57 +1300)]
auth/credentials: Add encrypt_samr_password()

This method encrypts a samr_Password structure with the current session
key, which allows for interactive SamLogon from Python.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agoselftest/dbcheck: Fix up msDS-RevealedUsers links with deleted target DN
Joseph Sutton [Fri, 11 Feb 2022 03:30:13 +0000 (16:30 +1300)]
selftest/dbcheck: Fix up msDS-RevealedUsers links with deleted target DN

Replicating test accounts to the RODC and then deleting them caused
stale msDS-RevealedUsers links to remain in the database.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/krb5: Add helper function to modify ticket flags
Joseph Sutton [Mon, 7 Feb 2022 23:15:36 +0000 (12:15 +1300)]
tests/krb5: Add helper function to modify ticket flags

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/krb5: Remove unused import
Joseph Sutton [Tue, 1 Feb 2022 07:59:15 +0000 (20:59 +1300)]
tests/krb5: Remove unused import

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/krb5: Add account to cleanup list before adding it to database
Joseph Sutton [Tue, 1 Feb 2022 07:57:22 +0000 (20:57 +1300)]
tests/krb5: Add account to cleanup list before adding it to database

This ensures accounts are still cleaned up if a test fails before adding
it to the cleanup list.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/krb5: Add more encryption type constants
Joseph Sutton [Tue, 1 Feb 2022 07:55:56 +0000 (20:55 +1300)]
tests/krb5: Add more encryption type constants

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/krb5: Remove accounts in reverse order of addition
Joseph Sutton [Tue, 1 Feb 2022 07:54:39 +0000 (20:54 +1300)]
tests/krb5: Remove accounts in reverse order of addition

This prevents problems if accounts are added as children of other
accounts.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>