summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-12-22 05:03:02 -0600
committerStefan Metzmacher <metze@samba.org>2007-12-24 01:51:01 -0600
commit249cc734cebfef31320ec10b05dbfaaaa39682ca (patch)
treed9362b9316ea4bcbbaf561d2d062d01fe574a1d7
parent09f820f0bd1a9fc7ffd171418ceb0e19df8e2e43 (diff)
downloadsamba-249cc734cebfef31320ec10b05dbfaaaa39682ca.tar.gz
samba-249cc734cebfef31320ec10b05dbfaaaa39682ca.tar.bz2
samba-249cc734cebfef31320ec10b05dbfaaaa39682ca.zip
r26565: Fix python registry bindings. 'PROVISION_PYTHON=yes make test' works now.
(This used to be commit 485d1fa3d17fe6cc7a0ecd80e8bac42d173bbb19)
-rw-r--r--source4/lib/registry/hive.c2
-rw-r--r--source4/lib/registry/hive.h2
-rw-r--r--source4/lib/registry/local.c2
-rw-r--r--source4/lib/registry/registry.h3
-rw-r--r--source4/lib/registry/registry.i16
-rw-r--r--source4/lib/registry/registry.py3
-rw-r--r--source4/lib/registry/registry_wrap.c189
-rw-r--r--source4/lib/registry/tests/bindings.py18
-rw-r--r--source4/lib/registry/tests/hive.c20
-rw-r--r--source4/libcli/util/errors.i2
-rw-r--r--source4/scripting/python/samba/provision.py4
11 files changed, 243 insertions, 18 deletions
diff --git a/source4/lib/registry/hive.c b/source4/lib/registry/hive.c
index 6a1623338d..d7d12076f3 100644
--- a/source4/lib/registry/hive.c
+++ b/source4/lib/registry/hive.c
@@ -107,7 +107,7 @@ WERROR hive_enum_key(TALLOC_CTX *mem_ctx,
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)
diff --git a/source4/lib/registry/hive.h b/source4/lib/registry/hive.h
index e82177d8b8..1e05f6b013 100644
--- a/source4/lib/registry/hive.h
+++ b/source4/lib/registry/hive.h
@@ -164,7 +164,7 @@ WERROR hive_enum_key(TALLOC_CTX *mem_ctx,
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,
diff --git a/source4/lib/registry/local.c b/source4/lib/registry/local.c
index 06c9031055..14b42797ba 100644
--- a/source4/lib/registry/local.c
+++ b/source4/lib/registry/local.c
@@ -216,7 +216,7 @@ static WERROR local_set_value(struct registry_key *key, const char *name,
{
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,
diff --git a/source4/lib/registry/registry.h b/source4/lib/registry/registry.h
index a02acbea1e..7999719909 100644
--- a/source4/lib/registry/registry.h
+++ b/source4/lib/registry/registry.h
@@ -247,9 +247,6 @@ WERROR reg_create_key(TALLOC_CTX *mem_ctx,
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,
diff --git a/source4/lib/registry/registry.i b/source4/lib/registry/registry.i
index 315afb0c31..3fabba9a66 100644
--- a/source4/lib/registry/registry.i
+++ b/source4/lib/registry/registry.i
@@ -137,6 +137,21 @@ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
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 @@ typedef struct hive_key {
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;
diff --git a/source4/lib/registry/registry.py b/source4/lib/registry/registry.py
index ff5653e915..bf8ac60498 100644
--- a/source4/lib/registry/registry.py
+++ b/source4/lib/registry/registry.py
@@ -79,6 +79,9 @@ reg_swigregister = _registry.reg_swigregister
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
diff --git a/source4/lib/registry/registry_wrap.c b/source4/lib/registry/registry_wrap.c
index ab6c2fb5e9..c02f9cacc6 100644
--- a/source4/lib/registry/registry_wrap.c
+++ b/source4/lib/registry/registry_wrap.c
@@ -3582,6 +3582,192 @@ fail:
}
+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 @@ static PyMethodDef SwigMethods[] = {
{ (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 }
};
diff --git a/source4/lib/registry/tests/bindings.py b/source4/lib/registry/tests/bindings.py
index be87efe594..9f93ee9382 100644
--- a/source4/lib/registry/tests/bindings.py
+++ b/source4/lib/registry/tests/bindings.py
@@ -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 @@ class HelperTests(unittest.TestCase):
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()
diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c
index e3a301710f..43ec9e4252 100644
--- a/source4/lib/registry/tests/hive.c
+++ b/source4/lib/registry/tests/hive.c
@@ -74,9 +74,9 @@ static bool test_keyinfo_nums(struct torture_context *tctx,
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 @@ static bool test_set_value(struct torture_context *tctx,
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 @@ static bool test_get_value(struct torture_context *tctx, const void *test_data)
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 @@ static bool test_del_value(struct torture_context *tctx, const void *test_data)
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 @@ static bool test_list_values(struct torture_context *tctx,
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);
diff --git a/source4/libcli/util/errors.i b/source4/libcli/util/errors.i
index d51c9e0ded..8d97daf537 100644
--- a/source4/libcli/util/errors.i
+++ b/source4/libcli/util/errors.i
@@ -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;
}
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index 1d606d80e5..b5fe3eba9e 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -281,12 +281,12 @@ def setup_templatesdb(path, setup_path, session_info, credentials, lp):
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,