s4-python: More cleanups.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 8 Apr 2010 19:01:17 +0000 (21:01 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 8 Apr 2010 21:20:36 +0000 (23:20 +0200)
source4/lib/ldb/tests/python/acl.py
source4/lib/ldb/tests/python/deletetest.py
source4/scripting/bin/samba_dnsupdate
source4/scripting/bin/upgradeprovision
source4/scripting/python/samba/netcmd/ntacl.py
source4/scripting/python/samba/ntacls.py
source4/scripting/python/samba/provision.py
source4/scripting/python/samba/samdb.py
source4/setup/provision

index 4f320ee668940c48bfa3576f770d7fa36aa76696..37265ef3d5cbce2c15eb74a556a14ae9f71bff55 100755 (executable)
@@ -2,7 +2,6 @@
 # -*- coding: utf-8 -*-
 # This is unit with tests for LDAP access checks
 
-import getopt
 import optparse
 import sys
 import os
@@ -13,9 +12,8 @@ sys.path.append("bin/python")
 
 import samba.getopt as options
 
-from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError
-from ldb import ERR_NO_SUCH_OBJECT, ERR_INVALID_DN_SYNTAX, ERR_UNWILLING_TO_PERFORM
-from ldb import ERR_INSUFFICIENT_ACCESS_RIGHTS
+from ldb import (
+    SCOPE_BASE, LdbError, ERR_NO_SUCH_OBJECT, ERR_INSUFFICIENT_ACCESS_RIGHTS)
 
 from samba.ndr import ndr_pack, ndr_unpack
 from samba.dcerpc import security
index 55f34fac141c39dbe6e3ac17c36bb4b8ac635979..44eb919e0917cd6a5f09adc239640aba8d39ae2e 100755 (executable)
@@ -6,8 +6,9 @@ import sys
 import os
 
 sys.path.append("bin/python")
-sys.path.append("../lib/subunit/python")
-sys.path.append("../lib/testtools")
+import samba
+samba.ensure_external_module("subunit", "subunit")
+samba.ensure_external_module("testtools", "testtools")
 
 import samba.getopt as options
 
index 73611c8901fb69d57209aa9be7184b8600d4cbda..cebfae28710b7ce462da5d545e5f33b20fb61adb 100755 (executable)
@@ -86,12 +86,7 @@ def get_credentials(lp):
         return
     creds = Credentials()
     creds.guess(lp)
-    try:
-        creds.set_machine_account(lp)
-    except:
-        print "Failed to set machine account"
-        raise
-
+    creds.set_machine_account(lp)
     (tmp_fd, ccachename) = tempfile.mkstemp()
     creds.get_named_ccache(lp, ccachename)
 
@@ -200,7 +195,7 @@ def get_subst_vars():
     vars = {}
 
     samdb = SamDB(url=lp.get("sam database"), session_info=system_session(),
-                             lp=lp)
+                  lp=lp)
 
     vars['DNSDOMAIN'] = lp.get('realm').lower()
     vars['HOSTNAME']  = lp.get('netbios name').lower() + "." + vars['DNSDOMAIN']
index a900728ed47a5bb8055ace89ccb40afd1e017500..c33ef6fcb999f04c2df95b93f6cb0933fe7513a1 100755 (executable)
@@ -668,6 +668,7 @@ def check_diff_name(newpaths, paths, creds, session, basedn, names, ischema):
                         try:
                             dump_denied_change(dn,att,messageEltFlagToString(msgElt.flags()),current[0][att],reference[0][att])
                         except:
+                            # FIXME: Should catch an explicit exception here
                             dump_denied_change(dn,att,messageEltFlagToString(msgElt.flags()),current[0][att],None)
                     delta.remove(att)
         delta.dn = dn
index ebb66864d7cc541c36c4307b7600bf478eecc966..ea6bcb6e37418c016d07792ca2d53f761b88460f 100644 (file)
@@ -63,7 +63,8 @@ class cmd_acl_set(Command):
         creds = credopts.get_credentials(lp)
         creds.set_kerberos_state(DONT_USE_KERBEROS)
         try:
-            ldb = Ldb(path, session_info=system_session(), credentials=creds,lp=lp)
+            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")
index edcd643b2a15548cb42c35ce80382c088862941c..16e9463f09d84af68b8be171b782766669568ab5 100644 (file)
@@ -41,29 +41,37 @@ def checkset_backend(lp,backend,eadbfile):
 def getntacl(lp, file, backend=None, eadbfile=None):
     checkset_backend(lp, backend, eadbfile)
     eadbname = lp.get("posix:eadb")
-    if eadbname != None and eadbname != "" :
+    if eadbname is not None and eadbname != "":
         try:
-            attribute = samba.xattr_tdb.wrap_getxattr(eadbname,file,xattr.XATTR_NTACL_NAME)
+            attribute = samba.xattr_tdb.wrap_getxattr(eadbname, file, 
+                xattr.XATTR_NTACL_NAME)
         except:
+            # FIXME: Don't catch all exceptions, just those related to opening 
+            # xattrdb
             print "Fail to open %s" % eadbname
-            attribute = samba.xattr_native.wrap_getxattr(file,xattr.XATTR_NTACL_NAME)
+            attribute = samba.xattr_native.wrap_getxattr(file,
+                xattr.XATTR_NTACL_NAME)
     else:
-        attribute = samba.xattr_native.wrap_getxattr(file,xattr.XATTR_NTACL_NAME)
+        attribute = samba.xattr_native.wrap_getxattr(file,
+            xattr.XATTR_NTACL_NAME)
     ntacl = ndr_unpack(xattr.NTACL,attribute)
     return ntacl
 
 def setntacl(lp, file, sddl, domsid, backend=None, eadbfile=None):
-    checkset_backend(lp,backend,eadbfile)
+    checkset_backend(lp, backend, eadbfile)
     ntacl=xattr.NTACL()
     ntacl.version = 1
     sid=security.dom_sid(domsid)
     sd = security.descriptor.from_sddl(sddl, sid)
     ntacl.info = sd
     eadbname = lp.get("posix:eadb")
-    if eadbname != None  and eadbname != "":
+    if eadbname is not None and eadbname != "":
         try:
-            samba.xattr_tdb.wrap_setxattr(eadbname,file,xattr.XATTR_NTACL_NAME,ndr_pack(ntacl))
+            samba.xattr_tdb.wrap_setxattr(eadbname,
+                file,xattr.XATTR_NTACL_NAME,ndr_pack(ntacl))
         except:
+            # FIXME: Don't catch all exceptions, just those related to opening 
+            # xattrdb
             print "Fail to open %s"%eadbname
             samba.xattr_native.wrap_setxattr(file,xattr.XATTR_NTACL_NAME,ndr_pack(ntacl))
     else:
index 71c04cfef9155c400b6dea3837285135bbbf89e3..abbcf5221055b8da7c1203ade0de669ce818d03a 100644 (file)
@@ -269,7 +269,8 @@ def setup_ldb(ldb, ldif_path, subst_vars):
     except:
         ldb.transaction_cancel()
         raise
-    ldb.transaction_commit()
+    else:
+        ldb.transaction_commit()
 
 
 def provision_paths_from_lp(lp, dnsdomain):
@@ -550,12 +551,11 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info,
 
         message("Setting up sam.ldb rootDSE")
         setup_samdb_rootdse(samdb, setup_path, names)
-
     except:
         samdb.transaction_cancel()
         raise
-
-    samdb.transaction_commit()
+    else:
+        samdb.transaction_commit()
 
         
 def secretsdb_self_join(secretsdb, domain, 
index 0dcea72ad77fae256b68819eaef0bd1bf78d4f84..2f33c31c632f0061b070ba1147e299b86542552a 100644 (file)
@@ -150,7 +150,8 @@ pwdLastSet: 0
         except:
             self.transaction_cancel()
             raise
-        self.transaction_commit()
+        else:
+            self.transaction_commit()
 
     def setpassword(self, filter, password, force_change_at_next_login=False):
         """Sets the password for a user
@@ -188,7 +189,8 @@ userPassword:: %s
         except:
             self.transaction_cancel()
             raise
-        self.transaction_commit()
+        else:
+            self.transaction_commit()
 
     def setexpiry(self, filter, expiry_seconds, no_expiry_req=False):
         """Sets the account expiry for a user
@@ -227,7 +229,8 @@ accountExpires: %u
         except:
             self.transaction_cancel()
             raise
-        self.transaction_commit()
+        else:
+            self.transaction_commit()
 
     def set_domain_sid(self, sid):
         """Change the domain SID used by this LDB.
index d0d35f807e0a1cc3cc34aafdfbc0fcd8c541ae86..117433de4d14927c7e0b6e10594b3e2907d4fe6b 100755 (executable)
@@ -219,7 +219,8 @@ elif opts.use_xattrs == "auto":
                        "O:S-1-5-32G:S-1-5-32", "S-1-5-32", "native")
                eadb = False
        except:
-               if lp.get("posix:eadb") == None:
+               # XXX: Should catch a specific exception here
+               if lp.get("posix:eadb") is None:
                        message("Notice: you are not root or your system do not support xattr, tdb backend for attributes has been selected")
                        message(" if you intend to use this provision in production you'd better rerun the script as root on a system supporting xattr")
        file.close()