The branch, master has been updated via 8111001 netcmd: Avoid catching all exceptions, avoid using ';' at the end of lines. via dc3df56 upgrade: Avoid catching all exceptions, just catch the ones we care about. from 9c979e8 s4:findprovisionusnranges - the default python path is detected over "env"
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 8111001977101288ca8277d5249776377c941974 Author: Jelmer Vernooij <jel...@samba.org> Date: Sat Oct 8 14:13:04 2011 +0200 netcmd: Avoid catching all exceptions, avoid using ';' at the end of lines. Autobuild-User: Jelmer Vernooij <jel...@samba.org> Autobuild-Date: Sat Oct 8 15:46:46 CEST 2011 on sn-devel-104 commit dc3df567bef9a462fd48d233f88ee59dbadcbd89 Author: Jelmer Vernooij <jel...@samba.org> Date: Sat Oct 8 14:07:18 2011 +0200 upgrade: Avoid catching all exceptions, just catch the ones we care about. ----------------------------------------------------------------------- Summary of changes: source4/scripting/python/samba/netcmd/gpo.py | 17 ++++++++--------- source4/scripting/python/samba/upgrade.py | 20 +++++++++----------- 2 files changed, 17 insertions(+), 20 deletions(-) Changeset truncated at 500 lines: diff --git a/source4/scripting/python/samba/netcmd/gpo.py b/source4/scripting/python/samba/netcmd/gpo.py index 06fa01c..8b96d37 100644 --- a/source4/scripting/python/samba/netcmd/gpo.py +++ b/source4/scripting/python/samba/netcmd/gpo.py @@ -34,8 +34,7 @@ from samba.netcmd import ( SuperCommand, ) from samba.samdb import SamDB -from samba import drs_utils, nttime2string, dsdb, dcerpc -from samba.dcerpc import misc +from samba import dsdb, dcerpc from samba.ndr import ndr_unpack import samba.security import samba.auth @@ -170,14 +169,14 @@ def get_gpo_info(samdb, gpo=None, displayname=None, dn=None): def parse_unc(unc): '''Parse UNC string into a hostname, a service, and a filepath''' if unc.startswith('\\\\') and unc.startswith('//'): - return [] + raise ValueError("UNC doesn't start with \\\\ or //") tmp = unc[2:].split('/', 2) if len(tmp) == 3: return tmp tmp = unc[2:].split('\\', 2) if len(tmp) == 3: - return tmp; - return [] + return tmp + raise ValueError("Invalid UNC string: %s" % unc) def copy_directory_remote_to_local(conn, remotedir, localdir): @@ -602,7 +601,7 @@ class cmd_dellink(Command): gplist.remove(g) break else: - raise CommandError("Specified GPO is not linked to this container"); + raise CommandError("Specified GPO is not linked to this container") m = ldb.Message() m.dn = ldb.Dn(self.samdb, container_dn) @@ -658,7 +657,7 @@ class cmd_getinheritance(Command): inheritance = 0 if 'gPOptions' in msg: - inheritance = int(msg['gPOptions'][0]); + inheritance = int(msg['gPOptions'][0]) if inheritance == dsdb.GPO_BLOCK_INHERITANCE: print("Container has GPO_BLOCK_INHERITANCE") @@ -713,7 +712,7 @@ class cmd_setinheritance(Command): if 'gPOptions' in msg: m['new_value'] = ldb.MessageElement(str(inheritance), ldb.FLAG_MOD_REPLACE, 'gPOptions') else: - m['new_value'] = ldb.MessageElement(str(inheritance), ldb.FLAG_MOD_ADD, 'gPOptions'); + m['new_value'] = ldb.MessageElement(str(inheritance), ldb.FLAG_MOD_ADD, 'gPOptions') try: self.samdb.modify(m) @@ -757,7 +756,7 @@ class cmd_fetch(Command): unc = msg['gPCFileSysPath'][0] try: [dom_name, service, sharepath] = parse_unc(unc) - except: + except ValueError: raise CommandError("Invalid GPO path (%s)" % unc) # SMB connect to DC diff --git a/source4/scripting/python/samba/upgrade.py b/source4/scripting/python/samba/upgrade.py index 4c293ed..60cff51 100644 --- a/source4/scripting/python/samba/upgrade.py +++ b/source4/scripting/python/samba/upgrade.py @@ -19,7 +19,6 @@ __docformat__ = "restructuredText" -import grp import ldb import time import pwd @@ -486,15 +485,12 @@ def upgrade_from_samba3(samba3, logger, targetdir, session_info=None, useeadb=Fa realm) # Find machine account and password - machinepass = None - machinerid = None - machinesid = None next_rid = 1000 try: machinepass = secrets_db.get_machine_password(netbiosname) - except: - pass + except KeyError: + machinepass = None # We must close the direct pytdb database before the C code loads it secrets_db.close() @@ -512,9 +508,11 @@ def upgrade_from_samba3(samba3, logger, targetdir, session_info=None, useeadb=Fa # Get machine account, sid, rid try: machineacct = s3db.getsampwnam('%s$' % netbiosname) + except passdb.error: + machinerid = None + machinesid = None + else: machinesid, machinerid = machineacct.user_sid.split() - except: - pass # Export account policy logger.info("Exporting account policy") @@ -536,7 +534,7 @@ def upgrade_from_samba3(samba3, logger, targetdir, session_info=None, useeadb=Fa elif group.sid_name_use == lsa.SID_NAME_DOM_GRP: try: members = s3db.enum_group_members(group.sid) - except: + except passdb.error: continue groupmembers[group.nt_name] = members elif group.sid_name_use == lsa.SID_NAME_WKN_GRP: @@ -590,10 +588,10 @@ Please fix this account before attempting to upgrade again userdata[username] = user try: uids[username] = s3db.sid_to_id(user.user_sid)[0] - except: + except passdb.error: try: uids[username] = pwd.getpwnam(username).pw_uid - except: + except passdb.error: pass if not admin_user and username.lower() == 'root': -- Samba Shared Repository