# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
import ldb
import samba
import time
# the correct values are above 0x80000000) values first and
# remove the 'second' value we see.
for o in reversed(ctr.array):
- print "%s: 0x%08x" % (dn, o.attid)
+ print("%s: 0x%08x" % (dn, o.attid))
att = self.samdb_schema.get_lDAPDisplayName_by_attid(o.attid)
if att.lower() in set_att:
self.report('ERROR: duplicate attributeID values for %s in %s on %s\n' % (att, attr, dn))
# 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 __future__ import print_function
+
import time
import os
import random
"""
if level <= DEBUG_LEVEL:
if not args:
- print >> sys.stderr, msg
+ print(msg, file=sys.stderr)
else:
- print >> sys.stderr, msg % tuple(args)
+ print(msg % tuple(args), file=sys.stderr)
def debug_lineno(*args):
""" Print an unformatted log message to stderr, contaning the line number
"""
tb = traceback.extract_stack(limit=2)
- print >> sys.stderr, (" %s:" "\033[01;33m"
- "%s " "\033[00m" % (tb[0][2], tb[0][1])),
+ print((" %s:" "\033[01;33m"
+ "%s " "\033[00m" % (tb[0][2], tb[0][1])), end=' ',
+ file=sys.stderr)
for a in args:
- print >> sys.stderr, a
- print >> sys.stderr
+ print(a, file=sys.stderr)
+ print(file=sys.stderr)
sys.stderr.flush()
def p(*args):
for a in args:
- print >>sys.stderr, "%s%s\033[00m" % (prefix, a)
+ print("%s%s\033[00m" % (prefix, a), file=sys.stderr)
return p
fn = getattr(traffic_packets, fn_name)
except AttributeError as e:
- print >>sys.stderr, "Conversation(%s) Missing handler %s" % \
- (conversation.conversation_id, fn_name)
+ print("Conversation(%s) Missing handler %s" % \
+ (conversation.conversation_id, fn_name),
+ file=sys.stderr)
return
# Don't display a message for kerberos packets, they're not directly
if fn is traffic_packets.null_packet:
return False
except AttributeError:
- print >>sys.stderr, "missing packet %s" % fn_name
+ print("missing packet %s" % fn_name, file=sys.stderr)
return False
return True
for i in range(5):
p += ',DC'
if p != k and p in dn_map:
- print >> sys.stderr, 'dn_map collison %s %s' % (k, p)
+ print('dn_map collison %s %s' % (k, p),
+ file=sys.stderr)
continue
dn_map[p] = dn_map[k]
# the number of concurrent threads, which allows us to make
# larger loads.
if gap > 0.15 and False:
- print >>sys.stderr, "sleeping for %f in main process" % (gap - 0.1)
+ print("sleeping for %f in main process" % (gap - 0.1),
+ file=sys.stderr)
time.sleep(gap - 0.1)
now = time.time() - start
gap = t - now
- print >>sys.stderr, "gap is now %f" % gap
+ print("gap is now %f" % gap, file=sys.stderr)
self.conversation_id = context.next_conversation_id()
pid = os.fork()
self.msg("starting %s [miss %.3f pid %d]" % (self, miss, pid))
self.replay(context)
except Exception:
- print >>sys.stderr,\
- ("EXCEPTION in child PID %d, conversation %s" % (pid, self))
+ print(("EXCEPTION in child PID %d, conversation %s" % (pid, self)),
+ file=sys.stderr)
traceback.print_exc(sys.stderr)
finally:
sys.stderr.close()
for f in files:
if isinstance(f, str):
f = open(f)
- print >>sys.stderr, "Ingesting %s" % (f.name,)
+ print("Ingesting %s" % (f.name,), file=sys.stderr)
for line in f:
p = Packet(line)
if p.protocol == 'dns' and dns_mode != 'include':
start_time = min(p.timestamp for p in packets)
last_packet = max(p.timestamp for p in packets)
- print >>sys.stderr, "gathering packets into conversations"
+ print("gathering packets into conversations", file=sys.stderr)
conversations = OrderedDict()
for p in packets:
p.timestamp -= start_time
conversations.append(c)
client += 1
- print >> sys.stderr, ("we have %d conversations at rate %f" %
- (len(conversations), rate))
+ print(("we have %d conversations at rate %f" %
+ (len(conversations), rate)), file=sys.stderr)
conversations.sort()
return conversations
**kwargs)
if len(accounts) < len(conversations):
- print >> sys.stderr, ("we have %d accounts but %d conversations" %
- (accounts, conversations))
+ print(("we have %d accounts but %d conversations" %
+ (accounts, conversations)), file=sys.stderr)
cstack = zip(sorted(conversations,
key=lambda x: x.start_time, reverse=True),
# to start. Conversations other than the last could still be
# going, but we don't care.
duration = cstack[0][0].packets[-1].timestamp + 1.0
- print >>sys.stderr, "We will stop after %.1f seconds" % duration
+ print("We will stop after %.1f seconds" % duration,
+ file=sys.stderr)
end = start + duration
elapsed = t - st
fork_time += elapsed
fork_n += 1
- print >>sys.stderr, "forked %s in pid %s (in %fs)" % (c, pid,
- elapsed)
+ print("forked %s in pid %s (in %fs)" % (c, pid,
+ elapsed),
+ file=sys.stderr)
if fork_n:
- print >>sys.stderr, ("forked %d times in %f seconds (avg %f)" %
- (fork_n, fork_time, fork_time / fork_n))
+ print(("forked %d times in %f seconds (avg %f)" %
+ (fork_n, fork_time, fork_time / fork_n)),
+ file=sys.stderr)
elif cstack:
debug(2, "no forks in batch ending %f" % batch_end)
break
if pid:
c = children.pop(pid, None)
- print >>sys.stderr, ("process %d finished conversation %s;"
- " %d to go" %
- (pid, c, len(children)))
+ print(("process %d finished conversation %s;"
+ " %d to go" %
+ (pid, c, len(children))), file=sys.stderr)
if time.time() >= end:
- print >>sys.stderr, "time to stop"
+ print("time to stop", file=sys.stderr)
break
except Exception:
- print >>sys.stderr, "EXCEPTION in parent"
+ print("EXCEPTION in parent", file=sys.stderr)
traceback.print_exc()
finally:
for s in (15, 15, 9):
- print >>sys.stderr, ("killing %d children with -%d" %
- (len(children), s))
+ print(("killing %d children with -%d" %
+ (len(children), s)), file=sys.stderr)
for pid in children:
try:
os.kill(pid, s)
raise
if pid != 0:
c = children.pop(pid, None)
- print >>sys.stderr, ("kill -%d %d KILLED conversation %s; "
- "%d to go" %
- (s, pid, c, len(children)))
+ print(("kill -%d %d KILLED conversation %s; "
+ "%d to go" %
+ (s, pid, c, len(children))),
+ file=sys.stderr)
if time.time() >= end:
break
time.sleep(1)
if children:
- print >>sys.stderr, "%d children are missing" % len(children)
+ print("%d children are missing" % len(children),
+ file=sys.stderr)
# there may be stragglers that were forked just as ^C was hit
# and don't appear in the list of children. We can get them
try:
os.killpg(0, 2)
except KeyboardInterrupt:
- print >>sys.stderr, "ignoring fake ^C"
+ print("ignoring fake ^C", file=sys.stderr)
def openLdb(host, creds, lp):
finds an already existing account or it has generated all the required
accounts.
"""
- print >>sys.stderr, ("Generating machine and conversation accounts, "
- "as required for %d conversations" % number)
+ print(("Generating machine and conversation accounts, "
+ "as required for %d conversations" % number),
+ file=sys.stderr)
added = 0
for i in range(number, 0, -1):
try:
else:
raise
if added > 0:
- print >>sys.stderr, "Added %d new machine accounts" % added
+ print("Added %d new machine accounts" % added,
+ file=sys.stderr)
added = 0
for i in range(number, 0, -1):
raise
if added > 0:
- print >>sys.stderr, "Added %d new user accounts" % added
+ print("Added %d new user accounts" % added,
+ file=sys.stderr)
def create_machine_account(ldb, instance_id, netbios_name, machinepass):
create_ou(ldb, instance_id)
- print >>sys.stderr, "Generating dummy user accounts"
+ print("Generating dummy user accounts", file=sys.stderr)
users_added = generate_users(ldb, instance_id, number_of_users, password)
if number_of_groups > 0:
- print >>sys.stderr, "Generating dummy groups"
+ print("Generating dummy groups", file=sys.stderr)
groups_added = generate_groups(ldb, instance_id, number_of_groups)
if group_memberships > 0:
- print >>sys.stderr, "Assigning users to groups"
+ print("Assigning users to groups", file=sys.stderr)
assignments = assign_groups(number_of_groups,
groups_added,
number_of_users,
users_added,
group_memberships)
- print >>sys.stderr, "Adding users to groups"
+ print("Adding users to groups", file=sys.stderr)
add_users_to_groups(ldb, instance_id, assignments)
if (groups_added > 0 and users_added == 0 and
number_of_groups != groups_added):
- print >>sys.stderr, "Warning: the added groups will contain no members"
+ print("Warning: the added groups will contain no members",
+ file=sys.stderr)
- print >>sys.stderr, ("Added %d users, %d groups and %d group memberships" %
- (users_added, groups_added, len(assignments)))
+ print(("Added %d users, %d groups and %d group memberships" %
+ (users_added, groups_added, len(assignments))),
+ file=sys.stderr)
def assign_groups(number_of_groups,
tw(line)
except (ValueError, IndexError):
# not a valid line print and ignore
- print >>sys.stderr, line
+ print(line, file=sys.stderr)
pass
duration = last - first
if successful == 0:
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
"""Joining a domain."""
from samba.auth import system_session
else:
if len(res_domaindns) == 0:
ctx.dns_backend = "NONE"
- print "NO DNS zone information found in source domain, not replicating DNS"
+ print("NO DNS zone information found in source domain, not replicating DNS")
else:
ctx.dns_backend = dns_backend
ctx.del_noerror(r.dn, recursive=True)
try:
ctx.samdb.delete(dn)
- print "Deleted %s" % dn
+ print("Deleted %s" % dn)
except Exception:
pass
def add_krbtgt_account(ctx):
'''RODCs need a special krbtgt account'''
- print "Adding %s" % ctx.krbtgt_dn
+ print("Adding %s" % ctx.krbtgt_dn)
rec = {
"dn" : ctx.krbtgt_dn,
"objectclass" : "user",
res = ctx.samdb.search(base=ctx.krbtgt_dn, scope=ldb.SCOPE_BASE, attrs=["samAccountName"])
ctx.krbtgt_name = res[0]["samAccountName"][0]
- print "Got krbtgt_name=%s" % ctx.krbtgt_name
+ print("Got krbtgt_name=%s" % ctx.krbtgt_name)
m = ldb.Message()
m.dn = ldb.Dn(ctx.samdb, ctx.acct_dn)
ctx.samdb.modify(m)
ctx.new_krbtgt_dn = "CN=%s,CN=Users,%s" % (ctx.krbtgt_name, ctx.base_dn)
- print "Renaming %s to %s" % (ctx.krbtgt_dn, ctx.new_krbtgt_dn)
+ print("Renaming %s to %s" % (ctx.krbtgt_dn, ctx.new_krbtgt_dn))
ctx.samdb.rename(ctx.krbtgt_dn, ctx.new_krbtgt_dn)
def drsuapi_connect(ctx):
def join_ntdsdsa_obj(ctx):
'''return the ntdsdsa object to add'''
- print "Adding %s" % ctx.ntds_dn
+ print("Adding %s" % ctx.ntds_dn)
rec = {
"dn" : ctx.ntds_dn,
"objectclass" : "nTDSDSA",
def join_add_objects(ctx):
'''add the various objects needed for the join'''
if ctx.acct_dn:
- print "Adding %s" % ctx.acct_dn
+ print("Adding %s" % ctx.acct_dn)
rec = {
"dn" : ctx.acct_dn,
"objectClass": "computer",
ctx.add_krbtgt_account()
if ctx.server_dn:
- print "Adding %s" % ctx.server_dn
+ print("Adding %s" % ctx.server_dn)
rec = {
"dn": ctx.server_dn,
"objectclass" : "server",
ctx.samdb.modify(m)
if ctx.connection_dn is not None:
- print "Adding %s" % ctx.connection_dn
+ print("Adding %s" % ctx.connection_dn)
rec = {
"dn" : ctx.connection_dn,
"objectclass" : "nTDSConnection",
ctx.samdb.add(rec)
if ctx.acct_dn:
- print "Adding SPNs to %s" % ctx.acct_dn
+ print("Adding SPNs to %s" % ctx.acct_dn)
m = ldb.Message()
m.dn = ldb.Dn(ctx.samdb, ctx.acct_dn)
for i in range(len(ctx.SPNs)):
# connections which are hard to set up and otherwise refuse with
# ERR_UNWILLING_TO_PERFORM. In this case we fall back to libnet
# over SAMR.
- print "Setting account password for %s" % ctx.samname
+ print("Setting account password for %s" % ctx.samname)
try:
ctx.samdb.setpassword("(&(objectClass=user)(sAMAccountName=%s))"
% ldb.binary_encode(ctx.samname),
for changetype, msg in recs:
assert changetype == ldb.CHANGETYPE_NONE
dns_acct_dn = msg["dn"]
- print "Adding DNS account %s with dns/ SPN" % msg["dn"]
+ print("Adding DNS account %s with dns/ SPN" % msg["dn"])
# Remove dns password (we will set it as a modify, as we can't do clearTextPassword over LDAP)
del msg["clearTextPassword"]
# connections which are hard to set up and otherwise refuse with
# ERR_UNWILLING_TO_PERFORM. In this case we fall back to libnet
# over SAMR.
- print "Setting account password for dns-%s" % ctx.myname
+ print("Setting account password for dns-%s" % ctx.myname)
try:
ctx.samdb.setpassword("(&(objectClass=user)(samAccountName=dns-%s))"
% ldb.binary_encode(ctx.myname),
def join_add_objects2(ctx):
"""add the various objects needed for the join, for subdomains post replication"""
- print "Adding %s" % ctx.partition_dn
+ print("Adding %s" % ctx.partition_dn)
name_map = {'SubdomainAdmins': "%s-%s" % (str(ctx.domsid), security.DOMAIN_RID_ADMINS)}
sd_binary = descriptor.get_paritions_crossref_subdomain_descriptor(ctx.forestsid, name_map=name_map)
rec = {
def join_provision(ctx):
"""Provision the local SAM."""
- print "Calling bare provision"
+ print("Calling bare provision")
smbconf = ctx.lp.configfile
sitename=ctx.site, lp=ctx.lp, ntdsguid=ctx.ntds_guid,
use_ntvfs=ctx.use_ntvfs, dns_backend=ctx.dns_backend,
plaintext_secrets=ctx.plaintext_secrets)
- print "Provision OK for domain DN %s" % presult.domaindn
+ print("Provision OK for domain DN %s" % presult.domaindn)
ctx.local_samdb = presult.samdb
ctx.lp = presult.lp
ctx.paths = presult.paths
def join_replicate(ctx):
"""Replicate the SAM."""
- print "Starting replication"
+ print("Starting replication")
ctx.local_samdb.transaction_start()
try:
source_dsa_invocation_id = misc.GUID(ctx.samdb.get_invocation_id())
if not ctx.subdomain:
# Replicate first the critical object for the basedn
if not ctx.domain_replica_flags & drsuapi.DRSUAPI_DRS_CRITICAL_ONLY:
- print "Replicating critical objects from the base DN of the domain"
+ print("Replicating critical objects from the base DN of the domain")
ctx.domain_replica_flags |= drsuapi.DRSUAPI_DRS_CRITICAL_ONLY
repl.replicate(ctx.base_dn, source_dsa_invocation_id,
destination_dsa_guid, rodc=ctx.RODC,
repl.replicate(ctx.base_dn, source_dsa_invocation_id,
destination_dsa_guid, rodc=ctx.RODC,
replica_flags=ctx.domain_replica_flags)
- print "Done with always replicated NC (base, config, schema)"
+ print("Done with always replicated NC (base, config, schema)")
# At this point we should already have an entry in the ForestDNS
# and DomainDNS NC (those under CN=Partions,DC=...) in order to
# indicate that we hold a replica for this NC.
for nc in (ctx.domaindns_zone, ctx.forestdns_zone):
if nc in ctx.nc_list:
- print "Replicating %s" % (str(nc))
+ print("Replicating %s" % (str(nc)))
repl.replicate(nc, source_dsa_invocation_id,
destination_dsa_guid, rodc=ctx.RODC,
replica_flags=ctx.replica_flags)
except samba.DsExtendedError as e1:
(enum, estr) = e1.args
if enum == drsuapi.DRSUAPI_EXOP_ERR_FSMO_NOT_OWNER:
- print "WARNING: Unable to replicate own RID Set, as server %s (the server we joined) is not the RID Master." % ctx.server
- print "NOTE: This is normal and expected, Samba will be able to create users after it contacts the RID Master at first startup."
+ print("WARNING: Unable to replicate own RID Set, as server %s (the server we joined) is not the RID Master." % ctx.server)
+ print("NOTE: This is normal and expected, Samba will be able to create users after it contacts the RID Master at first startup.")
else:
raise
ctx.source_dsa_invocation_id = source_dsa_invocation_id
ctx.destination_dsa_guid = destination_dsa_guid
- print "Committing SAM database"
+ print("Committing SAM database")
except:
ctx.local_samdb.transaction_cancel()
raise
ctx.send_DsReplicaUpdateRefs(nc)
if not ctx.clone_only and ctx.RODC:
- print "Setting RODC invocationId"
+ print("Setting RODC invocationId")
ctx.local_samdb.set_invocation_id(str(ctx.invocation_id))
ctx.local_samdb.set_opaque_integer("domainFunctionality",
ctx.behavior_version)
def join_setup_trusts(ctx):
"""provision the local SAM."""
- print "Setup domain trusts with server %s" % ctx.server
+ print("Setup domain trusts with server %s" % ctx.server)
binding_options = "" # why doesn't signing work here? w2k8r2 claims no session key
lsaconn = lsa.lsarpc("ncacn_np:%s[%s]" % (ctx.server, binding_options),
ctx.lp, ctx.creds)
ctx.join_finalise()
except:
try:
- print "Join failed - cleaning up"
+ print("Join failed - cleaning up")
except IOError:
pass
if not ctx.clone_only:
# 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 __future__ import print_function
import os
import itertools
def list_verify_tests():
for k, v in sorted(globals().items()):
if k.startswith('verify_graph_'):
- print k.replace('verify_graph_', '')
+ print(k.replace('verify_graph_', ''))
if v.__doc__:
- print ' %s%s%s' % (GREY, v.__doc__.rstrip(), C_NORMAL)
+ print(' %s%s%s' % (GREY, v.__doc__.rstrip(), C_NORMAL))
else:
- print
+ print()
#
# 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 __future__ import print_function
import re
entry.append(l)
else:
- print >>sys.stderr, "Invalid line: %s" % l,
+ print("Invalid line: %s" % l, end=' ', file=sys.stderr)
sys.exit(1)
if len(entry):
try:
display_specifiers_file = sys.argv[1]
except IndexError:
- print >>sys.stderr, "Usage: %s display-specifiers-ldif-file.txt" % (sys.argv[0])
+ print("Usage: %s display-specifiers-ldif-file.txt" % (sys.argv[0]), file=sys.stderr)
sys.exit(1)
- print read_ms_ldif(display_specifiers_file)
+ print(read_ms_ldif(display_specifiers_file))
# 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 __future__ import print_function
"""Generate LDIF from Github documentation."""
import re
out_folder = ''
if len(sys.argv) == 0:
- print >>sys.stderr, "Usage: %s <Forest-Wide-Updates.md> [<output folder>]" % (sys.argv[0])
+ print("Usage: %s <Forest-Wide-Updates.md> [<output folder>]" % (sys.argv[0]), file=sys.stderr)
sys.exit(1)
in_file = sys.argv[1]
# 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 __future__ import print_function
"""Generate LDIF from WSPP documentation."""
import re
entry.append(l)
else:
- print >>sys.stderr, "Invalid line: %s" % l,
+ print("Invalid line: %s" % l, end=' ', file=sys.stderr)
sys.exit(1)
if len(entry):
attr_file = sys.argv[1]
classes_file = sys.argv[2]
except IndexError:
- print >>sys.stderr, "Usage: %s attr-file.txt classes-file.txt" % (sys.argv[0])
+ print("Usage: %s attr-file.txt classes-file.txt" % (sys.argv[0]), file=sys.stderr)
sys.exit(1)
- print read_ms_schema(attr_file, classes_file)
+ print(read_ms_schema(attr_file, classes_file))
# 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 __future__ import print_function
"""Generate LDIF from Github documentation."""
import re
out_folder = ''
if len(sys.argv) == 0:
- print >>sys.stderr, "Usage: %s <Schema-Update.md> [<output folder>]" % (sys.argv[0])
+ print("Usage: %s <Schema-Update.md> [<output folder>]" % (sys.argv[0]), file=sys.stderr)
sys.exit(1)
in_file = sys.argv[1]
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
"""NT Acls."""
except Exception:
# FIXME: Don't catch all exceptions, just those related to opening
# xattrdb
- print "Fail to open %s" % dbname
+ print("Fail to open %s" % dbname)
attribute = samba.xattr_native.wrap_getxattr(file,
xattr.XATTR_NTACL_NAME)
else:
except Exception:
# FIXME: Don't catch all exceptions, just those related to opening
# xattrdb
- print "Fail to open %s" % dbname
+ print("Fail to open %s" % dbname)
samba.xattr_native.wrap_setxattr(file, xattr.XATTR_NTACL_NAME,
ndr_pack(ntacl))
else:
# 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 __future__ import print_function
"""Helpers used for upgrading between different database formats."""
import os
obj = hash_ts[k]
if obj["num"] > limit_print:
dt = _glue.nttime2string(_glue.unix2nttime(k*60))
- print "%s # of modification: %d \tmin: %d max: %d" % (dt , obj["num"],
+ print("%s # of modification: %d \tmin: %d max: %d" % (dt , obj["num"],
obj["min"],
- obj["max"])
+ obj["max"]))
if hash_ts[k]["num"] > 600:
kept_record.append(k)
if ldif != "":
file = tempfile.mktemp(dir=dest, prefix="usnprov", suffix=".ldif")
- print
- print "To track the USNs modified/created by provision and upgrade proivsion,"
- print " the following ranges are proposed to be added to your provision sam.ldb: \n%s" % ldif
- print "We recommend to review them, and if it's correct to integrate the following ldif: %s in your sam.ldb" % file
- print "You can load this file like this: ldbadd -H %s %s\n"%(str(samdb_path),file)
+ print()
+ print("To track the USNs modified/created by provision and upgrade proivsion,")
+ print(" the following ranges are proposed to be added to your provision sam.ldb: \n%s" % ldif)
+ print("We recommend to review them, and if it's correct to integrate the following ldif: %s in your sam.ldb" % file)
+ print("You can load this file like this: ldbadd -H %s %s\n"%(str(samdb_path),file))
ldif = "dn: @PROVISION\nprovisionnerID: %s\n%s" % (invocationid, ldif)
open(file,'w').write(ldif)
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
def render_placeholder(environ, start_response):
"""Send the user a simple placeholder about missing SWAT."""
status = '200 OK'
try:
import swat
except ImportError as e:
- print "NO SWAT: %r" % e
+ print("NO SWAT: %r" % e)
have_swat = False
else:
have_swat = True
if __name__ == '__main__':
from wsgiref import simple_server
httpd = simple_server.make_server('localhost', 8090, __call__)
- print "Serving HTTP on port 8090..."
+ print("Serving HTTP on port 8090...")
httpd.serve_forever()