diff options
author | Noel Power <noel.power@suse.com> | 2018-11-08 15:03:52 +0000 |
---|---|---|
committer | Noel Power <npower@samba.org> | 2018-12-10 10:38:21 +0100 |
commit | 9b18748c703593a3c257c47b626966b0bd6caa3f (patch) | |
tree | a7f8ea4076fd90d1b5a8ccb10e7b8ba2ea06bff0 /auth | |
parent | 8b10c7137165c3da10f908c250c0a59d4cca821b (diff) | |
download | samba-9b18748c703593a3c257c47b626966b0bd6caa3f.tar.gz |
auth/credentials: PY3 set_password should decode from unicode 'utf8'
set_password processes input using ParseTuple with "s" format, this
accepts string or unicode but...
Some py2 code is incorrectly using code like
credentials.set_password(pass.encode('utf8'))
however that won't work in PY3. We should just make sure the string
retrieved from unicode passed in is encoded with 'utf8'
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'auth')
-rw-r--r-- | auth/credentials/pycredentials.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/auth/credentials/pycredentials.c b/auth/credentials/pycredentials.c index 56174fefbb4..fa8ac2bcb9f 100644 --- a/auth/credentials/pycredentials.c +++ b/auth/credentials/pycredentials.c @@ -171,16 +171,18 @@ static PyObject *py_creds_get_password(PyObject *self, PyObject *unused) static PyObject *py_creds_set_password(PyObject *self, PyObject *args) { - char *newval; + const char *newval = NULL; enum credentials_obtained obt = CRED_SPECIFIED; int _obt = obt; - - if (!PyArg_ParseTuple(args, "s|i", &newval, &_obt)) { + PyObject *result = NULL; + if (!PyArg_ParseTuple(args, "es|i", "utf8", &newval, &_obt)) { return NULL; } obt = _obt; - return PyBool_FromLong(cli_credentials_set_password(PyCredentials_AsCliCredentials(self), newval, obt)); + result = PyBool_FromLong(cli_credentials_set_password(PyCredentials_AsCliCredentials(self), newval, obt)); + PyMem_Free(discard_const_p(void*, newval)); + return result; } static PyObject *py_creds_set_utf16_password(PyObject *self, PyObject *args) |