summaryrefslogtreecommitdiff
path: root/libcli
AgeCommit message (Collapse)AuthorFilesLines
2023-11-30libcli/smb: Call correct function to get HMAC output lengthJoseph Sutton1-2/+2
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30libcli/auth: Call correct function to get HMAC output lengthJoseph Sutton1-1/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30libcli/auth: Use correct enumeration constantJoseph Sutton1-1/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-30libcli/smb: Include missing headersJoseph Sutton1-0/+5
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: note suboptimality of conditional ACE Contains operatorsDouglas Bagnall1-0/+4
The Contains and Any_of operators could use a sorted comparison like compare_composites_via_sort(), rather than O(n²) nested loops. But that would involve amount of quite fiddly work that I am not starting on now. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Mon Nov 27 23:38:13 UTC 2023 on atb-devel-224
2023-11-27libcli/security: comparability check: claim members are of one typeDouglas Bagnall1-1/+12
We know from the way claims are defined, and from the code that checks sortedness and sets the flag. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: shift comparability check to shortcut exitsDouglas Bagnall1-24/+23
The ordinary comparison path, using the sorted arrays, already implicitly checks for comparability. We only need this when we're leaving early. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: add shortcuts for conditional ACE compareDouglas Bagnall1-0/+55
If the number of members does not match in certain ways we can say the sets are not equal without comparing the members. We first need to check for comparability, though, so that we can return an error if things aren't comparable. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: improve conditional ACE composite comparisonDouglas Bagnall1-42/+331
We had the comparison method wrong. Composites are compared as sets or flabby sets, depending on their origin. Until now we compared them as something a bit like sets, but not quite, in a maximally inefficient way. Claims are always sets, and the left hand side is always a claim, but literal composites on the right hand side can be multi-sets (containing duplicate values). When it comes to comparison, composites are reduced down to sets. To do the comparison we sort each side and compare in order. The fact that either side might ask for case-sensitive comparison (if it is a claim) is an interesting complication. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: separate out claim_v1_to_ace_composite_unchecked()Douglas Bagnall3-31/+62
For SDDL Resource ACE conversions we don't want to check too much claim validity so that a semi-invalid ACE can round-trip through deserialisation and serialisation. This is because Windows allows it, but also because if the check puts the values in a sorted order that makes the round-trip less round (that is, the return string is semantically the same but possibly different in byte order). The validity we're talking about is mostly uniqueness. For example `S:(RA;;;;;WD;("foo",TU,0,7,5,7))` has two 7s, and that would be invalid as a claim, but this is not checked while in ACE form. On the other hand `S:(RA;;;;;WD;("foo",TU,0,3,2))` is valid, but the return string will have 3 and 2 reversed when the check is made. We prefer the ACE to stay the same while it is just being an ACE. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: avoid leak on SDDL encode failureDouglas Bagnall1-1/+4
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: claim_v1_to_ace_token(): avoid unnecessary re-sortDouglas Bagnall1-15/+49
If it is a wire claim (which is probably most common), the checking and sorting has already happened. We don't need to make a copy to sort and check. In either case, there is still a copy step to make the conditional ACE token. This shuffles around some knownfails because the claim_v1_copy() function we were using is checking for duplicates, which we don't always want. That will be fixed soon. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: add_claim_to_token() re-sorts/checks claimsDouglas Bagnall1-0/+12
This function is used in tests and fuzzing. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: resource attribute claims use claim_v1_check_and_sort()Douglas Bagnall1-5/+30
Because RA ACEs live a double life, sometimes being ACEs and sometimes being claims, we make a copy of the claim strucutre for sorting and further use in conditional ACEs. We don't need to do that for wire claims, because they are not persistent or forwarded on to somewhere else. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: wire claim conversion uses claim_v1_check_and_sort()Douglas Bagnall1-0/+10
This roughly returns things to where they were a few commits ago, with the claims being checked for uniqueness. The difference is the claims will be sorted afterwards, and the uniqueness check will be far more efficient on large claims. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: claim_v1_check_and_sort(): add all typesDouglas Bagnall2-1/+135
To manage this sort we need a qsort_r-like sort context which holds: a) the value type, b) a case sensitive flag for the string compare, and c) a return flag indicating a failure. Failures are not picked up until after the sort finishes. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: begin claim_v1_check_and_sort with Boolean checksDouglas Bagnall2-0/+57
claim_v1_check_and_sort() is meant to sort the claim values and check that there are no duplicates, as well as making some value checks. In order to ease into the idea, we look first at the case where the claim has Boolean values. There are only two values allowed, which limits the length of a valid claim set and means we only really need to "sort" in the {1, 0} case, which we rewrite in place as {0, 1}. That's what will happen with other types: we'll sort in-place, make some checks on values, set flags, and return an error if there are duplicates or value errors. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: don't allow two NULL string claimsDouglas Bagnall1-1/+16
This restores the behaviour with regard to duplicate NULL strings that existed before the last commit. I'm putting it separately, because it seems so strange, and I not entirely certain the behaviour is intentional. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: wire claims conversion: remove strings uniqueness checkDouglas Bagnall1-25/+5
This changes the behaviour when one of the strings is NULL. Previously a single NULL string would be ignored, and two would cause an error. That will be restored in the next commit. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: int wire claims drop uniqueness checkDouglas Bagnall1-46/+21
And we allocate all the values together as an array, because we might as well. This and the next couple of commits might look like steps backwards, and they are, but they allow us to get a run-up to leap over a big fence. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: simplify wire claim conversion mem, 3/3: rm tmp_ctxDouglas Bagnall1-23/+13
The interstitial tmp_ctx now does nothing but be interstitial, so let's get rid of it. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: simplify wire claim conversion mem, 2/3: one treeDouglas Bagnall1-2/+2
These values would have leaked in the event of failure (but only onto the caller mem_ctx, which might be fleeting -- especially as its security token is now failing). Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: simplify wire claim conversion mem, 1/3: avoid NULL parentDouglas Bagnall1-10/+24
The reason for this, apart from weighing up possible over-allocations vs realloc costs, is in the first iteration of the loop, claim_values = talloc_array(claims, would allocate onto NULL, which leaks. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security/sddl: improve some SDDL error messagesDouglas Bagnall1-2/+4
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: sddl_conditional_ace: check a talloc_new()Douglas Bagnall1-0/+3
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: conditional ACE sddl writers take const tokensDouglas Bagnall1-6/+6
We don't change these when writing the SDDL. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27lib/security:CA: tokens_are_comparable() accepts NULL operatorDouglas Bagnall1-2/+4
In some circumstances we are going to know general comparability without having an operator around to use. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: CA: tokens_are_comparable() considers the obviousDouglas Bagnall1-0/+3
Existing callers already make this check, but we are soon going to use it in contexts that don't. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: add test_claims_conversionDouglas Bagnall8-0/+186
These are unit tests for converting wire claims into sorted claims v1 structures. These are based from packets derived from the krb5.conditional_ace tests, and currently don't test more than they do, but they work about a hundred thousand times quicker. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: test_run_conditional_ace tests more comparisonsDouglas Bagnall1-2/+51
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: test_run_conditional_ace can set debug levelsDouglas Bagnall1-1/+12
No -d, just `bin/test_run_conditional_ace 3`. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: remove redundant claim SID size checkDouglas Bagnall1-7/+0
blob_string_sid_to_sid() immediately checks the size is within 5-191, so the 1-10000 just gives you a different message in chircumstances you'll never see. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: avoid leak when converting SID claimsDouglas Bagnall1-6/+49
Apart from the leak fix, this is faster and stricter, not accepting SID string buffers with trailing garbage ("S-1-2-3qwerty" would have been accepted, but not now). Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security/tests: gunzip the oversized-acls test vectorsDouglas Bagnall2-0/+20
These are just as readable with `less` as they were with `zless`. This file has been slightly manually edited to add line-breaks. There is not an easy setting in Python's json module to get good formatting. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Mon Nov 27 02:10:12 UTC 2023 on atb-devel-224
2023-11-27libcli/security/tests: remove duplicate TX-integer tests from oversized-ACLsDouglas Bagnall1-0/+0
We had two sets of test vectors (Windows ground-truth for SDDL compilation) that got mixed up. The "oversized ACLs" set is ACLs that contain repeated ACEs, like "D:P(D;;;;;MP)(D;;;;;MP)" -- Windows will assign a size to the ACL that is greater than the sum of the ACEs, while Samba will not (in part because we don't actually store a size for the ACL, instead calculating it on the fly from the size of the ACEs). The "TX integers" set is for resource attribute ACEs with octet-string data that contains pure integers (lacking '#' characters) in their SDDL, like «(RA;;;;;WD;("bar",TX,0x0,0077,00,0077,00))». We used to think that was weird, and that RA-TX ACEs should contain octet-strings in the conditional ACE style. But now we have realised it's not weird, it's normal, and we have fixed our handling of these ACEs. As a result of this mix-up, some of the tests labelled as "oversized ACLs" started passing when we fixed the TX integer problem, and that was confusing. All of the removed tests are already on the TX integer set -- the removed ones were duplicates. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security:sddl: remove vestiges of shared conditional/resource ACE SID ↵Douglas Bagnall1-12/+1
parsing Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: improve error messages in RA ACE SDDLDouglas Bagnall1-2/+3
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: conditional ACE sid parser no longer expects RA ACEsDouglas Bagnall1-46/+20
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: parse resource attribute ace SIDs separatelyDouglas Bagnall1-1/+49
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security/sddl: write RA octet strings the Windows wayDouglas Bagnall1-1/+17
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: add a parser for resource attribute ACE byte stringsDouglas Bagnall1-2/+86
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: sddl_conditional_ace: remove check_resource_attr_type()Douglas Bagnall1-95/+0
This is unneeded, as now all the checks are done in the relevant parse_* functions. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: sddl_conditional_ace: add parse_bool for RA acesDouglas Bagnall1-0/+24
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: sddl_conditional_ace: add parse_uint for RA acesDouglas Bagnall1-0/+27
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: un-invert parse_resource_attr_list, check type firstDouglas Bagnall1-1/+22
We were reusing parse_literal() because it almost does what we need, but it is different enough that check_resource_attr_type() is large and complicated, and can't handle all the cases (in particular octet- strings and SIDs are different in resource ACEs). This way is better because we know the type in advance, so we can use that to choose the parser, which will help with octet-strings that are only digits. In this commit we're leaving the check there, but it soon won't do anything that the parse_* functions don't, and we will remove it. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security/test_sddl_conditional_ace: adjust RA octet parse testsDouglas Bagnall2-5/+5
We are going to parse octet strings like Windows (as opposed to like Windows docs), so the tests need changing. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security:sddl_condtional_ace: log compiler errors at some debug levelsDouglas Bagnall1-0/+2
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-27libcli/security: initialise conditional ACE token flagsDouglas Bagnall1-0/+1
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-20Use python.h from libreplaceAndreas Schneider3-3/+3
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15513 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-11-16libcli/security: Debug only when we failed to decodeNoel Power1-5/+8
Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>