[PATCH] libnet_ChangePassword() Python binding

Zahari Zahariev zahari.zahariev at postpath.com
Fri Jul 17 06:05:05 MDT 2009


Some additional cleaning of whitespace bug.
---
 source4/libnet/py_net.c |   65 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 58 insertions(+), 7 deletions(-)

diff --git a/source4/libnet/py_net.c b/source4/libnet/py_net.c
index 4770cff..9ffb719 100644
--- a/source4/libnet/py_net.c
+++ b/source4/libnet/py_net.c
@@ -1,18 +1,18 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    Samba utility functions
    Copyright (C) Jelmer Vernooij <jelmer at 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/>.
 */
@@ -43,8 +43,8 @@ static PyObject *py_net_join(PyObject *cls, PyObject *args, PyObject *kwargs)
 	struct libnet_context *libnet_ctx;
 	const char *kwnames[] = { "domain_name", "netbios_name", "join_type", "level", NULL };
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssii:Join", discard_const_p(char *, kwnames), 
-					 &r.in.domain_name, &r.in.netbios_name, 
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssii:Join", discard_const_p(char *, kwnames),
+					 &r.in.domain_name, &r.in.netbios_name,
 					 &r.in.join_type, &r.in.level))
 		return NULL;
 
@@ -62,7 +62,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);
 
@@ -74,11 +74,61 @@ static PyObject *py_net_join(PyObject *cls, PyObject *args, PyObject *kwargs)
 	return result;
 }
 
+static PyObject *py_net_change_password(PyObject *cls, PyObject *args, PyObject *kwargs)
+{
+	union libnet_ChangePassword r;
+	NTSTATUS status;
+	PyObject *result;
+	TALLOC_CTX *mem_ctx;
+	struct tevent_context *ev;
+	struct libnet_context *libnet_ctx;
+	const char *kwnames[] = { "account_name", "domain_name", "oldpassword", "newpassword", "level", NULL };
+
+	// r.generic.level			= LIBNET_CHANGE_PASSWORD_GENERIC;
+	// r.generic.in.account_name	= cli_credentials_get_username(ctx->credentials);
+	// r.generic.in.domain_name	= cli_credentials_get_domain(ctx->credentials);
+	// r.generic.in.oldpassword	= cli_credentials_get_password(ctx->credentials);
+	// r.generic.in.newpassword	= new_password;
+
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssssi:ChangePassword", discard_const_p(char *, kwnames),
+					 &r.generic.in.account_name, &r.generic.in.domain_name, &r.generic.in.oldpassword,
+					 &r.generic.in.newpassword, &r.generic.level))
+		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);
+
+	libnet_ctx = py_net_ctx(cls, ev);
+
+	status = libnet_ChangePassword(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;
+	}
+
+    result = Py_BuildValue("s", r.generic.out.error_string);
+
+	talloc_free(mem_ctx);
+
+	if (result == NULL)
+		return NULL;
+
+	return result;
+}
+
 static 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 char py_net_change_password_doc[] = "ChangePassword(account_name, domain_name, oldpassword, newpassword, level) -> (error_string)\n\n" \
+"Change password even with non-Administrator account.";
+
 static struct PyMethodDef net_methods[] = {
 	{"Join", (PyCFunction)py_net_join, METH_VARARGS|METH_KEYWORDS, py_net_join_doc},
+	{"ChangePassword", (PyCFunction)py_net_change_password, METH_VARARGS|METH_KEYWORDS, py_net_change_password_doc},
 	{NULL }
 };
 
@@ -86,3 +136,4 @@ void initnet(void)
 {
 	Py_InitModule("net", net_methods);
 }
+
-- 
1.5.6.3


--------------020905020609040406010401--


More information about the samba-technical mailing list