1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-05 21:57:51 +03:00

python: Fix python code for winreg, add test.

(This used to be commit bd3e6c41c42738fcfcc5cef4e65f0e219d358260)
This commit is contained in:
Jelmer Vernooij 2008-01-14 14:48:59 +01:00
parent e42322848b
commit 7dd468ff2e
6 changed files with 64 additions and 33 deletions

View File

@ -1,27 +0,0 @@
#!/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/>.
#
from echo import rpcecho
from param import LoadParm
lp = LoadParm()
lp.load("st/client/client.conf")
x = rpcecho("ncalrpc:", lp)
print x.AddOne(41)

View File

@ -605,3 +605,7 @@ PRIVATE_DEPENDENCIES = RPC_NDR_WINREG python_misc
[PYTHON::python_dcerpc_misc] [PYTHON::python_dcerpc_misc]
OBJ_FILES = gen_ndr/py_misc.o OBJ_FILES = gen_ndr/py_misc.o
[PYTHON::python_dcerpc_initshutdown]
OBJ_FILES = gen_ndr/py_initshutdown.o
PRIVATE_DEPENDENCIES = RPC_NDR_INITSHUTDOWN

View File

@ -665,6 +665,7 @@ sub ConvertObjectFromPythonLevel($$$$$$$$)
$self->pidl("} else {"); $self->pidl("} else {");
$self->indent; $self->indent;
} }
$self->pidl("$var_name = talloc_ptrtype($mem_ctx, $var_name);");
$self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), get_value_of($var_name), $fail); $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), get_value_of($var_name), $fail);
if ($l->{POINTER_TYPE} ne "ref") { if ($l->{POINTER_TYPE} ne "ref") {
$self->deindent; $self->deindent;
@ -686,7 +687,9 @@ sub ConvertObjectFromPythonLevel($$$$$$$$)
$self->pidl("{"); $self->pidl("{");
$self->indent; $self->indent;
$self->pidl("int $counter;"); $self->pidl("int $counter;");
$self->pidl("$var_name = talloc_array_ptrtype($mem_ctx, $var_name, PyList_Size($py_var));"); if (!$l->{IS_FIXED}) {
$self->pidl("$var_name = talloc_array_ptrtype($mem_ctx, $var_name, PyList_Size($py_var));");
}
$self->pidl("for ($counter = 0; $counter < PyList_Size($py_var); $counter++) {"); $self->pidl("for ($counter = 0; $counter < PyList_Size($py_var); $counter++) {");
$self->indent; $self->indent;
$self->ConvertObjectFromPythonLevel($env, $var_name, "PyList_GetItem($py_var, $counter)", $e, GetNextLevel($e, $l), $var_name."[$counter]", $fail); $self->ConvertObjectFromPythonLevel($env, $var_name, "PyList_GetItem($py_var, $counter)", $e, GetNextLevel($e, $l), $var_name."[$counter]", $fail);
@ -697,8 +700,7 @@ sub ConvertObjectFromPythonLevel($$$$$$$$)
} }
} elsif ($l->{TYPE} eq "DATA") { } elsif ($l->{TYPE} eq "DATA") {
if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE}) or if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE})) {
Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) {
$var_name = get_pointer_to($var_name); $var_name = get_pointer_to($var_name);
} }
$self->ConvertObjectFromPythonData($mem_ctx, $py_var, $l->{DATA_TYPE}, $var_name, $fail); $self->ConvertObjectFromPythonData($mem_ctx, $py_var, $l->{DATA_TYPE}, $var_name, $fail);
@ -841,8 +843,7 @@ sub ConvertObjectToPythonLevel($$$$$)
my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e); my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e);
$self->pidl("$py_var = py_import_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $var_name);"); $self->pidl("$py_var = py_import_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $var_name);");
} elsif ($l->{TYPE} eq "DATA") { } elsif ($l->{TYPE} eq "DATA") {
if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE}) or if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE})) {
Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) {
$var_name = get_pointer_to($var_name); $var_name = get_pointer_to($var_name);
} }
my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name); my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name);

View File

@ -10,7 +10,6 @@ DCE/RPC bindings
- wrap struct/bitmap/enum/union types - wrap struct/bitmap/enum/union types
- __ndr_pack__/__ndr_unpack__ members - __ndr_pack__/__ndr_unpack__ members
- scripting/bin/smbstatus.py - scripting/bin/smbstatus.py
- scripting/bin/winreg.py
not important before making Python the default: not important before making Python the default:
- scripting/python/samba/upgrade.py - scripting/python/samba/upgrade.py

View File

@ -0,0 +1,53 @@
#!/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/>.
#
#!/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 test_hklm(self):
(handle, _) = self.conn.OpenHKLM(None,
winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS)
self.conn.CloseKey(handle)

View File

@ -323,6 +323,7 @@ then
plantest "events.python" none PYTHONPATH="$PYTHONPATH:lib/events" $SUBUNITRUN tests plantest "events.python" none PYTHONPATH="$PYTHONPATH:lib/events" $SUBUNITRUN tests
plantest "samba3sam.python" none PYTHONPATH="$PYTHONPATH:dsdb/samdb/ldb_modules/tests" $SUBUNITRUN samba3sam plantest "samba3sam.python" none PYTHONPATH="$PYTHONPATH:dsdb/samdb/ldb_modules/tests" $SUBUNITRUN samba3sam
plantest "rpcecho.python" dc $SUBUNITRUN samba.tests.dcerpc.rpcecho plantest "rpcecho.python" dc $SUBUNITRUN samba.tests.dcerpc.rpcecho
plantest "winreg.python" dc $SUBUNITRUN samba.tests.dcerpc.registry
plantest "ldap.python" dc $PYTHON $samba4srcdir/lib/ldb/tests/python/ldap.py $CONFIGURATION \$SERVER -U\$USERNAME%\$PASSWORD -W \$DOMAIN plantest "ldap.python" dc $PYTHON $samba4srcdir/lib/ldb/tests/python/ldap.py $CONFIGURATION \$SERVER -U\$USERNAME%\$PASSWORD -W \$DOMAIN
plantest "blackbox.samba3dump" none $PYTHON scripting/bin/samba3dump $samba4srcdir/../testdata/samba3 plantest "blackbox.samba3dump" none $PYTHON scripting/bin/samba3dump $samba4srcdir/../testdata/samba3
rm -rf $PREFIX/upgrade rm -rf $PREFIX/upgrade