diff options
author | Petr Viktorin <pviktori@redhat.com> | 2017-05-03 16:57:07 +0200 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2017-05-19 22:20:15 +0200 |
commit | 40e409bf9e89a163c771b2a58493d2c1b496fae7 (patch) | |
tree | 28dceee63f2a27ebcc7b5355d94bfed91b4975b9 /auth/credentials/pycredentials.c | |
parent | b691f6d32f79ef8427f567612243dd51ea8d5584 (diff) | |
download | samba-40e409bf9e89a163c771b2a58493d2c1b496fae7.tar.gz |
python3: Use "y#" instead of "s#" for binary data in PyArg_ParseTuple
The "s#" format code for PyArg_ParseTupleAndKeywords and Py_BuildValue
converts a char* and size to/from Python str (with utf-8 encoding under
Python 3).
In some cases, we want bytes (str on Python 2, bytes on 3) instead. The
code for this is "y#" in Python 3, but that is not available in 2.
Introduce a PYARG_BYTES_LEN macro that expands to "s#" or "y#", and use
that in:
- credentials.get_ntlm_response (for input and output)
- ndr_unpack argument in PIDL generated code
Signed-off-by: Petr Viktorin <pviktori@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'auth/credentials/pycredentials.c')
-rw-r--r-- | auth/credentials/pycredentials.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/auth/credentials/pycredentials.c b/auth/credentials/pycredentials.c index 7f03f1f3496..283a73fcd72 100644 --- a/auth/credentials/pycredentials.c +++ b/auth/credentials/pycredentials.c @@ -96,7 +96,8 @@ static PyObject *py_creds_get_ntlm_response(PyObject *self, PyObject *args, PyOb tv_now = timeval_current(); server_timestamp = timeval_to_nttime(&tv_now); - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "is#|s#K", + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "i" PYARG_BYTES_LEN "|" PYARG_BYTES_LEN "K", discard_const_p(char *, kwnames), &flags, &challenge, &target_info.data, &target_info.length)) { return NULL; @@ -116,7 +117,8 @@ static PyObject *py_creds_get_ntlm_response(PyObject *self, PyObject *args, PyOb return NULL; } - ret = Py_BuildValue("{siss#ss#ss#ss#}", + ret = Py_BuildValue("{sis" PYARG_BYTES_LEN "s" PYARG_BYTES_LEN + "s" PYARG_BYTES_LEN "s" PYARG_BYTES_LEN "}", "flags", flags, "lm_reponse", (const char *)lm_response.data, lm_response.length, |