The branch, master has been updated via 84002281410 samba-tool domain: use string_to_level helper() via 8b17b2a5077 samba-tool domain: add string_to_level() helper via 5af823a7097 samba-tool domain: expand string_version_to_constant range via bcc9f7f35e9 samba-tool domain show: report level 2016 via 0363879d1fc samba-tool domain show: use level_to_string() via 6d4015265a1 samba-tool domain: helper function for domain level names via 2cdafb94312 samba-tool ldapcmp: use CommandError on auth failure via 960ae819ade samba-tool ldapcmp: use CommandError, not assertion via b13c121fcba samba-tool ldapcmp: do not assume common attributes via c26a8f6a41b samba-tool ldapcmp: use shorter names in cmp_attrs via 4959d07b965 samba-tool ldapcmp: use ValueError, not Exception via fbd815c1113 samba-tool dns: catch werror.WERR_ACCESS_DENIED via 2aa5b56b791 samba-tool dns: use DnsconnWrapper in zonecreate via ca82806f68a samba-tool dns: update_record uses DnsConnWrapper via 99d48c857f4 samba-tool dns: delete uses DnsConnWrapper messages via 38ccbf460dc samba-tool dns: add uses DnsConnWrapper messages via bee727a559a samba-tool dns: query uses DnsConnWrapper messages via 633872c7d25 samba-tool dns: zonedelete uses DnsConnWrapper messages via 36241042dd6 samba-tool dns: NAME_DOES_NOT_EXIST errors; add docstring via 1ae4738a8ca samba-tool dns: RECORD_DOES_NOT_EXIST errors as CommandErrors via 47684f5739b samba-tool dns: catch ZONE_ALREADY_EXISTS errors as CommandErrors via 9e774fc14ac samba-tool dns: catch DS_UNAVAILABLE errors as CommandErrors via e931104d1d9 samba-tool dns: use DnsConnWrapper widely via 26b86bc57e8 samba-tool dns: add a wrapper for better error messages via c824ad8dcb9 samba-tool domain: fix error string for account lockout duration via 6b1b5eade2f samba-tool dbcheck: improve --help for --reset-well-known-acls via 98e85fc611b samba-tool domain provision: better message if tdbbackup missing via f580c8b0427 samba-tool: do not force a traceback on CommandError via 90780936202 samba-tool: avoid traceback for NT_STATUS_NETWORK_UNREACHABLE via 1137647460c py/getopt: allow --option arguments to contain '=' via c2178d87c2f py/getopt: improve messages for bad --realm via 604832b8ffd py/getopt: improve messages for bad --debug arg via ca7535912b1 samba-tool: avoid traceback for options errors via 62fe118e99e samba-tool: reduce repetitious jargon on credentials failure via c61e8cdefca s4/tests/samba-tool drs showrepl: test NO_COLOR and --color variants via 7d178ab95bc s4/tests/samba-tool drs showrepl: use vars for common strings via eefc0304586 samba-tool: respect NO_COLOR env variable and --color options via ade31017583 py/samba/logger: respect NO_COLOR env variable via a45c76b5cd9 python/colour: helper functions to read all signs via 37f92c6cc69 samba-tool visualise: expand set of --color switches via 664653b8d14 pytest/samba-tool visualize: test '--color' aliases via 6160e956b59 samba-tool visualize: remove py2 compat for colour calculations via 6ced3d21513 samba-tool visualize: respect $NO_COLOR via e7d78400bdd pytest samba-tool visualize: extend colour tests for $NO_COLOR via d9443fadba2 pytest/samba-tool visualize: fix docstring via 98f5332b46f pytest: SambaToolCmdTest allows easier StringIO replacement via 0a5298f0c19 pytests: move ValidNetbiosNameTests to samba.tests.netbios via 24f7d714167 pytest/samba_tool_drs_no_dns: use TestCaseInTempDir.rm_files/.rm_dirs via 3f0aab45c81 pytest/samba_tool_drs: use TestCaseInTempDir.rm_files/.rm_dirs via 251360d6e58 pytest/samdb: use TestCaseInTempDir.rm_files/.rm_dirs via 7455c53fa4f pytest/join: use TestCaseInTempDir.rm_files/dirs via 4e3dabad0be pytest/samdb_api: use TestCaseInTempDir.rm_files via 85bc1552e39 pytest/downgradedatabase: use TestCaseInTempDir.rm_files via 2359741b285 pytest: add file removal helpers for TestCaseInTempDir from aa9f3a2da97 nsswitch:libwbclient - fix leak in wbcCtxPingDc2
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 84002281410d0ce67d301aeadead63c909f1a6d2 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 31 14:40:46 2022 +1200 samba-tool domain: use string_to_level helper() Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Autobuild-User(master): Douglas Bagnall <dbagn...@samba.org> Autobuild-Date(master): Tue Sep 6 22:07:23 UTC 2022 on sn-devel-184 commit 8b17b2a50771387bb267efb4dbd098e83fb64735 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 31 13:47:45 2022 +1200 samba-tool domain: add string_to_level() helper Reverse transform of level_to_string(), obviously. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 5af823a709738c343354dd20251025530bbb28bb Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 31 13:35:57 2022 +1200 samba-tool domain: expand string_version_to_constant range This won't actually have any effect yet -- the new values are inaccessible in the place it is used because the range is limited by the --function-level option config. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit bcc9f7f35e96b64b7947651f8dcd5e397388ba77 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 31 13:13:20 2022 +1200 samba-tool domain show: report level 2016 Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 0363879d1fc1c76ec717467e98f2f15f5e902b09 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 31 13:28:50 2022 +1200 samba-tool domain show: use level_to_string() Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 6d4015265a1df57a79fe6172ab7bbf6c0c992ce3 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 31 13:12:06 2022 +1200 samba-tool domain: helper function for domain level names Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 2cdafb943121db8df843c0ca1b12e87f2058cbf2 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Aug 18 11:53:29 2022 +1200 samba-tool ldapcmp: use CommandError on auth failure Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 960ae819ade522a72e3b8677fccd8ccd557f9a43 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Aug 18 11:52:54 2022 +1200 samba-tool ldapcmp: use CommandError, not assertion Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit b13c121fcbafc9b84e29e438715727e3e780ff92 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Aug 18 11:38:35 2022 +1200 samba-tool ldapcmp: do not assume common attributes This has caused numerous reports of ERROR(<class 'KeyError'>): uncaught exception - 'serverReferenceBL' File /usr/lib/python3/dist-packages/samba/netcmd/__init__.py, line 185, in _run return self.run(*args, **kwargs) File /usr/lib/python3/dist-packages/samba/netcmd/ldapcmp.py, line 957, in run if b1.diff(b2): File /usr/lib/python3/dist-packages/samba/netcmd/ldapcmp.py, line 781, in diff if object1 == object2: File /usr/lib/python3/dist-packages/samba/netcmd/ldapcmp.py, line 549, in __eq__ return self.cmp_attrs(other) File /usr/lib/python3/dist-packages/samba/netcmd/ldapcmp.py, line 590, in cmp_attrs if isinstance(self.attributes[x], list) and isinstance(other.attributes[x], list): because other does not have attribute 'x'. It is better to assume other.attributes[x] is None, which will compare as unequal to whatever self.attributes[x] is, showing up as a diff rather than a crash. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit c26a8f6a41bceba071147b101ce66bf54f098042 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Aug 18 11:34:53 2022 +1200 samba-tool ldapcmp: use shorter names in cmp_attrs This simplifies a fix in the next commit. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 4959d07b965b5567f486405c987af8f251ea4c19 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Aug 18 11:32:25 2022 +1200 samba-tool ldapcmp: use ValueError, not Exception Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit fbd815c111317568cf9001d9b68099276d42c1a2 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Aug 18 10:58:54 2022 +1200 samba-tool dns: catch werror.WERR_ACCESS_DENIED Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 2aa5b56b7919ceedef7937c7f3ea17bd2e8ccde2 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Sat Aug 13 12:55:01 2022 +1200 samba-tool dns: use DnsconnWrapper in zonecreate Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit ca82806f68ac86c842717d634407632bf0fd8127 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Aug 18 09:21:39 2022 +1200 samba-tool dns: update_record uses DnsConnWrapper The special thing about this one is the dns_conn is also used in the dns_record_match() library function, which wants a real dns connection. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 99d48c857f41f01a722b86720893b6827171dad8 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Fri Aug 12 17:17:16 2022 +1200 samba-tool dns: delete uses DnsConnWrapper messages Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 38ccbf460dc7d687f0bf4bc4dbea53d982ec6c9b Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Fri Aug 12 16:51:25 2022 +1200 samba-tool dns: add uses DnsConnWrapper messages Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit bee727a559a827c1e15a3b382fd9363c5bf285c0 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Fri Aug 12 16:46:03 2022 +1200 samba-tool dns: query uses DnsConnWrapper messages Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 633872c7d25e59c65f0f23c2f8f87535a171bfec Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Fri Aug 12 16:44:31 2022 +1200 samba-tool dns: zonedelete uses DnsConnWrapper messages Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 36241042dd6ef241e9a674c92131f17e317f78f4 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 17 17:59:50 2022 +1200 samba-tool dns: NAME_DOES_NOT_EXIST errors; add docstring In practice, these always refer to zones. We're adding the docstring now, because it made no sense when default_messages was empty. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 1ae4738a8ca0bdd22f1766bd39876456f7cba389 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 17 17:58:50 2022 +1200 samba-tool dns: RECORD_DOES_NOT_EXIST errors as CommandErrors Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 47684f5739b253ea55b28bbfeb07c63dd62bd6f2 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 17 17:58:03 2022 +1200 samba-tool dns: catch ZONE_ALREADY_EXISTS errors as CommandErrors Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 9e774fc14ace6f27f479511b7c780aa4e8941159 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 17 17:57:16 2022 +1200 samba-tool dns: catch DS_UNAVAILABLE errors as CommandErrors Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit e931104d1d9476c63b32dea58e45889b1af642e6 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Fri Aug 12 16:40:03 2022 +1200 samba-tool dns: use DnsConnWrapper widely This covers all the cases where there are no existing CommandError messages, and no other uses of the dns_conn (i.e., not cmd_update). Forthcoming commits will introduce default messages for these. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 26b86bc57e85280a9fc9aba26a49a16859c91b78 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Fri Aug 12 16:38:59 2022 +1200 samba-tool dns: add a wrapper for better error messages This will help turn simple common errors into CommandError messages. At this stage, no messages are intercepted. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit c824ad8dcb9222a75c7bdf756f605b840fb68a00 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Oct 28 09:51:06 2020 +1300 samba-tool domain: fix error string for account lockout duration Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 6b1b5eade2ff32200ad4c543dfb1543d5bd897ef Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Aug 11 15:18:02 2022 +1200 samba-tool dbcheck: improve --help for --reset-well-known-acls This option is for updating from pre-4.0.4 when something went wrong with ACLs. BUG: https://bugzilla.samba.org/show_bug.cgi?id=9872 Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 98e85fc611bc7ba64ef56b3cb03b60213af1b79b Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Mon Aug 22 11:48:53 2022 +1200 samba-tool domain provision: better message if tdbbackup missing BUG: https://bugzilla.samba.org/show_bug.cgi?id=12893 Reported-by: Jeff Sadowski <jeff.sadow...@gmail.com> Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit f580c8b0427d5aa4f63b5c6704d9c7819a0c61c4 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Sep 1 01:16:53 2022 +0000 samba-tool: do not force a traceback on CommandError When a CommandError has an 'inner exception', we have been printing drowning out the error message with a long traceback of the exception we tried to catch. People who really want to see tracebacks can use -d3. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 90780936202c3233e33fc6e2a8fac53680cdf63b Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Fri Aug 19 17:06:48 2022 +1200 samba-tool: avoid traceback for NT_STATUS_NETWORK_UNREACHABLE Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 1137647460cc143509eae598708bb9f1529463f6 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Fri Aug 19 16:53:40 2022 +1200 py/getopt: allow --option arguments to contain '=' smb.conf lines can have = on the right hand side. For example, in st/ad_dc/etc/smb.conf we have 3 examples, including: gpo update command = python3 source4/scripting/bin/samba-gpupdate [...] --target=Computer If we tried to provide the same line via --option, it would split on both '=', and the set value would end at '--target'. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit c2178d87c2fe524913d2ae059be2b3622ad7bd08 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Fri Aug 19 16:50:54 2022 +1200 py/getopt: improve messages for bad --realm Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 604832b8ffd242025d613fb5e35707a5185e8855 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Fri Aug 19 16:49:24 2022 +1200 py/getopt: improve messages for bad --debug arg Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit ca7535912b1d0564654a612deed4f002a2382da8 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Sep 1 15:32:07 2022 +1200 samba-tool: avoid traceback for options errors What option? None yet, but see the next two commits. We use a local reference to optparse.OptionValueError, to save typing and make the eventual switch to argparse easier. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 62fe118e99e6f0f2c9c09101ec0f79283a342171 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Fri Aug 19 10:12:07 2022 +1200 samba-tool: reduce repetitious jargon on credentials failure We already print the following due to DBG_ERR()s: cli_credentials_failed_kerberos_login: krb5_cc_get_principal failed: No such file or directory Failed to bind - LDAP error 49 LDAP_INVALID_CREDENTIALS - <8009030C: LdapErr: DSID-0C0904DC, comment: AcceptSecurityContext error, data 52e, v1db1> <> Failed to connect to 'ldap://10.53.57.30' with backend 'ldap': LDAP error 49 LDAP_INVALID_CREDENTIALS - <8009030C: LdapErr: DSID-0C0904DC, comment: AcceptSecurityContext error, data 52e, v1db1> <> We don't *really* need to follow that with: ERROR(ldb): LDAP connection to ldap://10.53.57.30 failed - LDAP error 49 LDAP_INVALID_CREDENTIALS - <8009030C: LdapErr: DSID-0C0904DC, comment: AcceptSecurityContext error, data 52e, v1db1> <> rather we can say: Bad username or password. Also, we don't really need to print a traceback, which we seem to do for some commands and not others. Maybe *sometimes* "bad username or password" might be technically incorrect (e.g. --simple-bind-dn), but in those cases the user is already behaving strangely, and they will still see the LDAP_INVALID_CREDENTIALS twice. Kerberos failures don't come this way. BUG: https://bugzilla.samba.org/show_bug.cgi?id=9608 Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit c61e8cdefcae917f65ae83cfe89d6e284df6b687 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 17 14:28:15 2022 +1200 s4/tests/samba-tool drs showrepl: test NO_COLOR and --color variants "--color variants" meaning --color=always instead of --color=yes, etc. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Joseph Sutton <josephsut...@catalyst.net.nz> commit 7d178ab95bc5b7017e46041cdbe7174590e21ea9 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 17 14:26:29 2022 +1200 s4/tests/samba-tool drs showrepl: use vars for common strings Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Joseph Sutton <josephsut...@catalyst.net.nz> commit eefc030458674b5bb5b8338f7a3b9c1df48ad8ef Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Jul 7 10:43:59 2021 +1200 samba-tool: respect NO_COLOR env variable and --color options This allows the NO_COLOR environment variable and --color=never to work for samba-tool commands that use this method. So far that means some parts of drs showrepl. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Joseph Sutton <josephsut...@catalyst.net.nz> commit ade31017583542aae13aabf819cb9f4fd7bea7b7 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Jul 7 10:43:17 2021 +1200 py/samba/logger: respect NO_COLOR env variable As per https://no-color.org/ Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Joseph Sutton <josephsut...@catalyst.net.nz> commit a45c76b5cd95ada77905ed5cfc979c5523c84160 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Jan 20 12:32:48 2022 +1300 python/colour: helper functions to read all signs 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.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Joseph Sutton <josephsut...@catalyst.net.nz> commit 37f92c6cc69b220439aef0c687c92a8e6baeb211 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 17 13:15:15 2022 +1200 samba-tool visualise: expand set of --color switches 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.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Joseph Sutton <josephsut...@catalyst.net.nz> commit 664653b8d14cbe21c954d248b2bb5ef0d2d60043 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 17 11:50:55 2022 +1200 pytest/samba-tool visualize: test '--color' aliases 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.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Joseph Sutton <josephsut...@catalyst.net.nz> commit 6160e956b5931a2cbeb98e042c2fe71981115ba0 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 17 11:57:00 2022 +1200 samba-tool visualize: remove py2 compat for colour calculations io.StringIO has .isatty(); the old cStringIO did not, Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Joseph Sutton <josephsut...@catalyst.net.nz> commit 6ced3d21513907dee7da6c0f7a4bd345120b439d Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 17 11:51:40 2022 +1200 samba-tool visualize: respect $NO_COLOR Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Joseph Sutton <josephsut...@catalyst.net.nz> commit e7d78400bdd66e53dea1f7317bc48b9fc0fd82b1 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Tue Aug 16 14:04:57 2022 +1200 pytest samba-tool visualize: extend colour tests for $NO_COLOR 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.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Joseph Sutton <josephsut...@catalyst.net.nz> commit d9443fadba2f09871fe14caac1c00b8c753223d3 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Aug 17 11:48:58 2022 +1200 pytest/samba-tool visualize: fix docstring Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Joseph Sutton <josephsut...@catalyst.net.nz> commit 98f5332b46fbddd44366ccaa2b11346a1d2bc10d Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Sun Aug 14 12:08:16 2022 +1200 pytest: SambaToolCmdTest allows easier StringIO replacement Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Joseph Sutton <josephsut...@catalyst.net.nz> commit 0a5298f0c191c1a6d5451b45ee1fc37c960f4166 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Jun 9 15:16:44 2022 +1200 pytests: move ValidNetbiosNameTests to samba.tests.netbios These were the only tests in __init__.py. Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 24f7d71416753b792d6fe029da6f366adb10383e Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Jun 15 13:23:32 2022 +1200 pytest/samba_tool_drs_no_dns: use TestCaseInTempDir.rm_files/.rm_dirs Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 3f0aab45c81c9f9b6b87eb68bc785902619dc10d Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Jun 8 19:53:57 2022 +1200 pytest/samba_tool_drs: use TestCaseInTempDir.rm_files/.rm_dirs Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 251360d6e58986dd53f0317319544e930dc61444 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Jun 15 13:22:24 2022 +1200 pytest/samdb: use TestCaseInTempDir.rm_files/.rm_dirs Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 7455c53fa4f7871b3980f820d22b0fd411195704 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Jun 15 13:21:16 2022 +1200 pytest/join: use TestCaseInTempDir.rm_files/dirs Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 4e3dabad0be0900a203896c2c2acb270d31b0a42 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Jun 15 13:20:41 2022 +1200 pytest/samdb_api: use TestCaseInTempDir.rm_files Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 85bc1552e3919d049d39a065824172a24933d38b Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Wed Jun 15 13:19:28 2022 +1200 pytest/downgradedatabase: use TestCaseInTempDir.rm_files Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 2359741b2854a8de9d151fe189be80a4bd087ff9 Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz> Date: Thu Jun 9 13:16:31 2022 +1200 pytest: add file removal helpers for TestCaseInTempDir 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.bagn...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> ----------------------------------------------------------------------- Summary of changes: python/samba/colour.py | 38 ++++ python/samba/getopt.py | 15 +- python/samba/logger.py | 4 +- python/samba/netcmd/__init__.py | 42 ++-- python/samba/netcmd/dbcheck.py | 6 +- python/samba/netcmd/dns.py | 223 ++++++++++++++------- python/samba/netcmd/domain.py | 108 ++++------ python/samba/netcmd/domain_backup.py | 6 + python/samba/netcmd/ldapcmp.py | 50 +++-- python/samba/netcmd/visualize.py | 15 +- python/samba/tdb_util.py | 4 + python/samba/tests/__init__.py | 47 +++-- python/samba/tests/blackbox/downgradedatabase.py | 14 +- python/samba/tests/join.py | 6 +- python/samba/tests/netbios.py | 12 ++ python/samba/tests/samba_tool/base.py | 15 +- python/samba/tests/samba_tool/visualize.py | 89 +++++++- python/samba/tests/samdb.py | 8 +- python/samba/tests/samdb_api.py | 10 +- source4/torture/drs/python/samba_tool_drs.py | 13 +- .../torture/drs/python/samba_tool_drs_no_dns.py | 14 +- .../torture/drs/python/samba_tool_drs_showrepl.py | 43 +++- 22 files changed, 517 insertions(+), 265 deletions(-) Changeset truncated at 500 lines: diff --git a/python/samba/colour.py b/python/samba/colour.py index 92af2fdef80..448b456b465 100644 --- a/python/samba/colour.py +++ b/python/samba/colour.py @@ -88,3 +88,41 @@ def xterm_256_colour(n, bg=False, bold=False): target = '48' if bg else '38' return "\033[%s%s;5;%dm" % (weight, target, int(n)) + + +def is_colour_wanted(stream, hint='auto'): + """The hint is presumably a --color argument. + + We follow the behaviour of GNU `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}. + * {always,never,auto} appears the commonest convention. + * if the caller tries to opt out of choosing and sets hint to None + or '', we assume 'auto'. + """ + if hint in ('no', 'never', 'none'): + return False + + if hint in ('yes', 'always', 'force'): + return True + + if hint not in ('auto', 'tty', 'if-tty', None, ''): + raise ValueError("unexpected colour hint: {hint}; " + "try always|never|auto") + + from os import environ + if environ.get('NO_COLOR'): + # Note: per spec, we treat the empty string as if unset. + return False + + if (hasattr(stream, 'isatty') and stream.isatty()): + return True + return False + + +def colour_if_wanted(stream, hint='auto'): + if is_colour_wanted(stream, hint): + switch_colour_on() + else: + switch_colour_off() diff --git a/python/samba/getopt.py b/python/samba/getopt.py index a271cd8a736..9e35273381f 100644 --- a/python/samba/getopt.py +++ b/python/samba/getopt.py @@ -31,6 +31,9 @@ from samba.credentials import ( import sys +OptionError = optparse.OptionValueError + + class SambaOptions(optparse.OptionGroup): """General Samba-related command line options.""" @@ -64,18 +67,24 @@ class SambaOptions(optparse.OptionGroup): self._configfile = arg def _set_debuglevel(self, option, opt_str, arg, parser): - self._lp.set('debug level', arg) + try: + self._lp.set('debug level', arg) + except RuntimeError: + raise OptionError(f"invalid -d/--debug value: '{arg}'") parser.values.debuglevel = arg def _set_realm(self, option, opt_str, arg, parser): - self._lp.set('realm', arg) + try: + self._lp.set('realm', arg) + except RuntimeError: + raise OptionError(f"invalid --realm value: '{arg}'") self.realm = arg def _set_option(self, option, opt_str, arg, parser): if arg.find('=') == -1: raise optparse.OptionValueError( "--option option takes a 'a=b' argument") - a = arg.split('=') + a = arg.split('=', 1) try: self._lp.set(a[0], a[1]) except Exception as e: diff --git a/python/samba/logger.py b/python/samba/logger.py index 667c6487a51..7fb2199e031 100644 --- a/python/samba/logger.py +++ b/python/samba/logger.py @@ -19,6 +19,7 @@ import sys import logging from samba.colour import GREY, YELLOW, GREEN, RED, DARK_RED, C_NORMAL +from samba.colour import is_colour_wanted LEVEL_COLORS = { logging.CRITICAL: DARK_RED, @@ -55,8 +56,7 @@ def get_samba_logger( (quiet and logging.WARNING) or logging.INFO) logger.setLevel(level) - - if (hasattr(stream, 'isatty') and stream.isatty()): + if is_colour_wanted(stream): Formatter = ColoredFormatter else: Formatter = logging.Formatter diff --git a/python/samba/netcmd/__init__.py b/python/samba/netcmd/__init__.py index bb70f72449e..73292489268 100644 --- a/python/samba/netcmd/__init__.py +++ b/python/samba/netcmd/__init__.py @@ -19,9 +19,9 @@ import optparse import samba from samba import colour -from samba.getopt import SambaOption +from samba.getopt import SambaOption, OptionError from samba.logger import get_samba_logger -from ldb import LdbError +from ldb import LdbError, ERR_INVALID_CREDENTIALS import sys import traceback import textwrap @@ -110,9 +110,21 @@ class Command(object): message = "uncaught exception" force_traceback = True - if isinstance(inner_exception, LdbError): + if isinstance(e, OptionError): + print(evalue, file=self.errf) + self.usage() + force_traceback = False + + elif isinstance(inner_exception, LdbError): (ldb_ecode, ldb_emsg) = inner_exception.args - self.errf.write("ERROR(ldb): %s - %s\n" % (message, ldb_emsg)) + if ldb_ecode == ERR_INVALID_CREDENTIALS: + print("Invalid username or password", file=self.errf) + force_traceback = False + elif ldb_emsg == 'LDAP client internal error: NT_STATUS_NETWORK_UNREACHABLE': + print("Could not reach remote server", file=self.errf) + force_traceback = False + else: + self.errf.write("ERROR(ldb): %s - %s\n" % (message, ldb_emsg)) elif isinstance(inner_exception, AssertionError): self.errf.write("ERROR(assert): %s\n" % message) force_traceback = True @@ -125,7 +137,6 @@ class Command(object): self.errf.write("ERROR: %s\n" % (message)) else: self.errf.write("ERROR(%s): %s - %s\n" % (str(etype), message, evalue)) - force_traceback = True if force_traceback or samba.get_debug_level() >= 3: traceback.print_tb(etraceback, file=self.errf) @@ -204,22 +215,11 @@ class Command(object): "constants" in the colour module to be either real colours or empty strings. """ - requested = requested.lower() - if requested == 'no': - colour.switch_colour_off() - - elif requested == 'yes': - colour.switch_colour_on() - - elif requested == 'auto': - if (hasattr(self.outf, 'isatty') and self.outf.isatty()): - colour.switch_colour_on() - else: - colour.switch_colour_off() - - else: - raise CommandError("Unknown --color option: %s " - "please choose from yes, no, auto") + try: + colour.colour_if_wanted(self.outf, requested) + except ValueError as e: + raise CommandError(f"Unknown --color option: {requested} " + "please choose from always|never|auto") class SuperCommand(Command): diff --git a/python/samba/netcmd/dbcheck.py b/python/samba/netcmd/dbcheck.py index f0dd85282e3..8827ee35d63 100644 --- a/python/samba/netcmd/dbcheck.py +++ b/python/samba/netcmd/dbcheck.py @@ -71,7 +71,11 @@ class cmd_dbcheck(Command): Option("--attrs", dest="attrs", default=None, help="list of attributes to check (space separated)"), Option("--reindex", dest="reindex", default=False, action="store_true", help="force database re-index"), Option("--force-modules", dest="force_modules", default=False, action="store_true", help="force loading of Samba modules and ignore the @MODULES record (for very old databases)"), - Option("--reset-well-known-acls", dest="reset_well_known_acls", default=False, action="store_true", help="reset ACLs on objects with well known default ACL values to the default"), + Option("--reset-well-known-acls", + dest="reset_well_known_acls", + default=False, action="store_true", + help=("reset ACLs on objects with well known default values" + " (for updating from early 4.0.x)")), Option("--quick-membership-checks", dest="quick_membership_checks", help=("Skips missing/orphaned memberOf backlinks checks, " "but speeds up dbcheck dramatically for domains with " diff --git a/python/samba/netcmd/dns.py b/python/samba/netcmd/dns.py index 7c4d3f9bc6a..22c961baaf3 100644 --- a/python/samba/netcmd/dns.py +++ b/python/samba/netcmd/dns.py @@ -56,6 +56,78 @@ def dns_connect(server, lp, creds): return dns_conn +class DnsConnWrapper: + """A wrapper around a dnsserver.dnsserver connection that makes it + harder not to report friendly messages. + + If, rather than + + dns_conn = dns_connect(server, lp, creds) + + you use + + dns_conn = DnsConnWrapper(server, lp, creds) + + then various common errors (for example, mispelled zones) on + common operations will raise CommandErrors that turn into + relatively nice messages (when compared to tracebacks). + + In addition, if you provide a messages keyword argument, it will + override the defaults. Note that providing None will turn off the + default, letting the original exception shine through. + + messages = { + werror.WERR_DNS_ERROR_ZONE_DOES_NOT_EXIST: ( + f'Zone {zone} does not exist and so could not be deleted.'), + werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST: None + } + res = dns_conn.DnssrvOperation2( # ... + messages=messages) + + This example changes the message for ZONE_DOES_NOT_EXIST and + avoids catching NAME_DOES_NOT_EXIST. + + Only WERRORErrors are intercepted. + """ + + default_messages = { + werror.WERR_DNS_ERROR_DS_UNAVAILABLE: "Could not contact RPC server", + werror.WERR_DNS_ERROR_ZONE_ALREADY_EXISTS: 'Zone already exists', + werror.WERR_DNS_ERROR_RECORD_DOES_NOT_EXIST: 'The record does not exist', + werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST: 'The zone does not exist', + werror.WERR_ACCESS_DENIED: 'Insufficient permissions', + } + + def __init__(self, server, lp, creds): + self.dns_conn = dns_connect(server, lp, creds) + + def __getattr__(self, name): + attr = getattr(self.dns_conn, name) + if name not in { + "DnssrvComplexOperation2", + "DnssrvEnumRecords2", + "DnssrvOperation2", + "DnssrvQuery2", + "DnssrvUpdateRecord2"}: + return attr + + def f(*args, messages={}): + try: + return attr(*args) + except WERRORError as e: + werr, errstr = e.args + if werr in messages: + if werr is None: + # None overrides a default message, leaving the bare exception + raise + raise CommandError(f"{messages[werr]} [{errstr}]", e) + if werr in self.default_messages: + raise CommandError(f"{self.default_messages[werr]} [{errstr}]", e) + raise + + return f + + def bool_string(flag): if flag == 0: ret = 'FALSE' @@ -418,7 +490,7 @@ class cmd_serverinfo(Command): versionopts=None): self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp) - dns_conn = dns_connect(server, self.lp, self.creds) + dns_conn = DnsConnWrapper(server, self.lp, self.creds) client_version = dns_client_version(cli_ver) @@ -495,7 +567,7 @@ class cmd_zoneoptions(Command): **kwargs): self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp) - dns_conn = dns_connect(server, self.lp, self.creds) + dns_conn = DnsConnWrapper(server, self.lp, self.creds) client_version = dns_client_version(cli_ver) nap_type = dnsserver.DNSSRV_TYPEID_NAME_AND_PARAM @@ -734,7 +806,7 @@ class cmd_zoneinfo(Command): versionopts=None): self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp) - dns_conn = dns_connect(server, self.lp, self.creds) + dns_conn = DnsConnWrapper(server, self.lp, self.creds) client_version = dns_client_version(cli_ver) @@ -805,7 +877,7 @@ class cmd_zonelist(Command): self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp) - dns_conn = dns_connect(server, self.lp, self.creds) + dns_conn = DnsConnWrapper(server, self.lp, self.creds) client_version = dns_client_version(cli_ver) @@ -846,7 +918,7 @@ class cmd_zonecreate(Command): self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp) - dns_conn = dns_connect(server, self.lp, self.creds) + dns_conn = DnsConnWrapper(server, self.lp, self.creds) zone = zone.lower() @@ -887,14 +959,14 @@ class cmd_zonecreate(Command): name_and_param.pszNodeName = 'AllowUpdate' name_and_param.dwParam = dnsp.DNS_ZONE_UPDATE_SECURE - try: - dns_conn.DnssrvOperation2(client_version, 0, server, zone, - 0, 'ResetDwordProperty', typeid, - name_and_param) - except WERRORError as e: - if e.args[0] == werror.WERR_DNS_ERROR_ZONE_ALREADY_EXISTS: - self.outf.write('Zone already exists.') - raise e + messages = { + werror.WERR_DNS_ERROR_ZONE_ALREADY_EXISTS: ( + f'Zone "{zone}" already exists.') + } + + dns_conn.DnssrvOperation2(client_version, 0, server, zone, + 0, 'ResetDwordProperty', typeid, + name_and_param, messages=messages) self.outf.write('Zone %s created successfully\n' % zone) @@ -917,18 +989,18 @@ class cmd_zonedelete(Command): self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp) - dns_conn = dns_connect(server, self.lp, self.creds) + dns_conn = DnsConnWrapper(server, self.lp, self.creds) zone = zone.lower() - try: - res = dns_conn.DnssrvOperation2(dnsserver.DNS_CLIENT_VERSION_LONGHORN, - 0, server, zone, 0, 'DeleteZoneFromDs', - dnsserver.DNSSRV_TYPEID_NULL, - None) - except WERRORError as e: - if e.args[0] == werror.WERR_DNS_ERROR_ZONE_DOES_NOT_EXIST: - raise CommandError('Zone does not exist and so could not be deleted.') - raise e + + messages = { + werror.WERR_DNS_ERROR_ZONE_DOES_NOT_EXIST: ( + f'Zone {zone} does not exist and so could not be deleted.'), + } + res = dns_conn.DnssrvOperation2(dnsserver.DNS_CLIENT_VERSION_LONGHORN, + 0, server, zone, 0, 'DeleteZoneFromDs', + dnsserver.DNSSRV_TYPEID_NULL, + None, messages=messages) self.outf.write('Zone %s deleted successfully\n' % zone) @@ -1000,16 +1072,16 @@ class cmd_query(Command): self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp) - dns_conn = dns_connect(server, self.lp, self.creds) + dns_conn = DnsConnWrapper(server, self.lp, self.creds) - try: - buflen, res = dns_conn.DnssrvEnumRecords2( - dnsserver.DNS_CLIENT_VERSION_LONGHORN, 0, server, zone, name, - None, record_type, select_flags, None, None) - except WERRORError as e: - if e.args[0] == werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST: - raise CommandError('Record or zone does not exist.') - raise e + messages = { + werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST: ( + 'Record or zone does not exist.') + } + buflen, res = dns_conn.DnssrvEnumRecords2( + dnsserver.DNS_CLIENT_VERSION_LONGHORN, 0, server, zone, name, + None, record_type, select_flags, None, None, + messages=messages) print_dnsrecords(self.outf, res) @@ -1035,7 +1107,7 @@ class cmd_roothints(Command): self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp) - dns_conn = dns_connect(server, self.lp, self.creds) + dns_conn = DnsConnWrapper(server, self.lp, self.creds) buflen, res = dns_conn.DnssrvEnumRecords2( dnsserver.DNS_CLIENT_VERSION_LONGHORN, 0, server, '..RootHints', @@ -1078,20 +1150,22 @@ class cmd_add_record(Command): self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp) - dns_conn = dns_connect(server, self.lp, self.creds) + dns_conn = DnsConnWrapper(server, self.lp, self.creds) add_rec_buf = dnsserver.DNS_RPC_RECORD_BUF() add_rec_buf.rec = rec - try: - dns_conn.DnssrvUpdateRecord2(dnsserver.DNS_CLIENT_VERSION_LONGHORN, - 0, server, zone, name, add_rec_buf, None) - except WERRORError as e: - if e.args[0] == werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST: - raise CommandError('Zone does not exist; record could not be added. zone[%s] name[%s]' % (zone, name)) - if e.args[0] == werror.WERR_DNS_ERROR_RECORD_ALREADY_EXISTS: - raise CommandError('Record already exists; record could not be added. zone[%s] name[%s]' % (zone, name)) - raise e + messages = { + werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST: ( + 'Zone does not exist; record could not be added. ' + f'zone[{zone}] name[{name}'), + werror.WERR_DNS_ERROR_RECORD_ALREADY_EXISTS: ( + 'Record already exists; record could not be added. ' + f'zone[{zone}] name[{name}]') + } + dns_conn.DnssrvUpdateRecord2(dnsserver.DNS_CLIENT_VERSION_LONGHORN, + 0, server, zone, name, add_rec_buf, None, + messages=messages) self.outf.write('Record added successfully\n') @@ -1141,11 +1215,11 @@ class cmd_update_record(Command): self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp) - dns_conn = dns_connect(server, self.lp, self.creds) + dns_conn = DnsConnWrapper(server, self.lp, self.creds) try: - rec_match = dns_record_match(dns_conn, server, zone, name, record_type, - olddata) + rec_match = dns_record_match(dns_conn.dns_conn, server, zone, + name, record_type, olddata) except DNSParseError as e: raise CommandError(*e.args) from None @@ -1164,18 +1238,19 @@ class cmd_update_record(Command): del_rec_buf = dnsserver.DNS_RPC_RECORD_BUF() del_rec_buf.rec = rec_match - try: - dns_conn.DnssrvUpdateRecord2(dnsserver.DNS_CLIENT_VERSION_LONGHORN, - 0, - server, - zone, - name, - add_rec_buf, - del_rec_buf) - except WERRORError as e: - if e.args[0] == werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST: - raise CommandError('Zone does not exist; record could not be updated.') - raise e + messages = { + werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST: ( + f'Zone {zone} does not exist; record could not be updated.'), + } + + dns_conn.DnssrvUpdateRecord2(dnsserver.DNS_CLIENT_VERSION_LONGHORN, + 0, + server, + zone, + name, + add_rec_buf, + del_rec_buf, + messages=messages) self.outf.write('Record updated successfully\n') @@ -1214,25 +1289,27 @@ class cmd_delete_record(Command): -- Samba Shared Repository