summaryrefslogtreecommitdiff
path: root/python/samba/netcmd
AgeCommit message (Collapse)AuthorFilesLines
2025-08-20samba-tool: copy user_keytrust to computer keytrustDouglas Bagnall2-0/+226
This is exactly a copy of user/keytrust.py to computer_keytrust.py with a title-case-preserving `s/user/computer/`. It works. The Computer model differs from the User model in that it appends a '$' to the end of account names if it senses the lack, otherwise these commands are using the same code paths. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2025-08-20samba-tool computer: remove unused importsDouglas Bagnall1-4/+1
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2025-08-20samba-tool: add user keytrust commandDouglas Bagnall2-0/+225
This allows manipulation of key credential links for users. See `man -l bin/default/docs-xml/manpages/samba-tool.8` for documentation. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2025-08-20samba-tool: Command.message() can print multiple linesDouglas Bagnall1-2/+3
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2025-08-20samba-tool: add verbose flag to @exception_to_command_errorDouglas Bagnall1-1/+19
Helpful in development. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2025-08-20samba-tool: add decorator to catch exception typesDouglas Bagnall1-0/+18
Often we [think we] know that all exceptions of a certain type should be formatted as CommandErrors (i.e., the traceback is suppressed, and the message is assumed intelligible). Rather than riddling .run() with try...except blocks to do this, we can @exception_to_command_error(ModelError) def run(...) which makes any ModelError into a CommandError in that samba-tool command. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2025-06-05samba-tool dns: add --allow-existing to not complain if records existDouglas Bagnall1-5/+17
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13613 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz> Reviewed-by: Rowland Penny <rpenny@samba.org>
2025-05-26samba-tool: Fix code spellingJennifer Sutton1-1/+1
Signed-off-by: Jennifer Sutton <jennifersutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2025-05-26python: Fix logging callJennifer Sutton1-1/+1
ERROR(<class AttributeError>): uncaught exception - RootLogger object has no attribute notice File "/samba/bin/python/samba/netcmd/__init__.py", line 387, in _run return self.run(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/samba/bin/python/samba/netcmd/domain/backup.py", line 698, in run logger.notice("back-up has no sysvol data") ^^^^^^^^^^^^^ 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-03-29samba-tool backup restore: cope with no sysvolDouglas Bagnall1-2/+5
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15661 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Sat Mar 29 08:25:39 UTC 2025 on atb-devel-224
2025-03-29samba-tool testparm: avoid lowering debug levelDouglas Bagnall1-1/+2
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Ralph Boehme <slow@samba.org>
2025-03-29samba-tool testparm: drop unsupported optionsDouglas Bagnall1-11/+1
These have been useless since 2011. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Ralph Boehme <slow@samba.org>
2025-03-29samba-tool gpo: use a real XML parser to check entity validityDouglas Bagnall1-20/+25
The expat parser comes with the Python standard library, so we can use it to check the entities work, rather than relying on a fragile regular expression. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Ralph Boehme <slow@samba.org>
2025-03-29samba-tool gpo: separate function for dtd header generationDouglas Bagnall1-6/+12
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Ralph Boehme <slow@samba.org>
2025-03-26samba-tool domain backup: add --no-sysvol optionThomas Karlsson1-9/+13
In some circumstances sysvol is not wanted in a backup. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15661 Signed-off-by: Thomas Karlsson <thomas.karlsson@relea.se> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
2025-03-25samba-tool gpo: better entities check copes with new linesDouglas Bagnall1-2/+2
Per https://www.w3.org/TR/xml/#sec-entity-decl (and MS references) there is always some whitespace between '<!ENTITY' and the name, and between the name and whatever is next. Also, it is valid XML to have newlines inside entity declarations, like this: <!ENTITY bubble "*S-1-5-113" > We used to create such files, so we should allow them. There is a kind of entity that has '%' before the name, and there are non-ascii names, which we continue not to support. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15829 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
2025-03-25samba-tool gpo backup fix --generalizeDouglas Bagnall1-3/+5
This was broken with commit ce56d336f234febfd4cb3da11dd584842c24ce1d but we didn't notice because the test was already broken. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15829 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
2025-03-25python:netcmd:gpo: fix crash when updating an MOTD GPOAndreas Hasenack1-2/+6
When the policy exists already, there is no exception and the code tries to use the "data" variable, but it doesn't exist because it was only defined in the exception handling. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15774 Signed-off-by: Andreas Hasenack <andreas.hasenack@canonical.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
2025-03-25samba-tool gpo: close opened filesDouglas Bagnall1-6/+10
It is almost certain that we are not going to run out of files, as they get garbage collected anyway, but in some circumstances these can fill your screen with "ResourceWarning: unclosed file" messages, which hides the real messages. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
2025-03-19python/gpo.py: avoid SDDL conversion for dsacl2fsaclRalph Boehme1-2/+1
This is not needed and has the potential to loose information if the sddl code wouldn't have all features implemented. No intended change in behaviour. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14927 Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Ralph Boehme <slow@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org>
2025-02-24samba-tool/testparm: make it clear that 'client use krb5 netlogon' is ↵Stefan Metzmacher1-0/+10
experimental BUG: https://bugzilla.samba.org/show_bug.cgi?id=15815 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2025-02-17python:lsa_utils: Fix fallback to OpenPolicy2Stefan Metzmacher1-50/+42
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15680 Pair-Programmed-With: Andreas Schneider <asn@samba.org> Signed-off-by: Andreas Schneider <asn@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Mon Feb 17 18:33:15 UTC 2025 on atb-devel-224
2025-02-17python:lsa_utils: Don't use optional arguments for OpenPolicyFallback()Andreas Schneider1-0/+1
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15680 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2025-02-08samba-tool contact: remove useless versionopts referencesDouglas Bagnall1-14/+1
These are now redundant as all samba-tool sub-commands handle -V/--version automatically. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
2025-02-08samba-tool: --version shortcircuits option evaluationDouglas Bagnall1-2/+5
This means in bin/samba-tool spn -h -V the -V takes precedence over the -h, as with the 'net' tool. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15770 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
2025-02-08samba-tool: all subcommands know --versionDouglas Bagnall2-7/+33
Before `samba-tool -V` would give you the version, but `samba-tool spn -V` would complain. An ad-hoc selection of sub-commands already supported --version, depending on whether VersionOptions was manually added to the takes_options dict. The .run() methods of these subcommands all take a 'versionopts' keyword argument, but never use it. If it was set (i.e., argv contained "--version"), the process never gets to .run(), so the value of versionopts.version is always None in run(). After this commit we can remove VersionOptions/versionopts from sub-commands. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15770 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
2025-02-08samba-tool: do not complain of no sub-command with '-V'Douglas Bagnall1-1/+2
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15770 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
2025-02-04netcmd: Increase the transaction_index_cache_size to 200k for schemaupgradeAndréas Leroux1-1/+5
Increasing this value greatly improve the performances of schema upgrade for large domains (>200k entries). The value 200000 is chosen because it is already used in join.py, and should be sufficient for known domains. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15795 Signed-off-by: Andréas Leroux <aleroux@tranquil.it> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2025-01-23samba-tool user disable: add new --remove-supplemental-groups optionBjörn Baumbach1-6/+40
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-23samba-tool user disable: make sure that filter matches only one userBjörn Baumbach1-0/+11
toggle_userAccountFlags() can only handle one user. Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Jule Anger <janger@samba.org>
2025-01-23samba-tool user disable: rename filter variable to search_filterBjörn Baumbach1-7/+10
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-23samba-tool user disable: set proper --filter option descriptionBjörn Baumbach1-1/+3
Seems to be copied from samba-tool user setpassword command. Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Jule Anger <janger@samba.org>
2025-01-23samba-tool group removemembers: avoid python backtrace on errorBjörn Baumbach1-1/+1
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>
2025-01-02testparm: do not fail if /run/samba does not existMichael Tokarev1-4/+2
testparm explicitly fails if $piddir or $lockdir does not exist. However, the daemons which actually use these directories, will create it on demand, there is no need to fail even simple testparm operations if the dirs are not there. This change lets to (pre)configure samba without bothering to pre-create the directories which are overwise needed only to fulfil testparm criteria. Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Pavel Filipenský <pfilipensky@samba.org>
2024-12-20samba-tool user: hashlib.sha1 is always presentDouglas Bagnall1-12/+4
We maybe thought we were checking that sha1 was in hashlib, but we were only checking that hashlib is in the Python library (`hashlib.sha1()` would not raise ImportError). The documentation says hashlib always contains sha1 -- if that changes, it is better we know by failing noisily with the import error at the top of the file. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15756 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-12-20samba-tool user: use _glue.crypt, not crypt.cryptDouglas Bagnall1-15/+6
Because we know we have _glue.crypt, and we know it raises exceptions rather than returning None, we can simplify the checks. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15756 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-12-20samba-tool: no traceback for unauthenticated rootdse accessDouglas Bagnall1-0/+3
Under some circumstances rootdse returns an operations error with "Operation unavailable without authentication" instead of insufficient access rights. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Douglas Bagnall <dbagnall@samba.org> Autobuild-Date(master): Fri Dec 20 00:00:02 UTC 2024 on atb-devel-224
2024-12-10samba-tool/backup: set the right permissions on our root dirBjörn Jacke1-0/+2
Since processes can run under the UID of the logged in user, it's required to make sure that the users have the permissions here. Signed-off-by: Bjoern Jacke <bjacke@samba.org> Reviewed-by: Björn Baumbach <bbaumbach@samba.org> Autobuild-User(master): Björn Baumbach <bb@sernet.de> Autobuild-Date(master): Tue Dec 10 11:40:27 UTC 2024 on atb-devel-224
2024-11-06samba-tool:: s/the the\b/the/ in docstringDouglas Bagnall1-1/+1
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Volker Lendecke <vl@samba.org>
2024-10-31netcmd: More explicit warning when python-gpg is missingAndréas Leroux1-1/+5
Signed-off-by: Andréas Leroux <aleroux@tranquil.it> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz> Autobuild-User(master): Douglas Bagnall <dbagnall@samba.org> Autobuild-Date(master): Thu Oct 31 00:23:09 UTC 2024 on atb-devel-224
2024-10-04netcmd:domain:policy: Fix missing conversion from tgt_lifetime minutes to ↵Andréas Leroux1-6/+12
10^(-7) seconds BUG: https://bugzilla.samba.org/show_bug.cgi?id=15692 Signed-off-by: Andréas Leroux <aleroux@tranquil.it> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz> Autobuild-User(master): Douglas Bagnall <dbagnall@samba.org> Autobuild-Date(master): Fri Oct 4 04:01:22 UTC 2024 on atb-devel-224
2024-09-24samba-tool: Fix for inability to delete GPOs containing GPWL policiesKacper Boström1-2/+2
GPOs containing GPWL (Wireless/Wired Protocol Extension) policies could not be deleted with samba-tool as those policies were stored as subentries of the GPO and only the main root was deleted. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15387 RN: Fix for inability to delete GPOs containing GPWL policies using samba-tool Signed-off-by: Kacper Boström <kacper@kacper.se> Reviewed-by: David Mulder <dmulder@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Tue Sep 24 17:11:53 UTC 2024 on atb-devel-224
2024-09-10netcmd: user: Fix typo in samba-tool error messageLyanis Souidi1-1/+1
Fix typo in "samba-tool user add" error message when adding a user with NIS features : the argument for the uid number is --uid-number and not --uidNumber. RN: Fix typo in samba-tool error message. Signed-off-by: Lyanis Souidi <lyanis.souidi@u-pec.fr> Reviewed-by: Jennifer Sutton <josutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2024-08-04python:netcmd: Explicitly delete samdb variablesJo Sutton1-2/+2
This makes our intent clear, and avoids accidental attempts to use these objects after they have been ‘disconnect()’ed. Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2024-06-12samba-tool ldapcmp: remove a dodgy unused methodDouglas Bagnall1-26/+0
We have bindings for stringifying GUIDs, so I intended to replace this rather complicated code with that, but it turns out that this method has been unused since 5d42260eecfd4f26cc82637ce1bc989083c9eb9d in 2013. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-06-12samba-tool domain trust: avoid useless use of string_to_byte_arrayDouglas Bagnall1-4/+4
`pw.encode('utf-16-le')` is always bytes. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-06-11samba-tool user readpasswords: avoid `assert` for validationDouglas Bagnall1-1/+4
`assert` can be optimised away if python is run with `-O`. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Tue Jun 11 05:32:28 UTC 2024 on atb-devel-224
2024-06-06python:netcmd: Create a SHA256SUM file with checksumsAndreas Schneider1-0/+25
This allows to verify the backup tarball contents with: sha256sum -c SHA256SUM Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-06-06python:netcmd: Only put regular files into the tarballAndreas Schneider1-1/+1
We also have ldapi, other sockets or pipes around, we don't want to add. This will be relevant for adding checksums later. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-05-22samba-tool: let 'samba-tool domain exportkeytab' take an --only-current-keys ↵Stefan Metzmacher1-2/+7
option Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>