summaryrefslogtreecommitdiff
path: root/lib/ldb
Commit message (Collapse)AuthorAgeFilesLines
* python: Safely clear structure membersJoseph Sutton2023-05-161-11/+8
| | | | | | | | Using Py_CLEAR() ensures that these structures are observed in a consistent state by any Python code that may run during deconstruction. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib:ldb: do not offset against NULL pointer in ldb_ldif_read()Dmitry Antipov2023-05-091-4/+4
| | | | | | | | | | | | | | | | | | | | Fix the following error observed running samba.test.registry compiled with clang-17 and UBsan: lib/ldb/common/ldb_ldif.c:881:9: runtime error: applying non-zero offset 137438953440 to null pointer #0 0x7faa0eb3932f in ldb_ldif_read lib/ldb/common/ldb_ldif.c:881 #1 0x7faa0eb3aec6 in ldb_ldif_read_string lib/ldb/common/ldb_ldif.c:1004 #2 0x7faa077ed759 in dsdb_set_schema_from_ldif source4/dsdb/schema/schema_set.c:1113 #3 0x7faa068fcbbf in py_dsdb_set_schema_from_ldif source4/dsdb/pydsdb.c:929 #4 0x7faa1d1d4507 in cfunction_call (/lib64/libpython3.11.so.1.0+0x1d4507) [... a lot of Python calls skipped...] I.e. number of elements should be checked against zero before making an attempt to access an element by index. Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* ldb: Implement ldap_whoami in pyldbVolker Lendecke2023-04-261-0/+36
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* ldb: Add the RFC4532 LDB_EXTENDED_WHOAMI_OID definitionVolker Lendecke2023-04-261-0/+5
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* pyldb: Handle allocation failureJoseph Sutton2023-04-121-0/+4
| | | | | | | | If we don't check for NULL after each loop iteration, the failure could be masked in the next iteration by talloc_asprintf_append() allocating on the NULL context. That could result in values getting lost. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
* ldb: Avoid undefined pointer arithmeticJoseph Sutton2023-04-121-9/+9
| | | | | | | | Computing a pointer that points outside of an array, and not to one past the last element, is undefined behaviour. To avoid this, do our comparisons in terms of lengths, not pointers. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
* ldb: Fix function documentation to be consistentJoseph Sutton2023-04-121-12/+12
| | | | Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
* ldb: Don't wrongly claim to return message elementsJoseph Sutton2023-04-121-0/+2
| | | | | | | | If the LDB_UNPACK_DATA_FLAG_NO_ATTRS flag is set, we don't return any elements, so we should set num_elements accordingly. This ensures callers don't try to access elements that aren't there. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
* ldb: Remove misleading commentJoseph Sutton2023-04-121-2/+2
| | | | | | | That an attribute has been access checked doesn't mean that the user has the right to view it. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
* ldb: Remove old misleading commentsJoseph Sutton2023-04-121-4/+0
| | | | | | | | | | | | Commit bed9efa6cda17ecca91bdf71227ec656b94dcf94 introduced ldb_msg_add_linearized_dn() to replace ldb_msg_add_dn(), but retained the now-incorrect associated comment. The comment later made its way into a function added later by commit 'CVE-2022-32746 ldb: Add functions for appending to an ldb_message'. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15008 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
* lib:ldb: Fix code spellingAndreas Schneider2023-04-114-5/+5
| | | | | | Best reviewed with: `git show --word-diff`. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
* lib:ldb:tests: Fix signedness build errorAndreas Schneider2023-04-061-1/+1
| | | | | | | | | | | | | lib/ldb/tests/ldb_filter_attrs_in_place_test.c:836:55: error: pointer targets in passing argument 1 of ‘_assert_string_equal’ differ in signedness [-Werror=pointer-sign] 836 | assert_string_equal(msg->elements[0].values[0].data, | ^ | | | uint8_t * {aka unsigned char *} Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* ldb: Use correct member of unionJoseph Sutton2023-04-052-9/+18
| | | | | Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb: Filter on search base before redacting messageJoseph Sutton2023-04-055-23/+48
| | | | | | | | | | | Redaction may be expensive if we end up needing to fetch a security descriptor to verify rights to an attribute. Checking the search scope is probably cheaper, so do that first. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb: Centralise checking for inaccessible matchesJoseph Sutton2023-04-051-25/+31
| | | | | | | | | This makes it less likely that we forget to handle a case. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb: Prevent disclosure of confidential attributesJoseph Sutton2023-04-056-0/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a hook, acl_redact_msg_for_filter(), in the aclread module, that marks inaccessible any message elements used by an LDAP search filter that the user has no right to access. Make the various ldb_match_*() functions check whether message elements are accessible, and refuse to match any that are not. Remaining message elements, not mentioned in the search filter, are checked in aclread_callback(), and any inaccessible elements are removed at this point. Certain attributes, namely objectClass, distinguishedName, name, and objectGUID, are always present, and hence the presence of said attributes is always allowed to be checked in a search filter. This corresponds with the behaviour of Windows. Further, we unconditionally allow the attributes isDeleted and isRecycled in a check for presence or equality. Windows is not known to make this special exception, but it seems mostly harmless, and should mitigate the performance impact on searches made by the show_deleted module. As a result of all these changes, our behaviour regarding confidential attributes happens to match Windows more closely. For the test in confidential_attr.py, we can now model our attribute handling with DC_MODE_RETURN_ALL, which corresponds to the behaviour exhibited by Windows. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org> Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb: Add ldb_parse_tree_get_attr()Joseph Sutton2023-04-053-0/+29
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb: Make use of ldb_filter_attrs_in_place()Joseph Sutton2023-04-053-57/+62
| | | | | | | | | | | | | | Change all uses of ldb_kv_filter_attrs() to use ldb_filter_attrs_in_place() instead. This function does less work than its predecessor, and no longer requires the allocation of a second ldb message. Some of the work is able to be split out into separate functions that each accomplish a single task, with a purpose to make the code clearer. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb: Make ldb_filter_attrs_in_place() work in placeJoseph Sutton2023-04-054-443/+308
| | | | | | | | | | | | | | | | | | | | | | ldb_filter_attrs() previously did too much. Now its replacement, ldb_filter_attrs_in_place(), only does the actual filtering, while taking ownership of each element's values is handled in a separate function, ldb_msg_elements_take_ownership(). Also, ldb_filter_attrs_in_place() no longer adds the distinguishedName to the message if it is missing. That is handled in another function, ldb_msg_add_distinguished_name(). As we're now modifying the original message rather than copying it into a new one, we no longer need the filtered_msg parameter. We adapt a test, based on ldb_filter_attrs_test, to exercise the new function. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb: Add function to filter message in placeJoseph Sutton2023-04-055-0/+1149
| | | | | | | | | | | | | | At present this function is an exact duplicate of ldb_filter_attrs(), but in the next commit we shall modify it to work in place, without the need for the allocation of a second message. The test is a near duplicate of the existing test for ldb_filter_attrs(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb: Add function to add distinguishedName to messageJoseph Sutton2023-04-053-3/+9
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb: Add function to remove excess capacity from an ldb messageJoseph Sutton2023-04-053-0/+20
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb: Add function to take ownership of an ldb messageJoseph Sutton2023-04-053-0/+46
| | | | | | | | | | | | | Many places in Samba depend upon various components of an ldb message being talloc allocated, and hence able to be used as talloc contexts. The elements and values of an unpacked ldb message point to unowned data inside the memory-mapped database, and this function ensures that such messages have talloc ownership of said elements and values. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb:tests: Ensure all tests are accounted forJoseph Sutton2023-04-051-2/+3
| | | | | | | | | | | | | Add ldb_filter_attrs_test to the list of tests so that it actually gets run. Remove a duplicate ldb_msg_test that was accidentally added in commit 5ca90e758ade97fb5e335029c7a1768094e70564. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb:tests: Ensure ldb_val data is zero-terminatedJoseph Sutton2023-04-051-85/+86
| | | | | | | | | | | | | | | | | If the value of an ldb message element is not zero-terminated, calling ldb_msg_find_attr_as_string() will cause the function to read off the end of the buffer in an attempt to verify that the value is zero-terminated. This can cause unexpected behaviour and make the test randomly fail. To avoid this, we must have a terminating null byte that is *not* counted as part of the length, and so we must calculate the length with strlen() rather than sizeof. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* CVE-2023-0614 ldb: Add functions for handling inaccessible message elementsJoseph Sutton2023-04-053-0/+33
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib:ldb:tests: Fix code spellingAndreas Schneider2023-04-047-21/+21
| | | | | | | | | | Best reviewed with: `git show --word-diff`. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Tue Apr 4 08:30:28 UTC 2023 on atb-devel-224
* lib:ldb:nssldb: Fix code spellingAndreas Schneider2023-04-041-1/+1
| | | | | | Best reviewed with: `git show --word-diff`. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib:ldb:ldb_sqlite3: Fix code spellingAndreas Schneider2023-04-041-1/+1
| | | | | | Best reviewed with: `git show --word-diff`. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib:ldb:ldb_map: Fix code spellingAndreas Schneider2023-04-042-3/+3
| | | | | | Best reviewed with: `git show --word-diff`. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib:ldb:ldb_key_value: Fix code spellingAndreas Schneider2023-04-045-12/+12
| | | | | | Best reviewed with: `git show --word-diff`. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib:ldb:include: Fix code spellingAndreas Schneider2023-04-042-5/+5
| | | | | | Best reviewed with: `git show --word-diff`. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib:ldb:common: Fix code spellingAndreas Schneider2023-04-045-7/+7
| | | | | | Best reviewed with: `git show --word-diff`. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* ldb: Add ldb_val -> bool,uint64,int64 parsing functionsJoseph Sutton2023-03-313-19/+52
| | | | | | | | | These functions allow us to parse any value of a message element, not only the first. They also unambiguously indicate whether an error has occurred. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* ldb: Split out ldb_val_as_dn() helper functionJoseph Sutton2023-03-313-2/+14
| | | | | Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* pyldb: Fix a copy&paste error, CID 1524512 DEADCODEVolker Lendecke2023-03-301-1/+1
| | | | | | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Thu Mar 30 08:08:32 UTC 2023 on atb-devel-224
* lib/ldb: add LDB_CHANGETYPE_MODRDN support to ldb_ldif_to_pyobject()Stefan Metzmacher2023-03-221-2/+51
| | | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib/ldb: add LDB_CHANGETYPE_DELETE support to ldb_ldif_to_pyobject()Stefan Metzmacher2023-03-221-0/+9
| | | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib/ldb: re-order code in ldb_ldif_to_pyobject()Stefan Metzmacher2023-03-221-10/+32
| | | | | | | | We don't allow MODRDN and DELETE for now as they don't work as is anyway. We'll add these in the next steps. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib/ldb: let ldb_ldif_parse_modrdn() handle names without 'rdn_name=' prefixStefan Metzmacher2023-03-221-0/+20
| | | | | | | This is needed in order to process schema updates. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* ldb: Don't create error string if there is no errorJoseph Sutton2023-03-221-7/+8
| | | | | | | We should only do this in the LDB_ERR_NO_SUCH_ATTRIBUTE case. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib:ldb: Correctly cast pointers for assert_string_equal()Andreas Schneider2023-03-152-16/+16
| | | | | | | | | | This is a change in cmocka to avoid hiding possible errors. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Wed Mar 15 07:53:54 UTC 2023 on atb-devel-224
* lib/ldb: Avoid allocation and memcpy() for every wildcard match candidateAndrew Bartlett2023-03-141-10/+50
| | | | | | | | | | | The value can be quite large, the allocation will take much longer than the actual match and is repeated per candidate record. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15331 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
* ldb: Make ldb_msg_remove_attr O(n)Joseph Sutton2023-03-081-3/+10
| | | | | | | Previously it was O(n²). Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib:pyldb: Throw error on invalid controlsJoseph Sutton2023-03-031-1/+26
| | | | | Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib:ldb: Fix typoJoseph Sutton2023-03-031-1/+1
| | | | | Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib:ldb: Print a debug message in case we have a corrupted MDBAndreas Schneider2023-02-151-0/+8
| | | | | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Wed Feb 15 09:05:56 UTC 2023 on atb-devel-224
* lib:ldb: Add the location to ldb_kv_parse_data_unpack() debug outputAndreas Schneider2023-02-151-1/+2
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
* ldb/pyldb: remove py2 ifdefsDouglas Bagnall2023-02-031-22/+0
| | | | | Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* ldb: change the version to 2.8.0 for Samba 4.19Stefan Metzmacher2023-01-183-2/+296
| | | | | | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Jule Anger <janger@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Wed Jan 18 17:25:51 UTC 2023 on atb-devel-224