summaryrefslogtreecommitdiff
path: root/python/samba/samdb.py
AgeCommit message (Collapse)AuthorFilesLines
2025-08-07python:samdb: remove dsdb_Dn aliasDouglas Bagnall1-5/+0
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2025-08-07py:samdb: add get_linearized to dsdb_dnDouglas Bagnall1-0/+5
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2025-08-07py:samdb: drop unused methods (get_binary_integer, get_bytes)Douglas Bagnall1-9/+1
get_binary_integer() is still a method on BinaryDn, but not on StringDn and PlainDn where it makes no sense. x.get_bytes() is merely an alias for x.binary. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2025-08-07python:samdb: replace dsdb_Dn with stricter typesDouglas Bagnall1-43/+199
dsdb_Dn() was a catchall for DN+Binary, DN+String, and plain DNs which needed to be sorted in a particular way. This meant it treated none of them exactly right. For example, a binary dsdb_Dn would be compared on the string representation of the binary portion, so 'B:2:ff:CN=foo' would not equal 'B:2:FF:CN=foo', when it should. It meant a field that expected a binary dsdb_DN would also accept a plain DN or a string DN, which is never actually allowed. Also the parsing was a bit dodgy, so a string like 'B:6:ff:CN=foo' would be accepted, when the length of the binary portion ("ff") is obviously different from that given ("6"). Here we solve many of the problems by making stricter subclasses but leaving a compatibility shim in place so that existing code continues to work. There is one INCOMPATIBLE change. Previously the `.binary` attribute of a dsdb_Dn was the hex-string, while now it is the actual binary data. In the case of StringDn, this means the utf-8 bytes. This affects dbcheck, which is fixed here (the .prefix assignment now correctly sets .binary). Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2025-06-16python: Do not interpret 16 character group names as GUIDsDouglas Bagnall1-1/+9
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15854 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Björn Baumbach <bb@samba.org> Autobuild-User(master): Douglas Bagnall <dbagnall@samba.org> Autobuild-Date(master): Mon Jun 16 22:22:27 UTC 2025 on atb-devel-224
2025-05-26python: Make use of OID comparator constantsJennifer Sutton1-1/+1
Signed-off-by: Jennifer Sutton <jennifersutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2025-05-26python:samdb: Add get_searchFlags_from_lDAPDisplayName() methodJennifer Sutton1-0/+4
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15852 Signed-off-by: Jennifer Sutton <jennifersutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2025-05-26python:samdb: Add get_must_contain_from_lDAPDisplayName() methodJennifer Sutton1-0/+4
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15852 Signed-off-by: Jennifer Sutton <jennifersutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2025-05-26python:samdb: Add get_lDAPDisplayName_by_governsID_id() methodJennifer Sutton1-0/+4
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15852 Signed-off-by: Jennifer Sutton <jennifersutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2025-01-23samba-tool user disable: add new --remove-supplemental-groups optionBjörn Baumbach1-8/+75
Removes all supplemental groups from a user, what is commonly wanted when a user is disabled. Pair-programmed-with: Stefan Metzmacher <metze@samba.org> Signed-off-by: Björn Baumbach <bb@sernet.de> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jule Anger <janger@samba.org> Autobuild-User(master): Björn Baumbach <bb@sernet.de> Autobuild-Date(master): Thu Jan 23 19:51:05 UTC 2025 on atb-devel-224
2025-01-23python/samdb: no need to set member_base_dn multiple timesBjörn Baumbach1-3/+3
Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Jule Anger <janger@samba.org>
2025-01-23python/samdb: fix group member removal by SIDBjörn Baumbach1-4/+28
Otherwise the removal of groupmembers by SID fails silently, because the DN does not match the the DN in group member list. Pair-programmed-with: Stefan Metzmacher <metze@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Jule Anger <janger@samba.org>
2025-01-23python/samdb: fix check which checks if user is already member of groupBjörn Baumbach1-1/+1
Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Jule Anger <janger@samba.org>
2025-01-23python/samdb: rename filter variable to search_filterBjörn Baumbach1-2/+2
filter() is a Python built-in function to filter iterables. Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Jule Anger <janger@samba.org>
2025-01-23python/samdb: add missing function parameter descriptionBjörn Baumbach1-0/+3
Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Jule Anger <janger@samba.org>
2025-01-23python/samdb: fix attribute name in parameter descriptionBjörn Baumbach1-6/+6
Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Jule Anger <janger@samba.org>
2024-04-24python: Move get_admin_sid() to SamDBJo Sutton1-0/+7
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-03-20py:samdb: make SamDB.__str__ show the URL and IDDouglas Bagnall1-0/+8
Getting the right samdb is going to matter more, so it is useful for debugging to see which is which. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-03-20python: samdb: Make connecting_user_sid a propertyRob van der Linde1-0/+3
This is following the same design as other similar properties like samdb.domain_sid, only it doesn't need a setter. Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-03-20python: samdb: Move get_connecting_user_sid to samdbRob van der Linde1-0/+5
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-03-01python:samdb: wrapper for _dsdb_create_gkdi_root_key()Douglas Bagnall1-0/+6
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-27python/samba/samdb: Only do caching of well known DNs in dbcheckAndrew Bartlett1-14/+1
The fact that get_wellknown_dn() returned a cached DN that could not be modified safely was unexpected, particularly given that other similar routines did not do that. The use case given at the time this was written by Matthieu Patou in 6122acad0f1a7bc23b6f58862c16968e13da979d was dbcheck, so move the cache there, and name it clearly. dbcheck is the only case that uses this rotuine in an inner loop. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2023-12-15python: use python3 style super statementsRob van der Linde1-6/+5
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-12-15python: pep257: docstring should use double quotesRob van der Linde1-37/+37
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-08-30python: Remove redundant backslashesJoseph Sutton1-1/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-06-23python:samba: Fix code spellingAndreas Schneider1-2/+2
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): Fri Jun 23 14:51:14 UTC 2023 on atb-devel-224
2023-04-28librpc/ndr/pysecurity: use better exceptionsDouglas Bagnall1-1/+1
The wrong string is the wrong value but the right type. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-02-23python: fix mutable default argumentsRob van der Linde1-2/+6
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Thu Feb 23 23:33:46 UTC 2023 on atb-devel-224
2022-05-10samdb: Avoid half-created accountsJoseph Sutton1-12/+35
If newuser() or newcomputer() create an account over LDAP, and an attempt to modify it (e.g. to change the password) fails, ensure that we properly clean up the account. If we are connected over LDAP, we won't have transactions to clean things up for us. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-05-10python: Use 'is' for identity when comparing against NoneJoseph Sutton1-1/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Tue May 10 06:12:10 UTC 2022 on sn-devel-184
2022-05-10python: Remove redundant assignmentsJoseph Sutton1-1/+0
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2021-06-22samdb: Create computer in wellknown user containerDavid Mulder1-1/+2
BUG: https://bugzilla.samba.org/show_bug.cgi?id=9143 Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-06-22samdb: Create group in wellknown user containerDavid Mulder1-1/+6
BUG: https://bugzilla.samba.org/show_bug.cgi?id=9143 Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-06-22samdb: Create user in wellknown user containerDavid Mulder1-1/+6
BUG: https://bugzilla.samba.org/show_bug.cgi?id=9143 Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-06-11ridalloc: Don't skip the first RID of a poolJoseph Sutton1-2/+2
Previously, if either of the rIDPreviousAllocation and rIDNextRID attributes were not present in a RID Set, the first RID in rIDAllocationPool was skipped over when determining their values. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2021-06-11dsdb: Add next_free_rid() function to allocate a RID without modifying the ↵Joseph Sutton1-0/+105
database If used to generate SIDs for objects, care should be taken, as the possibility for having duplicate objectSIDs can arise. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14669 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2021-03-10python: Disable calls to _dsdb_garbage_collect_tombstones without addcDavid Mulder1-0/+5
dsdb._dsdb_garbage_collect_tombstones isn't built without the addc, so ignore calls to it in samdb. Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-01-15samba-tool: Optionally hide disabled/expired accounts in "user list"Björn Baumbach1-0/+15
--hide-expired Do not list expired user accounts --hide-disabled Do not list disabled user accounts Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Volker Lendecke <vl@samba.org>
2020-11-11samdb: Add samdb.domain_netbios_name()Andrew Bartlett1-0/+15
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2020-11-03samba-tool: add new "user unlock" commandBjörn Baumbach1-0/+30
Can be used to unlock a user when the badPwdCount has been reached. Introduces SamDB error classes, as suggested by Douglas Bagnall <douglas.bagnall@catalyst.net.nz> - thanks! This helps to handle expected failures. Tracebacks of really unexpected failures will not be hidden. Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2020-10-02python2 reduction: Merge remaining compat code into commonDavid Mulder1-1/+1
The remaining compat code (get_string, get_bytes, cmp) are useful helper routines which we should simply merge into common (especially since there is some duplication here). Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Autobuild-User(master): David Mulder <dmulder@samba.org> Autobuild-Date(master): Fri Oct 2 14:49:36 UTC 2020 on sn-devel-184
2020-10-02python: Move dsdb_Dn to samdbDavid Mulder1-1/+75
The import dsdb needed for dsdb_Dn causes import errors when trying to import get_bytes/get_string in some places. Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2020-10-01samdb: add fullname_from_names() methodJule Anger1-19/+37
Add a method to construct the fullname, using the given name, the initials and the surname. If one of this values is empty, try to use the old one, given by an attributs set. If the combination is empty, the method will return the fallback-default parameter. Use this method to construct the CN or the displayName of users or contacts. Signed-off-by: Jule Anger <ja@sernet.de> Reviewed-by: Björn Baumbach <bb@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2020-10-01samdb: add prepare_attr_replace() methodJule Anger1-0/+23
Add a method to prepare a given Message to replace the given attribute. If the given new value is None or the old value and the new value are the same, do nothing. If the new value is empty, prepare to replace the given attribute with []. Else prepare to replace the given attribute with the new value. Use this for samdb.modify(msg). Signed-off-by: Jule Anger <ja@sernet.de> Reviewed-by: Björn Baumbach <bb@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2020-08-11python compat: remove text_typeDouglas Bagnall1-2/+1
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
2020-08-11python compat: remove binary_typeDouglas Bagnall1-5/+4
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
2020-01-21samba-tool group addmembers: add --member-base-dn option for group member searchBjörn Baumbach1-2/+5
Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Ralph Boehme <slow@samba.org>
2020-01-21samba-tool group addmembers: add --member-dn optionBjörn Baumbach1-26/+33
The --member-dn option allows to specify an object by it's DN. This is required to select a specific object if there are more than one with the same name. Multiple contacts can exist with the same name in different OUs. Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Ralph Boehme <slow@samba.org>
2020-01-21python/samdb: validation of group member types for group member filterBjörn Baumbach1-0/+6
Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Ralph Boehme <slow@samba.org>
2020-01-21python/samdb: add type "all" to search for all common types of group membersBjörn Baumbach1-0/+10
Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Ralph Boehme <slow@samba.org>