try:
return self.run(*args, **kwargs)
- except Exception, e:
+ except Exception as e:
self.show_command_error(e)
return -1
sam.toggle_userAccountFlags(search_filter, flag,
flags_str="Trusted-for-Delegation",
on=on, strict=True)
- except Exception, err:
+ except Exception as err:
raise CommandError(err)
sam.toggle_userAccountFlags(search_filter, flag,
flags_str="Trusted-to-Authenticate-for-Delegation",
on=on, strict=True)
- except Exception, err:
+ except Exception as err:
raise CommandError(err)
"msDS-AllowedToDelegateTo")
try:
sam.modify(msg)
- except Exception, err:
+ except Exception as err:
raise CommandError(err)
"msDS-AllowedToDelegateTo")
try:
sam.modify(msg)
- except Exception, err:
+ except Exception as err:
raise CommandError(err)
binding_str = "ncacn_ip_tcp:%s[sign]" % server
try:
dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
- except RuntimeError, e:
+ except RuntimeError as e:
raise CommandError('Connecting to DNS RPC server %s failed with %s' % (server, e))
return dns_conn
base_schema=base_schema,
plaintext_secrets=plaintext_secrets)
- except ProvisioningError, e:
+ except ProvisioningError as e:
raise CommandError("Provision failed", e)
result.report_logger(self.logger)
dc_dn = res[0].dn
uac = int(str(res[0]["userAccountControl"]))
- except Exception, e:
+ except Exception as e:
if not (dsa_options & DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL) and not samdb.am_rodc():
self.errf.write(
"Error while demoting, re-enabling inbound replication\n")
"userAccountControl")
try:
remote_samdb.modify(msg)
- except Exception, e:
+ except Exception as e:
if not (dsa_options & DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL) and not samdb.am_rodc():
self.errf.write(
"Error while demoting, re-enabling inbound replication")
try:
newdn = ldb.Dn(remote_samdb, "%s,%s" % (newrdn, str(computer_dn)))
remote_samdb.rename(dc_dn, newdn)
- except Exception, e:
+ except Exception as e:
if not (dsa_options & DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL) and not samdb.am_rodc():
self.errf.write(
"Error while demoting, re-enabling inbound replication\n")
try:
remote_samdb.delete(ldb.Dn(remote_samdb,
"%s,%s" % (s, str(newdn))))
- except ldb.LdbError, l:
+ except ldb.LdbError as l:
pass
self.errf.write("Demote successful\n")
else:
cur_account_lockout_duration = abs(int(res[0]["lockoutDuration"][0])) / (1e7 * 60)
cur_reset_account_lockout_after = abs(int(res[0]["lockOutObservationWindow"][0])) / (1e7 * 60)
- except Exception, e:
+ except Exception as e:
raise CommandError("Could not retrieve password properties!", e)
if subcommand == "show":
current_time=current_time,
tombstone_lifetime=tombstone_lifetime)
- except Exception, err:
+ except Exception as err:
if started_transaction:
samdb.transaction_cancel()
raise CommandError("Failed to expunge / garbage collect tombstones", err)
'''make a DRSUAPI connection to the server'''
try:
(ctx.drsuapi, ctx.drsuapi_handle, ctx.bind_supported_extensions) = drs_utils.drsuapi_connect(ctx.server, ctx.lp, ctx.creds)
- except Exception, e:
+ except Exception as e:
raise CommandError("DRS connection to %s failed" % ctx.server, e)
def samdb_connect(ctx):
ctx.samdb = SamDB(url="ldap://%s" % ctx.server,
session_info=system_session(),
credentials=ctx.creds, lp=ctx.lp)
- except Exception, e:
+ except Exception as e:
raise CommandError("LDAP connection to %s failed" % ctx.server, e)
def drs_errmsg(werr):
try:
(info_type, info) = self.drsuapi.DsReplicaGetInfo(
self.drsuapi_handle, 1, req1)
- except Exception, e:
+ except Exception as e:
raise CommandError("DsReplicaGetInfo of type %u failed" % info_type, e)
return (info_type, info)
(site, server) = drs_parse_ntds_dn(ntds_dn)
try:
ntds = self.samdb.search(base=ntds_dn, scope=ldb.SCOPE_BASE, attrs=['options', 'objectGUID', 'invocationId'])
- except Exception, e:
+ except Exception as e:
raise CommandError("Failed to search NTDS DN %s" % ntds_dn)
dsa_details = {
req1 = drsuapi.DsExecuteKCC1()
try:
self.drsuapi.DsExecuteKCC(self.drsuapi_handle, 1, req1)
- except Exception, e:
+ except Exception as e:
raise CommandError("DsExecuteKCC failed", e)
self.message("Consistency check on %s successful." % DC)
source_dsa_invocation_id, destination_dsa_guid,
rodc=rodc, full_sync=full_sync,
exop=exop, sync_forced=sync_forced)
- except Exception, e:
+ except Exception as e:
raise CommandError("Error replicating DN %s" % NC, e)
self.samdb.transaction_commit()
try:
drs_utils.sendDsReplicaSync(server_bind, server_bind_handle, source_dsa_guid, NC, req_options)
- except drs_utils.drsException, estr:
+ except drs_utils.drsException as estr:
raise CommandError("DsReplicaSync failed", estr)
if async_op:
self.message("Replicate from %s to %s was started." % (SOURCE_DC, DEST_DC))
try:
connection = samba.drs_utils.drsuapi_connect(samdb.host_dns_name(),
lp, creds)
- except samba.drs_utils.drsException, e:
+ except samba.drs_utils.drsException as e:
raise CommandError("Drsuapi Connect failed", e)
try:
drsuapi_handle,
master_guid,
NC, req_options)
- except samba.drs_utils.drsException, estr:
+ except samba.drs_utils.drsException as estr:
raise CommandError("Replication failed", estr)
outf.write("FSMO transfer of '%s' role successful\n" % role)
self.message("%s owner: %s" % (long_name, str(master)))
else:
self.message("%s has no current owner" % (long_name))
- except CommandError, e:
+ except CommandError as e:
self.message("%s: * %s" % (long_name, e.message))
class cmd_fsmo_transfer(Command):
ctx.samdb = SamDB(url=ctx.url,
session_info=system_session(),
credentials=ctx.creds, lp=ctx.lp)
- except Exception, e:
+ except Exception as e:
raise CommandError("LDAP connection to %s failed " % ctx.url, e)
if dc is None:
try:
dc = netcmd_finddc(lp, creds)
- except Exception, e:
+ except Exception as e:
raise RuntimeError("Could not find a DC for domain", e)
url = 'ldap://' + dc
return url
'displayName',
'gPCFileSysPath'],
controls=['sd_flags:1:%d' % sd_flags])
- except Exception, e:
+ except Exception as e:
if gpo is not None:
mesg = "Cannot get information for GPO %s" % gpo
else:
search_expr = "(&(objectClass=*)(gPLink=*%s*))" % gpo
try:
msg = samdb.search(expression=search_expr, attrs=['gPLink'])
- except Exception, e:
+ except Exception as e:
raise CommandError("Could not find container(s) with GPO %s" % gpo, e)
return msg
msg = samdb.search(base=container_dn, scope=ldb.SCOPE_BASE,
expression="(objectClass=*)",
attrs=['gPLink'])[0]
- except Exception, e:
+ except Exception as e:
raise CommandError("Container '%s' does not exist" % container_dn, e)
found = False
m['d0'] = ldb.MessageElement(msg['gPLink'][0], ldb.FLAG_MOD_DELETE, 'gPLink')
try:
samdb.modify(m)
- except Exception, e:
+ except Exception as e:
raise CommandError("Error removing GPO from container", e)
try:
self.samdb.modify(m)
- except Exception, e:
+ except Exception as e:
raise CommandError("Error adding GPO Link", e)
self.outf.write("Added/Updated GPO link\n")
try:
self.samdb.modify(m)
- except Exception, e:
+ except Exception as e:
raise CommandError("Error setting inheritance state %s" % inherit_state, e)
try:
os.mkdir(gpodir)
copy_directory_remote_to_local(conn, sharepath, gpodir)
- except Exception, e:
+ except Exception as e:
# FIXME: Catch more specific exception
raise CommandError("Error copying GPO from DC", e)
self.outf.write('GPO copied to %s\n' % gpodir)
os.mkdir(os.path.join(gpodir, "User"))
gpt_contents = "[General]\r\nVersion=0\r\n"
file(os.path.join(gpodir, "GPT.INI"), "w").write(gpt_contents)
- except Exception, e:
+ except Exception as e:
raise CommandError("Error Creating GPO files", e)
# Connect to DC over SMB
[dom_name, service, sharepath] = parse_unc(unc_path)
try:
conn = smb.SMB(dc_hostname, service, lp=self.lp, creds=self.creds)
- except Exception, e:
+ except Exception as e:
raise CommandError("Error connecting to '%s' using SMB" % dc_hostname, e)
self.samdb.transaction_start()
[dom_name, service, sharepath] = parse_unc(unc_path)
try:
conn = smb.SMB(dc_hostname, service, lp=self.lp, creds=self.creds)
- except Exception, e:
+ except Exception as e:
raise CommandError("Error connecting to '%s' using SMB" % dc_hostname, e)
self.samdb.transaction_start()
samdb.newgroup(groupname, groupou=groupou, grouptype = gtype,
description=description, mailaddress=mail_address, notes=notes,
gidnumber=gid_number, nisdomain=nis_domain)
- except Exception, e:
+ except Exception as e:
# FIXME: catch more specific exception
raise CommandError('Failed to create group "%s"' % groupname, e)
self.outf.write("Added group %s\n" % groupname)
try:
samdb.delete(group_dn)
- except Exception, e:
+ except Exception as e:
# FIXME: catch more specific exception
raise CommandError('Failed to remove group "%s"' % groupname, e)
self.outf.write("Deleted group %s\n" % groupname)
groupmembers = listofmembers.split(',')
samdb.add_remove_group_members(groupname, groupmembers,
add_members_operation=True)
- except Exception, e:
+ except Exception as e:
# FIXME: catch more specific exception
raise CommandError('Failed to add members "%s" to group "%s"' % (
listofmembers, groupname), e)
credentials=creds, lp=lp)
samdb.add_remove_group_members(groupname, listofmembers.split(","),
add_members_operation=False)
- except Exception, e:
+ except Exception as e:
# FIXME: Catch more specific exception
raise CommandError('Failed to remove members "%s" from group "%s"' % (listofmembers, groupname), e)
self.outf.write("Removed members from group %s\n" % groupname)
member_name = msg.get("cn", idx=0)
self.outf.write("%s\n" % member_name)
- except Exception, e:
+ except Exception as e:
raise CommandError('Failed to list members of "%s" group ' % groupname, e)
class cmd_group_move(Command):
try:
full_new_parent_dn = samdb.normalize_dn_in_domain(new_parent_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Invalid new_parent_dn "%s": %s' %
(new_parent_dn, e.message))
try:
samdb.rename(group_dn, full_new_group_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Failed to move group "%s"' % groupname, e)
self.outf.write('Moved group "%s" into "%s"\n' %
(groupname, full_new_parent_dn))
def delete_force(self, object_dn):
try:
self.ldb.delete(object_dn)
- except Ldb.LdbError, e:
+ except Ldb.LdbError as e:
assert "No such object" in str(e)
def get_attribute_name(self, key):
try:
samdb = SamDB(session_info=system_session(),
lp=lp)
- except Exception, e:
+ except Exception as e:
raise CommandError("Unable to open samdb:", e)
if not use_ntvfs and not use_s3fs:
try:
samdb = SamDB(session_info=system_session(),
lp=lp)
- except Exception, e:
+ except Exception as e:
raise CommandError("Unable to open samdb:", e)
if not use_ntvfs and not use_s3fs:
try:
samdb = SamDB(session_info=system_session(),
lp=lp)
- except Exception, e:
+ except Exception as e:
raise CommandError("Unable to open samdb:", e)
if not use_ntvfs and not use_s3fs:
sysvol = lp.get("path", "sysvol")
try:
samdb = SamDB(session_info=system_session(), lp=lp)
- except Exception, e:
+ except Exception as e:
raise CommandError("Unable to open samdb:", e)
domain_sid = security.dom_sid(samdb.domain_sid)
try:
full_old_ou_dn = samdb.normalize_dn_in_domain(old_ou_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Invalid old_ou_dn "%s": %s' %
(old_ou_dn, e.message))
try:
full_new_ou_dn = samdb.normalize_dn_in_domain(new_ou_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Invalid new_ou_dn "%s": %s' %
(new_ou_dn, e.message))
return
samdb.rename(full_old_ou_dn, full_new_ou_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Failed to rename ou "%s"' % full_old_ou_dn, e)
self.outf.write('Renamed ou "%s" to "%s"\n' % (full_old_ou_dn,
full_new_ou_dn))
domain_dn = ldb.Dn(samdb, samdb.domain_dn())
try:
full_old_ou_dn = samdb.normalize_dn_in_domain(old_ou_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Invalid old_ou_dn "%s": %s' %
(old_ou_dn, e.message))
try:
full_new_parent_dn = samdb.normalize_dn_in_domain(new_parent_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Invalid new_parent_dn "%s": %s' %
(new_parent_dn, e.message))
self.outf.write('Unable to find ou "%s"\n' % full_old_ou_dn)
return
samdb.rename(full_old_ou_dn, full_new_ou_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Failed to move ou "%s"' % full_old_ou_dn, e)
self.outf.write('Moved ou "%s" into "%s"\n' %
(full_old_ou_dn, full_new_parent_dn))
try:
full_ou_dn = samdb.normalize_dn_in_domain(ou_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Invalid ou_dn "%s": %s' % (ou_dn, e.message))
try:
samdb.create_ou(full_ou_dn, description=description)
- except Exception, e:
+ except Exception as e:
raise CommandError('Failed to create ou "%s"' % full_ou_dn, e)
self.outf.write('Created ou "%s"\n' % full_ou_dn)
try:
full_ou_dn = samdb.normalize_dn_in_domain(ou_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Invalid ou_dn "%s": %s' % (ou_dn, e.message))
minchilds = 0
child.dn.remove_base_components(len(domain_dn))
self.outf.write("%s\n" % child.dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Failed to list contents of ou "%s"' %
full_ou_dn, e)
try:
full_ou_dn = samdb.normalize_dn_in_domain(ou_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Invalid ou_dn "%s": %s' % (ou_dn, e.message))
controls = []
self.outf.write('Unable to find ou "%s"\n' % ou_dn)
return
samdb.delete(full_ou_dn, controls)
- except Exception, e:
+ except Exception as e:
raise CommandError('Failed to delete ou "%s"' % full_ou_dn, e)
self.outf.write('Deleted ou "%s"\n' % full_ou_dn)
try:
dn = self.get_dn(samdb, account)
- except RODCException, e:
+ except RODCException as e:
if not ignore_errors:
raise CommandError(str(e))
errors.append(e)
try:
repl.replicate(dn, source_dsa_invocation_id, destination_dsa_guid,
exop=drsuapi.DRSUAPI_EXOP_REPL_SECRET, rodc=True)
- except Exception, e:
+ except Exception as e:
local_samdb.transaction_cancel()
if not ignore_errors:
raise CommandError("Error replicating DN %s" % dn)
try:
sites.create_site(samdb, samdb.get_config_basedn(), sitename)
samdb.transaction_commit()
- except sites.SiteAlreadyExistsException, e:
+ except sites.SiteAlreadyExistsException as e:
samdb.transaction_cancel()
raise CommandError("Error while creating site %s, error: %s" %
(sitename, str(e)))
try:
sites.delete_site(samdb, samdb.get_config_basedn(), sitename)
samdb.transaction_commit()
- except sites.SiteException, e:
+ except sites.SiteException as e:
samdb.transaction_cancel()
raise CommandError(
"Error while removing site %s, error: %s" % (sitename, str(e)))
subnets.create_subnet(samdb, samdb.get_config_basedn(), subnetname,
site_of_subnet)
samdb.transaction_commit()
- except subnets.SubnetException, e:
+ except subnets.SubnetException as e:
samdb.transaction_cancel()
raise CommandError("Error while creating subnet %s: %s" %
(subnetname, e))
try:
subnets.delete_subnet(samdb, samdb.get_config_basedn(), subnetname)
samdb.transaction_commit()
- except subnets.SubnetException, e:
+ except subnets.SubnetException as e:
samdb.transaction_cancel()
raise CommandError("Error while removing subnet %s, error: %s" %
(subnetname, e))
subnets.set_subnet_site(samdb, samdb.get_config_basedn(),
subnetname, site_of_subnet)
samdb.transaction_commit()
- except subnets.SubnetException, e:
+ except subnets.SubnetException as e:
samdb.transaction_cancel()
raise CommandError("Error assigning subnet %s to site %s: %s" %
(subnetname, site_of_subnet, e))
try:
lp = sambaopts.get_loadparm()
- except RuntimeError, err:
+ except RuntimeError as err:
raise CommandError(err)
# We need this to force the output
uidnumber=uid_number, gidnumber=gid_number,
gecos=gecos, loginshell=login_shell,
smartcard_required=smartcard_required)
- except Exception, e:
+ except Exception as e:
raise CommandError("Failed to add user '%s': " % username, e)
self.outf.write("User '%s' created successfully\n" % username)
try:
samdb.delete(user_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Failed to remove user "%s"' % username, e)
self.outf.write("Deleted user %s\n" % username)
credentials=creds, lp=lp)
try:
samdb.enable_account(filter)
- except Exception, msg:
+ except Exception as msg:
raise CommandError("Failed to enable user '%s': %s" % (username or filter, msg))
self.outf.write("Enabled user '%s'\n" % (username or filter))
credentials=creds, lp=lp)
try:
samdb.disable_account(filter)
- except Exception, msg:
+ except Exception as msg:
raise CommandError("Failed to disable user '%s': %s" % (username or filter, msg))
try:
samdb.setexpiry(filter, days*24*3600, no_expiry_req=noexpiry)
- except Exception, msg:
+ except Exception as msg:
# FIXME: Catch more specific exception
raise CommandError("Failed to set expiry for user '%s': %s" % (
username or filter, msg))
try:
net.change_password(password.encode('utf-8'))
- except Exception, msg:
+ except Exception as msg:
# FIXME: catch more specific exception
raise CommandError("Failed to change password : %s" % msg)
self.outf.write("Changed password OK\n")
samdb.toggle_userAccountFlags(filter, flags, on=True)
command = "Failed to enable account for user '%s'" % (username or filter)
samdb.enable_account(filter)
- except Exception, msg:
+ except Exception as msg:
# FIXME: catch more specific exception
raise CommandError("%s: %s" % (command, msg))
self.outf.write("Added UF_SMARTCARD_REQUIRED OK\n")
samdb.setpassword(filter, password,
force_change_at_next_login=must_change_at_next_login,
username=username)
- except Exception, msg:
+ except Exception as msg:
# FIXME: catch more specific exception
raise CommandError("%s: %s" % (command, msg))
self.outf.write("Changed password OK\n")
try:
full_new_parent_dn = samdb.normalize_dn_in_domain(new_parent_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Invalid new_parent_dn "%s": %s' %
(new_parent_dn, e.message))
try:
samdb.rename(user_dn, full_new_user_dn)
- except Exception, e:
+ except Exception as e:
raise CommandError('Failed to move user "%s"' % username, e)
self.outf.write('Moved user "%s" into "%s"\n' %
(username, full_new_parent_dn))