1 # domain management - domain dcpromo
3 # Copyright Matthias Dieter Wallnoefer 2009
4 # Copyright Andrew Kroeger 2009
5 # Copyright Jelmer Vernooij 2007-2012
6 # Copyright Giampaolo Lauria 2011
7 # Copyright Matthieu Patou <mat@matws.net> 2011
8 # Copyright Andrew Bartlett 2008-2015
9 # Copyright Stefan Metzmacher 2012
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 import samba
.getopt
as options
27 from samba
.join
import join_DC
, join_RODC
28 from samba
.net
import Net
29 from samba
.netcmd
import Command
, CommandError
31 from .common
import (common_join_options
, common_ntvfs_options
,
32 common_provision_join_options
)
35 class cmd_domain_dcpromo(Command
):
36 """Promote an existing domain member or NT4 PDC to an AD DC."""
38 synopsis
= "%prog <dnsdomain> [DC|RODC] [options]"
40 takes_optiongroups
= {
41 "sambaopts": options
.SambaOptions
,
42 "versionopts": options
.VersionOptions
,
43 "credopts": options
.CredentialsOptions
,
47 takes_options
.extend(common_join_options
)
49 takes_options
.extend(common_provision_join_options
)
51 if samba
.is_ntvfs_fileserver_built():
52 takes_options
.extend(common_ntvfs_options
)
54 takes_args
= ["domain", "role?"]
56 def run(self
, domain
, role
=None, sambaopts
=None, credopts
=None,
57 versionopts
=None, server
=None, site
=None, targetdir
=None,
58 domain_critical_only
=False, machinepass
=None,
59 use_ntvfs
=False, dns_backend
=None,
60 quiet
=False, verbose
=False, plaintext_secrets
=False,
61 backend_store
=None, backend_store_size
=None):
62 lp
= sambaopts
.get_loadparm()
63 creds
= credopts
.get_credentials(lp
)
65 logger
= self
.get_logger(verbose
=verbose
, quiet
=quiet
)
67 netbios_name
= lp
.get("netbios name")
73 join_DC(logger
=logger
, server
=server
, creds
=creds
, lp
=lp
, domain
=domain
,
74 site
=site
, netbios_name
=netbios_name
, targetdir
=targetdir
,
75 domain_critical_only
=domain_critical_only
,
76 machinepass
=machinepass
, use_ntvfs
=use_ntvfs
,
77 dns_backend
=dns_backend
,
78 promote_existing
=True, plaintext_secrets
=plaintext_secrets
,
79 backend_store
=backend_store
,
80 backend_store_size
=backend_store_size
)
82 join_RODC(logger
=logger
, server
=server
, creds
=creds
, lp
=lp
, domain
=domain
,
83 site
=site
, netbios_name
=netbios_name
, targetdir
=targetdir
,
84 domain_critical_only
=domain_critical_only
,
85 machinepass
=machinepass
, use_ntvfs
=use_ntvfs
, dns_backend
=dns_backend
,
86 promote_existing
=True, plaintext_secrets
=plaintext_secrets
,
87 backend_store
=backend_store
,
88 backend_store_size
=backend_store_size
)
90 raise CommandError("Invalid role '%s' (possible values: DC, RODC)" % role
)