svn commit: samba r26565 - in branches/SAMBA_4_0: . source/lib/registry source/lib/registry/tests source/libcli/util source/scripting/python/samba

jelmer at samba.org jelmer at samba.org
Sat Dec 22 05:03:05 GMT 2007


Author: jelmer
Date: 2007-12-22 05:03:02 +0000 (Sat, 22 Dec 2007)
New Revision: 26565

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=26565

Log:
Fix python registry bindings. 'PROVISION_PYTHON=yes make test' works now.
Modified:
   branches/SAMBA_4_0/
   branches/SAMBA_4_0/source/lib/registry/hive.c
   branches/SAMBA_4_0/source/lib/registry/hive.h
   branches/SAMBA_4_0/source/lib/registry/local.c
   branches/SAMBA_4_0/source/lib/registry/registry.h
   branches/SAMBA_4_0/source/lib/registry/registry.i
   branches/SAMBA_4_0/source/lib/registry/registry.py
   branches/SAMBA_4_0/source/lib/registry/registry_wrap.c
   branches/SAMBA_4_0/source/lib/registry/tests/bindings.py
   branches/SAMBA_4_0/source/lib/registry/tests/hive.c
   branches/SAMBA_4_0/source/libcli/util/errors.i
   branches/SAMBA_4_0/source/scripting/python/samba/provision.py


Changeset:

Property changes on: branches/SAMBA_4_0
___________________________________________________________________
Name: bzr:revision-info
...skipped...
Name: bzr:revision-id:v3-trunk0
...skipped...

Modified: branches/SAMBA_4_0/source/lib/registry/hive.c
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/hive.c	2007-12-22 05:02:57 UTC (rev 26564)
+++ branches/SAMBA_4_0/source/lib/registry/hive.c	2007-12-22 05:03:02 UTC (rev 26565)
@@ -107,7 +107,7 @@
 				  last_mod_time);
 }
 
-WERROR hive_set_value(struct hive_key *key, const char *name, uint32_t type,
+WERROR hive_key_set_value(struct hive_key *key, const char *name, uint32_t type,
 					  const DATA_BLOB data)
 {
 	if (key->ops->set_value == NULL)

Modified: branches/SAMBA_4_0/source/lib/registry/hive.h
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/hive.h	2007-12-22 05:02:57 UTC (rev 26564)
+++ branches/SAMBA_4_0/source/lib/registry/hive.h	2007-12-22 05:03:02 UTC (rev 26565)
@@ -164,7 +164,7 @@
 		     const char **classname,
 		     NTTIME *last_mod_time);
 
-WERROR hive_set_value(struct hive_key *key, const char *name,
+WERROR hive_key_set_value(struct hive_key *key, const char *name,
 		      uint32_t type, const DATA_BLOB data);
 
 WERROR hive_get_value(TALLOC_CTX *mem_ctx,

Modified: branches/SAMBA_4_0/source/lib/registry/local.c
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/local.c	2007-12-22 05:02:57 UTC (rev 26564)
+++ branches/SAMBA_4_0/source/lib/registry/local.c	2007-12-22 05:03:02 UTC (rev 26565)
@@ -216,7 +216,7 @@
 {
 	struct local_key *local = (struct local_key *)key;
 
-	return hive_set_value(local->hive_key, name, type, data);
+	return hive_key_set_value(local->hive_key, name, type, data);
 }
 
 static WERROR local_get_value(TALLOC_CTX *mem_ctx,

Modified: branches/SAMBA_4_0/source/lib/registry/registry.h
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/registry.h	2007-12-22 05:02:57 UTC (rev 26564)
+++ branches/SAMBA_4_0/source/lib/registry/registry.h	2007-12-22 05:03:02 UTC (rev 26565)
@@ -247,9 +247,6 @@
 		      struct security_descriptor *security,
 		      struct registry_key **key);
 
-
-
-
 /* Utility functions */
 const char *str_regtype(int type);
 char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type,

Modified: branches/SAMBA_4_0/source/lib/registry/registry.i
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/registry.i	2007-12-22 05:02:57 UTC (rev 26564)
+++ branches/SAMBA_4_0/source/lib/registry/registry.i	2007-12-22 05:03:02 UTC (rev 26565)
@@ -137,6 +137,21 @@
                      struct loadparm_context *lp_ctx,
                      struct hive_key **root);
 
+%rename(open_ldb) reg_open_ldb_file;
+WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
+             struct auth_session_info *session_info,
+             struct cli_credentials *credentials,
+             struct loadparm_context *lp_ctx,
+             struct hive_key **k);
+
+%rename(create_dir) reg_create_directory;
+WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
+                const char *location, struct hive_key **key);
+
+%rename(open_dir) reg_open_directory;
+WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
+             const char *location, struct hive_key **key);
+
 %talloctype(hive_key);
 
 typedef struct hive_key {
@@ -144,6 +159,7 @@
         WERROR del(const char *name);
         WERROR flush(void);
         WERROR del_value(const char *name);
+        WERROR set_value(const char *name, uint32_t type, const DATA_BLOB data);
     }
 } hive_key;
 

Modified: branches/SAMBA_4_0/source/lib/registry/registry.py
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/registry.py	2007-12-22 05:02:57 UTC (rev 26564)
+++ branches/SAMBA_4_0/source/lib/registry/registry.py	2007-12-22 05:03:02 UTC (rev 26565)
@@ -79,6 +79,9 @@
 reg_swigregister(reg)
 
 hive_key = _registry.hive_key
+open_ldb = _registry.open_ldb
+create_dir = _registry.create_dir
+open_dir = _registry.open_dir
 open_samba = _registry.open_samba
 HKEY_CLASSES_ROOT = _registry.HKEY_CLASSES_ROOT
 HKEY_CURRENT_USER = _registry.HKEY_CURRENT_USER

Modified: branches/SAMBA_4_0/source/lib/registry/registry_wrap.c
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/registry_wrap.c	2007-12-22 05:02:57 UTC (rev 26564)
+++ branches/SAMBA_4_0/source/lib/registry/registry_wrap.c	2007-12-22 05:03:02 UTC (rev 26565)
@@ -3582,6 +3582,192 @@
 }
 
 
+SWIGINTERN PyObject *_wrap_open_ldb(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
+  PyObject *resultobj = 0;
+  TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ;
+  char *arg2 = (char *) 0 ;
+  struct auth_session_info *arg3 = (struct auth_session_info *) 0 ;
+  struct cli_credentials *arg4 = (struct cli_credentials *) 0 ;
+  struct loadparm_context *arg5 = (struct loadparm_context *) 0 ;
+  struct hive_key **arg6 = (struct hive_key **) 0 ;
+  WERROR result;
+  int res2 ;
+  char *buf2 = 0 ;
+  int alloc2 = 0 ;
+  void *argp3 = 0 ;
+  int res3 = 0 ;
+  void *argp4 = 0 ;
+  int res4 = 0 ;
+  void *argp5 = 0 ;
+  int res5 = 0 ;
+  struct hive_key *tmp6 ;
+  PyObject * obj0 = 0 ;
+  PyObject * obj1 = 0 ;
+  PyObject * obj2 = 0 ;
+  PyObject * obj3 = 0 ;
+  char *  kwnames[] = {
+    (char *) "location",(char *) "session_info",(char *) "credentials",(char *) "lp_ctx", NULL 
+  };
+  
+  {
+    arg3 = NULL; 
+  }
+  {
+    arg4 = NULL;
+  }
+  {
+    arg5 = loadparm_init(NULL);
+  }
+  {
+    arg1 = NULL;
+  }
+  {
+    arg6 = &tmp6; 
+  }
+  if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O|OOO:open_ldb",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail;
+  res2 = SWIG_AsCharPtrAndSize(obj0, &buf2, NULL, &alloc2);
+  if (!SWIG_IsOK(res2)) {
+    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "open_ldb" "', argument " "2"" of type '" "char const *""'");
+  }
+  arg2 = (char *)(buf2);
+  if (obj1) {
+    res3 = SWIG_ConvertPtr(obj1, &argp3,SWIGTYPE_p_auth_session_info, 0 |  0 );
+    if (!SWIG_IsOK(res3)) {
+      SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "open_ldb" "', argument " "3"" of type '" "struct auth_session_info *""'"); 
+    }
+    arg3 = (struct auth_session_info *)(argp3);
+  }
+  if (obj2) {
+    res4 = SWIG_ConvertPtr(obj2, &argp4,SWIGTYPE_p_cli_credentials, 0 |  0 );
+    if (!SWIG_IsOK(res4)) {
+      SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "open_ldb" "', argument " "4"" of type '" "struct cli_credentials *""'"); 
+    }
+    arg4 = (struct cli_credentials *)(argp4);
+  }
+  if (obj3) {
+    res5 = SWIG_ConvertPtr(obj3, &argp5,SWIGTYPE_p_loadparm_context, 0 |  0 );
+    if (!SWIG_IsOK(res5)) {
+      SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "open_ldb" "', argument " "5"" of type '" "struct loadparm_context *""'"); 
+    }
+    arg5 = (struct loadparm_context *)(argp5);
+  }
+  result = reg_open_ldb_file(arg1,(char const *)arg2,arg3,arg4,arg5,arg6);
+  {
+    if (!W_ERROR_IS_OK(result)) {
+      PyObject *obj = Py_BuildValue("(i,s)", (&result)->v, win_errstr(result));
+      PyErr_SetObject(PyExc_RuntimeError, obj);
+    } else if (resultobj == NULL) {
+      resultobj = Py_None;
+    }
+  }
+  {
+    Py_XDECREF(resultobj);
+    resultobj = SWIG_NewPointerObj(*arg6, SWIGTYPE_p_hive_key, 0);
+  }
+  if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
+  return resultobj;
+fail:
+  if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
+  return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_create_dir(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
+  PyObject *resultobj = 0;
+  TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ;
+  char *arg2 = (char *) 0 ;
+  struct hive_key **arg3 = (struct hive_key **) 0 ;
+  WERROR result;
+  int res2 ;
+  char *buf2 = 0 ;
+  int alloc2 = 0 ;
+  struct hive_key *tmp3 ;
+  PyObject * obj0 = 0 ;
+  char *  kwnames[] = {
+    (char *) "location", NULL 
+  };
+  
+  {
+    arg1 = NULL;
+  }
+  {
+    arg3 = &tmp3; 
+  }
+  if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:create_dir",kwnames,&obj0)) SWIG_fail;
+  res2 = SWIG_AsCharPtrAndSize(obj0, &buf2, NULL, &alloc2);
+  if (!SWIG_IsOK(res2)) {
+    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "create_dir" "', argument " "2"" of type '" "char const *""'");
+  }
+  arg2 = (char *)(buf2);
+  result = reg_create_directory(arg1,(char const *)arg2,arg3);
+  {
+    if (!W_ERROR_IS_OK(result)) {
+      PyObject *obj = Py_BuildValue("(i,s)", (&result)->v, win_errstr(result));
+      PyErr_SetObject(PyExc_RuntimeError, obj);
+    } else if (resultobj == NULL) {
+      resultobj = Py_None;
+    }
+  }
+  {
+    Py_XDECREF(resultobj);
+    resultobj = SWIG_NewPointerObj(*arg3, SWIGTYPE_p_hive_key, 0);
+  }
+  if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
+  return resultobj;
+fail:
+  if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
+  return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_open_dir(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
+  PyObject *resultobj = 0;
+  TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ;
+  char *arg2 = (char *) 0 ;
+  struct hive_key **arg3 = (struct hive_key **) 0 ;
+  WERROR result;
+  int res2 ;
+  char *buf2 = 0 ;
+  int alloc2 = 0 ;
+  struct hive_key *tmp3 ;
+  PyObject * obj0 = 0 ;
+  char *  kwnames[] = {
+    (char *) "location", NULL 
+  };
+  
+  {
+    arg1 = NULL;
+  }
+  {
+    arg3 = &tmp3; 
+  }
+  if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:open_dir",kwnames,&obj0)) SWIG_fail;
+  res2 = SWIG_AsCharPtrAndSize(obj0, &buf2, NULL, &alloc2);
+  if (!SWIG_IsOK(res2)) {
+    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "open_dir" "', argument " "2"" of type '" "char const *""'");
+  }
+  arg2 = (char *)(buf2);
+  result = reg_open_directory(arg1,(char const *)arg2,arg3);
+  {
+    if (!W_ERROR_IS_OK(result)) {
+      PyObject *obj = Py_BuildValue("(i,s)", (&result)->v, win_errstr(result));
+      PyErr_SetObject(PyExc_RuntimeError, obj);
+    } else if (resultobj == NULL) {
+      resultobj = Py_None;
+    }
+  }
+  {
+    Py_XDECREF(resultobj);
+    resultobj = SWIG_NewPointerObj(*arg3, SWIGTYPE_p_hive_key, 0);
+  }
+  if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
+  return resultobj;
+fail:
+  if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
+  return NULL;
+}
+
+
 SWIGINTERN PyObject *_wrap_open_samba(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
   PyObject *resultobj = 0;
   TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ;
@@ -3675,6 +3861,9 @@
 	 { (char *)"reg_swigregister", reg_swigregister, METH_VARARGS, NULL},
 	 { (char *)"reg_swiginit", reg_swiginit, METH_VARARGS, NULL},
 	 { (char *)"hive_key", (PyCFunction) _wrap_hive_key, METH_VARARGS | METH_KEYWORDS, NULL},
+	 { (char *)"open_ldb", (PyCFunction) _wrap_open_ldb, METH_VARARGS | METH_KEYWORDS, NULL},
+	 { (char *)"create_dir", (PyCFunction) _wrap_create_dir, METH_VARARGS | METH_KEYWORDS, NULL},
+	 { (char *)"open_dir", (PyCFunction) _wrap_open_dir, METH_VARARGS | METH_KEYWORDS, NULL},
 	 { (char *)"open_samba", (PyCFunction) _wrap_open_samba, METH_VARARGS | METH_KEYWORDS, NULL},
 	 { NULL, NULL, 0, NULL }
 };

Modified: branches/SAMBA_4_0/source/lib/registry/tests/bindings.py
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/tests/bindings.py	2007-12-22 05:02:57 UTC (rev 26564)
+++ branches/SAMBA_4_0/source/lib/registry/tests/bindings.py	2007-12-22 05:03:02 UTC (rev 26565)
@@ -17,8 +17,10 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+import os
 import unittest
 import registry
+import samba.tests
 
 class HelperTests(unittest.TestCase):
     def test_predef_to_name(self):
@@ -29,6 +31,22 @@
         self.assertEquals("REG_DWORD", registry.str_regtype(4))
 
 
+
+class HiveTests(samba.tests.TestCaseInTempDir):
+    def setUp(self):
+        super(HiveTests, self).setUp()
+        self.hive = registry.open_ldb(os.path.join(self.tempdir, "ldb_new.ldb"))
+
+    def test_ldb_new(self):
+        self.assertTrue(self.hive is not None)
+
+    def test_flush(self):
+        self.hive.flush()
+
+    def test_del_value(self):
+        self.hive.del_value("FOO")
+
+
 class RegistryTests(unittest.TestCase):
     def test_new(self):
         self.registry = registry.Registry()

Modified: branches/SAMBA_4_0/source/lib/registry/tests/hive.c
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/tests/hive.c	2007-12-22 05:02:57 UTC (rev 26564)
+++ branches/SAMBA_4_0/source/lib/registry/tests/hive.c	2007-12-22 05:03:02 UTC (rev 26565)
@@ -74,9 +74,9 @@
 				  NULL, &subkey);
 	torture_assert_werr_ok(tctx, error, "hive_key_add_name");
 
-	error = hive_set_value(root, "Answer", REG_DWORD,
+	error = hive_key_set_value(root, "Answer", REG_DWORD,
 			       data_blob_talloc(tctx, &data, sizeof(data)));
-	torture_assert_werr_ok(tctx, error, "hive_set_value");
+	torture_assert_werr_ok(tctx, error, "hive_key_set_value");
 
 	/* This is a new backend. There should be no subkeys and no
 	 * values */
@@ -154,9 +154,9 @@
 				  NULL, &subkey);
 	torture_assert_werr_ok(tctx, error, "hive_key_add_name");
 
-	error = hive_set_value(subkey, "Answer", REG_DWORD,
+	error = hive_key_set_value(subkey, "Answer", REG_DWORD,
 			       data_blob_talloc(mem_ctx, &data, sizeof(data)));
-	torture_assert_werr_ok(tctx, error, "hive_set_value");
+	torture_assert_werr_ok(tctx, error, "hive_key_set_value");
 
 	return true;
 }
@@ -179,9 +179,9 @@
 	torture_assert_werr_equal(tctx, error, WERR_NOT_FOUND,
 				  "getting missing value");
 
-	error = hive_set_value(subkey, "Answer", REG_DWORD,
+	error = hive_key_set_value(subkey, "Answer", REG_DWORD,
 			       data_blob_talloc(mem_ctx, &data, sizeof(data)));
-	torture_assert_werr_ok(tctx, error, "hive_set_value");
+	torture_assert_werr_ok(tctx, error, "hive_key_set_value");
 
 	error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value);
 	torture_assert_werr_ok(tctx, error, "getting value");
@@ -207,9 +207,9 @@
 							 NULL, &subkey);
 	torture_assert_werr_ok(tctx, error, "hive_key_add_name");
 
-	error = hive_set_value(subkey, "Answer", REG_DWORD,
+	error = hive_key_set_value(subkey, "Answer", REG_DWORD,
 			       data_blob_talloc(mem_ctx, &data, sizeof(data)));
-	torture_assert_werr_ok(tctx, error, "hive_set_value");
+	torture_assert_werr_ok(tctx, error, "hive_key_set_value");
 
 	error = hive_key_del_value(subkey, "Answer");
 	torture_assert_werr_ok(tctx, error, "deleting value");
@@ -240,9 +240,9 @@
 				  NULL, &subkey);
 	torture_assert_werr_ok(tctx, error, "hive_key_add_name");
 
-	error = hive_set_value(subkey, "Answer", REG_DWORD,
+	error = hive_key_set_value(subkey, "Answer", REG_DWORD,
 			       data_blob_talloc(mem_ctx, &data, sizeof(data)));
-	torture_assert_werr_ok(tctx, error, "hive_set_value");
+	torture_assert_werr_ok(tctx, error, "hive_key_set_value");
 
 	error = hive_get_value_by_index(mem_ctx, subkey, 0, &name,
 					&type, &value);

Modified: branches/SAMBA_4_0/source/libcli/util/errors.i
===================================================================
--- branches/SAMBA_4_0/source/libcli/util/errors.i	2007-12-22 05:02:57 UTC (rev 26564)
+++ branches/SAMBA_4_0/source/libcli/util/errors.i	2007-12-22 05:03:02 UTC (rev 26565)
@@ -22,6 +22,7 @@
     if (!W_ERROR_IS_OK($1)) {
         PyObject *obj = Py_BuildValue("(i,s)", $1.v, win_errstr($1));
         PyErr_SetObject(PyExc_RuntimeError, obj);
+        SWIG_fail;
     } else if ($result == NULL) {
         $result = Py_None;
     }
@@ -31,6 +32,7 @@
     if (NT_STATUS_IS_ERR($1)) {
         PyObject *obj = Py_BuildValue("(i,s)", $1.v, nt_errstr($1));
         PyErr_SetObject(PyExc_RuntimeError, obj);
+        SWIG_fail;
     } else if ($result == NULL) {
         $result = Py_None;
     }

Modified: branches/SAMBA_4_0/source/scripting/python/samba/provision.py
===================================================================
--- branches/SAMBA_4_0/source/scripting/python/samba/provision.py	2007-12-22 05:02:57 UTC (rev 26564)
+++ branches/SAMBA_4_0/source/scripting/python/samba/provision.py	2007-12-22 05:03:02 UTC (rev 26565)
@@ -281,12 +281,12 @@
 
 def setup_registry(path, setup_path, session_info, credentials, lp):
     reg = registry.Registry()
-    hive = registry.Hive(path, session_info=session_info, 
+    hive = registry.open_ldb(path, session_info=session_info, 
                          credentials=credentials, lp_ctx=lp)
     reg.mount_hive(hive, "HKEY_LOCAL_MACHINE")
     provision_reg = setup_path("provision.reg")
     assert os.path.exists(provision_reg)
-    reg.apply_patchfile(provision_reg)
+    reg.diff_apply(provision_reg)
 
 
 def setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, hostname, 



More information about the samba-cvs mailing list