summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/bin/epdump.py24
-rwxr-xr-x[-rw-r--r--]source4/scripting/bin/winreg.py133
-rw-r--r--source4/scripting/python/STATUS18
-rw-r--r--source4/scripting/python/config.mk2
-rw-r--r--source4/scripting/python/modules.c11
-rw-r--r--source4/scripting/python/pyrpc.h29
-rw-r--r--source4/scripting/python/pytalloc.c45
-rw-r--r--source4/scripting/python/pytalloc.h51
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/__init__.py0
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/registry.py50
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/rpcecho.py44
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/sam.py28
12 files changed, 349 insertions, 86 deletions
diff --git a/source4/scripting/bin/epdump.py b/source4/scripting/bin/epdump.py
new file mode 100644
index 0000000000..15dee33774
--- /dev/null
+++ b/source4/scripting/bin/epdump.py
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
+#
+# 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 sys
+
+if len(sys.argv) < 2:
+ print "Usage: %s <binding-string>" % sys.argv[0]
+ sys.exit(1)
diff --git a/source4/scripting/bin/winreg.py b/source4/scripting/bin/winreg.py
index 6cdc3a5898..f68f2d12f2 100644..100755
--- a/source4/scripting/bin/winreg.py
+++ b/source4/scripting/bin/winreg.py
@@ -7,87 +7,76 @@
#
import sys
+import winreg
+import optparse
+import samba.getopt as options
-options = GetOptions(ARGV,
- "POPT_AUTOHELP",
- "POPT_COMMON_SAMBA",
- "POPT_COMMON_CREDENTIALS",
- "createkey=s")
-if (options == undefined) {
- print "Failed to parse options"
- sys.exit(-1)
+parser = optparse.OptionParser("%s <BINDING> [path]" % sys.argv[0])
+parser.add_option_group(options.SambaOptions(parser))
+parser.add_option("--createkey", type="string", metavar="KEYNAME",
+ help="create a key")
-if len(sys.argv < 2:
- print "Usage: %s <BINDING> [path]" % sys.argv[0]
- sys.exit(-1)
+opts, args = parser.parse_args()
-binding = options.ARGV[0]
-reg = winregObj()
+if len(args) < 1:
+ parser.print_usage()
+ sys.exit(-1)
+
+binding = args[0]
print "Connecting to " + binding
-status = reg.connect(binding)
-if (status.is_ok != true) {
- print("Failed to connect to " + binding + " - " + status.errstr + "\n")
- return -1
-}
+conn = winreg.winreg(binding, opts.configfile)
-def list_values(path):
- list = reg.enum_values(path)
- if (list == undefined) {
- return
- }
- for (i=0;i<list.length;i++) {
- v = list[i]
- printf("\ttype=%-30s size=%4d '%s'\n", reg.typestring(v.type), v.size, v.name)
- if (v.type == reg.REG_SZ || v.type == reg.REG_EXPAND_SZ) {
- printf("\t\t'%s'\n", v.value)
- }
- if (v.type == reg.REG_MULTI_SZ) {
- for (j in v.value) {
- printf("\t\t'%s'\n", v.value[j])
- }
- }
- if (v.type == reg.REG_DWORD || v.type == reg.REG_DWORD_BIG_ENDIAN) {
- printf("\t\t0x%08x (%d)\n", v.value, v.value)
- }
- if (v.type == reg.REG_QWORD) {
- printf("\t\t0x%llx (%lld)\n", v.value, v.value)
- }
- }
+def list_values(key):
+ (num_values, max_valnamelen, max_valbufsize) = conn.QueryInfoKey(key, winreg.String())[4:8]
+ for i in range(num_values):
+ name = winreg.StringBuf()
+ name.size = max_valnamelen
+ (name, type, data, _, data_len) = conn.EnumValue(key, i, name, 0, "", max_valbufsize, 0)
+ print "\ttype=%-30s size=%4d '%s'" % type, len, name
+ if type in (winreg.REG_SZ, winreg.REG_EXPAND_SZ):
+ print "\t\t'%s'" % data
+# if (v.type == reg.REG_MULTI_SZ) {
+# for (j in v.value) {
+# printf("\t\t'%s'\n", v.value[j])
+# }
+# }
+# if (v.type == reg.REG_DWORD || v.type == reg.REG_DWORD_BIG_ENDIAN) {
+# printf("\t\t0x%08x (%d)\n", v.value, v.value)
+# }
+# if (v.type == reg.REG_QWORD) {
+# printf("\t\t0x%llx (%lld)\n", v.value, v.value)
+# }
-def list_path(path):
- count = 0
- list = reg.enum_path(path)
- if (list == undefined) {
- println("Unable to list " + path)
- return 0
- }
- list_values(path)
- count = count + list.length
- for (i=0;i<list.length;i++) {
- if (path) {
- npath = path + "\\" + list[i]
- } else {
- npath = list[i]
- }
- println(npath)
- count = count + list_path(npath)
- }
- return count
+def list_path(key, path):
+ count = 0
+ (num_subkeys, max_subkeylen, max_subkeysize) = conn.QueryInfoKey(key, winreg.String())[1:4]
+ for i in range(num_subkeys):
+ name = winreg.StringBuf()
+ name.size = max_subkeysize
+ keyclass = winreg.StringBuf()
+ keyclass.size = max_subkeysize
+ (name, _, _) = conn.EnumKey(key, i, name, keyclass=keyclass, last_changed_time=None)[0]
+ subkey = conn.OpenKey(key, name, 0, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS)
+ count += list_path(subkey, "%s\\%s" % (path, name))
+ list_values(subkey)
+ return count
-if len(sys.argv) > 2:
- root = sys.argv[2]
+if len(args) > 1:
+ root = args[1]
else:
- root = ''
+ root = "HKLM"
-if options.createkey:
- try:
- reg.create_key("HKLM\\SOFTWARE", options.createkey)
- except:
- print "Failed to create key"
+if opts.createkey:
+ reg.create_key("HKLM\\SOFTWARE", opt.createkey)
else:
- printf("Listing registry tree '%s'\n", root)
- count = list_path(root)
+ print "Listing registry tree '%s'" % root
+ try:
+ root_key = getattr(conn, "Open%s" % root)(None, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS)
+ except AttributeError:
+ print "Unknown root key name %s" % root
+ sys.exit(1)
+ count = list_path(root_key, root)
if count == 0:
- println("No entries found")
- sys.exit(1)
+ print "No entries found"
+ sys.exit(1)
diff --git a/source4/scripting/python/STATUS b/source4/scripting/python/STATUS
index 5972027f59..6e6475bfde 100644
--- a/source4/scripting/python/STATUS
+++ b/source4/scripting/python/STATUS
@@ -3,21 +3,13 @@ lib/ldb/tests/python/ldap.py: Fix remaining 3 FIXME's
provisioning in LDAP mode(TEST_LDAP=yes PROVISION_PYTHON=yes make test)
command-line vampire
provisioning: combine some of the python dictionaries
-hierarchy
-DCE/RPC bindings
- - pidl:
- Parse::Pidl::Samba::Python
- - wrap struct/bitmap/enum/union types
- - __ndr_pack__/__ndr_unpack__ members
- Parse::Pidl::Samba::NDR::Python
- - pidl generated client fns
- - one class per interface
- - AddOne()
-
- - scripting/bin/smbstatus.py
- - scripting/bin/winreg.py
+finish scripting/bin/smbstatus.py
not important before making Python the default:
+- hierarchy (rename samr -> dcerpc.samr, misc -> samba.misc, etc)
- scripting/python/samba/upgrade.py
- install python modules into system
- SWAT
+- __ndr_pack__/__ndr_unpack__ members for the NDR struct bindings
+- generate docstrings in DCE/RPC bindings
+- eliminate some variables from the python interface because they can be induced
diff --git a/source4/scripting/python/config.mk b/source4/scripting/python/config.mk
index cfd179aff5..f00b477919 100644
--- a/source4/scripting/python/config.mk
+++ b/source4/scripting/python/config.mk
@@ -5,7 +5,7 @@ OBJ_FILES = smbpython.o
[SUBSYSTEM::LIBPYTHON]
PUBLIC_DEPENDENCIES = EXT_LIB_PYTHON
INIT_FUNCTION_SENTINEL = { NULL, NULL }
-OBJ_FILES = modules.o
+OBJ_FILES = modules.o pytalloc.o
[PYTHON::python_uuid]
PRIVATE_DEPENDENCIES = LIBNDR
diff --git a/source4/scripting/python/modules.c b/source4/scripting/python/modules.c
index 55df51d881..b2dd50b507 100644
--- a/source4/scripting/python/modules.c
+++ b/source4/scripting/python/modules.c
@@ -35,6 +35,17 @@ extern void init_events(void);
extern void inituuid(void);
extern void init_net(void);
extern void initecho(void);
+extern void initwinreg(void);
+extern void initepmapper(void);
+extern void initinitshutdown(void);
+static void initdcerpc_misc(void) {}
+extern void initmgmt(void);
+extern void initatsvc(void);
+extern void initsamr(void);
+static void initdcerpc_security(void) {}
+extern void initlsa(void);
+extern void initsvcctl(void);
+extern void initwkssvc(void);
static struct _inittab py_modules[] = { STATIC_LIBPYTHON_MODULES };
diff --git a/source4/scripting/python/pyrpc.h b/source4/scripting/python/pyrpc.h
new file mode 100644
index 0000000000..5390c6923d
--- /dev/null
+++ b/source4/scripting/python/pyrpc.h
@@ -0,0 +1,29 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
+
+ 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/>.
+*/
+
+#define PY_CHECK_TYPE(type, var, fail) \
+ if (!type ## _Check(var)) {\
+ PyErr_Format(PyExc_TypeError, "Expected type %s", type ## _Type.tp_name); \
+ fail; \
+ }
+
+#define dom_sid2_Type dom_sid_Type
+#define dom_sid28_Type dom_sid_Type
+#define dom_sid2_Check dom_sid_Check
+#define dom_sid28_Check dom_sid28_Check
diff --git a/source4/scripting/python/pytalloc.c b/source4/scripting/python/pytalloc.c
new file mode 100644
index 0000000000..d8d3efe69c
--- /dev/null
+++ b/source4/scripting/python/pytalloc.c
@@ -0,0 +1,45 @@
+/*
+ Unix SMB/CIFS implementation.
+ Python/Talloc glue
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
+
+ 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/>.
+*/
+
+#include "includes.h"
+#include "scripting/python/pytalloc.h"
+
+void py_talloc_dealloc(PyObject* self)
+{
+ py_talloc_Object *obj = (py_talloc_Object *)self;
+ talloc_free(obj->talloc_ctx);
+ PyObject_Del(self);
+}
+
+PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx,
+ void *ptr)
+{
+ py_talloc_Object *ret = PyObject_New(py_talloc_Object, py_type);
+ ret->talloc_ctx = talloc_reference(NULL, mem_ctx);
+ ret->ptr = ptr;
+ return (PyObject *)ret;
+}
+
+PyObject *py_talloc_default_repr(PyObject *py_obj)
+{
+ py_talloc_Object *obj = (py_talloc_Object *)py_obj;
+
+ return PyString_FromFormat("<talloc: %s>",
+ talloc_get_name(obj->talloc_ctx));
+}
diff --git a/source4/scripting/python/pytalloc.h b/source4/scripting/python/pytalloc.h
new file mode 100644
index 0000000000..aad5840a67
--- /dev/null
+++ b/source4/scripting/python/pytalloc.h
@@ -0,0 +1,51 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
+
+ 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/>.
+*/
+
+#ifndef _PY_TALLOC_H_
+#define _PY_TALLOC_H_
+
+#include <Python.h>
+
+typedef struct {
+ PyObject_HEAD
+ TALLOC_CTX *talloc_ctx;
+ void *ptr;
+} py_talloc_Object;
+
+/* Deallocate a py_talloc_Object */
+void py_talloc_dealloc(PyObject* self);
+
+/* Retrieve the pointer for a py_talloc_object. Like talloc_get_type()
+ * but for py_talloc_Objects. */
+
+/* FIXME: Call PyErr_SetString(PyExc_TypeError, "expected " __STR(type) ")
+ * when talloc_get_type() returns NULL. */
+#define py_talloc_get_type(py_obj, type) \
+ talloc_get_type(py_talloc_get_ptr(py_obj), type)
+
+#define py_talloc_get_ptr(py_obj) ((py_talloc_Object *)py_obj)->ptr
+#define py_talloc_get_mem_ctx(py_obj) ((py_talloc_Object *)py_obj)->talloc_ctx
+
+PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
+#define py_talloc_import(py_type, talloc_ptr) py_talloc_import_ex(py_type, talloc_ptr, talloc_ptr)
+
+/* Sane default implementation of reprfunc. */
+PyObject *py_talloc_default_repr(PyObject *py_obj);
+
+#endif /* _PY_TALLOC_H_ */
diff --git a/source4/scripting/python/samba/tests/dcerpc/__init__.py b/source4/scripting/python/samba/tests/dcerpc/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/source4/scripting/python/samba/tests/dcerpc/__init__.py
diff --git a/source4/scripting/python/samba/tests/dcerpc/registry.py b/source4/scripting/python/samba/tests/dcerpc/registry.py
new file mode 100644
index 0000000000..f3f0b0fb1a
--- /dev/null
+++ b/source4/scripting/python/samba/tests/dcerpc/registry.py
@@ -0,0 +1,50 @@
+#!/usr/bin/python
+
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
+#
+# 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 winreg
+from param import LoadParm
+import unittest
+
+class WinregTests(unittest.TestCase):
+ def setUp(self):
+ lp_ctx = LoadParm()
+ lp_ctx.load("st/client/client.conf")
+ self.conn = winreg.winreg("ncalrpc:", lp_ctx)
+
+ def get_hklm(self):
+ return self.conn.OpenHKLM(None,
+ winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS)
+
+ def test_hklm(self):
+ handle = self.conn.OpenHKLM(None,
+ winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS)
+ self.conn.CloseKey(handle)
+
+ def test_getversion(self):
+ handle = self.get_hklm()
+ version = self.conn.GetVersion(handle)
+ self.assertEquals(int, version.__class__)
+ self.conn.CloseKey(handle)
+
+ def test_getkeyinfo(self):
+ handle = self.conn.OpenHKLM(None,
+ winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS)
+ x = self.conn.QueryInfoKey(handle, winreg.String())
+ self.assertEquals(9, len(x)) # should return a 9-tuple
+ self.conn.CloseKey(handle)
diff --git a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
new file mode 100644
index 0000000000..52c2bb8c72
--- /dev/null
+++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
+#
+# 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 echo
+from param import LoadParm
+import unittest
+
+class RpcEchoTests(unittest.TestCase):
+ def setUp(self):
+ lp_ctx = LoadParm()
+ lp_ctx.load("st/client/client.conf")
+ self.conn = echo.rpcecho("ncalrpc:", lp_ctx)
+
+ def test_addone(self):
+ self.assertEquals(2, self.conn.AddOne(1))
+
+ def test_echodata(self):
+ self.assertEquals([1,2,3], self.conn.EchoData(3, [1, 2, 3]))
+
+ def test_call(self):
+ self.assertEquals(u"foobar", self.conn.TestCall(u"foobar"))
+
+ def test_surrounding(self):
+ surrounding_struct = echo.Surrounding()
+ surrounding_struct.x = 4
+ surrounding_struct.surrounding = [1,2,3,4]
+ y = self.conn.TestSurrounding(surrounding_struct)
+ self.assertEquals(8 * [0], y.surrounding)
diff --git a/source4/scripting/python/samba/tests/dcerpc/sam.py b/source4/scripting/python/samba/tests/dcerpc/sam.py
new file mode 100644
index 0000000000..50caaf2348
--- /dev/null
+++ b/source4/scripting/python/samba/tests/dcerpc/sam.py
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
+#
+# 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 samr
+import unittest
+
+class SamrTests(unittest.TestCase):
+ def setUp(self):
+ self.conn = samr.samr("ncalrpc:", "st/client/client.conf")
+
+ def test_connect5(self):
+ (level, info, handle) = self.conn.Connect5(None, 0, 1, samr.ConnectInfo1())