diff options
Diffstat (limited to 'source4/scripting/python')
-rw-r--r-- | source4/scripting/python/STATUS | 18 | ||||
-rw-r--r-- | source4/scripting/python/config.mk | 2 | ||||
-rw-r--r-- | source4/scripting/python/modules.c | 11 | ||||
-rw-r--r-- | source4/scripting/python/pyrpc.h | 29 | ||||
-rw-r--r-- | source4/scripting/python/pytalloc.c | 45 | ||||
-rw-r--r-- | source4/scripting/python/pytalloc.h | 51 | ||||
-rw-r--r-- | source4/scripting/python/samba/tests/dcerpc/__init__.py | 0 | ||||
-rw-r--r-- | source4/scripting/python/samba/tests/dcerpc/registry.py | 50 | ||||
-rw-r--r-- | source4/scripting/python/samba/tests/dcerpc/rpcecho.py | 44 | ||||
-rw-r--r-- | source4/scripting/python/samba/tests/dcerpc/sam.py | 28 |
10 files changed, 264 insertions, 14 deletions
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()) |