The branch, master has been updated
via c5511056708 libnet4: check return value of DC lookup
via 2f93c9322b2 samba-tool contact: remove useless versionopts
references
via 6f7bc5cb12a py:get_opts:VersionOptions prints version in --help
via a61e192f25c samba-tool: --version shortcircuits option evaluation
via 8aec198306e samba-tool: all subcommands know --version
via 3a408f06aea samba-tool: do not complain of no sub-command with '-V'
via fd59b316b80 pytest: samba-tool --version tests
from c7d0adade09 vfs_shadow_copy2: Use VFS interface to derive mount
point
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit c5511056708fb1be3c2e1b2ad61af6643f92051c
Author: Björn Baumbach <[email protected]>
Date: Fri Feb 7 12:03:18 2025 +0100
libnet4: check return value of DC lookup
Avoids possible segmentation fault when the lookup fails.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15798
Pair-programmed-with: Volker Lendecke <[email protected]>
Signed-off-by: Volker Lendecke <[email protected]>
Signed-off-by: Björn Baumbach <[email protected]>
Reviewed-by: Douglas Bagnall <[email protected]>
Autobuild-User(master): Douglas Bagnall <[email protected]>
Autobuild-Date(master): Sat Feb 8 03:30:27 UTC 2025 on atb-devel-224
commit 2f93c9322b25c3515c72db0150039fe679c81b10
Author: Douglas Bagnall <[email protected]>
Date: Fri Jan 31 11:50:48 2025 +1300
samba-tool contact: remove useless versionopts references
These are now redundant as all samba-tool sub-commands handle
-V/--version automatically.
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Jennifer Sutton <[email protected]>
commit 6f7bc5cb12a687a8851f07788700fb44e134f894
Author: Douglas Bagnall <[email protected]>
Date: Thu Jan 30 21:22:04 2025 +1300
py:get_opts:VersionOptions prints version in --help
Because it might as well. Like this:
Version Options:
-V, --version Display version number (4.22.2)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15770
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Jennifer Sutton <[email protected]>
commit a61e192f25c61fc4f464585f6d4153c26aece352
Author: Douglas Bagnall <[email protected]>
Date: Wed Jan 15 15:32:18 2025 +1300
samba-tool: --version shortcircuits option evaluation
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 <[email protected]>
Reviewed-by: Jennifer Sutton <[email protected]>
commit 8aec198306ed005a815220e6ca3dfed6774290b2
Author: Douglas Bagnall <[email protected]>
Date: Wed Jan 15 15:33:18 2025 +1300
samba-tool: all subcommands know --version
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 <[email protected]>
Reviewed-by: Jennifer Sutton <[email protected]>
commit 3a408f06aeaceb22ea23f6f6e8118fb8e0490591
Author: Douglas Bagnall <[email protected]>
Date: Wed Jan 15 15:07:38 2025 +1300
samba-tool: do not complain of no sub-command with '-V'
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15770
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Jennifer Sutton <[email protected]>
commit fd59b316b80eac6fc1c2e62193995adc09d099cd
Author: Douglas Bagnall <[email protected]>
Date: Thu Jan 30 21:22:53 2025 +1300
pytest: samba-tool --version tests
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15770
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Jennifer Sutton <[email protected]>
-----------------------------------------------------------------------
Summary of changes:
python/samba/getopt.py | 4 ++--
python/samba/netcmd/__init__.py | 45 +++++++++++++++++++++++++++++++----
python/samba/netcmd/contact.py | 15 +-----------
python/samba/netcmd/main.py | 5 ----
python/samba/tests/samba_tool/help.py | 31 ++++++++++++++++++++++++
source4/libnet/libnet_lookup.c | 3 +++
6 files changed, 77 insertions(+), 26 deletions(-)
Changeset truncated at 500 lines:
diff --git a/python/samba/getopt.py b/python/samba/getopt.py
index 2620138c3de..b810e5ac797 100644
--- a/python/samba/getopt.py
+++ b/python/samba/getopt.py
@@ -32,6 +32,7 @@ from samba.credentials import (
MUST_USE_KERBEROS,
)
from samba._glue import get_burnt_commandline
+import samba
def check_bytes(option, opt, value):
@@ -310,10 +311,9 @@ class VersionOptions(OptionGroup):
super().__init__(parser, "Version Options")
self.add_option("-V", "--version", action="callback",
callback=self._display_version,
- help="Display version number")
+ help=f"Display version number ({samba.version})")
def _display_version(self, option, opt_str, arg, parser):
- import samba
print(samba.version)
sys.exit(0)
diff --git a/python/samba/netcmd/__init__.py b/python/samba/netcmd/__init__.py
index 2663d3d0cea..9aa4664418a 100644
--- a/python/samba/netcmd/__init__.py
+++ b/python/samba/netcmd/__init__.py
@@ -30,6 +30,7 @@ from samba.getopt import Option, OptionParser
from samba.logger import get_samba_logger
from samba.samdb import SamDB
from samba.dcerpc.security import SDDLValueError
+from samba import getopt as options
from .encoders import JSONEncoder
@@ -281,10 +282,16 @@ class Command(object):
option_class=Option)
parser.add_options(self.takes_options)
optiongroups = {}
+
+ # let samba-tool subcommands process --version
+ if "versionopts" not in self.takes_optiongroups:
+ self.takes_optiongroups["_versionopts"] = options.VersionOptions
+
for name in sorted(self.takes_optiongroups.keys()):
optiongroup = self.takes_optiongroups[name]
optiongroups[name] = optiongroup(parser)
parser.add_option_group(optiongroups[name])
+
if self.use_colour:
parser.add_option("--color",
help="use colour if available (default: auto)",
@@ -313,12 +320,36 @@ class Command(object):
return -1
# Filter out options from option groups
+ #
+ # run() methods on subclasses receive all direct options as
+ # keyword arguments, but options that come from OptionGroups
+ # (for example, --configfile from SambaOpts group) are removed
+ # from the direct keyword arguments list, and the option group
+ # itself becomes a keyword argument. The option can be
+ # accessed as an attribute of that (e.g. sambaopts.configfile).
+ #
+ # This allows for option groups to grow without needing to
+ # change the signature for all samba-tool tools.
+ #
+ # _versionopts special case.
+ # ==========================
+ #
+ # The _versionopts group was added automatically, and is
+ # removed here. It only has the -V/--version option, and that
+ # will have triggered already if given (as will --help, and
+ # errors on unknown options).
+ #
+ # Some subclasses take 'versionopts' which they expect to
+ # receive but never use.
+
kwargs = dict(opts.__dict__)
- for option_group in parser.option_groups:
+
+ for og_name, option_group in optiongroups.items():
for option in option_group.option_list:
if option.dest is not None and option.dest in kwargs:
del kwargs[option.dest]
- kwargs.update(optiongroups)
+ if og_name != '_versionopts':
+ kwargs[og_name] = option_group
if kwargs.get('output_format') == 'json':
self.preferred_output_format = 'json'
@@ -415,7 +446,10 @@ class SuperCommand(Command):
sub = self.subcommands[a]
return sub._resolve(sub_path, *sub_args, outf=outf, errf=errf)
- elif a in ['--help', 'help', None, '-h', '-V', '--version']:
+ if a in ['-V', '--version']:
+ return (self, [a])
+
+ if a in ['--help', 'help', None, '-h']:
# we pass these to the leaf node.
if a == 'help':
a = '--help'
@@ -426,8 +460,9 @@ class SuperCommand(Command):
print("%s: no such subcommand: %s\n" % (path, a), file=self.outf)
return (self, [])
- # We didn't find a subcommand, but maybe we found e.g. --version
- print("%s: missing subcommand\n" % (path), file=self.outf)
+ # We didn't find a subcommand, but maybe we found e.g. --help
+ if not deferred_args:
+ print("%s: missing subcommand\n" % (path), file=self.outf)
return (self, deferred_args)
def _run(self, *argv):
diff --git a/python/samba/netcmd/contact.py b/python/samba/netcmd/contact.py
index 064a3ce6691..b34e473f20e 100644
--- a/python/samba/netcmd/contact.py
+++ b/python/samba/netcmd/contact.py
@@ -100,14 +100,12 @@ class cmd_add(Command):
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
}
def run(self,
fullcontactname=None,
sambaopts=None,
credopts=None,
- versionopts=None,
H=None,
ou=None,
surname=None,
@@ -187,14 +185,12 @@ class cmd_delete(Command):
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
}
def run(self,
contactname,
sambaopts=None,
credopts=None,
- versionopts=None,
H=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)
@@ -267,13 +263,11 @@ class cmd_list(Command):
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
}
def run(self,
sambaopts=None,
credopts=None,
- versionopts=None,
H=None,
base_dn=None,
full_dn=False):
@@ -363,14 +357,12 @@ class cmd_edit(Command):
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
}
def run(self,
contactname,
sambaopts=None,
credopts=None,
- versionopts=None,
H=None,
editor=None):
lp = sambaopts.get_loadparm()
@@ -500,14 +492,12 @@ class cmd_show(Command):
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
}
def run(self,
contactname,
sambaopts=None,
credopts=None,
- versionopts=None,
H=None,
contact_attrs=None):
@@ -604,7 +594,6 @@ class cmd_move(Command):
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
}
def run(self,
@@ -612,7 +601,6 @@ class cmd_move(Command):
new_parent_dn,
sambaopts=None,
credopts=None,
- versionopts=None,
H=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)
@@ -743,11 +731,10 @@ class cmd_rename(Command):
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
}
- def run(self, contactname, credopts=None, sambaopts=None, versionopts=None,
+ def run(self, contactname, credopts=None, sambaopts=None,
H=None, surname=None, given_name=None, initials=None,
force_new_cn=None,
display_name=None, mail_address=None, reset_cn=None):
# illegal options
diff --git a/python/samba/netcmd/main.py b/python/samba/netcmd/main.py
index cce1f291f34..bc7274913d9 100644
--- a/python/samba/netcmd/main.py
+++ b/python/samba/netcmd/main.py
@@ -17,7 +17,6 @@
"""The main samba-tool command implementation."""
-from samba import getopt as options
from samba.netcmd import SuperCommand
@@ -52,10 +51,6 @@ class cache_loader(dict):
class cmd_sambatool(SuperCommand):
"""Main samba administration tool."""
- takes_optiongroups = {
- "versionopts": options.VersionOptions,
- }
-
subcommands = cache_loader()
subcommands["computer"] = None
diff --git a/python/samba/tests/samba_tool/help.py
b/python/samba/tests/samba_tool/help.py
index 16eb6b74c5d..3459dd21619 100644
--- a/python/samba/tests/samba_tool/help.py
+++ b/python/samba/tests/samba_tool/help.py
@@ -22,6 +22,7 @@ from samba.tests.samba_tool.base import SambaToolCmdTest
from samba.tests import BlackboxProcessError
from samba.tests import check_help_consistency
from samba.common import get_string
+from samba import version
class HelpTestCase(SambaToolCmdTest):
@@ -88,3 +89,33 @@ class HelpTestCase(SambaToolCmdTest):
"pleeease"])
self.assertIn("if '--pass-the-salt-please' is not misspelt", err)
self.assertIn("the appropriate list in is_password_option", err)
+
+ def test_version(self):
+ """Does --version work?"""
+ (result, out, err) = self.run_command(["samba-tool", "--version"])
+ self.assertEqual(version, out.strip())
+
+ def test_sub_command_version(self):
+ """Does --version work in a sub-command?"""
+ (result, out, err) = self.run_command(["samba-tool", "spn",
"--version"])
+ self.assertEqual(version, out.strip())
+
+ def test_leaf_command_version(self):
+ """Does --version work in a leaf command?"""
+ (result, out, err) = self.run_command(["samba-tool", "contact", "edit",
+ "--version"])
+ self.assertEqual(version, out.strip())
+
+ def test_help_version(self):
+ """Is version mentioned in --help?"""
+ (result, out, err) = self.run_command(["samba-tool", "spn", "--help"])
+ self.assertIn(version, out)
+
+ def test_version_beats_help(self):
+ """Does samba-tool --help --version print version?"""
+ (result, out, err) = self.run_command(["samba-tool", "spn", "--help",
"-V"])
+ self.assertEqual(version, out.strip())
+ (result, out, err) = self.run_command(["samba-tool", "--help", "-V"])
+ self.assertEqual(version, out.strip())
+ (result, out, err) = self.run_command(["samba-tool", "dns", "-V",
"--help"])
+ self.assertEqual(version, out.strip())
diff --git a/source4/libnet/libnet_lookup.c b/source4/libnet/libnet_lookup.c
index f8477c7258c..26cf26fe3e1 100644
--- a/source4/libnet/libnet_lookup.c
+++ b/source4/libnet/libnet_lookup.c
@@ -223,6 +223,9 @@ NTSTATUS libnet_LookupDCs_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
NTSTATUS status;
struct finddcs finddcs_io;
status = finddcs_cldap_recv(req, mem_ctx, &finddcs_io);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
talloc_free(req);
io->out.num_dcs = 1;
io->out.dcs = talloc(mem_ctx, struct nbt_dc_name);
--
Samba Shared Repository