From: Noel Power Date: Wed, 16 May 2018 15:46:41 +0000 (+0100) Subject: s4/libnet: Allow passwords containing non ascii characters to be passed X-Git-Tag: ldb-1.4.0~141 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75e1019f6162814eae3edb050d41784179cfa8ab;p=thirdparty%2Fsamba.git 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 Reviewed-by: Andrew Bartlett --- diff --git a/source4/libnet/py_net.c b/source4/libnet/py_net.c index 0567dbd6353..6aff373b359 100644 --- a/source4/libnet/py_net.c +++ b/source4/libnet/py_net.c @@ -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; }