1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

s4:domainlevel - General rework

- We support domain/forest function levels >= (Windows) 2003 Native -> adapt the
  domain/forest and DC function level restrictions.
- Consider also the lowest function level of a DC. The domain and forest function
  levels can never be higher than it.
- Improve the error handling by printing out messages to "stderr"
- Introduce the "choice" type for choice arguments (saves us some error handling)
This commit is contained in:
Matthias Dieter Wallnöfer 2009-09-21 21:46:14 +02:00
parent 1f2490e7d8
commit d6f69ebcc2

View File

@ -18,6 +18,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Notice: At the moment we have some more checks to do here on the special
# attributes (consider attribute "msDS-Behavior-Version). This is due to the
# fact that we on s4 LDB don't implement their change policy (only certain
# values, only increments possible...) yet.
import sys
# Find right directory when running from source tree
@ -32,6 +37,8 @@ from samba.samdb import SamDB
from samba import DS_DOMAIN_FUNCTION_2000, DS_DOMAIN_FUNCTION_2003
from samba import DS_DOMAIN_FUNCTION_2003_MIXED, DS_DOMAIN_FUNCTION_2008
from samba import DS_DOMAIN_FUNCTION_2008_R2
from samba import DS_DC_FUNCTION_2000, DS_DC_FUNCTION_2003, DS_DC_FUNCTION_2008
from samba import DS_DC_FUNCTION_2008_R2
parser = optparse.OptionParser("domainlevel (show | raise <options>)")
sambaopts = options.SambaOptions(parser)
@ -41,10 +48,12 @@ credopts = options.CredentialsOptions(parser)
parser.add_option_group(credopts)
parser.add_option("-H", help="LDB URL for database or target server", type=str)
parser.add_option("--quiet", help="Be quiet", action="store_true")
parser.add_option("--forest",
help="The forest function level (2000 | 2003 | 2008 | 2008_R2). We don't support the 2003 with mixed domains (NT4 DC support) level.", type=str)
parser.add_option("--domain",
help="The domain function level (2000 | 2003 | 2008 | 2008_R2). We don't support mixed/interim (NT4 DC support) levels.", type=str)
parser.add_option("--forest", type="choice",
choices=["2003", "2008", "2008_R2"],
help="The forest function level (2003 | 2008 | 2008_R2)")
parser.add_option("--domain", type="choice",
choices=["2003", "2008", "2008_R2"],
help="The domain function level (2003 | 2008 | 2008_R2)")
opts, args = parser.parse_args()
#
@ -78,29 +87,48 @@ res_domain = samdb.search(domain_dn, scope=ldb.SCOPE_BASE,
attrs=["msDS-Behavior-Version", "nTMixedDomain"])
assert(len(res_domain) == 1)
res_dc_s = samdb.search("CN=Sites,CN=Configuration," + domain_dn,
scope=ldb.SCOPE_SUBTREE, expression="(objectClass=nTDSDSA)",
attrs=["msDS-Behavior-Version"])
assert(len(res_dc_s) >= 1)
try:
level_forest = int(res_forest[0]["msDS-Behavior-Version"][0])
level_domain = int(res_domain[0]["msDS-Behavior-Version"][0])
level_domain_mixed = int(res_domain[0]["nTMixedDomain"][0])
min_level_dc = int(res_dc_s[0]["msDS-Behavior-Version"][0]) # Init value
for msg in res_dc_s:
if int(msg["msDS-Behavior-Version"][0]) < min_level_dc:
min_level_dc = int(msg["msDS-Behavior-Version"][0])
if level_forest < 0 or level_domain < 0:
print "ERROR: Domain and/or forest functional level(s) is/are invalid. Correct them or reprovision!"
print >>sys.stderr, "ERROR: Domain and/or forest function level(s) is/are invalid. Correct them or reprovision!"
sys.exit(1)
if min_level_dc < 0:
print >>sys.stderr, "ERROR: Lowest function level of a DC is invalid. Correct this or reprovision!"
sys.exit(1)
if level_forest > level_domain:
print "ERROR: Forest function level is higher than the domain level(s). That can't be. Correct this or reprovision!"
print >>sys.stderr, "ERROR: Forest function level is higher than the domain level(s). Correct this or reprovision!"
sys.exit(1)
except:
print "ERROR: Could not retrieve the actual domain and/or forest level!"
if level_domain > min_level_dc:
print >>sys.stderr, "ERROR: Domain function level is higher than the lowest function level of a DC. Correct this or reprovision!"
sys.exit(1)
except KeyError:
print >>sys.stderr, "ERROR: Could not retrieve the actual domain, forest level and/or lowest DC function level!"
if args[0] == "show":
print "So the levels can't be displayed!"
print >>sys.stderr, "So the levels can't be displayed!"
sys.exit(1)
if args[0] == "show":
message("Domain and forest function level for domain '" + domain_dn + "'")
if level_forest == DS_DOMAIN_FUNCTION_2003_MIXED:
message("\nATTENTION: You run SAMBA 4 on the 2003 with mixed domains (NT4 DC support) forest level. This isn't supported! Please raise!")
if (level_domain == DS_DOMAIN_FUNCTION_2000 and level_domain_mixed != 0) or level_domain == DS_DOMAIN_FUNCTION_2003_MIXED:
message("\nATTENTION: You run SAMBA 4 on a mixed/interim (NT4 DC support) domain level. This isn't supported! Please raise!")
if level_forest < DS_DOMAIN_FUNCTION_2003:
message("\nATTENTION: You run SAMBA 4 on a forest function level lower than Windows 2003 (Native). This isn't supported! Please raise!")
if level_domain < DS_DOMAIN_FUNCTION_2003:
message("\nATTENTION: You run SAMBA 4 on a domain function level lower than Windows 2003 (Native). This isn't supported! Please raise!")
if min_level_dc < DS_DC_FUNCTION_2003:
message("\nATTENTION: You run SAMBA 4 on a lowest function level of a DC lower than Windows 2003. This isn't supported! Please step-up or upgrade the concerning DC(s)!")
message("")
@ -134,26 +162,37 @@ if args[0] == "show":
outstr = "higher than 2008 R2"
message("Domain function level: (Windows) " + outstr)
if min_level_dc == DS_DC_FUNCTION_2000:
outstr = "2000"
elif min_level_dc == DS_DC_FUNCTION_2003:
outstr = "2003"
elif min_level_dc == DS_DC_FUNCTION_2008:
outstr = "2008"
elif min_level_dc == DS_DC_FUNCTION_2008_R2:
outstr = "2008 R2"
else:
outstr = "higher than 2008 R2"
message("Lowest function level of a DC: (Windows) " + outstr)
elif args[0] == "raise":
msgs = []
if opts.domain is not None:
arg = opts.domain
if arg == "2000":
new_level_domain = DS_DOMAIN_FUNCTION_2000
elif arg == "2003":
if arg == "2003":
new_level_domain = DS_DOMAIN_FUNCTION_2003
elif arg == "2008":
new_level_domain = DS_DOMAIN_FUNCTION_2008
elif arg == "2008_R2":
new_level_domain = DS_DOMAIN_FUNCTION_2008_R2
else:
print "ERROR: Wrong argument '" + arg + "'!"
sys.exit(1)
if new_level_domain <= level_domain and level_domain_mixed == 0:
print "ERROR: Domain function level can't be smaller equal to the actual one!"
print >>sys.stderr, "ERROR: Domain function level can't be smaller equal to the actual one!"
sys.exit(1)
if new_level_domain > min_level_dc:
print >>sys.stderr, "ERROR: Domain function level can't be higher than the lowest function level of a DC!"
sys.exit(1)
# Deactivate mixed/interim domain support
@ -178,24 +217,19 @@ elif args[0] == "raise":
if opts.forest is not None:
arg = opts.forest
if arg == "2000":
new_level_forest = DS_DOMAIN_FUNCTION_2000
elif arg == "2003":
if arg == "2003":
new_level_forest = DS_DOMAIN_FUNCTION_2003
elif arg == "2008":
new_level_forest = DS_DOMAIN_FUNCTION_2008
elif arg == "2008_R2":
new_level_forest = DS_DOMAIN_FUNCTION_2008_R2
else:
print "ERROR: Wrong argument '" + arg + "'!"
sys.exit(1)
if new_level_forest <= level_forest:
print "ERROR: Forest function level can't be smaller equal to the actual one!"
print >>sys.stderr, "ERROR: Forest function level can't be smaller equal to the actual one!"
sys.exit(1)
if new_level_forest > level_domain:
print "ERROR: Forest function level can't be higher than the domain function level(s). Please raise it/them first!"
print >>sys.stderr, "ERROR: Forest function level can't be higher than the domain function level(s). Please raise it/them first!"
sys.exit(1)
m = ldb.Message()
@ -212,5 +246,5 @@ elif args[0] == "raise":
message("\n".join(msgs))
else:
print "ERROR: Wrong argument '" + args[0] + "'!"
print >>sys.stderr, "ERROR: Wrong argument '" + args[0] + "'!"
sys.exit(1)