From: Volker Lendecke Date: Sat, 21 Sep 2024 00:42:16 +0000 (+0200) Subject: pylibsmb: Add unix_mode_to_wire and wire_mode_to_unix X-Git-Tag: tdb-1.4.13~1061 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2182a12c44752fd1e3cc9d76fe24745e795ca933;p=thirdparty%2Fsamba.git pylibsmb: Add unix_mode_to_wire and wire_mode_to_unix Make the wire-representation of mode_t available for tests Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c index 8dbef93834b..25b89380dd3 100644 --- a/source3/libsmb/pylibsmb.c +++ b/source3/libsmb/pylibsmb.c @@ -1265,6 +1265,42 @@ static PyObject *py_cli_close(struct py_cli_state *self, PyObject *args) Py_RETURN_NONE; } +static PyObject *py_wire_mode_to_unix(struct py_cli_state *self, + PyObject *args) +{ + unsigned long long wire = 0; + mode_t mode; + bool ok; + PyObject *v = NULL; + + ok = PyArg_ParseTuple(args, "K", &wire); + if (!ok) { + return NULL; + } + mode = wire_mode_to_unix(wire); + + v = Py_BuildValue("I", (unsigned)mode); + return v; +} + +static PyObject *py_unix_mode_to_wire(struct py_cli_state *self, + PyObject *args) +{ + unsigned long long mode = 0; + uint32_t wire; + bool ok; + PyObject *v = NULL; + + ok = PyArg_ParseTuple(args, "K", &mode); + if (!ok) { + return NULL; + } + wire = unix_mode_to_wire(mode); + + v = Py_BuildValue("I", (unsigned)wire); + return v; +} + static PyObject *py_cli_qfileinfo(struct py_cli_state *self, PyObject *args) { struct tevent_req *req = NULL; @@ -2871,6 +2907,18 @@ static PyTypeObject py_cli_state_type = { }; static PyMethodDef py_libsmb_methods[] = { + { + "unix_mode_to_wire", + (PyCFunction)py_unix_mode_to_wire, + METH_VARARGS, + "Convert mode_t to posix extensions wire format", + }, + { + "wire_mode_to_unix", + (PyCFunction)py_wire_mode_to_unix, + METH_VARARGS, + "Convert posix wire format mode to mode_t", + }, {0}, };