summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/dsdb/samdb/ldb_modules/tests/samba3sam.py11
-rw-r--r--source4/libcli/security/dom_sid.c2
-rw-r--r--source4/libcli/security/tests/bindings.py14
-rw-r--r--source4/librpc/ndr/py_security.c35
-rw-r--r--source4/param/pyparam.c5
-rw-r--r--source4/scripting/python/samba/provision.py6
-rw-r--r--source4/scripting/python/samba/samba3.py15
-rwxr-xr-xsource4/setup/provision-backend2
-rwxr-xr-xsource4/setup/upgrade2
9 files changed, 32 insertions, 60 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/tests/samba3sam.py b/source4/dsdb/samdb/ldb_modules/tests/samba3sam.py
index be192f8e74..75aaeb7366 100644
--- a/source4/dsdb/samdb/ldb_modules/tests/samba3sam.py
+++ b/source4/dsdb/samdb/ldb_modules/tests/samba3sam.py
@@ -28,7 +28,6 @@ from ldb import SCOPE_DEFAULT, SCOPE_BASE, SCOPE_SUBTREE
from samba import Ldb, substitute_var
from samba.tests import LdbTestCase, TestCaseInTempDir, cmdline_loadparm
import samba.dcerpc.security
-import samba.security
import samba.ndr
datadir = os.path.join(os.path.dirname(__file__),
@@ -118,14 +117,8 @@ class MapBaseTestCase(TestCaseInTempDir):
def assertSidEquals(self, text, ndr_sid):
sid_obj1 = samba.ndr.ndr_unpack(samba.dcerpc.security.dom_sid,
str(ndr_sid[0]))
- sid_obj2 = samba.security.Sid(text)
- # For now, this is the only way we can compare these since the
- # classes are in different places. Should reconcile that at some point.
- self.assertEquals(sid_obj1.sid_rev_num, sid_obj2.sid_rev_num)
- self.assertEquals(sid_obj1.num_auths, sid_obj2.num_auths)
- # FIXME: self.assertEquals(sid_obj1.id_auth, sid_obj2.id_auth)
- # FIXME: self.assertEquals(sid_obj1.sub_auths[:sid_obj1.num_auths],
- # sid_obj2.sub_auths[:sid_obj2.num_auths])
+ sid_obj2 = samba.dcerpc.security.dom_sid(text)
+ self.assertEquals(sid_obj1, sid_obj2)
class Samba3SamTestCase(MapBaseTestCase):
diff --git a/source4/libcli/security/dom_sid.c b/source4/libcli/security/dom_sid.c
index a83ebb0aa1..e1a6b8e8ee 100644
--- a/source4/libcli/security/dom_sid.c
+++ b/source4/libcli/security/dom_sid.c
@@ -53,7 +53,7 @@ static int dom_sid_compare_auth(const struct dom_sid *sid1, const struct dom_sid
Compare two sids.
*****************************************************************/
-static int dom_sid_compare(const struct dom_sid *sid1, const struct dom_sid *sid2)
+int dom_sid_compare(const struct dom_sid *sid1, const struct dom_sid *sid2)
{
int i;
diff --git a/source4/libcli/security/tests/bindings.py b/source4/libcli/security/tests/bindings.py
index b539de833d..aee18a63b8 100644
--- a/source4/libcli/security/tests/bindings.py
+++ b/source4/libcli/security/tests/bindings.py
@@ -18,11 +18,11 @@
#
import unittest
-from samba import security
+from samba.dcerpc import security
class SecurityTokenTests(unittest.TestCase):
def setUp(self):
- self.token = security.SecurityToken()
+ self.token = security.token()
def test_is_system(self):
self.assertFalse(self.token.is_system())
@@ -47,17 +47,17 @@ class SecurityTokenTests(unittest.TestCase):
class SecurityDescriptorTests(unittest.TestCase):
def setUp(self):
- self.descriptor = security.SecurityDescriptor()
+ self.descriptor = security.descriptor()
class DomSidTests(unittest.TestCase):
def test_parse_sid(self):
- sid = security.Sid("S-1-5-21")
+ sid = security.dom_sid("S-1-5-21")
self.assertEquals("S-1-5-21", str(sid))
def test_sid_equal(self):
- sid1 = security.Sid("S-1-5-21")
- sid2 = security.Sid("S-1-5-21")
+ sid1 = security.dom_sid("S-1-5-21")
+ sid2 = security.dom_sid("S-1-5-21")
self.assertTrue(sid1.__eq__(sid1))
self.assertTrue(sid1.__eq__(sid2))
@@ -67,7 +67,7 @@ class DomSidTests(unittest.TestCase):
def test_repr(self):
sid = security.random_sid()
- self.assertTrue(repr(sid).startswith("Sid('S-1-5-21-"))
+ self.assertTrue(repr(sid).startswith("dom_sid('S-1-5-21-"))
class PrivilegeTests(unittest.TestCase):
diff --git a/source4/librpc/ndr/py_security.c b/source4/librpc/ndr/py_security.c
index 2d01dedaec..5100517c57 100644
--- a/source4/librpc/ndr/py_security.c
+++ b/source4/librpc/ndr/py_security.c
@@ -32,19 +32,14 @@ static void PyType_AddMethods(PyTypeObject *type, PyMethodDef *methods)
}
}
-static PyObject *py_dom_sid_eq(PyObject *self, PyObject *args)
+static int py_dom_sid_cmp(PyObject *self, PyObject *py_other)
{
struct dom_sid *this = py_talloc_get_ptr(self), *other;
- PyObject *py_other;
-
- if (!PyArg_ParseTuple(args, "O", &py_other))
- return NULL;
-
- other = py_talloc_get_type(py_other, struct dom_sid);
+ other = py_talloc_get_ptr(py_other);
if (other == NULL)
- return Py_False;
+ return -1;
- return dom_sid_equal(this, other)?Py_True:Py_False;
+ return dom_sid_compare(this, other);
}
static PyObject *py_dom_sid_str(PyObject *self)
@@ -82,17 +77,12 @@ static int py_dom_sid_init(PyObject *self, PyObject *args, PyObject *kwargs)
return 0;
}
-static PyMethodDef py_dom_sid_extra_methods[] = {
- { "__eq__", (PyCFunction)py_dom_sid_eq, METH_VARARGS, "S.__eq__(x) -> S == x" }, \
- { NULL }
-};
-
static void py_dom_sid_patch(PyTypeObject *type)
{
type->tp_init = py_dom_sid_init;
type->tp_str = py_dom_sid_str;
type->tp_repr = py_dom_sid_repr;
- PyType_AddMethods(type, py_dom_sid_extra_methods);
+ type->tp_compare = py_dom_sid_cmp;
}
#define PY_DOM_SID_PATCH py_dom_sid_patch
@@ -162,19 +152,6 @@ static PyObject *py_descriptor_sacl_del(PyObject *self, PyObject *args)
return Py_None;
}
-static PyObject *py_descriptor_eq(PyObject *self, PyObject *args)
-{
- struct security_descriptor *desc1 = py_talloc_get_ptr(self), *desc2;
- PyObject *py_other;
-
- if (!PyArg_ParseTuple(args, "O", &py_other))
- return NULL;
-
- desc2 = py_talloc_get_ptr(py_other);
-
- return PyBool_FromLong(security_descriptor_equal(desc1, desc2));
-}
-
static PyObject *py_descriptor_new(PyTypeObject *self, PyObject *args, PyObject *kwargs)
{
return py_talloc_import(self, security_descriptor_initialise(NULL));
@@ -190,8 +167,6 @@ static PyMethodDef py_descriptor_extra_methods[] = {
NULL },
{ "sacl_del", (PyCFunction)py_descriptor_sacl_del, METH_VARARGS,
NULL },
- { "__eq__", (PyCFunction)py_descriptor_eq, METH_VARARGS,
- NULL },
{ NULL }
};
diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c
index 69a9263c23..04bef07231 100644
--- a/source4/param/pyparam.c
+++ b/source4/param/pyparam.c
@@ -26,7 +26,6 @@
#include "pytalloc.h"
#define PyLoadparmContext_AsLoadparmContext(obj) py_talloc_get_ptr(obj)
-#define PyLoadparmContext_Check(obj) PyObject_TypeCheck(obj, &PyLoadparmContext)
PyAPI_DATA(PyTypeObject) PyLoadparmContext;
PyAPI_DATA(PyTypeObject) PyLoadparmService;
@@ -142,7 +141,7 @@ static PyObject *py_lp_ctx_load(py_talloc_Object *self, PyObject *args)
ret = lp_load((struct loadparm_context *)self->ptr, filename);
if (!ret) {
- PyErr_SetString(PyExc_RuntimeError, "Unable to load file");
+ PyErr_Format(PyExc_RuntimeError, "Unable to load file %s", filename);
return NULL;
}
return Py_None;
@@ -154,7 +153,7 @@ static PyObject *py_lp_ctx_load_default(py_talloc_Object *self)
ret = lp_load_default(self->ptr);
if (!ret) {
- PyErr_SetString(PyExc_RuntimeError, "Unable to load file");
+ PyErr_SetString(PyExc_RuntimeError, "Unable to load default file");
return NULL;
}
return Py_None;
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index 9cd5c0e162..150e5c00df 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -80,6 +80,7 @@ class ProvisionPaths(object):
self.olmmrserveridsconf = None
self.olmmrsyncreplconf = None
+
class ProvisionNames(object):
def __init__(self):
self.rootdn = None
@@ -362,7 +363,8 @@ def make_smbconf(smbconf, setup_path, hostname, domain, realm, serverrole,
default_lp = param.LoadParm()
#Load non-existant file
- default_lp.load(smbconf)
+ if os.path.exists(smbconf):
+ default_lp.load(smbconf)
if targetdir is not None:
privatedir_line = "private dir = " + os.path.abspath(os.path.join(targetdir, "private"))
@@ -920,8 +922,6 @@ def provision(setup_dir, message, session_info,
if domainsid is None:
domainsid = security.random_sid()
- else:
- domainsid = security.Sid(domainsid)
if policyguid is None:
policyguid = str(uuid.uuid4())
diff --git a/source4/scripting/python/samba/samba3.py b/source4/scripting/python/samba/samba3.py
index 1dc90bfcf3..c8ddbc8864 100644
--- a/source4/scripting/python/samba/samba3.py
+++ b/source4/scripting/python/samba/samba3.py
@@ -666,12 +666,15 @@ class ParamFile(object):
Does not use a parameter table, unlike the "normal".
"""
- def __init__(self):
- self._sections = {}
+ def __init__(self, sections=None):
+ self._sections = sections or {}
def _sanitize_name(self, name):
return name.strip().lower().replace(" ","")
+ def __repr__(self):
+ return "ParamFile(%r)" % self._sections
+
def read(self, filename):
"""Read a file.
@@ -683,7 +686,7 @@ class ParamFile(object):
if not l:
continue
if l[0] == "[" and l[-1] == "]":
- section = self._sanitize_name(l[1:-2])
+ section = self._sanitize_name(l[1:-1])
self._sections.setdefault(section, {})
elif "=" in l:
(k, v) = l.split("=", 1)
@@ -704,7 +707,9 @@ class ParamFile(object):
if not section in self._sections:
return None
param = self._sanitize_name(param)
- return self._sections[section].get(param)
+ if not param in self._sections[section]:
+ return None
+ return self._sections[section][param].strip()
def __getitem__(self, section):
return self._sections[section]
@@ -745,7 +750,7 @@ class Samba3(object):
def get_sam_db(self):
lp = self.get_conf()
- backends = str(lp.get("passdb backend")).split(" ")
+ backends = (lp.get("passdb backend") or "").split(" ")
if ":" in backends[0]:
(name, location) = backends[0].split(":", 2)
else:
diff --git a/source4/setup/provision-backend b/source4/setup/provision-backend
index 7d20ef5202..aad7de4327 100755
--- a/source4/setup/provision-backend
+++ b/source4/setup/provision-backend
@@ -83,7 +83,7 @@ if opts.realm is None or opts.domain is None:
parser.print_usage()
sys.exit(1)
-smbconf = sambaopts.get_loadparm().configfile()
+smbconf = sambaopts.get_loadparm().configfile
if opts.server_role == "dc":
server_role = "domain controller"
diff --git a/source4/setup/upgrade b/source4/setup/upgrade
index 03c6747d4e..3363c3a962 100755
--- a/source4/setup/upgrade
+++ b/source4/setup/upgrade
@@ -62,7 +62,7 @@ if setup_dir is None:
setup_dir = "setup"
lp = sambaopts.get_loadparm()
-smbconf = lp.configfile()
+smbconf = lp.configfile
creds = credopts.get_credentials(lp)
upgrade_provision(samba3, setup_dir, message, credentials=creds, session_info=system_session(),