From: Volker Lendecke Date: Tue, 1 Aug 2023 13:26:49 +0000 (+0200) Subject: pylibsmb: Use reparse_data_buffer_parse() X-Git-Tag: tevent-0.16.0~1069 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e71a6ab5ddef9bdfff85f677a086e4ab1e03b232;p=thirdparty%2Fsamba.git pylibsmb: Use reparse_data_buffer_parse() Remove the last direct caller of symlink_reparse_buffer_parse() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/libcli/smb/py_reparse_symlink.c b/libcli/smb/py_reparse_symlink.c index b998b2e27a1..44f6e4850cd 100644 --- a/libcli/smb/py_reparse_symlink.c +++ b/libcli/smb/py_reparse_symlink.c @@ -20,7 +20,9 @@ #include "replace.h" #include "python/modules.h" #include "python/py3compat.h" -#include "reparse_symlink.h" +#include "libcli/util/pyerrors.h" +#include "reparse.h" +#include "smb_constants.h" static PyObject *py_reparse_put(PyObject *module, PyObject *args) { @@ -104,11 +106,10 @@ static PyObject *py_reparse_symlink_get(PyObject *module, PyObject *args) { char *buf = NULL; Py_ssize_t buflen; - struct symlink_reparse_struct syml = { - .flags = 0, - }; + struct reparse_data_buffer *syml = NULL; + struct symlink_reparse_struct *lnk = NULL; PyObject *result = NULL; - int ret; + NTSTATUS status; bool ok; ok = PyArg_ParseTuple(args, PYARG_BYTES_LEN ":get", &buf, &buflen); @@ -116,21 +117,33 @@ static PyObject *py_reparse_symlink_get(PyObject *module, PyObject *args) return NULL; } - ret = symlink_reparse_buffer_parse(NULL, &syml, (uint8_t *)buf, buflen); - if (ret != 0) { - errno = ret; - PyErr_SetFromErrno(PyExc_RuntimeError); + syml = talloc(NULL, struct reparse_data_buffer); + if (syml == NULL) { + PyErr_NoMemory(); + return NULL; + } + + status = reparse_data_buffer_parse(syml, syml, (uint8_t *)buf, buflen); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(syml); + PyErr_SetNTSTATUS(status); + return NULL; + } + + if (syml->tag != IO_REPARSE_TAG_SYMLINK) { + TALLOC_FREE(syml); + PyErr_SetNTSTATUS(NT_STATUS_INVALID_NETWORK_RESPONSE); return NULL; } + lnk = &syml->parsed.lnk; result = Py_BuildValue("ssII", - syml.substitute_name, - syml.print_name, - (unsigned)syml.unparsed_path_length, - (unsigned)syml.flags); + lnk->substitute_name, + lnk->print_name, + (unsigned)lnk->unparsed_path_length, + (unsigned)lnk->flags); - TALLOC_FREE(syml.print_name); - TALLOC_FREE(syml.substitute_name); + TALLOC_FREE(syml); return result; }