s3:pylibsmb: Make s3 and s4 listings return the same dict
authorTim Beale <timbeale@catalyst.net.nz>
Tue, 4 Dec 2018 03:25:10 +0000 (16:25 +1300)
committerTim Beale <timbeale@samba.org>
Mon, 7 Jan 2019 00:23:08 +0000 (01:23 +0100)
Make the python dictionary generated by the s3 .list() use the same keys
as the current source4 dict. The reason for using the source4 dict is
that other python code depends on these keys (e.g. ntacls.py), whereas
the source3 API is currently unused.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/tests/smb.py
source3/libsmb/pylibsmb.c

index b951a4bc38882f7c4ae0da7621b98a93a528583a..28560ca71c978aef8c48b33c920ce5c3b96eb4ea 100644 (file)
@@ -85,7 +85,7 @@ class SMBTests(samba.tests.TestCase):
 
         # each item in the listing is a has with expected keys
         expected_keys = ['attrib', 'mtime', 'name', 'short_name', 'size']
-        for item in self.conn.list(addom):
+        for item in self.smb_conn.list(addom):
             for key in expected_keys:
                 self.assertIn(key, item,
                               msg="Key '%s' not in listing '%s'" % (key, item))
index 15c051f40b5541483d7be724f8e1158eaa8e1d14..64da3891783a80a212373262bf705dc18cd9c124 100644 (file)
@@ -912,9 +912,18 @@ static NTSTATUS list_helper(const char *mntpoint, struct file_info *finfo,
                return NT_STATUS_OK;
        }
 
-       file = Py_BuildValue("{s:s,s:i}",
+       /*
+        * Build a dictionary representing the file info.
+        * Note: Windows does not always return short_name (so it may be None)
+        */
+       file = Py_BuildValue("{s:s,s:i,s:s,s:O,s:l}",
                             "name", finfo->name,
-                            "mode", (int)finfo->mode);
+                            "attrib", (int)finfo->mode,
+                            "short_name", finfo->short_name,
+                            "size", PyLong_FromUnsignedLongLong(finfo->size),
+                            "mtime",
+                            convert_timespec_to_time_t(finfo->mtime_ts));
+
        if (file == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -1184,7 +1193,12 @@ static PyMethodDef py_cli_state_methods[] = {
          "directory contents as a dictionary\n"
          "\t\tDEFAULT_ATTRS: FILE_ATTRIBUTE_SYSTEM | "
          "FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_ARCHIVE\n\n"
-         "\t\tList contents of a directory." },
+         "\t\tList contents of a directory. The keys are, \n"
+         "\t\t\tname: Long name of the directory item\n"
+         "\t\t\tshort_name: Short name of the directory item\n"
+         "\t\t\tsize: File size in bytes\n"
+         "\t\t\tattrib: Attributes\n"
+         "\t\t\tmtime: Modification time\n" },
        { "get_oplock_break", (PyCFunction)py_cli_get_oplock_break,
          METH_VARARGS, "Wait for an oplock break" },
        { "unlink", (PyCFunction)py_smb_unlink,