--- /dev/null
+# domain management - common code
+#
+# Copyright Catlayst .Net Ltd 2017-2023
+# Copyright Jelmer Vernooij 2007-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/>.
+#
+
+from samba.dsdb import (
+ DS_DOMAIN_FUNCTION_2000,
+ DS_DOMAIN_FUNCTION_2003,
+ DS_DOMAIN_FUNCTION_2008,
+ DS_DOMAIN_FUNCTION_2008_R2,
+ DS_DOMAIN_FUNCTION_2012,
+ DS_DOMAIN_FUNCTION_2012_R2,
+ DS_DOMAIN_FUNCTION_2003_MIXED,
+ DS_DOMAIN_FUNCTION_2016
+)
+
+string_version_to_constant = {
+ "2000": DS_DOMAIN_FUNCTION_2000,
+ "2003": DS_DOMAIN_FUNCTION_2003,
+ "2008": DS_DOMAIN_FUNCTION_2008,
+ "2008_R2": DS_DOMAIN_FUNCTION_2008_R2,
+ "2012": DS_DOMAIN_FUNCTION_2012,
+ "2012_R2": DS_DOMAIN_FUNCTION_2012_R2,
+ "2016": DS_DOMAIN_FUNCTION_2016,
+}
+
+
+def string_to_level(string):
+ """Interpret a string indicating a functional level."""
+ return string_version_to_constant[string]
+
+
+def level_to_string(level):
+ """turn the level enum number into a printable string."""
+ if level < DS_DOMAIN_FUNCTION_2000:
+ return "invalid"
+ strings = {
+ DS_DOMAIN_FUNCTION_2000: "2000",
+ DS_DOMAIN_FUNCTION_2003_MIXED: \
+ "2003 with mixed domains/interim (NT4 DC support)",
+ DS_DOMAIN_FUNCTION_2003: "2003",
+ DS_DOMAIN_FUNCTION_2008: "2008",
+ DS_DOMAIN_FUNCTION_2008_R2: "2008 R2",
+ DS_DOMAIN_FUNCTION_2012: "2012",
+ DS_DOMAIN_FUNCTION_2012_R2: "2012 R2",
+ DS_DOMAIN_FUNCTION_2016: "2016",
+ }
+ return strings.get(level, "higher than 2016")
from .claim import cmd_domain_claim
from .classicupgrade import cmd_domain_classicupgrade
from .common import (common_join_options, common_ntvfs_options,
- common_provision_join_options, string_to_level)
+ common_provision_join_options)
from .dcpromo import cmd_domain_dcpromo
from .demote import cmd_domain_demote
from .functional_prep import cmd_domain_functional_prep
from uuid import UUID
-from samba.dsdb import (
- DS_DOMAIN_FUNCTION_2000,
- DS_DOMAIN_FUNCTION_2003,
- DS_DOMAIN_FUNCTION_2008,
- DS_DOMAIN_FUNCTION_2008_R2,
- DS_DOMAIN_FUNCTION_2012,
- DS_DOMAIN_FUNCTION_2012_R2,
- DS_DOMAIN_FUNCTION_2003_MIXED,
- DS_DOMAIN_FUNCTION_2016
-)
from samba.netcmd import CommandError, Option
from samba.samdb import get_default_backend_store
]
-string_version_to_constant = {
- "2000": DS_DOMAIN_FUNCTION_2000,
- "2003": DS_DOMAIN_FUNCTION_2003,
- "2008": DS_DOMAIN_FUNCTION_2008,
- "2008_R2": DS_DOMAIN_FUNCTION_2008_R2,
- "2012": DS_DOMAIN_FUNCTION_2012,
- "2012_R2": DS_DOMAIN_FUNCTION_2012_R2,
- "2016": DS_DOMAIN_FUNCTION_2016,
-}
-
-
-def string_to_level(string):
- """Interpret a string indicating a functional level."""
- try:
- return string_version_to_constant[string]
- except KeyError as e:
- raise CommandError(f"'{string}' is not a valid domain level")
-
-
-def level_to_string(level):
- """turn the level enum number into a printable string."""
- if level < DS_DOMAIN_FUNCTION_2000:
- return "invalid"
- strings = {
- DS_DOMAIN_FUNCTION_2000: "2000",
- DS_DOMAIN_FUNCTION_2003_MIXED: \
- "2003 with mixed domains/interim (NT4 DC support)",
- DS_DOMAIN_FUNCTION_2003: "2003",
- DS_DOMAIN_FUNCTION_2008: "2008",
- DS_DOMAIN_FUNCTION_2008_R2: "2008 R2",
- DS_DOMAIN_FUNCTION_2012: "2012",
- DS_DOMAIN_FUNCTION_2012_R2: "2012 R2",
- DS_DOMAIN_FUNCTION_2016: "2016",
- }
- return strings.get(level, "higher than 2016")
-
-
def parse_text(value):
"""Parse message element to string value."""
if value is not None:
from samba.netcmd.fsmo import get_fsmo_roleowner
from samba.samdb import SamDB
-from .common import string_to_level
+from samba import functional_level
class cmd_domain_functional_prep(Command):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp)
H = kwargs.get("H")
- target_level = string_to_level(kwargs.get("function_level"))
+ function_level = kwargs.get("function_level")
+ try:
+ target_level = functional_level.string_to_level(function_level)
+ except KeyError:
+ raise CommandError(f"'{function_level}' is not known to Samba as an AD functional level")
+
forest_prep = kwargs.get("forest_prep")
domain_prep = kwargs.get("domain_prep")
from samba.netcmd import Command, CommandError, Option
from samba.samdb import SamDB
-from .common import level_to_string, string_to_level
+from samba import functional_level
class cmd_domain_level(Command):
self.message("")
- outstr = level_to_string(level_forest)
+ outstr = functional_level.level_to_string(level_forest)
self.message("Forest function level: (Windows) " + outstr)
if level_domain == DS_DOMAIN_FUNCTION_2000 and level_domain_mixed:
outstr = "2000 mixed (NT4 DC support)"
else:
- outstr = level_to_string(level_domain)
+ outstr = functional_level.level_to_string(level_domain)
self.message("Domain function level: (Windows) " + outstr)
- outstr = level_to_string(min_level_dc)
+ outstr = functional_level.level_to_string(min_level_dc)
self.message("Lowest function level of a DC: (Windows) " + outstr)
elif subcommand == "raise":
msgs = []
if domain_level is not None:
- new_level_domain = string_to_level(domain_level)
+ try:
+ new_level_domain = functional_level.string_to_level(domain_level)
+ except KeyError:
+ raise CommandError(f"New functional level '{domain_level}' is not known to Samba as an AD functional level")
if new_level_domain <= level_domain and level_domain_mixed == 0:
raise CommandError("Domain function level can't be smaller than or equal to the actual one!")