summaryrefslogtreecommitdiff
path: root/python
AgeCommit message (Collapse)AuthorFilesLines
2022-09-06py/samba/logger: respect NO_COLOR env variableDouglas Bagnall1-2/+2
As per https://no-color.org/ Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-06python/colour: helper functions to read all signsDouglas Bagnall1-0/+38
The accepted hints are presumably arguments to --color. We follow the behaviour of `ls` in what we accept. `git` is stricter, accepting only {always,never,auto}. `grep` is looser accepting mixed case variants. historically we have used {yes,no,auto}. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-06samba-tool visualise: expand set of --color switchesDouglas Bagnall1-3/+7
To match convention, and elsewhere. We can't easily use colour.is_colour_wanted() because we could (via --output) be intending to write to a file that isn't open yet, so we have no .isatty() to query. Also, because --color-scheme implies --color (as documented in --help), it trumps most 'auto' checks, but not NO_COLOR. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-06pytest/samba-tool visualize: test '--color' aliasesDouglas Bagnall1-5/+19
By convention, 'tty' is a common alias for 'auto', 'always' and 'force' mean 'yes', and 'never' means no. It seems 'never; and 'always' are more common than 'yes' and 'no'. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-06samba-tool visualize: remove py2 compat for colour calculationsDouglas Bagnall1-3/+0
io.StringIO has .isatty(); the old cStringIO did not, Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-06samba-tool visualize: respect $NO_COLORDouglas Bagnall1-0/+2
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-06pytest samba-tool visualize: extend colour tests for $NO_COLORDouglas Bagnall1-0/+73
As described at https://no-color.org/, the NO_COLOR environment variable is a widely used defacto-ish standard for asking for no colour. If someone goes NO_COLOR=whatever samba-tool ... we want to assume they want no ANSI colour codes, as if they had used --color=no. But first we want to test that, so here we are. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-06pytest/samba-tool visualize: fix docstringDouglas Bagnall1-1/+1
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-06pytest: SambaToolCmdTest allows easier StringIO replacementDouglas Bagnall1-6/+9
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-06pytests: move ValidNetbiosNameTests to samba.tests.netbiosDouglas Bagnall2-12/+12
These were the only tests in __init__.py. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Noel Power <npower@samba.org>
2022-09-06pytest/samdb: use TestCaseInTempDir.rm_files/.rm_dirsDouglas Bagnall1-6/+2
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Noel Power <npower@samba.org>
2022-09-06pytest/join: use TestCaseInTempDir.rm_files/dirsDouglas Bagnall1-4/+2
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Noel Power <npower@samba.org>
2022-09-06pytest/samdb_api: use TestCaseInTempDir.rm_filesDouglas Bagnall1-9/+1
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Noel Power <npower@samba.org>
2022-09-06pytest/downgradedatabase: use TestCaseInTempDir.rm_filesDouglas Bagnall1-8/+6
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Noel Power <npower@samba.org>
2022-09-06pytest: add file removal helpers for TestCaseInTempDirDouglas Bagnall1-0/+35
In several places we end a test by deleting a number of files and directories, but we do it rather haphazardly with unintentionally differing error handling. For example, in some tests we currently have something like: try: shutil.rmtree(os.path.join(self.tempdir, "a")) os.remove(os.path.join(self.tempdir, "b")) shutil.rmtree(os.path.join(self.tempdir, "c")) except Exception: pass where if, for example, the removal of "b" fails, the removal of "c" will not be attempted. That will result in the tearDown method raising an exception, and we're no better off. If the above code is replaced with self.rm_files('b') self.rm_dirs('a', 'c') the failure to remove 'b' will cause a test error, *unless* the failure was due to a FileNotFoundError (a.k.a. an OSError with errno ENOENT), in which case we ignore it, as was probably the original intention. If on the other hand, we have self.rm_files('b', must_exist=True) self.rm_dirs('a', 'c') then the FileNotFoundError causes a failure (not an error). We take a little bit of care to stay within self.tempdir, to protect test authors who accidentally write something like `self.rm_dirs('/')`. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Noel Power <npower@samba.org>
2022-09-02tests: Test basic handling of SMB2_CREATE_TAG_POSIXVolker Lendecke1-0/+59
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Fri Sep 2 14:31:25 UTC 2022 on sn-devel-184
2022-09-02pylibsmb: Add create_ex()Volker Lendecke1-0/+12
This is an extension of the create() function allowing smb2 create contexts to be passed back and forth and also returning the smb_create_returns. A new function seemed necessary for me because we need to return not just the fnum. So I chose a 3-tuple, see the test for an example how to use this. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2022-09-02tests: Test invalid smb3 unix negotiate contextsVolker Lendecke1-1/+34
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2022-09-02tests: Add smb3 posix negotiate testsVolker Lendecke1-0/+70
Make sure we do and don't announce posix depending on "smb3 unix extensions" parameter Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2022-08-26pyglue:generate_random_[machine]_password: ValueError for bad valuesDouglas Bagnall1-0/+10
The actual range is 14 to 255 for machine passwords, and there is a min <= max check for both. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Fri Aug 26 08:59:28 UTC 2022 on sn-devel-184
2022-08-26pyglue: generate_random_[machine]_password: reject negative numbersDouglas Bagnall1-2/+27
Other range errors (e.g. min > max) are caught in the wrapped functions which returns EINVAL, so we don't recapitulate that logic (see next commit though). Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-08-26pyglue: generate_random_bytes/str accept positive numbers onlyDouglas Bagnall1-4/+16
We aren't yet able to generate negative numbers of random bytes. Instead a request for -n bytes is implicitly converted into one for SIZE_MAX - n bytes, which is typically very large. Memory exhaustion seems a likely outcome. With this patch callers will see a ValueError. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-08-26pyglue: check talloc buffer for random bytesDouglas Bagnall1-0/+4
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-08-26pytest/segfault: abort for generate_random_bytes(-1)Douglas Bagnall1-0/+6
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-08-25python:tests: Allocate OID range for testing to avoid collisionsJoseph Sutton1-1/+7
sid_strings.py used the same OID range as ldap_schema.py, which occasionally led to test failures when the same OID was generated twice. Using a different range, and making use of the expected RID if we have it, should reduce the likelihood of collisions. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Thu Aug 25 13:55:47 UTC 2022 on sn-devel-184
2022-08-06samba-tool gpo: clean up tmpdir after createDouglas Bagnall1-0/+4
'fetch' and 'backup' might also leave files in /tmp, but in those cases we want the files. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15006 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: David Mulder <dmulder@suse.com> Autobuild-User(master): Douglas Bagnall <dbagnall@samba.org> Autobuild-Date(master): Sat Aug 6 01:42:09 UTC 2022 on sn-devel-184
2022-08-06samba-tool: allow testparm to dump global section onlyDouglas Bagnall1-1/+4
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15070 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: David Mulder <dmulder@suse.com>
2022-08-06pytest/netcmd: test samba-tool testparm global sectionDouglas Bagnall1-0/+8
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: David Mulder <dmulder@suse.com>
2022-07-28CVE-2022-32743 tests/py_credentials: Add tests for setting dNSHostName with ↵Joseph Sutton1-2/+279
LogonGetDomainInfo() Test that the value is properly validated, and that it can be set regardless of rights on the account. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14833 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2022-07-28py/uptodateness: more details in missing dn reportDouglas Bagnall1-1/+1
This does not fix bug 15127, but it improves reporting. https://bugzilla.samba.org/show_bug.cgi?id=15127 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Thu Jul 28 06:18:43 UTC 2022 on sn-devel-184
2022-07-27CVE-2022-2031 tests/krb5: Add test that we cannot provide a TGT to kpasswdJoseph Sutton1-0/+28
The kpasswd service should require a kpasswd service ticket, and disallow TGTs. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15047 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15049 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27CVE-2022-2031 tests/krb5: Test truncated forms of server principalsJoseph Sutton1-3/+27
We should not be able to use krb@REALM instead of krbtgt@REALM. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15047 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27CVE-2022-2031 tests/krb5: Add tests for kpasswd serviceJoseph Sutton4-1/+1033
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15047 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15049 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15074 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27CVE-2022-2031 tests/krb5: Consider kadmin/* principals as TGS for MIT KRB5 ↵Joseph Sutton2-5/+28
>= 1.20 With MIT Kerberos >= 1.20, we should not expect a ticket checksum in tickets to principals such as kpasswd/changepw, as they are encrypted with the krbtgt's key. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15047 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15049 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15074 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27CVE-2022-2031 tests/krb5: Add kpasswd_exchange() methodJoseph Sutton1-13/+251
Now we can test the kpasswd service from Python. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15047 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15049 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15074 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27CVE-2022-2031 tests/krb5: Allow requesting a TGT to a different sname and realmJoseph Sutton1-6/+13
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15047 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15049 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15074 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27tests/krb5: Add option for creating accounts with expired passwordsJoseph Sutton1-2/+8
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27tests/krb5: Fix enum typoJoseph Sutton1-2/+2
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27CVE-2022-2031 tests/krb5: Add methods to send and receive generic messagesJoseph Sutton1-17/+27
This allows us to send and receive kpasswd messages, while avoiding the existing logic for encoding and decoding other Kerberos message types. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15047 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15049 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15074 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27CVE-2022-2031 tests/krb5: Add 'port' parameter to connect()Joseph Sutton1-5/+6
This allows us to use the kpasswd port, 464. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15047 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15049 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15074 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27CVE-2022-2031 tests/krb5: Add methods to create ASN1 kpasswd structuresJoseph Sutton1-0/+95
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15047 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15049 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15074 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27CVE-2022-2031 tests/krb5: Add new definitions for kpasswdJoseph Sutton3-1/+31
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15047 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15049 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15074 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27CVE-2022-32744 tests/krb5: Correctly calculate salt for pre-existing accountsJoseph Sutton2-0/+2
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15074 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27CVE-2022-2031 tests/krb5: Split out _make_tgs_request()Joseph Sutton2-84/+85
This allows us to make use of it in other tests. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15047 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-27CVE-2022-32744 tests/krb5: Correctly handle specifying account kvnoJoseph Sutton1-1/+1
The environment variable is a string, but we expect an integer. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15074 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-22gpo: samba-gpupdate use s3 param for registry confDavid Mulder2-6/+10
Cause samba-gpupdate to use an s3 param so that it can load settings from registry configuration. Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Fri Jul 22 20:40:51 UTC 2022 on sn-devel-184
2022-06-26samba-tool user: Accomodate missing unicodePwd in getpassword commandJoseph Sutton1-9/+29
To allow for the NT hash not being stored when NTLM authentication is disabled, we use the AES256 key instead for verification against the other packages if the unicodePwd attribute is not present. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-26samba-tool user: When possible, obtain AES256 key and saltJoseph Sutton1-13/+26
We will make use of these in the next commit to check that the supplemental packages are up-to-date with the current password. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-26tests/krb5: Add test for presence of NT hashJoseph Sutton3-3/+149
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-17s3/client: fix dfs deltree, resolve dfs pathNoel Power1-8/+0
since 4cc4938a2866738aaff4dc91550bb7a5ad05d7fb do_list seems to deal with non dfs root path, hence we need to resolve the path before calling cli_unlink. Also remove the knownfail We additionally have to also remove the fallback to remove 'file3' int the smbcacls_dfs_propagate_inherit.teardown as the deltree that happens in the baseclass now succeeds. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15100 Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Fri Jun 17 17:12:07 UTC 2022 on sn-devel-184