summaryrefslogtreecommitdiff
path: root/source4/scripting/python/samba/netcmd
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting/python/samba/netcmd')
-rw-r--r--source4/scripting/python/samba/netcmd/drs.py20
-rw-r--r--source4/scripting/python/samba/netcmd/gpo.py21
-rw-r--r--source4/scripting/python/samba/netcmd/group.py20
-rw-r--r--source4/scripting/python/samba/netcmd/newuser.py5
-rw-r--r--source4/scripting/python/samba/netcmd/ntacl.py5
-rw-r--r--source4/scripting/python/samba/netcmd/pwsettings.py4
-rw-r--r--source4/scripting/python/samba/netcmd/rodc.py8
-rw-r--r--source4/scripting/python/samba/netcmd/setpassword.py5
8 files changed, 40 insertions, 48 deletions
diff --git a/source4/scripting/python/samba/netcmd/drs.py b/source4/scripting/python/samba/netcmd/drs.py
index 387524b943..6f5b5b8ed3 100644
--- a/source4/scripting/python/samba/netcmd/drs.py
+++ b/source4/scripting/python/samba/netcmd/drs.py
@@ -44,8 +44,8 @@ def drsuapi_connect(ctx):
try:
ctx.drsuapi = drsuapi.drsuapi(binding_string, ctx.lp, ctx.creds)
(ctx.drsuapi_handle, ctx.bind_supported_extensions) = drs_utils.drs_DsBind(ctx.drsuapi)
- except Exception, estr:
- raise CommandError("DRS connection to %s failed - %s" % (ctx.server, estr))
+ except Exception, e:
+ raise CommandError("DRS connection to %s failed" % ctx.server, e)
def samdb_connect(ctx):
@@ -54,8 +54,8 @@ def samdb_connect(ctx):
ctx.samdb = SamDB(url="ldap://%s" % ctx.server,
session_info=system_session(),
credentials=ctx.creds, lp=ctx.lp)
- except Exception, estr:
- raise CommandError("LDAP connection to %s failed - %s" % (ctx.server, estr))
+ except Exception, e:
+ raise CommandError("LDAP connection to %s failed" % ctx.server, e)
def drs_errmsg(werr):
@@ -119,8 +119,8 @@ class cmd_drs_showrepl(Command):
req1.info_type = info_type
try:
(info_type, info) = ctx.drsuapi.DsReplicaGetInfo(ctx.drsuapi_handle, 1, req1)
- except Exception, estr:
- raise CommandError("DsReplicaGetInfo failed : %s" % estr)
+ except Exception, e:
+ raise CommandError("DsReplicaGetInfo of type %u failed" % info_type, e)
return (info_type, info)
@@ -221,8 +221,8 @@ class cmd_drs_kcc(Command):
req1 = drsuapi.DsExecuteKCC1()
try:
self.drsuapi.DsExecuteKCC(self.drsuapi_handle, 1, req1)
- except Exception, (ecode, estr):
- raise CommandError("DsExecuteKCC failed - %s" % estr)
+ except Exception, e:
+ raise CommandError("DsExecuteKCC failed", e)
print("Consistency check on %s successful." % DC)
@@ -289,8 +289,8 @@ class cmd_drs_replicate(Command):
try:
self.drsuapi.DsReplicaSync(self.drsuapi_handle, 1, req1)
- except Exception, (ecode, estr):
- raise CommandError("DsReplicaSync failed - %s" % estr)
+ except Exception, e:
+ raise CommandError("DsReplicaSync failed", estr)
print("Replicate from %s to %s was successful." % (SOURCE_DC, DEST_DC))
diff --git a/source4/scripting/python/samba/netcmd/gpo.py b/source4/scripting/python/samba/netcmd/gpo.py
index 90b7a5efaa..5e8748adc5 100644
--- a/source4/scripting/python/samba/netcmd/gpo.py
+++ b/source4/scripting/python/samba/netcmd/gpo.py
@@ -41,8 +41,8 @@ def samdb_connect(ctx):
ctx.samdb = SamDB(url=ctx.url,
session_info=system_session(),
credentials=ctx.creds, lp=ctx.lp)
- except Exception, estr:
- raise CommandError("LDAP connection to %s failed - %s" % (ctx.url, estr))
+ except Exception, e:
+ raise CommandError("LDAP connection to %s failed " % ctx.url, e)
def attr_default(msg, attrname, default):
@@ -114,9 +114,12 @@ class cmd_listall(Command):
("GPO_FLAG_USER_DISABLE", dsdb.GPO_FLAG_USER_DISABLE ),
( "GPO_FLAG_MACHINE_DISABLE", dsdb.GPO_FLAG_MACHINE_DISABLE ) ]
- msg = self.samdb.search(base=policies_dn, scope=ldb.SCOPE_ONELEVEL,
- expression="(objectClass=groupPolicyContainer)",
- attrs=['nTSecurityDescriptor', 'versionNumber', 'flags', 'name', 'displayName', 'gPCFileSysPath'])
+ try:
+ msg = self.samdb.search(base=policies_dn, scope=ldb.SCOPE_ONELEVEL,
+ expression="(objectClass=groupPolicyContainer)",
+ attrs=['nTSecurityDescriptor', 'versionNumber', 'flags', 'name', 'displayName', 'gPCFileSysPath'])
+ except Exception, e:
+ raise CommandError("Failed to list policies in %s" % policies_dn, e)
for m in msg:
print("GPO : %s" % m['name'][0])
print("display name : %s" % m['displayName'][0])
@@ -158,15 +161,15 @@ class cmd_list(Command):
try:
user_dn = self.samdb.search(expression='(&(samAccountName=%s)(objectclass=User))' % username)[0].dn
- except Exception, estr:
- raise CommandError("Failed to find user %s - %s" % (username, estr))
+ except Exception, e:
+ raise CommandError("Failed to find user %s" % username, e)
# check if its a computer account
try:
msg = self.samdb.search(base=user_dn, scope=ldb.SCOPE_BASE, attrs=['objectClass'])[0]
is_computer = 'computer' in msg['objectClass']
- except Exception, estr:
- raise CommandError("Failed to find objectClass for user %s - %s" % (username, estr))
+ except Exception, e:
+ raise CommandError("Failed to find objectClass for user %s" % username, e)
print("TODO: get user token")
# token = self.samdb.get_user_token(username)
diff --git a/source4/scripting/python/samba/netcmd/group.py b/source4/scripting/python/samba/netcmd/group.py
index 3a467fb28c..57f31cd511 100644
--- a/source4/scripting/python/samba/netcmd/group.py
+++ b/source4/scripting/python/samba/netcmd/group.py
@@ -83,9 +83,8 @@ class cmd_group_add(Command):
credentials=creds, lp=lp)
samdb.newgroup(groupname, groupou=groupou, grouptype = gtype,
description=description, mailaddress=mail_address, notes=notes)
- except ldb.LdbError, (num, msg):
- raise CommandError('Failed to create group "%s" : %s' % (
- groupname, msg))
+ except Exception, e:
+ raise CommandError('Failed to create group "%s"' % groupname, e)
class cmd_group_delete(Command):
@@ -114,9 +113,8 @@ class cmd_group_delete(Command):
samdb = SamDB(url=H, session_info=system_session(),
credentials=creds, lp=lp)
samdb.deletegroup(groupname)
- except ldb.LdbError, (num, msg):
- raise CommandError('Failed to remove group "%s": %s' % (
- groupname , msg))
+ except Exception, e:
+ raise CommandError('Failed to remove group "%s"' % groupname, e)
class cmd_group_add_members(Command):
@@ -146,9 +144,8 @@ class cmd_group_add_members(Command):
samdb = SamDB(url=H, session_info=system_session(),
credentials=creds, lp=lp)
samdb.add_remove_group_members(groupname, listofmembers, add_members_operation=True)
- except ldb.LdbError, (num, msg):
- raise CommandError('Failed to add members "%s" to group "%s": %s' % (
- listofmembers, groupname , msg))
+ except Exception, e:
+ raise CommandError('Failed to add members "%s" to group "%s"' % (listofmembers, groupname), e)
class cmd_group_remove_members(Command):
@@ -178,9 +175,8 @@ class cmd_group_remove_members(Command):
samdb = SamDB(url=H, session_info=system_session(),
credentials=creds, lp=lp)
samdb.add_remove_group_members(groupname, listofmembers, add_members_operation=False)
- except ldb.LdbError, (num, msg):
- raise CommandError('Failed to remove members "%s" from group "%s": %s' % (
- listofmembers, groupname , msg))
+ except Exception, e:
+ raise CommandError('Failed to remove members "%s" from group "%s"' % (listofmembers, groupname), e)
class cmd_group(SuperCommand):
diff --git a/source4/scripting/python/samba/netcmd/newuser.py b/source4/scripting/python/samba/netcmd/newuser.py
index 693568dee2..05c7bfc1bb 100644
--- a/source4/scripting/python/samba/netcmd/newuser.py
+++ b/source4/scripting/python/samba/netcmd/newuser.py
@@ -91,7 +91,6 @@ class cmd_newuser(Command):
jobtitle=job_title, department=department, company=company, description=description,
mailaddress=mail_address, internetaddress=internet_address,
telephonenumber=telephone_number, physicaldeliveryoffice=physical_delivery_office)
- except ldb.LdbError, (num, msg):
- raise CommandError('Failed to create user "%s" : %s' % (
- username, msg))
+ except Exception, e:
+ raise CommandError('Failed to create user "%s"' % username, e)
diff --git a/source4/scripting/python/samba/netcmd/ntacl.py b/source4/scripting/python/samba/netcmd/ntacl.py
index 8365658761..49f8fbc77f 100644
--- a/source4/scripting/python/samba/netcmd/ntacl.py
+++ b/source4/scripting/python/samba/netcmd/ntacl.py
@@ -65,9 +65,8 @@ class cmd_acl_set(Command):
try:
ldb = Ldb(path, session_info=system_session(), credentials=creds,
lp=lp)
- except:
- # XXX: Should catch a particular exception type
- raise CommandError("Unable to read domain SID from configuration files")
+ except Exception, e:
+ raise CommandError("Unable to read domain SID from configuration files", e)
attrs = ["objectSid"]
print lp.get("realm")
res = ldb.search(expression="(objectClass=*)",
diff --git a/source4/scripting/python/samba/netcmd/pwsettings.py b/source4/scripting/python/samba/netcmd/pwsettings.py
index 4a1645dd91..3f1a8e189d 100644
--- a/source4/scripting/python/samba/netcmd/pwsettings.py
+++ b/source4/scripting/python/samba/netcmd/pwsettings.py
@@ -86,8 +86,8 @@ class cmd_pwsettings(Command):
# ticks -> days
cur_min_pwd_age = int(abs(int(res[0]["minPwdAge"][0])) / (1e7 * 60 * 60 * 24))
cur_max_pwd_age = int(abs(int(res[0]["maxPwdAge"][0])) / (1e7 * 60 * 60 * 24))
- except KeyError:
- raise CommandError("Could not retrieve password properties!")
+ except Exception, e:
+ raise CommandError("Could not retrieve password properties!", e)
if subcommand == "show":
self.message("Password informations for domain '%s'" % domain_dn)
diff --git a/source4/scripting/python/samba/netcmd/rodc.py b/source4/scripting/python/samba/netcmd/rodc.py
index 5f97c32b28..b1f9d66d1f 100644
--- a/source4/scripting/python/samba/netcmd/rodc.py
+++ b/source4/scripting/python/samba/netcmd/rodc.py
@@ -106,12 +106,8 @@ class cmd_rodc_preload(Command):
try:
repl.replicate(dn, source_dsa_invocation_id, destination_dsa_guid,
exop=drsuapi.DRSUAPI_EXOP_REPL_SECRET, rodc=True)
- except RuntimeError, (ecode, estring):
- if estring == 'WERR_DS_DRA_ACCESS_DENIED':
- local_samdb.transaction_cancel()
- raise CommandError("Access denied replicating DN %s" % dn)
- else:
- raise
+ except Exception, e:
+ raise CommandError("Error replicating DN %s" % dn, e)
local_samdb.transaction_commit()
diff --git a/source4/scripting/python/samba/netcmd/setpassword.py b/source4/scripting/python/samba/netcmd/setpassword.py
index 047a95afae..b32b651822 100644
--- a/source4/scripting/python/samba/netcmd/setpassword.py
+++ b/source4/scripting/python/samba/netcmd/setpassword.py
@@ -75,7 +75,6 @@ class cmd_setpassword(Command):
samdb.setpassword(filter, password,
force_change_at_next_login=must_change_at_next_login,
username=username)
- except ldb.LdbError, (num, msg):
- raise CommandError('Failed to set password for user "%s" - %s' %
- (username, msg))
+ except Exception, e:
+ raise CommandError('Failed to set password for user "%s"' % username, e)
print "Changed password OK"