[SCM] Samba Shared Repository - branch master updated

Andrew Tridgell tridge at samba.org
Sun Aug 22 01:38:27 MDT 2010


The branch, master has been updated
       via  d7d19fd... s4-net: better error message on net setpassword
       via  a2012df... librpc: add python bindings for the netlogon pipe
       via  d55b19b... pyldb: do type checking on the list form of ldb add
       via  24159a5... pidl: give the varible name for bad type in python calls
       via  34b8615... pidl: cope with bad type conversions in unions
       via  5a025c8... pidl: added a __ndr_print__() method on python NDR objects
      from  45ac8ff... s3: Fix netgrent configure checks for compilers not supporting -Werror-implicit-function-declaration

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit d7d19fdc84d73fda85e1794af7c7122ded6b24bb
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sun Aug 22 14:51:12 2010 +1000

    s4-net: better error message on net setpassword

commit a2012dfc6b73f74fb9e9e3d815f3b8ede340f552
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sun Aug 22 14:50:46 2010 +1000

    librpc: add python bindings for the netlogon pipe
    
    Pair-Programmed-With: Jelmer Vernooij <jelmer at samba.org>

commit d55b19b56af3fc8e122a890adad8b56bb05814be
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sun Aug 22 14:50:22 2010 +1000

    pyldb: do type checking on the list form of ldb add
    
    Pair-Programmed-With: Jelmer Vernooij <jelmer at samba.org>

commit 24159a59a3b404346e7931ef8817d09eeeb0711f
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sun Aug 22 14:49:10 2010 +1000

    pidl: give the varible name for bad type in python calls
    
    This makes it much clearer which argument to a function had the wrong
    type

commit 34b86155743f0ef1916bc3ae15907961c230c9ab
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sun Aug 22 14:47:22 2010 +1000

    pidl: cope with bad type conversions in unions
    
    This prevents a crash when converting bad types in NDR unions
    
    Pair-Programmed-With: Jelmer Vernooij <jelmer at samba.org>

commit 5a025c82f566b378a125abf0f9e74fc076d394c0
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sun Aug 22 14:46:01 2010 +1000

    pidl: added a __ndr_print__() method on python NDR objects
    
    This allows you to print a returned NDR structure using
    s.__ndr_print__() which gives an easy view of complex
    structures, such as those from netlogon

-----------------------------------------------------------------------

Summary of changes:
 pidl/lib/Parse/Pidl/Samba4/Python.pm               |   23 +++++++++++++++++++-
 source4/lib/ldb/pyldb.c                            |    6 +++++
 source4/librpc/rpc/pyrpc.h                         |    2 +-
 source4/librpc/wscript_build                       |    6 +++++
 .../scripting/python/samba/netcmd/setpassword.py   |    8 ++++--
 5 files changed, 40 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 75aa0a8..f7968b4 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -288,11 +288,24 @@ sub PythonStruct($$$$$$)
 		$self->deindent;
 		$self->pidl("}");
 		$self->pidl("");
+
+		$self->pidl("static PyObject *py_$name\_ndr_print(PyObject *py_obj)");
+		$self->pidl("{");
+		$self->indent;
+		$self->pidl("$cname *object = ($cname *)py_talloc_get_ptr(py_obj);");
+		$self->pidl("char *retstr;");
+		$self->pidl("retstr = ndr_print_struct_string(py_talloc_get_mem_ctx(py_obj), (ndr_print_fn_t)ndr_print_$name, \"$name\", object);");
+		$self->pidl("return PyString_FromString(retstr);");
+		$self->deindent;
+		$self->pidl("}");
+		$self->pidl("");
+
 		$py_methods = "py_$name\_methods";
 		$self->pidl("static PyMethodDef $py_methods\[] = {");
 		$self->indent;
 		$self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_NOARGS, \"S.pack() -> blob\\nNDR pack\" },");
 		$self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS, \"S.unpack(blob) -> None\\nNDR unpack\" },");
+		$self->pidl("{ \"__ndr_print__\", (PyCFunction)py_$name\_ndr_print, METH_VARARGS, \"S.print(blob) -> None\\nNDR print\" },");
 		$self->pidl("{ NULL, NULL, 0, NULL }");
 		$self->deindent;
 		$self->pidl("};");
@@ -973,7 +986,15 @@ sub ConvertObjectFromPythonLevel($$$$$$$$)
 	} elsif ($l->{TYPE} eq "SWITCH") {
 		$var_name = get_pointer_to($var_name);
 		my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e);
-		$self->assign($var_name, "py_export_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $py_var)");
+		my $switch_ptr = "$e->{NAME}_switch_$l->{LEVEL_INDEX}";
+		$self->pidl("{");
+		$self->indent;
+		$self->pidl("void *$switch_ptr;");
+		$self->pidl("$switch_ptr = py_export_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $py_var);");
+		$self->pidl("if ($switch_ptr == NULL) { $fail }");
+		$self->assign($var_name, "$switch_ptr");
+		$self->deindent;
+		$self->pidl("}");
 	} elsif ($l->{TYPE} eq "SUBCONTEXT") {
 		$self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), $var_name, $fail);
 	} else {
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index 19123c3..f1b73a9 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -1691,6 +1691,12 @@ struct ldb_message_element *PyObject_AsMessageElement(TALLOC_CTX *mem_ctx,
 		me->values = talloc_array(me, struct ldb_val, me->num_values);
 		for (i = 0; i < me->num_values; i++) {
 			PyObject *obj = PySequence_GetItem(set_obj, i);
+			if (!PyString_Check(obj)) {
+				PyErr_Format(PyExc_TypeError,
+					     "Expected string as element %d in list", i);
+				talloc_free(me);
+				return NULL;
+			}
 
 			me->values[i].length = PyString_Size(obj);
 			me->values[i].data = talloc_memdup(me, 
diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h
index f49122a..4ba9bd3 100644
--- a/source4/librpc/rpc/pyrpc.h
+++ b/source4/librpc/rpc/pyrpc.h
@@ -24,7 +24,7 @@
 
 #define PY_CHECK_TYPE(type, var, fail) \
 	if (!PyObject_TypeCheck(var, type)) {\
-		PyErr_Format(PyExc_TypeError, "Expected type %s", (type)->tp_name); \
+		PyErr_Format(PyExc_TypeError, "Expected type %s for %s", (type)->tp_name, #var); \
 		fail; \
 	}
 
diff --git a/source4/librpc/wscript_build b/source4/librpc/wscript_build
index 9133bc8..62cb229 100755
--- a/source4/librpc/wscript_build
+++ b/source4/librpc/wscript_build
@@ -783,6 +783,12 @@ bld.SAMBA_PYTHON('python_dcerpc_xattr',
 	realname='samba/dcerpc/xattr.so'
 	)
 
+bld.SAMBA_PYTHON('python_netlogon',
+	source='../../librpc/gen_ndr/py_netlogon.c',
+	deps='RPC_NDR_NETLOGON PYTALLOC pyparam_util pycredentials python_dcerpc',
+	realname='samba/dcerpc/netlogon.so'
+	)
+
 bld.SAMBA_SCRIPT('python_dcerpc_init',
                  pattern='rpc/dcerpc.py',
                  installdir='python/samba/dcerpc',
diff --git a/source4/scripting/python/samba/netcmd/setpassword.py b/source4/scripting/python/samba/netcmd/setpassword.py
index e01fa23..047a95a 100644
--- a/source4/scripting/python/samba/netcmd/setpassword.py
+++ b/source4/scripting/python/samba/netcmd/setpassword.py
@@ -26,6 +26,7 @@ from getpass import getpass
 from samba.auth import system_session
 from samba.samdb import SamDB
 from samba import gensec
+import ldb
 
 class cmd_setpassword(Command):
     """(Re)sets the password on a user account"""
@@ -74,6 +75,7 @@ class cmd_setpassword(Command):
             samdb.setpassword(filter, password,
                               force_change_at_next_login=must_change_at_next_login,
                               username=username)
-        except:
-            raise CommandError('Failed to set password for user "%s"' %
-                username)
+        except ldb.LdbError, (num, msg):
+            raise CommandError('Failed to set password for user "%s" - %s' %
+                               (username, msg))
+        print "Changed password OK"


-- 
Samba Shared Repository


More information about the samba-cvs mailing list