libsmb: infer posix context from info_level
authorRalph Boehme <slow@samba.org>
Sun, 29 Oct 2023 10:21:47 +0000 (11:21 +0100)
committerRalph Boehme <slow@samba.org>
Tue, 31 Oct 2023 04:38:42 +0000 (04:38 +0000)
No need for an explcit additional argument, we can just infer this from the
info_level.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: David Mulder <dmulder@samba.org>
python/samba/tests/smb3unix.py
source3/libsmb/cli_smb2_fnum.c
source3/libsmb/cli_smb2_fnum.h
source3/libsmb/clilist.c
source3/libsmb/proto.h
source3/libsmb/pylibsmb.c

index bdca1e5d41a4c3cab422f8f7b571596215c7e200..5281f906099f70776a10e20d086bac588e391362 100644 (file)
@@ -119,8 +119,7 @@ class Smb3UnixTests(samba.tests.libsmb.LibsmbTests):
             self.assertNotEqual(expected_count, 0, 'No files were found')
 
             actual_count = len(c.list('',
-                                info_level=libsmb.SMB2_FIND_POSIX_INFORMATION,
-                                posix=True))
+                                info_level=libsmb.SMB2_FIND_POSIX_INFORMATION))
             self.assertEqual(actual_count-2, expected_count,
                              'SMB2_FIND_POSIX_INFORMATION failed to list contents')
 
@@ -239,7 +238,7 @@ class Smb3UnixTests(samba.tests.libsmb.LibsmbTests):
                                 CreateContexts=[posix_context(perm)])
                 c.close(f)
 
-            res = c.list("", info_level=libsmb.SMB2_FIND_POSIX_INFORMATION, posix=True)
+            res = c.list("", info_level=libsmb.SMB2_FIND_POSIX_INFORMATION)
             found_files = {get_string(i['name']): i['perms'] for i in res}
             for fname, perm in test_files.items():
                 self.assertIn(get_string(fname), found_files.keys(),
@@ -262,7 +261,7 @@ class Smb3UnixTests(samba.tests.libsmb.LibsmbTests):
             posix=True)
         self.assertTrue(c.have_posix())
 
-        res = c.list("", info_level=libsmb.SMB2_FIND_POSIX_INFORMATION, posix=True)
+        res = c.list("", info_level=libsmb.SMB2_FIND_POSIX_INFORMATION)
         found_files = {get_string(i['name']): i for i in res}
         dotdot = found_files['..']
         self.assertEqual('S-1-0-0', dotdot['owner_sid'],
index 2092fc550480d611f3c219fd43fba0adc56d9df1..c2cca874b6519486c35cbc539cbe2d11cbd430a4 100644 (file)
@@ -1453,8 +1453,7 @@ struct tevent_req *cli_smb2_list_send(
        struct tevent_context *ev,
        struct cli_state *cli,
        const char *pathname,
-       unsigned int info_level,
-       bool posix)
+       unsigned int info_level)
 {
        struct tevent_req *req = NULL, *subreq = NULL;
        struct cli_smb2_list_state *state = NULL;
@@ -1477,7 +1476,9 @@ struct tevent_req *cli_smb2_list_send(
                return tevent_req_post(req, ev);
        }
 
-       if (smbXcli_conn_have_posix(cli->conn) && posix) {
+       if (smbXcli_conn_have_posix(cli->conn) &&
+               info_level == SMB2_FIND_POSIX_INFORMATION)
+       {
                NTSTATUS status;
 
                /* The mode MUST be 0 when opening an existing file/dir, and
index cde6a3ac333582c48cbda5419d58e0d3aedcbaf3..abac569385ddedca21f7e10502b5549ee13484ce 100644 (file)
@@ -106,8 +106,7 @@ struct tevent_req *cli_smb2_list_send(
        struct tevent_context *ev,
        struct cli_state *cli,
        const char *pathname,
-       unsigned int info_level,
-       bool posix);
+       unsigned int info_level);
 NTSTATUS cli_smb2_list_recv(
        struct tevent_req *req,
        TALLOC_CTX *mem_ctx,
index 9ef3f73a24a158d5aeb7a70138587b3494d5fc7e..54b46b09e0e2953d9d46ab5a4f6b25312724d2b8 100644 (file)
@@ -1002,8 +1002,7 @@ struct tevent_req *cli_list_send(TALLOC_CTX *mem_ctx,
                                 struct cli_state *cli,
                                 const char *mask,
                                 uint32_t attribute,
-                                uint16_t info_level,
-                                bool posix)
+                                uint16_t info_level)
 {
        struct tevent_req *req = NULL;
        struct cli_list_state *state;
@@ -1017,7 +1016,7 @@ struct tevent_req *cli_list_send(TALLOC_CTX *mem_ctx,
 
        if (proto >= PROTOCOL_SMB2_02) {
                state->subreq = cli_smb2_list_send(state, ev, cli, mask,
-                                                  info_level, posix);
+                                                  info_level);
                state->recv_fn = cli_smb2_list_recv;
        } else if (proto >= PROTOCOL_LANMAN2) {
                state->subreq = cli_list_trans_send(
@@ -1230,7 +1229,7 @@ NTSTATUS cli_list(struct cli_state *cli,
                        ? SMB_FIND_FILE_BOTH_DIRECTORY_INFO : SMB_FIND_INFO_STANDARD;
        }
 
-       req = cli_list_send(frame, ev, cli, mask, attribute, info_level, false);
+       req = cli_list_send(frame, ev, cli, mask, attribute, info_level);
        if (req == NULL) {
                goto fail;
        }
index b5a0311469e0530bd5542d96f4d1ee87e6e256f2..35b6577a4bdb61263851e5767ccf1810d4350b7f 100644 (file)
@@ -772,8 +772,7 @@ struct tevent_req *cli_list_send(TALLOC_CTX *mem_ctx,
                                 struct cli_state *cli,
                                 const char *mask,
                                 uint32_t attribute,
-                                uint16_t info_level,
-                                bool posix);
+                                uint16_t info_level);
 NTSTATUS cli_list_recv(
        struct tevent_req *req,
        TALLOC_CTX *mem_ctx,
index 2a51a2a158c434dc25ecaaa7d0f2d637546c8ff3..efaed925ff0d04ee50208ece96c8bddf1ae8fac1 100644 (file)
@@ -2006,7 +2006,6 @@ static NTSTATUS do_listing(struct py_cli_state *self,
                           const char *base_dir, const char *user_mask,
                           uint16_t attribute,
                           unsigned int info_level,
-                          bool posix,
                           NTSTATUS (*callback_fn)(struct file_info *,
                                                   const char *, void *),
                           void *priv)
@@ -2032,7 +2031,7 @@ static NTSTATUS do_listing(struct py_cli_state *self,
        dos_format(mask);
 
        req = cli_list_send(NULL, self->ev, self->cli, mask, attribute,
-                           info_level, posix);
+                           info_level);
        if (req == NULL) {
                status = NT_STATUS_NO_MEMORY;
                goto done;
@@ -2062,18 +2061,17 @@ static PyObject *py_cli_list(struct py_cli_state *self,
        char *user_mask = NULL;
        unsigned int attribute = LIST_ATTRIBUTE_MASK;
        unsigned int info_level = 0;
-       bool posix = false;
        NTSTATUS status;
        enum protocol_types proto = smbXcli_conn_protocol(self->cli->conn);
        PyObject *result = NULL;
-       const char *kwlist[] = { "directory", "mask", "attribs", "posix",
+       const char *kwlist[] = { "directory", "mask", "attribs",
                                 "info_level", NULL };
        NTSTATUS (*callback_fn)(struct file_info *, const char *, void *) =
                &list_helper;
 
-       if (!ParseTupleAndKeywords(args, kwds, "z|sIpI:list", kwlist,
+       if (!ParseTupleAndKeywords(args, kwds, "z|sII:list", kwlist,
                                   &base_dir, &user_mask, &attribute,
-                                  &posix, &info_level)) {
+                                  &info_level)) {
                return NULL;
        }
 
@@ -2090,11 +2088,11 @@ static PyObject *py_cli_list(struct py_cli_state *self,
                }
        }
 
-       if (posix) {
+       if (info_level == SMB2_FIND_POSIX_INFORMATION) {
                callback_fn = &list_posix_helper;
        }
        status = do_listing(self, base_dir, user_mask, attribute,
-                           info_level, posix, callback_fn, result);
+                           info_level, callback_fn, result);
 
        if (!NT_STATUS_IS_OK(status)) {
                Py_XDECREF(result);