summaryrefslogtreecommitdiff
path: root/source4/libnet
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2018-05-16 16:46:41 +0100
committerNoel Power <npower@samba.org>2018-05-17 11:31:28 +0200
commit75e1019f6162814eae3edb050d41784179cfa8ab (patch)
tree6c851663fd3626d1720841dfa07f9fb8ad8fcc33 /source4/libnet
parenta8d8c6ec439fb64ce33dc2406bb38792050ca3a1 (diff)
downloadsamba-75e1019f6162814eae3edb050d41784179cfa8ab.tar.gz
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>
Diffstat (limited to 'source4/libnet')
-rw-r--r--source4/libnet/py_net.c23
1 files changed, 14 insertions, 9 deletions
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;
}