]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pylibsmb: Add unix_mode_to_wire and wire_mode_to_unix
authorVolker Lendecke <vl@samba.org>
Sat, 21 Sep 2024 00:42:16 +0000 (02:42 +0200)
committerRalph Boehme <slow@samba.org>
Thu, 26 Sep 2024 15:22:46 +0000 (15:22 +0000)
Make the wire-representation of mode_t available for tests

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/libsmb/pylibsmb.c

index 8dbef93834b15226538862fdb4b7b9ddc6779be5..25b89380dd3d6704675eb5b348004303ba677aa1 100644 (file)
@@ -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},
 };