1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-17 04:23:50 +03:00

libsmb: infer posix context from info_level

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>
This commit is contained in:
Ralph Boehme
2023-10-29 11:21:47 +01:00
parent 6944aa7caf
commit ea89dd0069
6 changed files with 18 additions and 23 deletions

View 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'],

View 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

View 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,

View 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;
}

View 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,

View 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);