samba.git
2 years agoCVE-2020-25719 mit-samba: If we use client_princ, always lookup the db entry
Andreas Schneider [Mon, 12 Jul 2021 09:20:29 +0000 (11:20 +0200)]
CVE-2020-25719 mit-samba: If we use client_princ, always lookup the db entry

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

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
[abartlet@samba.org backported due to support for MIT KDB < 10
 in Samba 4.14]

2 years agoCVE-2020-25719 mit-samba: Add ks_free_principal()
Andreas Schneider [Wed, 14 Jul 2021 12:51:34 +0000 (14:51 +0200)]
CVE-2020-25719 mit-samba: Add ks_free_principal()

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

[abartlet@samba.org As submitted in patch to Samba bugzilla
 to address this issue as https://attachments.samba.org/attachment.cgi?id=16724
 on overall bug https://bugzilla.samba.org/show_bug.cgi?id=14725]

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2 years agoCVE-2020-25719 mit-samba: Make ks_get_principal() internally public
Andreas Schneider [Mon, 12 Jul 2021 10:32:12 +0000 (12:32 +0200)]
CVE-2020-25719 mit-samba: Make ks_get_principal() internally public

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

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 pytest: Raise an error when adding a dynamic test that would overwrite...
Joseph Sutton [Wed, 27 Oct 2021 06:18:20 +0000 (19:18 +1300)]
CVE-2020-25722 pytest: Raise an error when adding a dynamic test that would overwrite an existing test

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 s4/torture: Expect additional PAC buffers
Joseph Sutton [Thu, 28 Oct 2021 22:00:38 +0000 (11:00 +1300)]
CVE-2020-25719 s4/torture: Expect additional PAC buffers

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Add tests for mismatched names with user-to-user
Joseph Sutton [Tue, 26 Oct 2021 08:09:32 +0000 (21:09 +1300)]
CVE-2020-25719 tests/krb5: Add tests for mismatched names with user-to-user

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Add test for user-to-user with no sname
Joseph Sutton [Tue, 26 Oct 2021 08:06:58 +0000 (21:06 +1300)]
CVE-2020-25719 tests/krb5: Add test for user-to-user with no sname

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Add tests for requester SID PAC buffer
Joseph Sutton [Tue, 26 Oct 2021 08:04:25 +0000 (21:04 +1300)]
CVE-2020-25719 tests/krb5: Add tests for requester SID PAC buffer

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Add tests for PAC-REQUEST padata
Joseph Sutton [Tue, 26 Oct 2021 08:19:44 +0000 (21:19 +1300)]
CVE-2020-25719 tests/krb5: Add tests for PAC-REQUEST padata

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Add tests for PAC attributes buffer
Joseph Sutton [Tue, 26 Oct 2021 08:02:08 +0000 (21:02 +1300)]
CVE-2020-25719 tests/krb5: Add tests for PAC attributes buffer

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Add expected parameters to cache key for obtaining tickets
Joseph Sutton [Tue, 26 Oct 2021 22:18:36 +0000 (11:18 +1300)]
CVE-2020-25719 tests/krb5: Add expected parameters to cache key for obtaining tickets

If multiple calls to get_tgt() or get_service_ticket() specify different
expected parameters, we want to perform the request again so that the
checking can be performed, rather than reusing a previously obtained
ticket and potentially skipping checks.

It should be fine to cache tickets with the same expected parameters, as
tickets that fail to be obtained will not be stored in the cache, so the
checking will happen for every call.

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Add EXPECT_PAC environment variable to expect pac from...
Joseph Sutton [Tue, 26 Oct 2021 07:47:24 +0000 (20:47 +1300)]
CVE-2020-25719 tests/krb5: Add EXPECT_PAC environment variable to expect pac from all TGS tickets

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Add testing for PAC_TYPE_REQUESTER_SID PAC buffer
Joseph Sutton [Tue, 26 Oct 2021 07:51:13 +0000 (20:51 +1300)]
CVE-2020-25719 tests/krb5: Add testing for PAC_TYPE_REQUESTER_SID PAC buffer

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Add testing for PAC_TYPE_ATTRIBUTES_INFO PAC buffer
Joseph Sutton [Tue, 26 Oct 2021 07:50:09 +0000 (20:50 +1300)]
CVE-2020-25719 tests/krb5: Add testing for PAC_TYPE_ATTRIBUTES_INFO PAC buffer

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Add _modify_tgt() method for modifying already obtained...
Joseph Sutton [Tue, 26 Oct 2021 21:25:08 +0000 (10:25 +1300)]
CVE-2020-25719 tests/krb5: Add _modify_tgt() method for modifying already obtained tickets

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Extend _get_tgt() method to allow more modifications to...
Joseph Sutton [Tue, 26 Oct 2021 08:12:12 +0000 (21:12 +1300)]
CVE-2020-25719 tests/krb5: Extend _get_tgt() method to allow more modifications to tickets

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: tests/krb5: Adjust expected error code for S4U2Self no...
Joseph Sutton [Tue, 26 Oct 2021 08:08:34 +0000 (21:08 +1300)]
CVE-2020-25719 tests/krb5: tests/krb5: Adjust expected error code for S4U2Self no-PAC tests

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Adjust expected error codes for user-to-user tests
Joseph Sutton [Tue, 26 Oct 2021 08:20:51 +0000 (21:20 +1300)]
CVE-2020-25719 tests/krb5: Adjust expected error codes for user-to-user tests

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Adjust PAC tests to prepare for new PAC_ATTRIBUTES_INFO...
Joseph Sutton [Tue, 26 Oct 2021 08:15:53 +0000 (21:15 +1300)]
CVE-2020-25719 tests/krb5: Adjust PAC tests to prepare for new PAC_ATTRIBUTES_INFO buffer

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Use correct credentials for user-to-user tests
Joseph Sutton [Tue, 26 Oct 2021 08:14:45 +0000 (21:14 +1300)]
CVE-2020-25719 tests/krb5: Use correct credentials for user-to-user tests

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Return ticket from _tgs_req()
Joseph Sutton [Tue, 26 Oct 2021 08:05:08 +0000 (21:05 +1300)]
CVE-2020-25719 tests/krb5: Return ticket from _tgs_req()

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Expect 'renew-till' element when renewing a TGT
Joseph Sutton [Tue, 26 Oct 2021 07:51:46 +0000 (20:51 +1300)]
CVE-2020-25719 tests/krb5: Expect 'renew-till' element when renewing a TGT

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Don't expect a kvno for user-to-user
Joseph Sutton [Tue, 26 Oct 2021 07:51:34 +0000 (20:51 +1300)]
CVE-2020-25719 tests/krb5: Don't expect a kvno for user-to-user

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Allow update_pac_checksums=True if the PAC is not present
Joseph Sutton [Tue, 26 Oct 2021 07:47:53 +0000 (20:47 +1300)]
CVE-2020-25719 tests/krb5: Allow update_pac_checksums=True if the PAC is not present

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 tests/krb5: Provide expected parameters for both AS-REQs in get_tgt()
Joseph Sutton [Tue, 26 Oct 2021 07:44:45 +0000 (20:44 +1300)]
CVE-2020-25719 tests/krb5: Provide expected parameters for both AS-REQs in get_tgt()

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 krb5pac.idl: Add PAC_REQUESTER_SID PAC buffer type
Joseph Sutton [Tue, 26 Oct 2021 07:33:49 +0000 (20:33 +1300)]
CVE-2020-25719 krb5pac.idl: Add PAC_REQUESTER_SID PAC buffer type

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 krb5pac.idl: Add PAC_ATTRIBUTES_INFO PAC buffer type
Joseph Sutton [Tue, 26 Oct 2021 07:33:38 +0000 (20:33 +1300)]
CVE-2020-25719 krb5pac.idl: Add PAC_ATTRIBUTES_INFO PAC buffer type

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25718 tests/krb5: Fix indentation
Joseph Sutton [Tue, 26 Oct 2021 07:56:10 +0000 (20:56 +1300)]
CVE-2020-25718 tests/krb5: Fix indentation

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 selftest: Adapt ldap.py tests to new objectClass restrictions
Joseph Sutton [Thu, 28 Oct 2021 23:20:49 +0000 (12:20 +1300)]
CVE-2020-25722 selftest: Adapt ldap.py tests to new objectClass restrictions

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/util: remove unused dsdb_get_single_valued_attr()
Douglas Bagnall [Thu, 21 Oct 2021 00:49:28 +0000 (13:49 +1300)]
CVE-2020-25722 s4/dsdb/util: remove unused dsdb_get_single_valued_attr()

Nobody uses it now. It never really did what it said it did. Almost
every use was wrong. It was a trap.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/pwd_hash: rework pwdLastSet bypass
Douglas Bagnall [Wed, 20 Oct 2021 04:20:54 +0000 (17:20 +1300)]
CVE-2020-25722 s4/dsdb/pwd_hash: rework pwdLastSet bypass

This tightens the logic a bit, in that a message with trailing DELETE
elements is no longer accepted when the bypass flag is set. In any case
this is an unlikely scenario as this is an internal flag set by a private
control in pdb_samba_dsdb_replace_by_sam().

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/pwd_hash: password_hash_bypass gets all values
Douglas Bagnall [Wed, 20 Oct 2021 04:19:42 +0000 (17:19 +1300)]
CVE-2020-25722 s4/dsdb/pwd_hash: password_hash_bypass gets all values

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: samldb_fsmo_role_owner_check() wants one value
Douglas Bagnall [Wed, 20 Oct 2021 23:52:07 +0000 (12:52 +1300)]
CVE-2020-25722 s4/dsdb/samldb: samldb_fsmo_role_owner_check() wants one value

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: samldb_fsmo_role_owner_check checks values
Douglas Bagnall [Wed, 20 Oct 2021 04:18:21 +0000 (17:18 +1300)]
CVE-2020-25722 s4/dsdb/samldb: samldb_fsmo_role_owner_check checks values

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: samldb_service_principal_names_change checks values
Douglas Bagnall [Wed, 20 Oct 2021 04:18:10 +0000 (17:18 +1300)]
CVE-2020-25722 s4/dsdb/samldb: samldb_service_principal_names_change checks values

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: samldb_group_type_change() checks all values
Douglas Bagnall [Wed, 20 Oct 2021 04:17:50 +0000 (17:17 +1300)]
CVE-2020-25722 s4/dsdb/samldb: samldb_group_type_change() checks all values

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: samldb_lockout_time() checks all values
Douglas Bagnall [Wed, 20 Oct 2021 04:17:31 +0000 (17:17 +1300)]
CVE-2020-25722 s4/dsdb/samldb: samldb_lockout_time() checks all values

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: samldb_pwd_last_set_change() checks all values
Douglas Bagnall [Wed, 20 Oct 2021 04:16:34 +0000 (17:16 +1300)]
CVE-2020-25722 s4/dsdb/samldb: samldb_pwd_last_set_change() checks all values

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb _user_account_control_change() always add final value
Douglas Bagnall [Wed, 20 Oct 2021 04:15:43 +0000 (17:15 +1300)]
CVE-2020-25722 s4/dsdb/samldb _user_account_control_change() always add final value

dsdb_get_single_valued_attr() was finding the last non-delete element for
userAccountControl and changing its value to the computed value.
Unfortunately, the last non-delete element might not be the last element,
and a subsequent delete might remove it.

Instead we just add a replace on the end.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: samldb_user_account_control_change() checks all values
Douglas Bagnall [Wed, 20 Oct 2021 04:15:00 +0000 (17:15 +1300)]
CVE-2020-25722 s4/dsdb/samldb: samldb_user_account_control_change() checks all values

There is another call to dsdb_get_expected_new_values() in this function
that we change in the next commit.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: samldb_prim_group_change() checks all values
Douglas Bagnall [Wed, 20 Oct 2021 04:14:05 +0000 (17:14 +1300)]
CVE-2020-25722 s4/dsdb/samldb: samldb_prim_group_change() checks all values

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: samldb_schema_add_handle_mapiid() checks all values
Douglas Bagnall [Wed, 20 Oct 2021 04:13:35 +0000 (17:13 +1300)]
CVE-2020-25722 s4/dsdb/samldb: samldb_schema_add_handle_mapiid() checks all values

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: samldb_schema_add_handle_linkid() checks all values
Douglas Bagnall [Wed, 20 Oct 2021 04:12:49 +0000 (17:12 +1300)]
CVE-2020-25722 s4/dsdb/samldb: samldb_schema_add_handle_linkid() checks all values

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: samldb_sam_accountname_valid_check() check all values
Douglas Bagnall [Fri, 22 Oct 2021 01:52:49 +0000 (14:52 +1300)]
CVE-2020-25722 s4/dsdb/samldb: samldb_sam_accountname_valid_check() check all values

Using dsdb_get_expected_new_values().

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: samldb_get_single_valued_attr() check all values
Douglas Bagnall [Wed, 20 Oct 2021 04:10:44 +0000 (17:10 +1300)]
CVE-2020-25722 s4/dsdb/samldb: samldb_get_single_valued_attr() check all values

using dsdb_get_expected_new_values().

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb modules: add dsdb_get_expected_new_values()
Douglas Bagnall [Wed, 20 Oct 2021 04:09:21 +0000 (17:09 +1300)]
CVE-2020-25722 s4/dsdb modules: add dsdb_get_expected_new_values()

This function collects a superset of all the new values for the specified
attribute that could result from an ldb add or modify message.

In most cases -- where there is a single add or modify -- the exact set
of added values is returned, and this is done reasonably efficiently
using the existing element. Where it gets complicated is when there are
multiple elements for the same attribute in a message. Anything added
before a replace or delete will be included in these results but may not
end up in the database if the message runs its course. Examples:

   sequence           result
1. ADD                the element is returned (exact)
2. REPLACE            the element is returned (exact)
3. ADD, ADD           both elements are concatenated together (exact)
4. ADD, REPLACE       both elements are concatenated together (superset)
5. REPLACE, ADD       both elements are concatenated together (exact)
6. ADD, DEL, ADD      adds are concatenated together (superset)
7. REPLACE, REPLACE   both concatenated (superset)
8. DEL, ADD           last element is returned (exact)

Why this? In the past we have treated dsdb_get_single_valued_attr() as if
it returned the complete set of possible database changes, when in fact it
only returned the last non-delete. That is, it could have missed values
in examples 3-7 above.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: reject SPN with too few/many components
Douglas Bagnall [Fri, 22 Oct 2021 03:03:18 +0000 (16:03 +1300)]
CVE-2020-25722 s4/dsdb/samldb: reject SPN with too few/many components

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: check for SPN uniqueness, including aliases
Douglas Bagnall [Fri, 22 Oct 2021 00:14:32 +0000 (13:14 +1300)]
CVE-2020-25722 s4/dsdb/samldb: check for SPN uniqueness, including aliases

Not only should it not be possible to add a servicePrincipalName that
is already present in the domain, it should not be possible to add one
that is implied by an entry in sPNMappings, unless the user is adding
an alias to another SPN and has rights to alter that one.

For example, with the default sPNMappings, cifs/ is an alias pointing to
host/, meaning if there is no cifs/example.com SPN, the host/example.com
one will be used instead. A user can add the cifs/example.com SPN only
if they can also change the host/example.com one (because adding the
cifs/ effectively changes the host/). The reverse is refused in all cases,
unless they happen to be on the same object. That is, if there is a
cifs/example.com SPN, there is no way to add host/example.com elsewhere.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: check sAMAccountName for illegal characters
Douglas Bagnall [Fri, 22 Oct 2021 02:27:25 +0000 (15:27 +1300)]
CVE-2020-25722 s4/dsdb/samldb: check sAMAccountName for illegal characters

This only for the real account name, not the account name implicit in
a UPN. It doesn't matter if a UPN implies an illegal sAMAccountName,
since that is not going to conflict with a real one.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: check for clashes in UPNs/samaccountnames
Douglas Bagnall [Fri, 22 Oct 2021 00:17:34 +0000 (13:17 +1300)]
CVE-2020-25722 s4/dsdb/samldb: check for clashes in UPNs/samaccountnames

We already know duplicate sAMAccountNames and UserPrincipalNames are bad,
but we also have to check against the values these imply in each other.

For example, imagine users with SAM account names "Alice" and "Bob" in
the realm "example.com". If they do not have explicit UPNs, by the logic
of MS-ADTS 5.1.1.1.1 they use the implict UPNs "alice@example.com" and
"bob@example.com", respectively. If Bob's UPN gets set to
"alice@example.com", it will clash with Alice's implicit one.

Therefore we refuse to allow a UPN that implies an existing SAM account
name and vice versa.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: unique_attr_check uses samldb_get_single_valued_attr()
Douglas Bagnall [Fri, 22 Oct 2021 00:16:30 +0000 (13:16 +1300)]
CVE-2020-25722 s4/dsdb/samldb: unique_attr_check uses samldb_get_single_valued_attr()

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/samldb: add samldb_get_single_valued_attr() helper
Douglas Bagnall [Fri, 22 Oct 2021 01:12:25 +0000 (14:12 +1300)]
CVE-2020-25722 s4/dsdb/samldb: add samldb_get_single_valued_attr() helper

This takes a string of logic out of samldb_unique_attr_check() that we
are going to need in other places, and that would be very tedious to
repeat.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/cracknames: add comment pointing to samldb spn handling
Douglas Bagnall [Thu, 12 Aug 2021 09:53:16 +0000 (21:53 +1200)]
CVE-2020-25722 s4/cracknames: add comment pointing to samldb spn handling

These need to stay a little bit in sync. The reverse comment is there.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 pytest: test setting servicePrincipalName over ldap
Douglas Bagnall [Fri, 6 Aug 2021 00:03:18 +0000 (12:03 +1200)]
CVE-2020-25722 pytest: test setting servicePrincipalName over ldap

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 pytest: test sAMAccountName/userPrincipalName over ldap
Douglas Bagnall [Mon, 13 Sep 2021 02:15:09 +0000 (14:15 +1200)]
CVE-2020-25722 pytest: test sAMAccountName/userPrincipalName over ldap

Because the sam account name + the dns host name is used as the
default user principal name, we need to check for collisions between
these. Fixes are coming in upcoming patches.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 blackbox/upgrades tests: ignore SPN for ldapcmp
Douglas Bagnall [Thu, 28 Oct 2021 00:07:01 +0000 (13:07 +1300)]
CVE-2020-25722 blackbox/upgrades tests: ignore SPN for ldapcmp

We need to have the SPNs there before someone else nabs them, which
makes the re-provisioned old releases different from the reference
versions that we keep for this comparison.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/provision: add host/ SPNs at the start
Douglas Bagnall [Wed, 27 Oct 2021 20:45:36 +0000 (09:45 +1300)]
CVE-2020-25722 s4/provision: add host/ SPNs at the start

There are two reasons for this. Firstly, leaving SPNs unclaimed is
dangerous, as someone else could grab them first. Secondly, in some
circumstances (self join) we try to add a DNS/ SPN a little bit later
in provision. Under the rules we are introducing for CVE-2020-25722,
this will make our later attempts to add HOST/ fail.

This causes a few errors in samba4.blackbox.dbcheck.* tests, which
assert that revivified old domains match stored reference versions.
Now they don't, because they have servicePrincipalNames.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 tests: blackbox samba-tool spn non-admin test
Douglas Bagnall [Wed, 1 Sep 2021 06:35:02 +0000 (18:35 +1200)]
CVE-2020-25722 tests: blackbox samba-tool spn non-admin test

It is soon going to be impossible to add duplicate SPNs (short of
going behind DSDB's back on the local filesystem). Our test of adding
SPNs on non-admin users doubled as the test for adding a duplicate (using
--force). As --force is gone, we add these tests on Guest after the SPN
on Administrator is gone.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 samba-tool spn add: remove --force option
Douglas Bagnall [Thu, 26 Aug 2021 23:36:42 +0000 (11:36 +1200)]
CVE-2020-25722 samba-tool spn add: remove --force option

This did not actually *force* the creation of a duplicate SPN, it just
ignored the client-side check for the existing copy. Soon we are going
to enforce SPN uniqueness on the server side, and this --force will not
work. This will make the --force test fail, and if that tests fail, so
will others that depend the duplicate values. So we remove those tests.

It is wrong-headed to try to make duplicate SPNs in any case, which is
probably why there is no sign of anyone ever having used this option.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 samba-tool spn: accept -H for database url
Douglas Bagnall [Wed, 28 Jul 2021 05:38:50 +0000 (05:38 +0000)]
CVE-2020-25722 samba-tool spn: accept -H for database url

Following the convention and making testing easier

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/cracknames: lookup_spn_alias doesn't need krb5 context
Douglas Bagnall [Tue, 10 Aug 2021 23:02:36 +0000 (23:02 +0000)]
CVE-2020-25722 s4/cracknames: lookup_spn_alias doesn't need krb5 context

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4/dsdb/cracknames: always free tmp_ctx in spn_alias
Douglas Bagnall [Wed, 11 Aug 2021 04:56:07 +0000 (16:56 +1200)]
CVE-2020-25722 s4/dsdb/cracknames: always free tmp_ctx in spn_alias

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 pytest: assertRaisesLdbError invents a message if you're lazy
Douglas Bagnall [Sun, 24 Oct 2021 02:18:05 +0000 (15:18 +1300)]
CVE-2020-25722 pytest: assertRaisesLdbError invents a message if you're lazy

This makes it easier to convert tests that don't have good messages.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 pytests: add reverse lookup dict for LDB error codes
Douglas Bagnall [Sun, 3 Oct 2021 23:56:42 +0000 (12:56 +1300)]
CVE-2020-25722 pytests: add reverse lookup dict for LDB error codes

You can give ldb_err() it a number, an LdbError, or a sequence of
numbers, and it will return the corresponding strings. Examples:

ldb_err(68)       # "LDB_ERR_ENTRY_ALREADY_EXISTS"
LDB_ERR_LUT[68]   # "LDB_ERR_ENTRY_ALREADY_EXISTS"

expected = (ldb.ERR_INSUFFICIENT_ACCESS_RIGHTS,
            ldb.ERR_INVALID_CREDENTIALS)
try:
    foo()
except ldb.LdbError as e:
    self.fail(f"got {ldb_err(e)}, expected one of {ldb_err(expected)}")

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 Check for all errors from acl_check_extended_right() in acl_check_spn()
Andrew Bartlett [Mon, 1 Nov 2021 04:21:16 +0000 (17:21 +1300)]
CVE-2020-25722 Check for all errors from acl_check_extended_right() in acl_check_spn()

We should not fail open on error.

BUG:  https://bugzilla.samba.org/show_bug.cgi?id=14876
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2 years agoCVE-2020-25722 Check all elements in acl_check_spn() not just the first one
Andrew Bartlett [Mon, 1 Nov 2021 04:19:29 +0000 (17:19 +1300)]
CVE-2020-25722 Check all elements in acl_check_spn() not just the first one

Thankfully we are aleady in a loop over all the message elements in
acl_modify() so this is an easy and safe change to make.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14876
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2 years agoCVE-2020-25722: s4-acl: Make sure Control Access Rights honor the Applies-to attribute
Nadezhda Ivanova [Mon, 18 Oct 2021 11:27:59 +0000 (14:27 +0300)]
CVE-2020-25722: s4-acl: Make sure Control Access Rights honor the Applies-to attribute

Validate Writes and Control Access Rights only grant access if the
object is of the type listed in the Right's appliesTo attribute. For
example, even though a Validated-SPN access may be granted to a user
object in the SD, it should only pass if the object is of class
computer This patch enforces the appliesTo attribute classes for
access checks from within the ldb stack.

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

Signed-off-by: Nadezhda Ivanova <nivanova@symas.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722: s4-acl: test Control Access Rights honor the Applies-to attribute
Nadezhda Ivanova [Mon, 25 Oct 2021 11:54:56 +0000 (14:54 +0300)]
CVE-2020-25722: s4-acl: test Control Access Rights honor the Applies-to attribute

Validate Writes and Control Access Rights should only grant access if the
object is of the type listed in the Right's appliesTo attribute.
Tests to verify this behavior

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

Signed-off-by: Nadezhda Ivanova <nivanova@symas.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25722 s4:dsdb:tests: Add missing self.fail() calls
Joseph Sutton [Fri, 8 Oct 2021 02:49:31 +0000 (15:49 +1300)]
CVE-2020-25722 s4:dsdb:tests: Add missing self.fail() calls

Without these calls the tests could pass if an expected error did not
occur.

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
[abartlet@samba.org Included in backport as changing ACLs while
 ACL tests are not checking for unexpected success would be bad]

2 years agoCVE-2020-25722 Add test for SPN deletion followed by addition
Joseph Sutton [Mon, 18 Oct 2021 01:07:41 +0000 (14:07 +1300)]
CVE-2020-25722 Add test for SPN deletion followed by addition

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
[abartlet@samba.org Removed transaction hooks, these do nothing over
 remote LDAP]

2 years agoCVE-2020-25717: s3:auth: simplify make_session_info_krb5() by removing unused arguments
Stefan Metzmacher [Fri, 8 Oct 2021 16:03:04 +0000 (18:03 +0200)]
CVE-2020-25717: s3:auth: simplify make_session_info_krb5() by removing unused arguments

This is only ever be called in standalone mode with an MIT realm,
so we don't have a PAC/info3 structure.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:auth: simplify get_user_from_kerberos_info() by removing the unuse...
Stefan Metzmacher [Fri, 8 Oct 2021 15:59:59 +0000 (17:59 +0200)]
CVE-2020-25717: s3:auth: simplify get_user_from_kerberos_info() by removing the unused logon_info argument

This code is only every called in standalone mode on a MIT realm,
it means we never have a PAC and we also don't have winbindd arround.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:auth: let auth3_generate_session_info_pac() reject a PAC in standa...
Stefan Metzmacher [Tue, 5 Oct 2021 16:12:49 +0000 (18:12 +0200)]
CVE-2020-25717: s3:auth: let auth3_generate_session_info_pac() reject a PAC in standalone mode

We should be strict in standalone mode, that we only support MIT realms
without a PAC in order to keep the code sane.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: selftest: configure 'ktest' env with winbindd and idmap_autorid
Stefan Metzmacher [Tue, 5 Oct 2021 15:14:01 +0000 (17:14 +0200)]
CVE-2020-25717: selftest: configure 'ktest' env with winbindd and idmap_autorid

The 'ktest' environment was/is designed to test kerberos in an active
directory member setup. It was created at a time we wanted to test
smbd/winbindd with kerberos without having the source4 ad dc available.

This still applies to testing the build with system krb5 libraries
but without relying on a running ad dc.

As a domain member setup requires a running winbindd, we should test it
that way, in order to reflect a valid setup.

As a side effect it provides a way to demonstrate that we can accept
smb connections authenticated via kerberos, but no connection to
a domain controller! In order get this working offline, we need an
idmap backend with ID_TYPE_BOTH support, so we use 'autorid', which
should be the default choice.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:auth: let auth3_generate_session_info_pac() delegate everything...
Stefan Metzmacher [Mon, 4 Oct 2021 17:42:20 +0000 (19:42 +0200)]
CVE-2020-25717: s3:auth: let auth3_generate_session_info_pac() delegate everything to make_server_info_wbcAuthUserInfo()

This consolidates the code paths used for NTLMSSP and Kerberos!

I checked what we were already doing for NTLMSSP, which is this:

a) source3/auth/auth_winbind.c calls wbcAuthenticateUserEx()
b) as a domain member we require a valid response from winbindd,
   otherwise we'll return NT_STATUS_NO_LOGON_SERVERS
c) we call make_server_info_wbcAuthUserInfo(), which internally
   calls make_server_info_info3()
d) auth_check_ntlm_password() calls
   smb_pam_accountcheck(unix_username, rhost), where rhost
   is only an ipv4 or ipv6 address (without reverse dns lookup)
e) from auth3_check_password_send/auth3_check_password_recv()
   server_returned_info will be passed to auth3_generate_session_info(),
   triggered by gensec_session_info(), which means we'll call into
   create_local_token() in order to transform auth_serversupplied_info
   into auth_session_info.

For Kerberos gensec_session_info() will call
auth3_generate_session_info_pac() via the gensec_generate_session_info_pac()
helper function. The current logic is this:

a) gensec_generate_session_info_pac() is the function that
   evaluates the 'gensec:require_pac', which defaulted to 'no'
   before.
b) auth3_generate_session_info_pac() called
   wbcAuthenticateUserEx() in order to pass the PAC blob
   to winbindd, but only to prime its cache, e.g. netsamlogon cache
   and others. Most failures were just ignored.
c) If the PAC blob is available, it extracted the PAC_LOGON_INFO
   from it.
d) Then we called the horrible get_user_from_kerberos_info() function:
   - It uses a first part of the tickets principal name (before the @)
     as username and combines that with the 'logon_info->base.logon_domain'
     if the logon_info (PAC) is present.
   - As a fallback without a PAC it's tries to ask winbindd for a mapping
     from realm to netbios domain name.
   - Finally is falls back to using the realm as netbios domain name
   With this information is builds 'userdomain+winbind_separator+useraccount'
   and calls map_username() followed by smb_getpwnam() with create=true,
   Note this is similar to the make_server_info_info3() => check_account()
   => smb_getpwnam() logic under 3.
   - It also calls smb_pam_accountcheck(), but may pass the reverse DNS lookup name
     instead of the ip address as rhost.
   - It does some MAP_TO_GUEST_ON_BAD_UID logic and auto creates the
     guest account.
e) We called create_info3_from_pac_logon_info()
f) make_session_info_krb5() calls gets called and triggers this:
   - If get_user_from_kerberos_info() mapped to guest, it calls
     make_server_info_guest()
   - If create_info3_from_pac_logon_info() created a info3 from logon_info,
     it calls make_server_info_info3()
   - Without a PAC it tries pdb_getsampwnam()/make_server_info_sam() with
     a fallback to make_server_info_pw()
   From there it calls create_local_token()

I tried to change auth3_generate_session_info_pac() to behave similar
to auth_winbind.c together with auth3_generate_session_info() as
a domain member, as we now rely on a PAC:

a) As domain member we require a PAC and always call wbcAuthenticateUserEx()
   and require a valid response!
b) we call make_server_info_wbcAuthUserInfo(), which internally
   calls make_server_info_info3(). Note make_server_info_info3()
   handles MAP_TO_GUEST_ON_BAD_UID and make_server_info_guest()
   internally.
c) Similar to auth_check_ntlm_password() we now call
   smb_pam_accountcheck(unix_username, rhost), where rhost
   is only an ipv4 or ipv6 address (without reverse dns lookup)
d) From there it calls create_local_token()

As standalone server (in an MIT realm) we continue
with the already existing code logic, which works without a PAC:
a) we keep smb_getpwnam() with create=true logic as it
   also requires an explicit 'add user script' option.
b) In the following commits we assert that there's
   actually no PAC in this mode, which means we can
   remove unused and confusing code.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:ntlm_auth: let ntlm_auth_generate_session_info_pac() base the...
Stefan Metzmacher [Tue, 21 Sep 2021 10:44:01 +0000 (12:44 +0200)]
CVE-2020-25717: s3:ntlm_auth: let ntlm_auth_generate_session_info_pac() base the name on the PAC LOGON_INFO only

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:ntlm_auth: fix memory leaks in ntlm_auth_generate_session_info_pac()
Stefan Metzmacher [Tue, 21 Sep 2021 10:27:28 +0000 (12:27 +0200)]
CVE-2020-25717: s3:ntlm_auth: fix memory leaks in ntlm_auth_generate_session_info_pac()

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 CVE-2020-25717: s4:auth: remove unused auth_generate_session_info_prin...
Stefan Metzmacher [Mon, 11 Oct 2021 21:17:19 +0000 (23:17 +0200)]
CVE-2020-25719 CVE-2020-25717: s4:auth: remove unused auth_generate_session_info_principal()

We'll require a PAC at the main gensec layer already.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25719 CVE-2020-25717: auth/gensec: always require a PAC in domain mode ...
Stefan Metzmacher [Tue, 5 Oct 2021 16:11:57 +0000 (18:11 +0200)]
CVE-2020-25719 CVE-2020-25717: auth/gensec: always require a PAC in domain mode (DC or member)

AD domains always provide a PAC unless UF_NO_AUTH_DATA_REQUIRED is set
on the service account, which can only be explicitly configured,
but that's an invalid configuration!

We still try to support standalone servers in an MIT realm,
as legacy setup.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
[jsutton@samba.org Removed knownfail entries]

2 years agoCVE-2020-25717: Add FreeIPA domain controller role
Alexander Bokovoy [Wed, 11 Nov 2020 16:50:45 +0000 (18:50 +0200)]
CVE-2020-25717: Add FreeIPA domain controller role

As we want to reduce use of 'classic domain controller' role but FreeIPA
relies on it internally, add a separate role to mark FreeIPA domain
controller role.

It means that role won't result in ROLE_STANDALONE.

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

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

Signed-off-by: Alexander Bokovoy <ab@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:auth: don't let create_local_token depend on !winbind_ping()
Stefan Metzmacher [Mon, 4 Oct 2021 16:03:55 +0000 (18:03 +0200)]
CVE-2020-25717: s3:auth: don't let create_local_token depend on !winbind_ping()

We always require a running winbindd on a domain member, so
we should better fail a request instead of silently alter
the behaviour, which results in a different unix token, just
because winbindd might be restarted.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:lib: add lp_allow_trusted_domains() logic to is_allowed_domain()
Stefan Metzmacher [Tue, 21 Sep 2021 11:13:52 +0000 (13:13 +0200)]
CVE-2020-25717: s3:lib: add lp_allow_trusted_domains() logic to is_allowed_domain()

is_allowed_domain() is a central place we already use to
trigger NT_STATUS_AUTHENTICATION_FIREWALL_FAILED, so
we can add additional logic there.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:auth: remove fallbacks in smb_getpwnam()
Ralph Boehme [Fri, 8 Oct 2021 10:33:16 +0000 (12:33 +0200)]
CVE-2020-25717: s3:auth: remove fallbacks in smb_getpwnam()

So far we tried getpwnam("DOMAIN\account") first and
always did a fallback to getpwnam("account") completely
ignoring the domain part, this just causes problems
as we mix "DOMAIN1\account", "DOMAIN2\account",
and "account"!

As we require a running winbindd for domain member setups
we should no longer do a fallback to just "account" for
users served by winbindd!

For users of the local SAM don't use this code path,
as check_sam_security() doesn't call check_account().

The only case where smb_getpwnam("account") happens is
when map_username() via ("username map [script]")  mapped
"DOMAIN\account" to something without '\', but that is
explicitly desired by the admin.

Note: use 'git show -w'

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

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

Signed-off-by: Ralph Boehme <slow@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:auth: no longer let check_account() autocreate local users
Stefan Metzmacher [Fri, 8 Oct 2021 16:08:20 +0000 (18:08 +0200)]
CVE-2020-25717: s3:auth: no longer let check_account() autocreate local users

So far we autocreated local user accounts based on just the
account_name (just ignoring any domain part).

This only happens via a possible 'add user script',
which is not typically defined on domain members
and on NT4 DCs local users already exist in the
local passdb anyway.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:auth: we should not try to autocreate the guest account
Stefan Metzmacher [Fri, 8 Oct 2021 15:40:30 +0000 (17:40 +0200)]
CVE-2020-25717: s3:auth: we should not try to autocreate the guest account

We should avoid autocreation of users as much as possible.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:auth: Check minimum domain uid
Samuel Cabrero [Tue, 28 Sep 2021 08:45:11 +0000 (10:45 +0200)]
CVE-2020-25717: s3:auth: Check minimum domain uid

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

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

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
[abartlet@samba.org Removed knownfail on advice from metze]

2 years agoCVE-2020-25717: s3:auth: let auth3_generate_session_info_pac() forward the low level...
Stefan Metzmacher [Fri, 8 Oct 2021 17:57:18 +0000 (19:57 +0200)]
CVE-2020-25717: s3:auth: let auth3_generate_session_info_pac() forward the low level errors

Mapping everything to ACCESS_DENIED makes it hard to debug problems,
which may happen because of our more restrictive behaviour in future.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: selftest: Add a test for the new 'min domain uid' parameter
Samuel Cabrero [Tue, 5 Oct 2021 14:56:06 +0000 (16:56 +0200)]
CVE-2020-25717: selftest: Add a test for the new 'min domain uid' parameter

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

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

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
[abartlet@samba.org Fixed knowfail per instruction from metze]

2 years agoCVE-2020-25717: selftest: Add ad_member_no_nss_wb environment
Samuel Cabrero [Tue, 5 Oct 2021 10:31:29 +0000 (12:31 +0200)]
CVE-2020-25717: selftest: Add ad_member_no_nss_wb environment

This environment creates an AD member that doesn't have
'nss_winbind' configured, while winbindd is still started.

For testing we map a DOMAIN\root user to the local root
account and unix token of the local root user.

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

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

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
[abartlet@samba.org backported to Samba 4.14 without offline
 tests in Samba3.pm]

2 years agoCVE-2020-25717: loadparm: Add new parameter "min domain uid"
Samuel Cabrero [Tue, 28 Sep 2021 08:43:40 +0000 (10:43 +0200)]
CVE-2020-25717: loadparm: Add new parameter "min domain uid"

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

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

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
[abartlet@samba.org Backported from master/4.15 due to
 conflicts with other new parameters]

2 years agoCVE-2020-25717: auth/ntlmssp: start with authoritative = 1
Stefan Metzmacher [Tue, 26 Oct 2021 15:42:41 +0000 (17:42 +0200)]
CVE-2020-25717: auth/ntlmssp: start with authoritative = 1

This is not strictly needed, but makes it easier to audit
that we don't miss important places.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:auth: start with authoritative = 1
Stefan Metzmacher [Tue, 26 Oct 2021 15:42:41 +0000 (17:42 +0200)]
CVE-2020-25717: s3:auth: start with authoritative = 1

This is not strictly needed, but makes it easier to audit
that we don't miss important places.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:rpcclient: start with authoritative = 1
Stefan Metzmacher [Tue, 26 Oct 2021 15:42:41 +0000 (17:42 +0200)]
CVE-2020-25717: s3:rpcclient: start with authoritative = 1

This is not strictly needed, but makes it easier to audit
that we don't miss important places.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:torture: start with authoritative = 1
Stefan Metzmacher [Tue, 26 Oct 2021 15:42:41 +0000 (17:42 +0200)]
CVE-2020-25717: s3:torture: start with authoritative = 1

This is not strictly needed, but makes it easier to audit
that we don't miss important places.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:ntlm_auth: start with authoritative = 1
Stefan Metzmacher [Tue, 26 Oct 2021 15:42:41 +0000 (17:42 +0200)]
CVE-2020-25717: s3:ntlm_auth: start with authoritative = 1

This is not strictly needed, but makes it easier to audit
that we don't miss important places.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s4:auth_simple: start with authoritative = 1
Stefan Metzmacher [Tue, 26 Oct 2021 15:42:41 +0000 (17:42 +0200)]
CVE-2020-25717: s4:auth_simple: start with authoritative = 1

This is not strictly needed, but makes it easier to audit
that we don't miss important places.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s4:smb_server: start with authoritative = 1
Stefan Metzmacher [Tue, 26 Oct 2021 15:42:41 +0000 (17:42 +0200)]
CVE-2020-25717: s4:smb_server: start with authoritative = 1

This is not strictly needed, but makes it easier to audit
that we don't miss important places.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s4:torture: start with authoritative = 1
Stefan Metzmacher [Tue, 26 Oct 2021 15:42:41 +0000 (17:42 +0200)]
CVE-2020-25717: s4:torture: start with authoritative = 1

This is not strictly needed, but makes it easier to audit
that we don't miss important places.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s4:auth/ntlm: make sure auth_check_password() defaults to r->out...
Stefan Metzmacher [Mon, 4 Oct 2021 15:29:34 +0000 (17:29 +0200)]
CVE-2020-25717: s4:auth/ntlm: make sure auth_check_password() defaults to r->out.authoritative = true

We need to make sure that temporary failures don't trigger a fallback
to the local SAM that silently ignores the domain name part for users.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2 years agoCVE-2020-25717: s3:winbindd: make sure we default to r->out.authoritative = true
Stefan Metzmacher [Mon, 4 Oct 2021 15:29:34 +0000 (17:29 +0200)]
CVE-2020-25717: s3:winbindd: make sure we default to r->out.authoritative = true

We need to make sure that temporary failures don't trigger a fallback
to the local SAM that silently ignores the domain name part for users.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>