mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
netcmd: domain: move dcpromo command to domain/dcpromo.py
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
d26054d7da
commit
72f6f7a79c
@ -105,7 +105,9 @@ from samba import dsdb
|
|||||||
|
|
||||||
from .backup import cmd_domain_backup
|
from .backup import cmd_domain_backup
|
||||||
from .classicupgrade import cmd_domain_classicupgrade
|
from .classicupgrade import cmd_domain_classicupgrade
|
||||||
from .common import common_ntvfs_options
|
from .common import (common_join_options, common_ntvfs_options,
|
||||||
|
common_provision_join_options)
|
||||||
|
from .dcpromo import cmd_domain_dcpromo
|
||||||
|
|
||||||
string_version_to_constant = {
|
string_version_to_constant = {
|
||||||
"2000": DS_DOMAIN_FUNCTION_2000,
|
"2000": DS_DOMAIN_FUNCTION_2000,
|
||||||
@ -117,39 +119,6 @@ string_version_to_constant = {
|
|||||||
"2016": DS_DOMAIN_FUNCTION_2016,
|
"2016": DS_DOMAIN_FUNCTION_2016,
|
||||||
}
|
}
|
||||||
|
|
||||||
common_provision_join_options = [
|
|
||||||
Option("--machinepass", type="string", metavar="PASSWORD",
|
|
||||||
help="choose machine password (otherwise random)"),
|
|
||||||
Option("--plaintext-secrets", action="store_true",
|
|
||||||
help="Store secret/sensitive values as plain text on disk" +
|
|
||||||
"(default is to encrypt secret/sensitive values)"),
|
|
||||||
Option("--backend-store", type="choice", metavar="BACKENDSTORE",
|
|
||||||
choices=["tdb", "mdb"],
|
|
||||||
help="Specify the database backend to be used "
|
|
||||||
"(default is %s)" % get_default_backend_store()),
|
|
||||||
Option("--backend-store-size", type="bytes", metavar="SIZE",
|
|
||||||
help="Specify the size of the backend database, currently only " +
|
|
||||||
"supported by lmdb backends (default is 8 Gb)."),
|
|
||||||
Option("--targetdir", metavar="DIR",
|
|
||||||
help="Set target directory (where to store provision)", type=str),
|
|
||||||
Option("-q", "--quiet", help="Be quiet", action="store_true"),
|
|
||||||
]
|
|
||||||
|
|
||||||
common_join_options = [
|
|
||||||
Option("--server", help="DC to join", type=str),
|
|
||||||
Option("--site", help="site to join", type=str),
|
|
||||||
Option("--domain-critical-only",
|
|
||||||
help="only replicate critical domain objects",
|
|
||||||
action="store_true"),
|
|
||||||
Option("--dns-backend", type="choice", metavar="NAMESERVER-BACKEND",
|
|
||||||
choices=["SAMBA_INTERNAL", "BIND9_DLZ", "NONE"],
|
|
||||||
help="The DNS server backend. SAMBA_INTERNAL is the builtin name server (default), "
|
|
||||||
"BIND9_DLZ uses samba4 AD to store zone information, "
|
|
||||||
"NONE skips the DNS setup entirely (this DC will not be a DNS server)",
|
|
||||||
default="SAMBA_INTERNAL"),
|
|
||||||
Option("-v", "--verbose", help="Be verbose", action="store_true")
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def level_to_string(level):
|
def level_to_string(level):
|
||||||
"""turn the level enum number into a printable string."""
|
"""turn the level enum number into a printable string."""
|
||||||
@ -596,65 +565,6 @@ class cmd_domain_provision(Command):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class cmd_domain_dcpromo(Command):
|
|
||||||
"""Promote an existing domain member or NT4 PDC to an AD DC."""
|
|
||||||
|
|
||||||
synopsis = "%prog <dnsdomain> [DC|RODC] [options]"
|
|
||||||
|
|
||||||
takes_optiongroups = {
|
|
||||||
"sambaopts": options.SambaOptions,
|
|
||||||
"versionopts": options.VersionOptions,
|
|
||||||
"credopts": options.CredentialsOptions,
|
|
||||||
}
|
|
||||||
|
|
||||||
takes_options = []
|
|
||||||
takes_options.extend(common_join_options)
|
|
||||||
|
|
||||||
takes_options.extend(common_provision_join_options)
|
|
||||||
|
|
||||||
if samba.is_ntvfs_fileserver_built():
|
|
||||||
takes_options.extend(common_ntvfs_options)
|
|
||||||
|
|
||||||
takes_args = ["domain", "role?"]
|
|
||||||
|
|
||||||
def run(self, domain, role=None, sambaopts=None, credopts=None,
|
|
||||||
versionopts=None, server=None, site=None, targetdir=None,
|
|
||||||
domain_critical_only=False, machinepass=None,
|
|
||||||
use_ntvfs=False, dns_backend=None,
|
|
||||||
quiet=False, verbose=False, plaintext_secrets=False,
|
|
||||||
backend_store=None, backend_store_size=None):
|
|
||||||
lp = sambaopts.get_loadparm()
|
|
||||||
creds = credopts.get_credentials(lp)
|
|
||||||
net = Net(creds, lp, server=credopts.ipaddress)
|
|
||||||
|
|
||||||
logger = self.get_logger(verbose=verbose, quiet=quiet)
|
|
||||||
|
|
||||||
netbios_name = lp.get("netbios name")
|
|
||||||
|
|
||||||
if role is not None:
|
|
||||||
role = role.upper()
|
|
||||||
|
|
||||||
if role == "DC":
|
|
||||||
join_DC(logger=logger, server=server, creds=creds, lp=lp, domain=domain,
|
|
||||||
site=site, netbios_name=netbios_name, targetdir=targetdir,
|
|
||||||
domain_critical_only=domain_critical_only,
|
|
||||||
machinepass=machinepass, use_ntvfs=use_ntvfs,
|
|
||||||
dns_backend=dns_backend,
|
|
||||||
promote_existing=True, plaintext_secrets=plaintext_secrets,
|
|
||||||
backend_store=backend_store,
|
|
||||||
backend_store_size=backend_store_size)
|
|
||||||
elif role == "RODC":
|
|
||||||
join_RODC(logger=logger, server=server, creds=creds, lp=lp, domain=domain,
|
|
||||||
site=site, netbios_name=netbios_name, targetdir=targetdir,
|
|
||||||
domain_critical_only=domain_critical_only,
|
|
||||||
machinepass=machinepass, use_ntvfs=use_ntvfs, dns_backend=dns_backend,
|
|
||||||
promote_existing=True, plaintext_secrets=plaintext_secrets,
|
|
||||||
backend_store=backend_store,
|
|
||||||
backend_store_size=backend_store_size)
|
|
||||||
else:
|
|
||||||
raise CommandError("Invalid role '%s' (possible values: DC, RODC)" % role)
|
|
||||||
|
|
||||||
|
|
||||||
class cmd_domain_join(Command):
|
class cmd_domain_join(Command):
|
||||||
"""Join domain as either member or backup domain controller."""
|
"""Join domain as either member or backup domain controller."""
|
||||||
|
|
||||||
|
@ -23,8 +23,42 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from samba.netcmd import Option
|
from samba.netcmd import Option
|
||||||
|
from samba.samdb import get_default_backend_store
|
||||||
|
|
||||||
common_ntvfs_options = [
|
common_ntvfs_options = [
|
||||||
Option("--use-ntvfs", help="Use NTVFS for the fileserver (default = no)",
|
Option("--use-ntvfs", help="Use NTVFS for the fileserver (default = no)",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
common_provision_join_options = [
|
||||||
|
Option("--machinepass", type="string", metavar="PASSWORD",
|
||||||
|
help="choose machine password (otherwise random)"),
|
||||||
|
Option("--plaintext-secrets", action="store_true",
|
||||||
|
help="Store secret/sensitive values as plain text on disk" +
|
||||||
|
"(default is to encrypt secret/sensitive values)"),
|
||||||
|
Option("--backend-store", type="choice", metavar="BACKENDSTORE",
|
||||||
|
choices=["tdb", "mdb"],
|
||||||
|
help="Specify the database backend to be used "
|
||||||
|
"(default is %s)" % get_default_backend_store()),
|
||||||
|
Option("--backend-store-size", type="bytes", metavar="SIZE",
|
||||||
|
help="Specify the size of the backend database, currently only " +
|
||||||
|
"supported by lmdb backends (default is 8 Gb)."),
|
||||||
|
Option("--targetdir", metavar="DIR",
|
||||||
|
help="Set target directory (where to store provision)", type=str),
|
||||||
|
Option("-q", "--quiet", help="Be quiet", action="store_true"),
|
||||||
|
]
|
||||||
|
|
||||||
|
common_join_options = [
|
||||||
|
Option("--server", help="DC to join", type=str),
|
||||||
|
Option("--site", help="site to join", type=str),
|
||||||
|
Option("--domain-critical-only",
|
||||||
|
help="only replicate critical domain objects",
|
||||||
|
action="store_true"),
|
||||||
|
Option("--dns-backend", type="choice", metavar="NAMESERVER-BACKEND",
|
||||||
|
choices=["SAMBA_INTERNAL", "BIND9_DLZ", "NONE"],
|
||||||
|
help="The DNS server backend. SAMBA_INTERNAL is the builtin name server (default), "
|
||||||
|
"BIND9_DLZ uses samba4 AD to store zone information, "
|
||||||
|
"NONE skips the DNS setup entirely (this DC will not be a DNS server)",
|
||||||
|
default="SAMBA_INTERNAL"),
|
||||||
|
Option("-v", "--verbose", help="Be verbose", action="store_true")
|
||||||
|
]
|
||||||
|
91
python/samba/netcmd/domain/dcpromo.py
Normal file
91
python/samba/netcmd/domain/dcpromo.py
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
# domain management - domain dcpromo
|
||||||
|
#
|
||||||
|
# Copyright Matthias Dieter Wallnoefer 2009
|
||||||
|
# Copyright Andrew Kroeger 2009
|
||||||
|
# Copyright Jelmer Vernooij 2007-2012
|
||||||
|
# Copyright Giampaolo Lauria 2011
|
||||||
|
# Copyright Matthieu Patou <mat@matws.net> 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
import samba
|
||||||
|
import samba.getopt as options
|
||||||
|
from samba.join import join_DC, join_RODC
|
||||||
|
from samba.net import Net
|
||||||
|
from samba.netcmd import Command, CommandError
|
||||||
|
|
||||||
|
from .common import (common_join_options, common_ntvfs_options,
|
||||||
|
common_provision_join_options)
|
||||||
|
|
||||||
|
|
||||||
|
class cmd_domain_dcpromo(Command):
|
||||||
|
"""Promote an existing domain member or NT4 PDC to an AD DC."""
|
||||||
|
|
||||||
|
synopsis = "%prog <dnsdomain> [DC|RODC] [options]"
|
||||||
|
|
||||||
|
takes_optiongroups = {
|
||||||
|
"sambaopts": options.SambaOptions,
|
||||||
|
"versionopts": options.VersionOptions,
|
||||||
|
"credopts": options.CredentialsOptions,
|
||||||
|
}
|
||||||
|
|
||||||
|
takes_options = []
|
||||||
|
takes_options.extend(common_join_options)
|
||||||
|
|
||||||
|
takes_options.extend(common_provision_join_options)
|
||||||
|
|
||||||
|
if samba.is_ntvfs_fileserver_built():
|
||||||
|
takes_options.extend(common_ntvfs_options)
|
||||||
|
|
||||||
|
takes_args = ["domain", "role?"]
|
||||||
|
|
||||||
|
def run(self, domain, role=None, sambaopts=None, credopts=None,
|
||||||
|
versionopts=None, server=None, site=None, targetdir=None,
|
||||||
|
domain_critical_only=False, machinepass=None,
|
||||||
|
use_ntvfs=False, dns_backend=None,
|
||||||
|
quiet=False, verbose=False, plaintext_secrets=False,
|
||||||
|
backend_store=None, backend_store_size=None):
|
||||||
|
lp = sambaopts.get_loadparm()
|
||||||
|
creds = credopts.get_credentials(lp)
|
||||||
|
net = Net(creds, lp, server=credopts.ipaddress)
|
||||||
|
|
||||||
|
logger = self.get_logger(verbose=verbose, quiet=quiet)
|
||||||
|
|
||||||
|
netbios_name = lp.get("netbios name")
|
||||||
|
|
||||||
|
if role is not None:
|
||||||
|
role = role.upper()
|
||||||
|
|
||||||
|
if role == "DC":
|
||||||
|
join_DC(logger=logger, server=server, creds=creds, lp=lp, domain=domain,
|
||||||
|
site=site, netbios_name=netbios_name, targetdir=targetdir,
|
||||||
|
domain_critical_only=domain_critical_only,
|
||||||
|
machinepass=machinepass, use_ntvfs=use_ntvfs,
|
||||||
|
dns_backend=dns_backend,
|
||||||
|
promote_existing=True, plaintext_secrets=plaintext_secrets,
|
||||||
|
backend_store=backend_store,
|
||||||
|
backend_store_size=backend_store_size)
|
||||||
|
elif role == "RODC":
|
||||||
|
join_RODC(logger=logger, server=server, creds=creds, lp=lp, domain=domain,
|
||||||
|
site=site, netbios_name=netbios_name, targetdir=targetdir,
|
||||||
|
domain_critical_only=domain_critical_only,
|
||||||
|
machinepass=machinepass, use_ntvfs=use_ntvfs, dns_backend=dns_backend,
|
||||||
|
promote_existing=True, plaintext_secrets=plaintext_secrets,
|
||||||
|
backend_store=backend_store,
|
||||||
|
backend_store_size=backend_store_size)
|
||||||
|
else:
|
||||||
|
raise CommandError("Invalid role '%s' (possible values: DC, RODC)" % role)
|
Loading…
Reference in New Issue
Block a user