from samba.common import dsdb_Dn
from samba.ndr import (ndr_unpack, ndr_pack)
+#colours for prettier logs
+C_NORMAL = "\033[00m"
+DARK_RED = "\033[00;31m"
+RED = "\033[01;31m"
+DARK_GREEN = "\033[00;32m"
+GREEN = "\033[01;32m"
+YELLOW = "\033[01;33m"
+DARK_YELLOW = "\033[00;33m"
+DARK_BLUE = "\033[00;34m"
+BLUE = "\033[01;34m"
+PURPLE = "\033[00;35m"
+MAGENTA = "\033[01;35m"
+DARK_CYAN = "\033[00;36m"
+CYAN = "\033[01;36m"
+GREY = "\033[00;37m"
+WHITE = "\033[01;37m"
+REV_RED = "\033[01;41m"
+
class KCCError(Exception):
pass
def __str__(self):
'''Debug dump string output of class'''
- text = "%s:" % self.__class__.__name__
+ text = "%s%s%s:" % (CYAN, self.__class__.__name__, C_NORMAL)
text = text + "\n\tnc_dnstr=%s" % self.nc_dnstr
text = text + "\n\tnc_guid=%s" % str(self.nc_guid)
return True
-def write_dot_file(basename, edge_list, label=None, destdir=None):
+def write_dot_file(basename, edge_list, label=None, destdir=None, reformat_labels=True, directed=False):
from tempfile import NamedTemporaryFile
if label:
basename += '_' + label.translate(None, ', ') #fix DN, guid labels
f = NamedTemporaryFile(suffix='.dot', prefix=basename + '_', delete=False, dir=destdir)
graphname = ''.join(x for x in basename if x.isalnum())
- print >>f, 'graph %s {' % graphname
- print >>f, 'label="%s";\nfontsize=20' % (label or graphname)
+ print >>f, '%s %s {' % ('digraph' if directed else 'graph', graphname)
+ print >>f, 'label="%s";\nfontsize=20;' % (label or graphname)
for a, b in edge_list:
- print >>f, '"%s" -- "%s"' % (a, b)
+ if reformat_labels:
+ a = a.replace(',', '\\n')
+ b = b.replace(',', '\\n')
+ line = '->' if directed else '--'
+ print >>f, '"%s" %s "%s";' % (a, line, b)
print >>f, '}'
-
f.close()
if mydsa.is_ro() or opts.readonly:
for dnstr, connect in mydsa.connect_table.items():
if connect.to_be_deleted:
- logger.info("TO BE DELETED:\n%s" % connect)
+ DEBUG_GREEN("TO BE DELETED:\n%s" % connect)
if connect.to_be_added:
- logger.info("TO BE ADDED:\n%s" % connect)
+ DEBUG_GREEN("TO BE ADDED:\n%s" % connect)
# Peform deletion from our tables but perform
# no database modification
for t_guid, transport in self.transport_table.items():
if transport.name != 'IP':
continue
- logger.debug(t_guid)
+ DEBUG_RED(t_guid)
# FLAG_CR_NTDS_DOMAIN 0x00000002
if (vertex.is_red() and transport.name != "IP" and
vertex.part.system_flags & 0x00000002):
# partition (NC x) then continue
needed, ro, partial = nc_x.should_be_present(dc_local)
- logger.debug("construct_intrasite_graph(): enter" +
+ DEBUG_YELLOW("construct_intrasite_graph(): enter" +
"\n\tgc_only=%d" % gc_only +
"\n\tdetect_stale=%d" % detect_stale +
"\n\tneeded=%s" % needed +
"\n%s" % nc_x)
if not needed:
+ DEBUG_RED("%s lacks 'should be present' status, aborting construct_intersite_graph!" %
+ nc_x.nc_dnstr)
return
# Create a NCReplica that matches what the local replica
self.load_all_transports()
self.load_all_sitelinks()
+ if True:
+ dot_edges = []
+ for site in self.site_table.values():
+ for dsa in site.dsa_table.values():
+ for con in dsa.connect_table.values():
+ dot_edges.append((dsa.dsa_dnstr, con.from_dnstr))
+
+ write_dot_file('dsa_initial', dot_edges, directed=True)
+
+
+ dot_edges = []
+ for site in self.site_table.values():
+ for dsa in site.dsa_table.values():
+ c_rep = get_dsa_config_rep(dsa)
+ c_rep.load_repsFrom(self.samdb)
+ for x in c_rep.rep_repsFrom:
+ #print dir(x)
+ dot_edges.append((c_rep.rep_dsa_dnstr, x.nc_dnstr))
+
+ write_dot_file('config_repsFrom_initial', dot_edges, directed=True)
+
+ dot_edges = []
+ for site in self.site_table.values():
+ for dsa in site.dsa_table.values():
+ for x in dsa.current_rep_table:
+ dot_edges.append((dsa.dsa_dnstr, x))
+
+ write_dot_file('dsa_repsFrom_initial', dot_edges, directed=True)
+
+ dot_edges = []
+ for link in self.sitelink_table.values():
+ for a, b in itertools.combinations(link.site_list, 2):
+ dot_edges.append((str(a), str(b)))
+
+ write_dot_file('dsa_sitelink_initial', dot_edges, directed=False)
+
+
+
# These are the published steps (in order) for the
# MS-TECH description of the KCC algorithm ([MS-ADTS] 6.2.2)
for con in dsa.connect_table.values():
dot_edges.append((dsa.dsa_dnstr, con.from_dnstr))
- write_dot_file('dsa_final', dot_edges)
+ write_dot_file('dsa_final', dot_edges, directed=True)
except:
raise
logger.addHandler(logging.StreamHandler(sys.stdout))
DEBUG = logger.debug
+def DEBUG_RED(*args):
+ DEBUG('%s%s%s' % (RED, args[0], C_NORMAL), *args[1:])
+def DEBUG_GREEN(*args):
+ DEBUG('%s%s%s' % (GREEN, args[0], C_NORMAL), *args[1:])
+def DEBUG_YELLOW(*args):
+ DEBUG('%s%s%s' % (YELLOW, args[0], C_NORMAL), *args[1:])
+
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)