1
0
mirror of https://github.com/samba-team/samba.git synced 2025-07-29 15:42:04 +03:00

s4-python: More cleanups.

This commit is contained in:
Jelmer Vernooij
2010-04-08 21:01:17 +02:00
parent a35d876537
commit dd4ef4e106
9 changed files with 37 additions and 29 deletions

View File

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This is unit with tests for LDAP access checks # This is unit with tests for LDAP access checks
import getopt
import optparse import optparse
import sys import sys
import os import os
@ -13,9 +12,8 @@ sys.path.append("bin/python")
import samba.getopt as options import samba.getopt as options
from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError from ldb import (
from ldb import ERR_NO_SUCH_OBJECT, ERR_INVALID_DN_SYNTAX, ERR_UNWILLING_TO_PERFORM SCOPE_BASE, LdbError, ERR_NO_SUCH_OBJECT, ERR_INSUFFICIENT_ACCESS_RIGHTS)
from ldb import ERR_INSUFFICIENT_ACCESS_RIGHTS
from samba.ndr import ndr_pack, ndr_unpack from samba.ndr import ndr_pack, ndr_unpack
from samba.dcerpc import security from samba.dcerpc import security

View File

@ -6,8 +6,9 @@ import sys
import os import os
sys.path.append("bin/python") sys.path.append("bin/python")
sys.path.append("../lib/subunit/python") import samba
sys.path.append("../lib/testtools") samba.ensure_external_module("subunit", "subunit")
samba.ensure_external_module("testtools", "testtools")
import samba.getopt as options import samba.getopt as options

View File

@ -86,12 +86,7 @@ def get_credentials(lp):
return return
creds = Credentials() creds = Credentials()
creds.guess(lp) creds.guess(lp)
try:
creds.set_machine_account(lp) creds.set_machine_account(lp)
except:
print "Failed to set machine account"
raise
(tmp_fd, ccachename) = tempfile.mkstemp() (tmp_fd, ccachename) = tempfile.mkstemp()
creds.get_named_ccache(lp, ccachename) creds.get_named_ccache(lp, ccachename)

View File

@ -668,6 +668,7 @@ def check_diff_name(newpaths, paths, creds, session, basedn, names, ischema):
try: try:
dump_denied_change(dn,att,messageEltFlagToString(msgElt.flags()),current[0][att],reference[0][att]) dump_denied_change(dn,att,messageEltFlagToString(msgElt.flags()),current[0][att],reference[0][att])
except: except:
# FIXME: Should catch an explicit exception here
dump_denied_change(dn,att,messageEltFlagToString(msgElt.flags()),current[0][att],None) dump_denied_change(dn,att,messageEltFlagToString(msgElt.flags()),current[0][att],None)
delta.remove(att) delta.remove(att)
delta.dn = dn delta.dn = dn

View File

@ -63,7 +63,8 @@ class cmd_acl_set(Command):
creds = credopts.get_credentials(lp) creds = credopts.get_credentials(lp)
creds.set_kerberos_state(DONT_USE_KERBEROS) creds.set_kerberos_state(DONT_USE_KERBEROS)
try: try:
ldb = Ldb(path, session_info=system_session(), credentials=creds,lp=lp) ldb = Ldb(path, session_info=system_session(), credentials=creds,
lp=lp)
except: except:
# XXX: Should catch a particular exception type # XXX: Should catch a particular exception type
raise CommandError("Unable to read domain SID from configuration files") raise CommandError("Unable to read domain SID from configuration files")

View File

@ -41,29 +41,37 @@ def checkset_backend(lp,backend,eadbfile):
def getntacl(lp, file, backend=None, eadbfile=None): def getntacl(lp, file, backend=None, eadbfile=None):
checkset_backend(lp, backend, eadbfile) checkset_backend(lp, backend, eadbfile)
eadbname = lp.get("posix:eadb") eadbname = lp.get("posix:eadb")
if eadbname != None and eadbname != "" : if eadbname is not None and eadbname != "":
try: 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: except:
# FIXME: Don't catch all exceptions, just those related to opening
# xattrdb
print "Fail to open %s" % eadbname 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: 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) ntacl = ndr_unpack(xattr.NTACL,attribute)
return ntacl return ntacl
def setntacl(lp, file, sddl, domsid, backend=None, eadbfile=None): def setntacl(lp, file, sddl, domsid, backend=None, eadbfile=None):
checkset_backend(lp,backend,eadbfile) checkset_backend(lp, backend, eadbfile)
ntacl=xattr.NTACL() ntacl=xattr.NTACL()
ntacl.version = 1 ntacl.version = 1
sid=security.dom_sid(domsid) sid=security.dom_sid(domsid)
sd = security.descriptor.from_sddl(sddl, sid) sd = security.descriptor.from_sddl(sddl, sid)
ntacl.info = sd ntacl.info = sd
eadbname = lp.get("posix:eadb") eadbname = lp.get("posix:eadb")
if eadbname != None and eadbname != "": if eadbname is not None and eadbname != "":
try: 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: except:
# FIXME: Don't catch all exceptions, just those related to opening
# xattrdb
print "Fail to open %s"%eadbname print "Fail to open %s"%eadbname
samba.xattr_native.wrap_setxattr(file,xattr.XATTR_NTACL_NAME,ndr_pack(ntacl)) samba.xattr_native.wrap_setxattr(file,xattr.XATTR_NTACL_NAME,ndr_pack(ntacl))
else: else:

View File

@ -269,6 +269,7 @@ def setup_ldb(ldb, ldif_path, subst_vars):
except: except:
ldb.transaction_cancel() ldb.transaction_cancel()
raise raise
else:
ldb.transaction_commit() ldb.transaction_commit()
@ -550,11 +551,10 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info,
message("Setting up sam.ldb rootDSE") message("Setting up sam.ldb rootDSE")
setup_samdb_rootdse(samdb, setup_path, names) setup_samdb_rootdse(samdb, setup_path, names)
except: except:
samdb.transaction_cancel() samdb.transaction_cancel()
raise raise
else:
samdb.transaction_commit() samdb.transaction_commit()

View File

@ -150,6 +150,7 @@ pwdLastSet: 0
except: except:
self.transaction_cancel() self.transaction_cancel()
raise raise
else:
self.transaction_commit() self.transaction_commit()
def setpassword(self, filter, password, force_change_at_next_login=False): def setpassword(self, filter, password, force_change_at_next_login=False):
@ -188,6 +189,7 @@ userPassword:: %s
except: except:
self.transaction_cancel() self.transaction_cancel()
raise raise
else:
self.transaction_commit() self.transaction_commit()
def setexpiry(self, filter, expiry_seconds, no_expiry_req=False): def setexpiry(self, filter, expiry_seconds, no_expiry_req=False):
@ -227,6 +229,7 @@ accountExpires: %u
except: except:
self.transaction_cancel() self.transaction_cancel()
raise raise
else:
self.transaction_commit() self.transaction_commit()
def set_domain_sid(self, sid): def set_domain_sid(self, sid):

View File

@ -219,7 +219,8 @@ elif opts.use_xattrs == "auto":
"O:S-1-5-32G:S-1-5-32", "S-1-5-32", "native") "O:S-1-5-32G:S-1-5-32", "S-1-5-32", "native")
eadb = False eadb = False
except: 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("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") 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() file.close()