[SCM] Samba Shared Repository - branch master updated

Jelmer Vernooij jelmer at samba.org
Fri Dec 25 06:49:37 MST 2009


The branch, master has been updated
       via  ef453c6... py_net/libnet: Remove C++-style comments, add more error checking, move initialization of dcerpc subsystem to libnet.
       via  33699bb... s4-libnet: Simple test for net.SetPassword() python binding
       via  20c7c27... s4-libnet: Python binding for libnet_SetPassword()
       via  f03e88f... s4-net: Fix 'talloc_free with references ...' error
      from  078482a... s4:auth: change auth_check_password_send/recv to tevent_req

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


- Log -----------------------------------------------------------------
commit ef453c63af3d29c428029aa39a5b59b0317c76ce
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Dec 25 14:48:45 2009 +0100

    py_net/libnet: Remove C++-style comments, add more error checking, move
    initialization of dcerpc subsystem to libnet.

commit 33699bb1be03f0288562c899aa8f3963ff1cc312
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Thu Dec 24 05:50:58 2009 +0200

    s4-libnet: Simple test for net.SetPassword() python binding
    
    Signed-off-by: Jelmer Vernooij <jelmer at samba.org>

commit 20c7c27322e95ab75ea711a825e593b0adac9114
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Thu Dec 24 05:43:21 2009 +0200

    s4-libnet: Python binding for libnet_SetPassword()
    
    Signed-off-by: Jelmer Vernooij <jelmer at samba.org>

commit f03e88fa4bc1101ca9031d697f33e36effb669fd
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Thu Dec 24 04:08:12 2009 +0200

    s4-net: Fix 'talloc_free with references ...' error
    
    Signed-off-by: Jelmer Vernooij <jelmer at samba.org>

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

Summary of changes:
 source4/libnet/libnet.c                    |    3 +
 source4/libnet/libnet_passwd.c             |    8 ++--
 source4/libnet/py_net.c                    |   78 +++++++++++++++++++++++++---
 source4/torture/libnet/python/samr-test.py |   62 ++++++++++++++++++++++
 4 files changed, 140 insertions(+), 11 deletions(-)
 create mode 100644 source4/torture/libnet/python/samr-test.py


Changeset truncated at 500 lines:

diff --git a/source4/libnet/libnet.c b/source4/libnet/libnet.c
index b10fb65..86cf80b 100644
--- a/source4/libnet/libnet.c
+++ b/source4/libnet/libnet.c
@@ -42,6 +42,9 @@ struct libnet_context *libnet_context_init(struct tevent_context *ev,
 	ctx->event_ctx = ev;
 	ctx->lp_ctx = lp_ctx;
 
+	/* make sure dcerpc is initialized */
+	dcerpc_init(lp_ctx);
+
 	/* name resolution methods */
 	ctx->resolve_ctx = lp_resolve_context(lp_ctx);
 
diff --git a/source4/libnet/libnet_passwd.c b/source4/libnet/libnet_passwd.c
index cb09e30..8195347 100644
--- a/source4/libnet/libnet_passwd.c
+++ b/source4/libnet/libnet_passwd.c
@@ -109,11 +109,11 @@ static NTSTATUS libnet_ChangePassword_samr(struct libnet_context *ctx, TALLOC_CT
 								   nt_errstr(status));
 			r->samr.out.error_string = talloc_asprintf(mem_ctx,
 								   "samr_ChangePasswordUser3 for '%s\\%s' failed: %s",
-								   r->samr.in.domain_name, r->samr.in.account_name, 
+								   r->samr.in.domain_name, r->samr.in.account_name,
 								   nt_errstr(status));
 		}
 		goto disconnect;
-	} 
+	}
 
 	/* prepare samr_ChangePasswordUser2 */
 	encode_pw_buffer(lm_pass.data, r->samr.in.newpassword, STR_ASCII|STR_TERMINATE);
@@ -216,7 +216,7 @@ static NTSTATUS libnet_ChangePassword_samr(struct libnet_context *ctx, TALLOC_CT
 #endif
 disconnect:
 	/* close connection */
-	talloc_free(c.out.dcerpc_pipe);
+	talloc_unlink(ctx, c.out.dcerpc_pipe);
 
 	return status;
 }
@@ -627,7 +627,7 @@ static NTSTATUS libnet_SetPassword_samr(struct libnet_context *ctx, TALLOC_CTX *
 
 disconnect:
 	/* close connection */
-	talloc_free(c.out.dcerpc_pipe);
+	talloc_unlink(ctx, c.out.dcerpc_pipe);
 
 	return status;
 }
diff --git a/source4/libnet/py_net.c b/source4/libnet/py_net.c
index 4d3e81c..e5ca5e1 100644
--- a/source4/libnet/py_net.c
+++ b/source4/libnet/py_net.c
@@ -1,18 +1,19 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    Samba utility functions
    Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2008
-   
+   Copyright (C) Kamen Mazdrashki <kamen.mazdrashki at postpath.com> 2009
+
    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/>.
 */
@@ -65,10 +66,16 @@ static PyObject *py_net_join(PyObject *cls, PyObject *args, PyObject *kwargs)
 	creds = cli_credentials_from_py_object(py_creds);
 	if (creds == NULL) {
 		PyErr_SetString(PyExc_TypeError, "Expected credentials object");
+		talloc_free(mem_ctx);
 		return NULL;
 	}
 
 	libnet_ctx = py_net_ctx(cls, ev, creds);
+	if (libnet_ctx == NULL) {
+		PyErr_SetString(PyExc_RuntimeError, "Unable to initialize libnet");
+		talloc_free(mem_ctx);
+		return NULL;
+	}
 
 	status = libnet_Join(libnet_ctx, mem_ctx, &r);
 	if (NT_STATUS_IS_ERR(status)) {
@@ -77,7 +84,7 @@ static PyObject *py_net_join(PyObject *cls, PyObject *args, PyObject *kwargs)
 		return NULL;
 	}
 
-	result = Py_BuildValue("sss", r.out.join_password, 
+	result = Py_BuildValue("sss", r.out.join_password,
 			       dom_sid_string(mem_ctx, r.out.domain_sid),
 			       r.out.domain_name);
 
@@ -89,15 +96,72 @@ static PyObject *py_net_join(PyObject *cls, PyObject *args, PyObject *kwargs)
 	return result;
 }
 
-static char py_net_join_doc[] = "join(domain_name, netbios_name, join_type, level) -> (join_password, domain_sid, domain_name)\n\n" \
+static PyObject *py_net_set_password(PyObject *cls, PyObject *args, PyObject *kwargs)
+{
+	union libnet_SetPassword r;
+	NTSTATUS status;
+	PyObject *py_creds;
+	TALLOC_CTX *mem_ctx;
+	struct tevent_context *ev;
+	struct libnet_context *libnet_ctx;
+	struct cli_credentials *creds;
+	const char *kwnames[] = { "account_name", "domain_name", "newpassword", "credentials", NULL };
+
+	r.generic.level = LIBNET_SET_PASSWORD_GENERIC;
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sssO:SetPassword", discard_const_p(char *, kwnames),
+					 &r.generic.in.account_name, &r.generic.in.domain_name,
+					 &r.generic.in.newpassword, &py_creds)) {
+		return NULL;
+	}
+
+	/* FIXME: we really need to get a context from the caller or we may end
+	 * up with 2 event contexts */
+	ev = s4_event_context_init(NULL);
+	mem_ctx = talloc_new(ev);
+
+	creds = cli_credentials_from_py_object(py_creds);
+	if (creds == NULL) {
+		PyErr_SetString(PyExc_TypeError, "Expected credentials object");
+		return NULL;
+	}
+
+	libnet_ctx = py_net_ctx(cls, ev, creds);
+
+	status = libnet_SetPassword(libnet_ctx, mem_ctx, &r);
+	if (NT_STATUS_IS_ERR(status)) {
+		PyErr_SetString(PyExc_RuntimeError, r.generic.out.error_string);
+		talloc_free(mem_ctx);
+		return NULL;
+	}
+
+	Py_RETURN_NONE;
+}
+
+static const char py_net_join_doc[] = "join(domain_name, netbios_name, join_type, level) -> (join_password, domain_sid, domain_name)\n\n" \
 "Join the domain with the specified name.";
 
+static const char py_net_set_password_doc[] = "SetPassword(account_name, domain_name, newpassword) -> True\n\n" \
+"Set password for a user. You must supply credential with enough rights to do this.\n\n" \
+"Sample usage is:\n" \
+"creds = samba.credentials.Credentials()\n" \
+"creds.set_username('admin_user')\n" \
+"creds.set_domain('domain_name')\n" \
+"creds.set_password('pass')\n\n" \
+"net.SetPassword(account_name=<account_name>,\n" \
+"                domain_name=creds.get_domain(),\n" \
+"                newpassword=new_pass,\n" \
+"                credentials=creds)\n";
+
+
 static struct PyMethodDef net_methods[] = {
 	{"Join", (PyCFunction)py_net_join, METH_VARARGS|METH_KEYWORDS, py_net_join_doc},
+	{"SetPassword", (PyCFunction)py_net_set_password, METH_VARARGS|METH_KEYWORDS, py_net_set_password_doc},
 	{NULL }
 };
 
 void initnet(void)
 {
-	Py_InitModule("net", net_methods);
+	Py_InitModule3("net", net_methods, NULL);
 }
+
diff --git a/source4/torture/libnet/python/samr-test.py b/source4/torture/libnet/python/samr-test.py
new file mode 100644
index 0000000..d68456b
--- /dev/null
+++ b/source4/torture/libnet/python/samr-test.py
@@ -0,0 +1,62 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Unix SMB/CIFS implementation.
+# Copyright (C) Kamen Mazdrashki <kamen.mazdrashki at postpath.com> 2009
+#
+# 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/>.
+#
+
+#
+# Usage:
+#  export ACCOUNT_NAME=kamen
+#  export NEW_PASS=test
+#  export SUBUNITRUN=$samba4srcdir/scripting/bin/subunitrun
+#  PYTHONPATH="$samba4srcdir/torture/libnet/python" $SUBUNITRUN samr-test -Ukma-exch.devel/Administrator%333
+#
+
+import sys
+import os
+
+from samba import net
+import unittest
+import samba.tests
+
+if not "ACCOUNT_NAME" in os.environ.keys():
+    parser.error("Please supply ACCOUNT_NAME in environment")
+
+if not "NEW_PASS" in os.environ.keys():
+    parser.error("Please supply NEW_PASS in environment")
+
+account_name = os.environ["ACCOUNT_NAME"]
+new_pass = os.environ["NEW_PASS"]
+
+creds = samba.tests.cmdline_credentials
+
+#
+# Tests start here
+#
+
+class Libnet_SetPwdTest(unittest.TestCase):
+
+    ########################################################################################
+
+    def test_SetPassword(self):
+        net.SetPassword(account_name=account_name,
+                        domain_name=creds.get_domain(),
+                        newpassword=new_pass,
+                        credentials=creds)
+
+    ########################################################################################
+


-- 
Samba Shared Repository


More information about the samba-cvs mailing list