mirror of
https://github.com/samba-team/samba.git
synced 2025-08-02 00:22:11 +03:00
dbcheck: improved error checking in fixup of missing metdata
when fixing missing attributes in replPropertyMetaData, allow user to confirm changes, and check for exceptions Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org> Pair-Programmed-With: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
@ -67,6 +67,7 @@ class dbcheck(object):
|
|||||||
self.fix_all_DN_GUIDs = False
|
self.fix_all_DN_GUIDs = False
|
||||||
self.remove_all_deleted_DN_links = False
|
self.remove_all_deleted_DN_links = False
|
||||||
self.fix_all_target_mismatch = False
|
self.fix_all_target_mismatch = False
|
||||||
|
self.fix_all_metadata = False
|
||||||
|
|
||||||
def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=[], attrs=['*']):
|
def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=[], attrs=['*']):
|
||||||
'''perform a database check, returning the number of errors found'''
|
'''perform a database check, returning the number of errors found'''
|
||||||
@ -351,22 +352,22 @@ class dbcheck(object):
|
|||||||
return list_att
|
return list_att
|
||||||
|
|
||||||
|
|
||||||
def fix_metadata(self, dn, list):
|
def fix_metadata(self, dn, attr):
|
||||||
res = self.samdb.search(base = dn, scope=ldb.SCOPE_BASE, attrs = list,
|
'''re-write replPropertyMetaData elements for a single attribute for a
|
||||||
controls = ["search_options:1:2"])
|
object. This is used to fix missing replPropertyMetaData elements'''
|
||||||
|
res = self.samdb.search(base = dn, scope=ldb.SCOPE_BASE, attrs = [attr],
|
||||||
|
controls = ["search_options:1:2", "show_deleted:1"])
|
||||||
msg = res[0]
|
msg = res[0]
|
||||||
nmsg = ldb.Message()
|
nmsg = ldb.Message()
|
||||||
|
|
||||||
delta = self.samdb.msg_diff(nmsg, msg)
|
|
||||||
nmsg.dn = dn
|
nmsg.dn = dn
|
||||||
|
nmsg[attr] = ldb.MessageElement(msg[attr], ldb.FLAG_MOD_REPLACE, attr)
|
||||||
|
try:
|
||||||
|
self.samdb.modify(nmsg, controls = ["relax:0", "provision:0", "show_deleted:1"])
|
||||||
|
except Exception, err:
|
||||||
|
self.report("Failed to fix metadata for attribute %s : %s" % (attr, err))
|
||||||
|
return
|
||||||
|
self.report("Fixed metadata for attribute %s" % attr)
|
||||||
|
|
||||||
for att in delta:
|
|
||||||
if att == "dn":
|
|
||||||
continue
|
|
||||||
val = delta.get(att)
|
|
||||||
nmsg[att] = ldb.MessageElement(val, ldb.FLAG_MOD_REPLACE, att)
|
|
||||||
|
|
||||||
self.samdb.modify(nmsg, controls = ["relax:0", "provision:0"])
|
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# check one object - calls to individual error handlers above
|
# check one object - calls to individual error handlers above
|
||||||
@ -433,19 +434,16 @@ class dbcheck(object):
|
|||||||
break
|
break
|
||||||
|
|
||||||
show_dn = True
|
show_dn = True
|
||||||
if len(list_attrs_seen):
|
for att in list_attrs_seen:
|
||||||
attrs_to_fix = []
|
if not att in list_attrs_from_md:
|
||||||
for att in list_attrs_seen:
|
if show_dn:
|
||||||
if not att in list_attrs_from_md:
|
self.report("On object %s" % dn)
|
||||||
if show_dn:
|
show_dn = False
|
||||||
print "On object %s" % dn
|
error_count += 1
|
||||||
show_dn = False
|
self.report("ERROR: Attribute %s not present in replication metadata" % att)
|
||||||
print " Attribute %s not present in replication metadata" % (att)
|
if not self.confirm_all("Fix missing replPropertyMetaData element '%s'" % att, 'fix_all_metadata'):
|
||||||
error_count += 1
|
self.report("Not fixing missing replPropertyMetaData element '%s'" % att)
|
||||||
attrs_to_fix.append(att)
|
continue
|
||||||
|
self.fix_metadata(dn, att)
|
||||||
if len(attrs_to_fix) and self.fix:
|
|
||||||
self.fix_metadata(dn, attrs_to_fix)
|
|
||||||
|
|
||||||
|
|
||||||
return error_count
|
return error_count
|
||||||
|
Reference in New Issue
Block a user