from samba import gensec, Ldb, drs_utils, arcfour_encrypt, string_to_byte_array
import ldb
import samba
-import sys
import uuid
from samba.ndr import ndr_pack, ndr_unpack
from samba.dcerpc import security, drsuapi, misc, nbt, lsa, drsblobs, dnsserver, dnsp
from samba import werror
from base64 import b64encode
from samba import WERRORError, NTSTATUSError
-from samba.dnsserver import ARecord, AAAARecord, PTRRecord, CNameRecord, NSRecord, MXRecord, SOARecord, SRVRecord, TXTRecord
from samba import sd_utils
+from samba.dnsserver import ARecord, AAAARecord, CNameRecord
import logging
-import talloc
import random
import time
import re
import tempfile
from samba.compat import text_type
from samba.compat import get_string
+from samba.netcmd import CommandError
class DCJoinException(Exception):
try:
ctx.cldap_ret = ctx.net.finddc(domain=domain, flags=nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE)
except NTSTATUSError as error:
- raise Exception("Failed to find a writeable DC for domain '%s': %s" %
- (domain, error[1]))
+ raise CommandError("Failed to find a writeable DC for domain '%s': %s" %
+ (domain, error.args[1]))
except Exception:
- raise Exception("Failed to find a writeable DC for domain '%s'" % domain)
+ raise CommandError("Failed to find a writeable DC for domain '%s'" % domain)
if ctx.cldap_ret.client_site is not None and ctx.cldap_ret.client_site != "":
ctx.site = ctx.cldap_ret.client_site
return ctx.cldap_ret.pdc_dns_name
pass
ctx.net.set_password(account_name=ctx.samname,
domain_name=ctx.domain_name,
- newpassword=ctx.acct_pass.encode('utf-8'))
+ newpassword=ctx.acct_pass)
res = ctx.samdb.search(base=ctx.acct_dn, scope=ldb.SCOPE_BASE,
attrs=["msDS-KeyVersionNumber",
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.encode('utf-8'))
+ repl_creds.set_password(ctx.acct_pass)
else:
repl_creds = ctx.creds
# if the connection was disconnected, then reconnect
if (enum == ldb.ERR_OPERATIONS_ERROR and
- 'NT_STATUS_CONNECTION_DISCONNECTED' in estr):
+ ('NT_STATUS_CONNECTION_DISCONNECTED' in estr or
+ 'NT_STATUS_CONNECTION_RESET' in estr)):
ctx.logger.warning("LDB connection disconnected. Reconnecting")
ctx.samdb = SamDB(url="ldap://%s" % ctx.server,
session_info=system_session(),
"""
client_version = dnsserver.DNS_CLIENT_VERSION_LONGHORN
- record_type = dnsp.DNS_TYPE_A
select_flags = dnsserver.DNS_RPC_VIEW_AUTHORITY_DATA |\
dnsserver.DNS_RPC_VIEW_NO_CHILDREN
name_found = True
- sd_helper = samba.sd_utils.SDUtils(ctx.samdb)
+ sd_helper = sd_utils.SDUtils(ctx.samdb)
change_owner_sd = security.descriptor()
change_owner_sd.owner_sid = ctx.new_dc_account_sid