1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-25 17:57:42 +03:00

s4/libnet: Allow passwords containing non ascii characters to be passed

Although we can pass unicode to py_net_change_password unfortunately in
Python2 unicode strings are encoded with the default encoding (e.g. ascii)
 when extracting the unicode string to buffer.
In Python3 the default encoding for "s" format is utf8. Use the "es"
format instead of "s" so we can specify the encoding so behaviour is
correct in py2/py3.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Noel Power 2018-05-16 16:46:41 +01:00 committed by Noel Power
parent a8d8c6ec43
commit 75e1019f61

View File

@ -155,21 +155,26 @@ static PyObject *py_net_change_password(py_net_Object *self, PyObject *args, PyO
{
union libnet_ChangePassword r;
NTSTATUS status;
TALLOC_CTX *mem_ctx;
struct tevent_context *ev;
TALLOC_CTX *mem_ctx = NULL;
struct tevent_context *ev = NULL;
const char *kwnames[] = { "newpassword", "oldpassword", "domain", "username", NULL };
const char *newpass = NULL;
const char *oldpass = NULL;
ZERO_STRUCT(r);
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|sss:change_password",
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "es|esss:change_password",
discard_const_p(char *, kwnames),
&r.generic.in.newpassword,
&r.generic.in.oldpassword,
"utf8",
&newpass,
"utf8",
&oldpass,
&r.generic.in.domain_name,
&r.generic.in.account_name)) {
return NULL;
}
r.generic.in.newpassword = newpass;
r.generic.in.oldpassword = oldpass;
r.generic.level = LIBNET_CHANGE_PASSWORD_GENERIC;
if (r.generic.in.account_name == NULL) {
r.generic.in.account_name
@ -200,12 +205,12 @@ static PyObject *py_net_change_password(py_net_Object *self, PyObject *args, PyO
r.generic.out.error_string
? r.generic.out.error_string
: nt_errstr(status));
talloc_free(mem_ctx);
return NULL;
}
talloc_free(mem_ctx);
PyMem_Free(discard_const_p(char,newpass));
PyMem_Free(discard_const_p(char,oldpass));
Py_RETURN_NONE;
}