From: Rob van der Linde Date: Fri, 31 Mar 2023 00:05:07 +0000 (+1300) Subject: netcmd: domain: move leave command to domain/leave.py X-Git-Tag: talloc-2.4.1~1182 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e7ad2364a5ec5cc709467430f7014bc5c5bd5d2d;p=thirdparty%2Fsamba.git netcmd: domain: move leave command to domain/leave.py Signed-off-by: Rob van der Linde Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/netcmd/domain/__init__.py b/python/samba/netcmd/domain/__init__.py index 778a3b523e5..76c8bdeb07e 100644 --- a/python/samba/netcmd/domain/__init__.py +++ b/python/samba/netcmd/domain/__init__.py @@ -55,11 +55,8 @@ from samba.netcmd.fsmo import get_fsmo_roleowner from samba.netcmd.common import (NEVER_TIMESTAMP, timestamp_to_mins, timestamp_to_days) -from samba.samba3 import param as s3param from samba import string_to_byte_array from samba.auth_util import system_session_unix -from samba.net_s3 import Net as s3_Net -from samba.param import default_path from samba import is_ad_dc_built from samba.dsdb import ( @@ -106,6 +103,7 @@ from .functional_prep import cmd_domain_functional_prep from .info import cmd_domain_info from .join import cmd_domain_join from .keytab import cmd_domain_export_keytab +from .leave import cmd_domain_leave def level_to_string(level): @@ -486,36 +484,6 @@ class cmd_domain_provision(Command): return None -class cmd_domain_leave(Command): - """Cause a domain member to leave the joined domain.""" - - synopsis = "%prog [options]" - - takes_optiongroups = { - "sambaopts": options.SambaOptions, - "versionopts": options.VersionOptions, - "credopts": options.CredentialsOptions, - } - - takes_options = [ - Option("--keep-account", action="store_true", - help="Disable the machine account instead of deleting it.") - ] - - takes_args = [] - - def run(self, sambaopts=None, credopts=None, versionopts=None, - keep_account=False): - lp = sambaopts.get_loadparm() - creds = credopts.get_credentials(lp) - - s3_lp = s3param.get_context() - smb_conf = lp.configfile if lp.configfile else default_path() - s3_lp.load(smb_conf) - s3_net = s3_Net(creds, s3_lp) - s3_net.leave(keep_account) - - class cmd_domain_level(Command): """Raise domain and forest function levels.""" diff --git a/python/samba/netcmd/domain/leave.py b/python/samba/netcmd/domain/leave.py new file mode 100644 index 00000000000..0d58360721e --- /dev/null +++ b/python/samba/netcmd/domain/leave.py @@ -0,0 +1,59 @@ +# domain management - domain leave +# +# Copyright Matthias Dieter Wallnoefer 2009 +# Copyright Andrew Kroeger 2009 +# Copyright Jelmer Vernooij 2007-2012 +# Copyright Giampaolo Lauria 2011 +# Copyright Matthieu Patou 2011 +# Copyright Andrew Bartlett 2008-2015 +# Copyright Stefan Metzmacher 2012 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import samba.getopt as options +from samba.net_s3 import Net as s3_Net +from samba.netcmd import Command, Option +from samba.param import default_path +from samba.samba3 import param as s3param + + +class cmd_domain_leave(Command): + """Cause a domain member to leave the joined domain.""" + + synopsis = "%prog [options]" + + takes_optiongroups = { + "sambaopts": options.SambaOptions, + "versionopts": options.VersionOptions, + "credopts": options.CredentialsOptions, + } + + takes_options = [ + Option("--keep-account", action="store_true", + help="Disable the machine account instead of deleting it.") + ] + + takes_args = [] + + def run(self, sambaopts=None, credopts=None, versionopts=None, + keep_account=False): + lp = sambaopts.get_loadparm() + creds = credopts.get_credentials(lp) + + s3_lp = s3param.get_context() + smb_conf = lp.configfile if lp.configfile else default_path() + s3_lp.load(smb_conf) + s3_net = s3_Net(creds, s3_lp) + s3_net.leave(keep_account)