Fix more tests, improve repr() functions for various Python types.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 21 Dec 2008 22:05:35 +0000 (23:05 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 21 Dec 2008 22:05:35 +0000 (23:05 +0100)
source4/dsdb/samdb/ldb_modules/tests/samba3sam.py
source4/libcli/security/dom_sid.c
source4/libcli/security/tests/bindings.py
source4/librpc/ndr/py_security.c
source4/param/pyparam.c
source4/scripting/python/samba/provision.py
source4/scripting/python/samba/samba3.py
source4/setup/provision-backend
source4/setup/upgrade

index be192f8e74f746ce1213edd3d1300f219cdb2243..75aaeb7366e666d32f93702ada0007705cb8c414 100644 (file)
@@ -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):
index a83ebb0aa1542819f26fff3802a62be944d14813..e1a6b8e8ee8dfde7a1c4a542f410c91b7bac64bc 100644 (file)
@@ -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;
 
index b539de833d2f521aafe8544ff3de27ce5d1ee265..aee18a63b8cca40193adcff893e795ecc6b8a72f 100644 (file)
 #
 
 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):
index 2d01dedaecc084b8bcb3cd20c164a63e5b94fcc8..5100517c57f76f137e844b0179e74c2fb6805d65 100644 (file)
@@ -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 }
 };
 
index 69a9263c2317ceb796a289ea822d0a52169a4bf1..04bef072314f99d79945656dc87ac98b8e59bc63 100644 (file)
@@ -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;
index 9cd5c0e162cf815842d639e82f1e1b40908adfdb..150e5c00df8f7c2c322747aa8e0c4b2f764f5965 100644 (file)
@@ -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())
index 1dc90bfcf3e67c80d2e30464afd2fc5768b1f79a..c8ddbc8864d3be23bac79035140d592dd36692de 100644 (file)
@@ -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:
index 7d20ef520234f337bc3a1dfec9d3ec44f4a969f8..aad7de43271126d28dc8471e5dc211d62e3b4403 100755 (executable)
@@ -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"
index 03c6747d4e7cdb1c892ef25de5d74579a8fcfb0e..3363c3a9624c0ad13d6f0fe8a9b4b300c6962428 100755 (executable)
@@ -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(),