From d79566c782f308d470a6075593c3e8fb6b7bcad0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 1 Nov 2022 16:14:06 +0100 Subject: [PATCH] pylibsmb: Add fsctl() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/libsmb/pylibsmb.c | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c index c121e0415b9..3f6dc5deac6 100644 --- a/source3/libsmb/pylibsmb.c +++ b/source3/libsmb/pylibsmb.c @@ -2420,6 +2420,57 @@ static PyObject *py_smb_smb1_symlink( Py_RETURN_NONE; } +static PyObject *py_cli_fsctl( + struct py_cli_state *self, PyObject *args, PyObject *kwds) +{ + int fnum, ctl_code; + int max_out = 0; + char *buf = NULL; + Py_ssize_t buflen; + DATA_BLOB in = { .data = NULL, }; + DATA_BLOB out = { .data = NULL, }; + struct tevent_req *req = NULL; + PyObject *result = NULL; + static const char *kwlist[] = { + "fnum", "ctl_code", "in", "max_out", NULL, + }; + NTSTATUS status; + bool ok; + + ok = ParseTupleAndKeywords( + args, + kwds, + "ii" PYARG_BYTES_LEN "i", + kwlist, + &fnum, + &ctl_code, + &buf, + &buflen, + &max_out); + if (!ok) { + return NULL; + } + + in = (DATA_BLOB) { .data = (uint8_t *)buf, .length = buflen, }; + + req = cli_fsctl_send( + NULL, self->ev, self->cli, fnum, ctl_code, &in, max_out); + + if (!py_tevent_req_wait_exc(self, req)) { + return NULL; + } + + status = cli_fsctl_recv(req, NULL, &out); + if (!NT_STATUS_IS_OK(status)) { + PyErr_SetNTSTATUS(status); + return NULL; + } + + result = PyBytes_FromStringAndSize((char *)out.data, out.length); + data_blob_free(&out); + return result; +} + static PyMethodDef py_cli_state_methods[] = { { "settimeout", (PyCFunction)py_cli_settimeout, METH_VARARGS, "settimeout(new_timeout_msecs) => return old_timeout_msecs" }, @@ -2516,6 +2567,11 @@ static PyMethodDef py_cli_state_methods[] = { METH_VARARGS, "smb1_symlink(target, newname) -> None", }, + { "fsctl", + (PyCFunction)py_cli_fsctl, + METH_VARARGS|METH_KEYWORDS, + "fsctl(fnum, ctl_code, in_bytes, max_out) -> out_bytes", + }, { NULL, NULL, 0, NULL } };