summaryrefslogtreecommitdiff
path: root/python
AgeCommit message (Collapse)AuthorFilesLines
2024-02-29py:nt_time: add nt_time_from_string()Douglas Bagnall1-0/+44
This is for samba-tool, which could do with a common understanding of time strings across various sub-tools. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-29pytest:audit_log_base: use string_is_guid()Douglas Bagnall1-8/+3
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-29pytest:auth_log_base: use string_is_guid()Douglas Bagnall1-8/+3
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-29pylibs: add string_is_guid() helper.Douglas Bagnall1-0/+32
In various places we use regular expressions to check for GUID-ness, though typically we don't match GUIDs with uppercase hex digits when we really should. If we centralise the check, we have more chance of getting it right. Pair-programmed-by: Andrew Bartlett <abartlet@samba.org> Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Thu Feb 29 02:38:07 UTC 2024 on atb-devel-224
2024-02-29samba-tool: with --json, error messages are in JSONDouglas Bagnall1-0/+13
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-29samba-tool: instances remember whether --json was requestedDouglas Bagnall1-0/+8
All our subcommands are going to learn --json eventually, and they shouldn't all have to do this individually. The next commit uses this to automatically format CommandErrors as JSON. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-29samba-tool: add self.print_json_status() helperDouglas Bagnall1-0/+44
This is a helper to return JSON for simple messages. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-29samba-tool: avoid mutable Command class valuesDouglas Bagnall1-2/+2
These values are shared across all instances of the class, which makes no difference in samba-tool itself, because there is one instance per process. But in tests we can have many Command classes at once (due to runcmd()), and if any of them happened to append to takes_args or takes_options rather than replacing it, well, the effect would be subtle. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-29samba-tool domain level: avoid using assertDouglas Bagnall1-4/+8
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-29samba-tool domain claim: use secrets module for tokenDouglas Bagnall1-4/+2
`binascii.hexlify(os.urandom(8)).decode()` was fine, but `os.urandom` is OS specific and can theoretically block (says the documentation). We will let Python's secrets module worry about such details. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-29samba-tool user getpassword: Also return the time a GMSA password is valid untilAndrew Bartlett2-9/+39
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2024-02-29samba-tool: Allow ;format=UnixTime etc to operate on virtual attributesAndrew Bartlett1-1/+5
To convert a virtual attribute we must understand that it has been put into "obj" under the name including the ;format= part and so we must look it back up with that name when looking to covert it from (say) NTTIME to a unix time. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2024-02-29python/samba/tests: Include more detail on invoication in test of ↵Andrew Bartlett1-1/+3
"samba-tool user show" Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2024-02-29samba-tool user getpassword: Do not show preview of gMSA passwordAndrew Bartlett1-2/+18
The AD server will send a preview of the next gMSA password, 5mins before it is expected to be active. This is useful in a keytab, which needs to be in place before a ticket could possibly be issued, but is not helpful for authentication, as the server also accepts passwords for 5mins after the change. This avoids needing teach all users of this tool how to fall back to the previous password for a 5min period every 30 days, by default. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2024-02-28python/samba/tests/krb5: Expect SID_FRESH_PUBLIC_KEY_IDENTITY (only) when ↵Andrew Bartlett1-1/+13
PKINIT freshness used Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-27python: Fail the test if we don’t receive an NTSTATUSErrorJo Sutton1-0/+4
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-27tests/krb5: Move assertLocalSamDB() into RawKerberosTestJo Sutton2-8/+8
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-27tests/krb5: type hintingJo Sutton1-6/+8
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-27python/tests: Use TestCaseInTempDir rather than "private dir" for exported ↵Andrew Bartlett1-3/+5
keytab Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-27python/tests: Convert dckeytab test to use new NDR keytab parserAndrew Bartlett1-18/+17
This is much nicer than reading strings out of the binary file. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-27python/tests: Add test for new krb5 keytab parserAndrew Bartlett1-0/+18
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-27python/samba/samdb: Only do caching of well known DNs in dbcheckAndrew Bartlett2-22/+26
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>
2024-02-26python:gp: Implement client site lookup in site_dn_for_machine()Andreas Schneider1-23/+45
This is [MS-GPOL] 3.2.5.1.4 Site Search. The netr_DsRGetSiteName() needs to run over local rpc, however we do not have the call implemented in our rpc_server. What netr_DsRGetSiteName() actually does is an ldap query to get the sitename, we can just do the same. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15588 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): Mon Feb 26 08:06:08 UTC 2024 on atb-devel-224
2024-02-16python:tests: Remove unused importsJo Sutton2-5/+5
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16python: Reformat nt_time.pyJo Sutton1-3/+1
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16samba-tool: Display friendlier error message if no password is availableJo Sutton1-16/+8
‘samba-tool user get-kerberos-ticket’ is supposed to display an error message if no password is available. However, the conditions for which the message is displayed are impossible to be met. If ‘utf16_pw’ is not None, the message is not displayed; if ‘utf16_pw’ *is* None, ‘nt_pass’ is assigned with a samr.Password object, which is not None — and so the message is still not displayed. Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16python:tests: Pass correct arguments to set_named_ccache()Jo Sutton1-1/+1
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16python:tests: Fix code spellingJo Sutton1-1/+1
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16python:tests: Produce more helpful error message for future GKIDsJo Sutton1-1/+2
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-02-16netcmd: models: add GroupManagedServiceAccount modelRob van der Linde3-6/+99
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: models: add missing fields to User modelRob van der Linde3-4/+71
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: models: add missing enum fields to Group modelRob van der Linde3-2/+21
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: models: make Group.system_flags a flags based EnumFieldRob van der Linde3-10/+39
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: models: add Computer model subclass of UserRob van der Linde2-0/+44
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: models: stop using LookupError exception and change it to NotFoundRob van der Linde5-16/+17
LookupError is a base class for IndexError and KeyError and isn't really the appropriate exception. NotFound inherits from ModelError just like the other model exceptions. Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: models: rename DoesNotExist exception to NotFoundRob van der Linde3-8/+8
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: models: SDDLField move line down where it gets usedRob van der Linde1-1/+2
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: models: SDDLField parses to object instead of stringRob van der Linde2-20/+30
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: delegation: don't use assert but raise CommandErrorRob van der Linde1-7/+14
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: delegation: initial value not required because of raise belowRob van der Linde1-1/+0
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: delegation: move line down where it gets usedRob van der Linde1-1/+1
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: delegation: pep8 fix blank linesRob van der Linde1-1/+0
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: bugfix: json encoder failed to call super methodRob van der Linde1-1/+1
This lead to a strange recursion error when a field came up that the JSONEncoder couldn't encode. Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: json encoder supports security descriptor objectsRob van der Linde1-0/+4
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-16netcmd: support hyphens in top-level commands and convert to underscoreRob van der Linde1-2/+3
Hyphens in python modules are invalid and makes them only importable by importlib, which makes them harder to import in tests. Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
2024-02-08netcmd: models: mark some hidden fields on the base Model as readonlyRob van der Linde1-5/+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-02-08netcmd: models: tests: add tests for NtTimeFieldRob van der Linde1-0/+22
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-02-08netcmd: models: add new NtTimeField model fieldRob van der Linde1-0/+26
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-02-08netcmd: models: model field DateTimeField returns datetime in UTCRob van der Linde2-9/+14
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-02-08netcmd: models: move enum import to correct placeRob van der Linde1-2/+1
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>