svn commit: samba r26073 - in branches/SAMBA_4_0: . source/lib/registry source/lib/registry/tests source/selftest

jelmer at samba.org jelmer at samba.org
Wed Nov 21 12:31:27 GMT 2007


Author: jelmer
Date: 2007-11-21 12:31:26 +0000 (Wed, 21 Nov 2007)
New Revision: 26073

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

Log:
Import Python bindings for the registry.

Added:
   branches/SAMBA_4_0/source/lib/registry/registry.i
   branches/SAMBA_4_0/source/lib/registry/tests/bindings.py
Modified:
   branches/SAMBA_4_0/
   branches/SAMBA_4_0/source/lib/registry/config.mk
   branches/SAMBA_4_0/source/selftest/samba4_tests.sh


Changeset:

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

Modified: branches/SAMBA_4_0/source/lib/registry/config.mk
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/config.mk	2007-11-21 12:31:23 UTC (rev 26072)
+++ branches/SAMBA_4_0/source/lib/registry/config.mk	2007-11-21 12:31:26 UTC (rev 26073)
@@ -35,7 +35,7 @@
 		rpc.o
 PUBLIC_DEPENDENCIES = \
 		LIBSAMBA-UTIL CHARSET TDR_REGF LIBLDB \
-		RPC_NDR_WINREG
+		RPC_NDR_WINREG LDB_WRAP
 PUBLIC_HEADERS = registry.h hive.h patchfile.h
 # End MODULE registry_ldb
 ################################################
@@ -100,3 +100,8 @@
 		tests/hive.o \
 		tests/diff.o \
 		tests/registry.o
+
+[PYTHON::swig_registry]
+PUBLIC_DEPENDENCIES = registry LIBPYTHON
+SWIG_FILE = registry.i
+

Added: branches/SAMBA_4_0/source/lib/registry/registry.i
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/registry.i	2007-11-21 12:31:23 UTC (rev 26072)
+++ branches/SAMBA_4_0/source/lib/registry/registry.i	2007-11-21 12:31:26 UTC (rev 26073)
@@ -0,0 +1,150 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2007
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+%module registry
+
+%{
+/* Include headers */
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "includes.h"
+#include "registry.h"
+
+typedef struct registry_context reg;
+typedef struct hive_key hive;
+%}
+
+/* FIXME: This should be in another file */
+%typemap(default) struct auth_session_info * {
+    $1 = NULL; 
+}
+
+%import "stdint.i"
+%import "../../lib/talloc/talloc.i"
+%import "../../auth/credentials/credentials.i"
+%import "../../libcli/util/errors.i"
+
+/* Utility functions */
+
+const char *reg_get_predef_name(uint32_t hkey);
+const char *str_regtype(int type);
+
+/* Registry contexts */
+%typemap(in,numinputs=0) struct registry_context ** (struct registry_context *tmp) {
+    $1 = &tmp; 
+}
+
+%typemap(argout) struct registry_context ** {
+    $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_registry_context, 0);
+}
+
+%rename(Registry) reg_open_local;
+WERROR reg_open_local(TALLOC_CTX *parent_ctx, struct registry_context **ctx,
+                      struct auth_session_info *session_info,
+                      struct cli_credentials *credentials);
+
+%typemap(in) const char ** {
+  /* Check if is a list */
+  if (PyList_Check($input)) {
+    int size = PyList_Size($input);
+    int i = 0;
+    $1 = (char **) malloc((size+1)*sizeof(const char *));
+    for (i = 0; i < size; i++) {
+      PyObject *o = PyList_GetItem($input,i);
+      if (PyString_Check(o))
+    $1[i] = PyString_AsString(PyList_GetItem($input,i));
+      else {
+    PyErr_SetString(PyExc_TypeError,"list must contain strings");
+    free($1);
+    return NULL;
+      }
+    }
+    $1[i] = 0;
+  } else {
+    PyErr_SetString(PyExc_TypeError,"not a list");
+    return NULL;
+  }
+}
+
+%typemap(freearg) const char ** {
+  free((char **) $1);
+}
+
+typedef struct registry_context {
+    %extend {
+
+    ~reg() { talloc_free($self); }
+    WERROR get_predefined_key_by_name(const char *name, 
+                                      struct registry_key **key);
+
+    WERROR get_predefined_key(uint32_t hkey_id, struct registry_key **key);
+    WERROR apply_patchfile(const char *filename)
+    {
+        return reg_diff_apply(filename, $self);
+    }
+
+    WERROR mount_hive(struct hive_key *hive_key, uint32_t hkey_id,
+                      const char **elements=NULL);
+    }
+
+    %pythoncode {
+        def mount(self, path, hkey_id, elements=[]):
+            self.mount_hive(Hive(path), hkey_id, elements)
+    }
+} reg;
+
+/* Hives */
+%typemap(in,numinputs=0) struct hive_key ** (struct hive_key *tmp) {
+    $1 = &tmp; 
+}
+
+%typemap(argout) struct hive_key ** {
+    Py_XDECREF($result);
+    $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_hive_key, 0);
+}
+
+%rename(Hive) reg_open_hive;
+WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
+                     struct auth_session_info *session_info,
+                     struct cli_credentials *credentials,
+                     struct hive_key **root);
+
+typedef struct hive_key {
+    %extend {
+        ~hive() { talloc_free($self); }
+    }
+} hive;
+
+%rename(open_samba) reg_open_samba;
+
+WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
+                      struct registry_context **ctx,
+                      struct auth_session_info *session_info,
+                      struct cli_credentials *credentials);
+
+/* Constants */
+%constant uint32_t HKEY_CLASSES_ROOT = HKEY_CLASSES_ROOT;
+%constant uint32_t HKEY_CURRENT_USER = HKEY_CURRENT_USER;
+%constant uint32_t HKEY_LOCAL_MACHINE = HKEY_LOCAL_MACHINE;
+%constant uint32_t HKEY_USERS = HKEY_USERS;
+%constant uint32_t HKEY_PERFORMANCE_DATA = HKEY_PERFORMANCE_DATA;
+%constant uint32_t HKEY_CURRENT_CONFIG = HKEY_CURRENT_CONFIG;
+%constant uint32_t HKEY_DYN_DATA = HKEY_DYN_DATA;
+%constant uint32_t HKEY_PERFORMANCE_TEXT = HKEY_PERFORMANCE_TEXT;
+%constant uint32_t HKEY_PERFORMANCE_NLSTEXT = HKEY_PERFORMANCE_NLSTEXT;

Added: branches/SAMBA_4_0/source/lib/registry/tests/bindings.py
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/tests/bindings.py	2007-11-21 12:31:23 UTC (rev 26072)
+++ branches/SAMBA_4_0/source/lib/registry/tests/bindings.py	2007-11-21 12:31:26 UTC (rev 26073)
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2007
+#   
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#   
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#   
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import unittest
+import registry
+
+class HelperTests(unittest.TestCase):
+    def test_predef_to_name(self):
+        self.assertEquals("HKEY_LOCAL_MACHINE", 
+                          registry.reg_get_predef_name(0x80000002))
+
+    def test_str_regtype(self):
+        self.assertEquals("REG_DWORD", registry.str_regtype(4))
+
+
+class RegistryTests(unittest.TestCase):
+    def test_new(self):
+        self.registry = registry.Registry()

Modified: branches/SAMBA_4_0/source/selftest/samba4_tests.sh
===================================================================
--- branches/SAMBA_4_0/source/selftest/samba4_tests.sh	2007-11-21 12:31:23 UTC (rev 26072)
+++ branches/SAMBA_4_0/source/selftest/samba4_tests.sh	2007-11-21 12:31:26 UTC (rev 26073)
@@ -296,4 +296,5 @@
 then
 	plantest "ldb.python" none PYTHONPATH=bin/python trial lib/ldb/tests/python/api.py
 	plantest "credentials.python" none PYTHONPATH=bin/python trial auth/credentials/tests/bindings.py
+	plantest "registry.python" none PYTHONPATH=bin/python trial lib/registry/tests/bindings.py
 fi



More information about the samba-cvs mailing list