+ rec["objectCategory"] = "CN=NTDS-DSA,%s" % ctx.schema_dn
+ rec["HasMasterNCs"] = nc_list
+ if ctx.behavior_version >= samba.dsdb.DS_DOMAIN_FUNCTION_2003:
+ rec["msDS-HasMasterNCs"] = ctx.nc_list
+ rec["options"] = "1"
+ rec["invocationId"] = ndr_pack(ctx.invocation_id)
+ ctx.DsAddEntry([rec])
+
+ # find the GUID of our NTDS DN
+ res = ctx.samdb.search(base=ctx.ntds_dn, scope=ldb.SCOPE_BASE, attrs=["objectGUID"])
+ ctx.ntds_guid = misc.GUID(ctx.samdb.schema_format_value("objectGUID", res[0]["objectGUID"][0]))
+
+ def join_add_objects(ctx):
+ '''add the various objects needed for the join'''
+ if ctx.acct_dn:
+ print "Adding %s" % ctx.acct_dn
+ rec = {
+ "dn" : ctx.acct_dn,
+ "objectClass": "computer",
+ "displayname": ctx.samname,
+ "samaccountname" : ctx.samname,
+ "userAccountControl" : str(ctx.userAccountControl | samba.dsdb.UF_ACCOUNTDISABLE),
+ "dnshostname" : ctx.dnshostname}
+ if ctx.behavior_version >= samba.dsdb.DS_DOMAIN_FUNCTION_2008:
+ rec['msDS-SupportedEncryptionTypes'] = str(samba.dsdb.ENC_ALL_TYPES)
+ elif ctx.promote_existing:
+ rec['msDS-SupportedEncryptionTypes'] = []
+ if ctx.managedby:
+ rec["managedby"] = ctx.managedby
+ elif ctx.promote_existing:
+ rec["managedby"] = []
+
+ if ctx.never_reveal_sid:
+ rec["msDS-NeverRevealGroup"] = ctx.never_reveal_sid
+ elif ctx.promote_existing:
+ rec["msDS-NeverRevealGroup"] = []
+
+ if ctx.reveal_sid:
+ rec["msDS-RevealOnDemandGroup"] = ctx.reveal_sid
+ elif ctx.promote_existing:
+ rec["msDS-RevealOnDemandGroup"] = []
+
+ if ctx.promote_existing:
+ if ctx.promote_from_dn != ctx.acct_dn:
+ ctx.samdb.rename(ctx.promote_from_dn, ctx.acct_dn)
+ ctx.samdb.modify(ldb.Message.from_dict(ctx.samdb, rec, ldb.FLAG_MOD_REPLACE))
+ else:
+ ctx.samdb.add(rec)
+
+ if ctx.krbtgt_dn:
+ ctx.add_krbtgt_account()
+
+ print "Adding %s" % ctx.server_dn
+ rec = {
+ "dn": ctx.server_dn,
+ "objectclass" : "server",
+ # windows uses 50000000 decimal for systemFlags. A windows hex/decimal mixup bug?
+ "systemFlags" : str(samba.dsdb.SYSTEM_FLAG_CONFIG_ALLOW_RENAME |
+ samba.dsdb.SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE |
+ samba.dsdb.SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE),
+ # windows seems to add the dnsHostName later
+ "dnsHostName" : ctx.dnshostname}
+
+ if ctx.acct_dn:
+ rec["serverReference"] = ctx.acct_dn
+
+ ctx.samdb.add(rec)
+
+ if ctx.subdomain:
+ # the rest is done after replication
+ ctx.ntds_guid = None
+ return
+
+ ctx.join_add_ntdsdsa()
+
+ if ctx.connection_dn is not None:
+ print "Adding %s" % ctx.connection_dn
+ rec = {
+ "dn" : ctx.connection_dn,
+ "objectclass" : "nTDSConnection",
+ "enabledconnection" : "TRUE",
+ "options" : "65",
+ "fromServer" : ctx.dc_ntds_dn}
+ ctx.samdb.add(rec)
+
+ if 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)):
+ ctx.SPNs[i] = ctx.SPNs[i].replace("$NTDSGUID", str(ctx.ntds_guid))
+ m["servicePrincipalName"] = ldb.MessageElement(ctx.SPNs,
+ ldb.FLAG_MOD_REPLACE,
+ "servicePrincipalName")
+ ctx.samdb.modify(m)
+
+ # The account password set operation should normally be done over
+ # LDAP. Windows 2000 DCs however allow this only with SSL
+ # 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
+ try:
+ ctx.samdb.setpassword("(&(objectClass=user)(sAMAccountName=%s))"
+ % ldb.binary_encode(ctx.samname),
+ ctx.acct_pass,
+ force_change_at_next_login=False,
+ username=ctx.samname)
+ except ldb.LdbError, (num, _):
+ if num != ldb.ERR_UNWILLING_TO_PERFORM:
+ pass
+ ctx.net.set_password(account_name=ctx.samname,
+ domain_name=ctx.domain_name,
+ newpassword=ctx.acct_pass)
+
+ res = ctx.samdb.search(base=ctx.acct_dn, scope=ldb.SCOPE_BASE,
+ attrs=["msDS-KeyVersionNumber"])
+ if "msDS-KeyVersionNumber" in res[0]:
+ ctx.key_version_number = int(res[0]["msDS-KeyVersionNumber"][0])
+ else:
+ ctx.key_version_number = None
+
+ print("Enabling account")
+ m = ldb.Message()
+ m.dn = ldb.Dn(ctx.samdb, ctx.acct_dn)
+ m["userAccountControl"] = ldb.MessageElement(str(ctx.userAccountControl),
+ ldb.FLAG_MOD_REPLACE,
+ "userAccountControl")
+ ctx.samdb.modify(m)
+
+ def join_add_objects2(ctx):
+ """add the various objects needed for the join, for subdomains post replication"""
+
+ print "Adding %s" % ctx.partition_dn
+ # NOTE: windows sends a ntSecurityDescriptor here, we
+ # let it default
+ rec = {
+ "dn" : ctx.partition_dn,
+ "objectclass" : "crossRef",
+ "objectCategory" : "CN=Cross-Ref,%s" % ctx.schema_dn,
+ "nCName" : ctx.base_dn,
+ "nETBIOSName" : ctx.domain_name,
+ "dnsRoot": ctx.dnsdomain,
+ "trustParent" : ctx.parent_partition_dn,
+ "systemFlags" : str(samba.dsdb.SYSTEM_FLAG_CR_NTDS_NC|samba.dsdb.SYSTEM_FLAG_CR_NTDS_DOMAIN)}
+ if ctx.behavior_version >= samba.dsdb.DS_DOMAIN_FUNCTION_2003:
+ rec["msDS-Behavior-Version"] = str(ctx.behavior_version)
+
+ rec2 = {
+ "dn" : ctx.ntds_dn,
+ "objectclass" : "nTDSDSA",
+ "systemFlags" : str(samba.dsdb.SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE),
+ "dMDLocation" : ctx.schema_dn}
+
+ nc_list = [ ctx.base_dn, ctx.config_dn, ctx.schema_dn ]
+
+ if ctx.behavior_version >= samba.dsdb.DS_DOMAIN_FUNCTION_2003:
+ rec2["msDS-Behavior-Version"] = str(ctx.behavior_version)
+
+ if ctx.behavior_version >= samba.dsdb.DS_DOMAIN_FUNCTION_2003:
+ rec2["msDS-HasDomainNCs"] = ctx.base_dn
+
+ rec2["objectCategory"] = "CN=NTDS-DSA,%s" % ctx.schema_dn
+ rec2["HasMasterNCs"] = nc_list
+ if ctx.behavior_version >= samba.dsdb.DS_DOMAIN_FUNCTION_2003:
+ rec2["msDS-HasMasterNCs"] = ctx.nc_list
+ rec2["options"] = "1"
+ rec2["invocationId"] = ndr_pack(ctx.invocation_id)
+
+ objects = ctx.DsAddEntry([rec, rec2])
+ if len(objects) != 2:
+ raise DCJoinException("Expected 2 objects from DsAddEntry")
+
+ ctx.ntds_guid = objects[1].guid
+
+ print("Replicating partition DN")
+ ctx.repl.replicate(ctx.partition_dn,
+ misc.GUID("00000000-0000-0000-0000-000000000000"),
+ ctx.ntds_guid,
+ exop=drsuapi.DRSUAPI_EXOP_REPL_OBJ,
+ replica_flags=drsuapi.DRSUAPI_DRS_WRIT_REP)
+
+ print("Replicating NTDS DN")
+ ctx.repl.replicate(ctx.ntds_dn,
+ misc.GUID("00000000-0000-0000-0000-000000000000"),
+ ctx.ntds_guid,
+ exop=drsuapi.DRSUAPI_EXOP_REPL_OBJ,
+ replica_flags=drsuapi.DRSUAPI_DRS_WRIT_REP)
+
+ def join_provision(ctx):
+ """Provision the local SAM."""
+
+ print "Calling bare provision"
+
+ logger = logging.getLogger("provision")
+ logger.addHandler(logging.StreamHandler(sys.stdout))
+ smbconf = ctx.lp.configfile
+
+ presult = provision(logger, system_session(), None, smbconf=smbconf,
+ targetdir=ctx.targetdir, samdb_fill=FILL_DRS, realm=ctx.realm,
+ rootdn=ctx.root_dn, domaindn=ctx.base_dn,
+ schemadn=ctx.schema_dn, configdn=ctx.config_dn,
+ serverdn=ctx.server_dn, domain=ctx.domain_name,
+ hostname=ctx.myname, domainsid=ctx.domsid,
+ machinepass=ctx.acct_pass, serverrole="domain controller",
+ sitename=ctx.site, lp=ctx.lp, ntdsguid=ctx.ntds_guid,
+ use_ntvfs=ctx.use_ntvfs, dns_backend=ctx.dns_backend)
+ print "Provision OK for domain DN %s" % presult.domaindn
+ ctx.local_samdb = presult.samdb
+ ctx.lp = presult.lp
+ ctx.paths = presult.paths
+ ctx.names = presult.names
+
+ def join_provision_own_domain(ctx):
+ """Provision the local SAM."""
+
+ # we now operate exclusively on the local database, which
+ # we need to reopen in order to get the newly created schema
+ print("Reconnecting to local samdb")
+ ctx.samdb = SamDB(url=ctx.local_samdb.url,
+ session_info=system_session(),
+ lp=ctx.local_samdb.lp,
+ global_schema=False)
+ ctx.samdb.set_invocation_id(str(ctx.invocation_id))
+ ctx.local_samdb = ctx.samdb
+
+ print("Finding domain GUID from ncName")
+ res = ctx.local_samdb.search(base=ctx.partition_dn, scope=ldb.SCOPE_BASE, attrs=['ncName'],
+ controls=["extended_dn:1:1"])
+ domguid = str(misc.GUID(ldb.Dn(ctx.samdb, res[0]['ncName'][0]).get_extended_component('GUID')))
+ print("Got domain GUID %s" % domguid)
+
+ print("Calling own domain provision")
+
+ logger = logging.getLogger("provision")
+ logger.addHandler(logging.StreamHandler(sys.stdout))
+
+ secrets_ldb = Ldb(ctx.paths.secrets, session_info=system_session(), lp=ctx.lp)
+
+ presult = provision_fill(ctx.local_samdb, secrets_ldb,
+ logger, ctx.names, ctx.paths, domainsid=security.dom_sid(ctx.domsid),
+ domainguid=domguid,
+ targetdir=ctx.targetdir, samdb_fill=FILL_SUBDOMAIN,
+ machinepass=ctx.acct_pass, serverrole="domain controller",
+ lp=ctx.lp, hostip=ctx.names.hostip, hostip6=ctx.names.hostip6,
+ dns_backend=ctx.dns_backend)
+ print("Provision OK for domain %s" % ctx.names.dnsdomain)
+
+ def join_replicate(ctx):
+ """Replicate the SAM."""
+
+ print "Starting replication"
+ ctx.local_samdb.transaction_start()
+ try:
+ source_dsa_invocation_id = misc.GUID(ctx.samdb.get_invocation_id())
+ if ctx.ntds_guid is None:
+ print("Using DS_BIND_GUID_W2K3")
+ destination_dsa_guid = misc.GUID(drsuapi.DRSUAPI_DS_BIND_GUID_W2K3)
+ else:
+ destination_dsa_guid = ctx.ntds_guid
+
+ if ctx.RODC:
+ repl_creds = Credentials()
+ repl_creds.guess(ctx.lp)
+ repl_creds.set_kerberos_state(DONT_USE_KERBEROS)
+ repl_creds.set_username(ctx.samname)
+ repl_creds.set_password(ctx.acct_pass)
+ else:
+ repl_creds = ctx.creds
+
+ binding_options = "seal"
+ if int(ctx.lp.get("log level")) >= 5:
+ binding_options += ",print"
+ repl = drs_utils.drs_Replicate(
+ "ncacn_ip_tcp:%s[%s]" % (ctx.server, binding_options),
+ ctx.lp, repl_creds, ctx.local_samdb)
+
+ repl.replicate(ctx.schema_dn, source_dsa_invocation_id,
+ destination_dsa_guid, schema=True, rodc=ctx.RODC,
+ replica_flags=ctx.replica_flags)
+ repl.replicate(ctx.config_dn, source_dsa_invocation_id,
+ destination_dsa_guid, rodc=ctx.RODC,
+ replica_flags=ctx.replica_flags)
+ 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"
+ ctx.domain_replica_flags |= drsuapi.DRSUAPI_DRS_CRITICAL_ONLY | drsuapi.DRSUAPI_DRS_GET_ANC
+ repl.replicate(ctx.base_dn, source_dsa_invocation_id,
+ destination_dsa_guid, rodc=ctx.RODC,
+ replica_flags=ctx.domain_replica_flags)
+ ctx.domain_replica_flags ^= drsuapi.DRSUAPI_DRS_CRITICAL_ONLY | drsuapi.DRSUAPI_DRS_GET_ANC
+ else:
+ ctx.domain_replica_flags |= drsuapi.DRSUAPI_DRS_GET_ANC
+ 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)"
+
+ for nc in (ctx.domaindns_zone, ctx.forestdns_zone):
+ if nc in ctx.nc_list:
+ print "Replicating %s" % (str(nc))
+ repl.replicate(nc, source_dsa_invocation_id,
+ destination_dsa_guid, rodc=ctx.RODC,
+ replica_flags=ctx.replica_flags)
+
+ if 'DC=ForestDnsZones,%s' % ctx.root_dn in ctx.nc_list:
+ repl.replicate('DC=ForestDnsZones,%s' % ctx.root_dn, source_dsa_invocation_id,
+ destination_dsa_guid, rodc=ctx.RODC,
+ replica_flags=ctx.replica_flags)
+ # FIXME At this point we should add 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
+
+ if ctx.RODC:
+ repl.replicate(ctx.acct_dn, source_dsa_invocation_id,
+ destination_dsa_guid,
+ exop=drsuapi.DRSUAPI_EXOP_REPL_SECRET, rodc=True)
+ repl.replicate(ctx.new_krbtgt_dn, source_dsa_invocation_id,
+ destination_dsa_guid,
+ exop=drsuapi.DRSUAPI_EXOP_REPL_SECRET, rodc=True)
+ ctx.repl = repl
+ ctx.source_dsa_invocation_id = source_dsa_invocation_id
+ ctx.destination_dsa_guid = destination_dsa_guid
+
+ print "Committing SAM database"
+ except:
+ ctx.local_samdb.transaction_cancel()
+ raise
+ else:
+ ctx.local_samdb.transaction_commit()
+
+ def send_DsReplicaUpdateRefs(ctx, dn):
+ r = drsuapi.DsReplicaUpdateRefsRequest1()
+ r.naming_context = drsuapi.DsReplicaObjectIdentifier()
+ r.naming_context.dn = str(dn)
+ r.naming_context.guid = misc.GUID("00000000-0000-0000-0000-000000000000")
+ r.naming_context.sid = security.dom_sid("S-0-0")
+ r.dest_dsa_guid = ctx.ntds_guid
+ r.dest_dsa_dns_name = "%s._msdcs.%s" % (str(ctx.ntds_guid), ctx.dnsforest)
+ r.options = drsuapi.DRSUAPI_DRS_ADD_REF | drsuapi.DRSUAPI_DRS_DEL_REF
+ if not ctx.RODC:
+ r.options |= drsuapi.DRSUAPI_DRS_WRIT_REP
+
+ if ctx.drsuapi:
+ ctx.drsuapi.DsReplicaUpdateRefs(ctx.drsuapi_handle, 1, r)
+
+ def join_finalise(ctx):
+ """Finalise the join, mark us synchronised and setup secrets db."""
+
+ logger = logging.getLogger("provision")
+ logger.addHandler(logging.StreamHandler(sys.stdout))
+
+ # FIXME we shouldn't do this in all cases
+ # If for some reasons we joined in another site than the one of
+ # DC we just replicated from then we don't need to send the updatereplicateref
+ # as replication between sites is time based and on the initiative of the
+ # requesting DC
+ print "Sending DsReplicateUpdateRefs for all the replicated partitions"
+ for nc in ctx.full_nc_list:
+ ctx.send_DsReplicaUpdateRefs(nc)
+
+ if ctx.RODC:
+ print "Setting RODC invocationId"
+ ctx.local_samdb.set_invocation_id(str(ctx.invocation_id))
+ ctx.local_samdb.set_opaque_integer("domainFunctionality",
+ ctx.behavior_version)
+ m = ldb.Message()
+ m.dn = ldb.Dn(ctx.local_samdb, "%s" % ctx.ntds_dn)
+ m["invocationId"] = ldb.MessageElement(ndr_pack(ctx.invocation_id),
+ ldb.FLAG_MOD_REPLACE,
+ "invocationId")
+ ctx.local_samdb.modify(m)
+
+ # Note: as RODC the invocationId is only stored
+ # on the RODC itself, the other DCs never see it.
+ #
+ # Thats is why we fix up the replPropertyMetaData stamp
+ # for the 'invocationId' attribute, we need to change
+ # the 'version' to '0', this is what windows 2008r2 does as RODC
+ #
+ # This means if the object on a RWDC ever gets a invocationId
+ # attribute, it will have version '1' (or higher), which will
+ # will overwrite the RODC local value.
+ ctx.local_samdb.set_attribute_replmetadata_version(m.dn,
+ "invocationId",
+ 0)
+
+ print "Setting isSynchronized and dsServiceName"
+ m = ldb.Message()
+ m.dn = ldb.Dn(ctx.local_samdb, '@ROOTDSE')
+ m["isSynchronized"] = ldb.MessageElement("TRUE", ldb.FLAG_MOD_REPLACE, "isSynchronized")
+ m["dsServiceName"] = ldb.MessageElement("<GUID=%s>" % str(ctx.ntds_guid),
+ ldb.FLAG_MOD_REPLACE, "dsServiceName")
+ ctx.local_samdb.modify(m)
+
+ if ctx.subdomain:
+ return
+
+ secrets_ldb = Ldb(ctx.paths.secrets, session_info=system_session(), lp=ctx.lp)
+
+ print "Setting up secrets database"
+ secretsdb_self_join(secrets_ldb, domain=ctx.domain_name,
+ realm=ctx.realm,
+ dnsdomain=ctx.dnsdomain,
+ netbiosname=ctx.myname,
+ domainsid=security.dom_sid(ctx.domsid),
+ machinepass=ctx.acct_pass,
+ secure_channel_type=ctx.secure_channel_type,
+ key_version_number=ctx.key_version_number)
+
+ if ctx.dns_backend.startswith("BIND9_"):
+ dnspass = samba.generate_random_password(128, 255)
+
+ setup_bind9_dns(ctx.local_samdb, secrets_ldb, security.dom_sid(ctx.domsid),
+ ctx.names, ctx.paths, ctx.lp, logger,
+ dns_backend=ctx.dns_backend,
+ dnspass=dnspass, os_level=ctx.behavior_version,
+ targetdir=ctx.targetdir)
+
+ def join_setup_trusts(ctx):
+ """provision the local SAM."""
+
+ def arcfour_encrypt(key, data):
+ from Crypto.Cipher import ARC4
+ c = ARC4.new(key)
+ return c.encrypt(data)
+
+ def string_to_array(string):
+ blob = [0] * len(string)
+
+ for i in range(len(string)):
+ blob[i] = ord(string[i])
+
+ return blob
+
+ 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)
+
+ objectAttr = lsa.ObjectAttribute()
+ objectAttr.sec_qos = lsa.QosInfo()
+
+ pol_handle = lsaconn.OpenPolicy2(''.decode('utf-8'),
+ objectAttr, security.SEC_FLAG_MAXIMUM_ALLOWED)
+
+ info = lsa.TrustDomainInfoInfoEx()
+ info.domain_name.string = ctx.dnsdomain
+ info.netbios_name.string = ctx.domain_name
+ info.sid = security.dom_sid(ctx.domsid)
+ info.trust_direction = lsa.LSA_TRUST_DIRECTION_INBOUND | lsa.LSA_TRUST_DIRECTION_OUTBOUND
+ info.trust_type = lsa.LSA_TRUST_TYPE_UPLEVEL
+ info.trust_attributes = lsa.LSA_TRUST_ATTRIBUTE_WITHIN_FOREST
+
+ try:
+ oldname = lsa.String()
+ oldname.string = ctx.dnsdomain
+ oldinfo = lsaconn.QueryTrustedDomainInfoByName(pol_handle, oldname,
+ lsa.LSA_TRUSTED_DOMAIN_INFO_FULL_INFO)
+ print("Removing old trust record for %s (SID %s)" % (ctx.dnsdomain, oldinfo.info_ex.sid))
+ lsaconn.DeleteTrustedDomain(pol_handle, oldinfo.info_ex.sid)
+ except RuntimeError:
+ pass
+
+ password_blob = string_to_array(ctx.trustdom_pass.encode('utf-16-le'))
+
+ clear_value = drsblobs.AuthInfoClear()
+ clear_value.size = len(password_blob)
+ clear_value.password = password_blob
+
+ clear_authentication_information = drsblobs.AuthenticationInformation()
+ clear_authentication_information.LastUpdateTime = samba.unix2nttime(int(time.time()))
+ clear_authentication_information.AuthType = lsa.TRUST_AUTH_TYPE_CLEAR
+ clear_authentication_information.AuthInfo = clear_value
+
+ authentication_information_array = drsblobs.AuthenticationInformationArray()
+ authentication_information_array.count = 1
+ authentication_information_array.array = [clear_authentication_information]
+
+ outgoing = drsblobs.trustAuthInOutBlob()
+ outgoing.count = 1
+ outgoing.current = authentication_information_array
+
+ trustpass = drsblobs.trustDomainPasswords()
+ confounder = [3] * 512
+
+ for i in range(512):
+ confounder[i] = random.randint(0, 255)
+
+ trustpass.confounder = confounder
+
+ trustpass.outgoing = outgoing
+ trustpass.incoming = outgoing
+
+ trustpass_blob = ndr_pack(trustpass)
+
+ encrypted_trustpass = arcfour_encrypt(lsaconn.session_key, trustpass_blob)
+
+ auth_blob = lsa.DATA_BUF2()
+ auth_blob.size = len(encrypted_trustpass)
+ auth_blob.data = string_to_array(encrypted_trustpass)
+
+ auth_info = lsa.TrustDomainInfoAuthInfoInternal()
+ auth_info.auth_blob = auth_blob
+
+ trustdom_handle = lsaconn.CreateTrustedDomainEx2(pol_handle,
+ info,
+ auth_info,
+ security.SEC_STD_DELETE)
+
+ rec = {
+ "dn" : "cn=%s,cn=system,%s" % (ctx.dnsforest, ctx.base_dn),
+ "objectclass" : "trustedDomain",
+ "trustType" : str(info.trust_type),
+ "trustAttributes" : str(info.trust_attributes),
+ "trustDirection" : str(info.trust_direction),
+ "flatname" : ctx.forest_domain_name,
+ "trustPartner" : ctx.dnsforest,
+ "trustAuthIncoming" : ndr_pack(outgoing),
+ "trustAuthOutgoing" : ndr_pack(outgoing)
+ }
+ ctx.local_samdb.add(rec)
+
+ rec = {
+ "dn" : "cn=%s$,cn=users,%s" % (ctx.forest_domain_name, ctx.base_dn),
+ "objectclass" : "user",
+ "userAccountControl" : str(samba.dsdb.UF_INTERDOMAIN_TRUST_ACCOUNT),
+ "clearTextPassword" : ctx.trustdom_pass.encode('utf-16-le')
+ }
+ ctx.local_samdb.add(rec)
+
+
+ def do_join(ctx):
+ # full_nc_list is the list of naming context (NC) for which we will
+ # send a updateRef command to the partner DC
+ ctx.nc_list = [ ctx.config_dn, ctx.schema_dn ]
+ ctx.full_nc_list = [ctx.base_dn, ctx.config_dn, ctx.schema_dn ]
+
+ if not ctx.subdomain:
+ ctx.nc_list += [ctx.base_dn]
+ if ctx.dns_backend != "NONE":
+ ctx.nc_list += [ctx.domaindns_zone]
+
+ if ctx.dns_backend != "NONE":
+ ctx.full_nc_list += ['DC=DomainDnsZones,%s' % ctx.base_dn]
+ ctx.full_nc_list += ['DC=ForestDnsZones,%s' % ctx.root_dn]
+ ctx.nc_list += ['DC=ForestDnsZones,%s' % ctx.root_dn]
+
+ if ctx.promote_existing:
+ ctx.promote_possible()
+ else:
+ ctx.cleanup_old_join()
+
+ try:
+ ctx.join_add_objects()
+ ctx.join_provision()
+ ctx.join_replicate()
+ if ctx.subdomain:
+ ctx.join_add_objects2()
+ ctx.join_provision_own_domain()
+ ctx.join_setup_trusts()
+ ctx.join_finalise()
+ except:
+ print "Join failed - cleaning up"
+ ctx.cleanup_old_join()
+ raise
+
+
+def join_RODC(server=None, creds=None, lp=None, site=None, netbios_name=None,
+ targetdir=None, domain=None, domain_critical_only=False,
+ machinepass=None, use_ntvfs=False, dns_backend=None,
+ promote_existing=False):
+ """Join as a RODC."""
+
+ ctx = dc_join(server, creds, lp, site, netbios_name, targetdir, domain,
+ machinepass, use_ntvfs, dns_backend, promote_existing)
+
+ lp.set("workgroup", ctx.domain_name)
+ print("workgroup is %s" % ctx.domain_name)
+
+ lp.set("realm", ctx.realm)
+ print("realm is %s" % ctx.realm)
+