summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2023-04-12 15:31:03 +0200
committerVolker Lendecke <vl@samba.org>2023-04-18 14:58:36 +0000
commit1e738cb061c939e23663d6eb007baf4eea6d8fda (patch)
tree0eaebb93cfa72e3cef3805638309f221d814143b
parent526f381f413d1cb5cde93b9542034f5ebfcfcc10 (diff)
downloadsamba-1e738cb061c939e23663d6eb007baf4eea6d8fda.tar.gz
libsmb: Introduce type-safe struct cli_smb2_create_flags
This makes it clearer what to pass into the create_flags argument to cli_smb2_create_fnum(). There was already confusion in source3/torture/test_smb2.c: It passed in SMB2_OPLOCK_LEVEL_NONE (which was okay because it #defines to 0), but it should have been a straight 0, for example SMB2_OPLOCK_LEVEL_EXCLUSIVE would have been wrong. This way adding other flags (.nofollow comes to mind) will be much easier to handle. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
-rw-r--r--examples/fuse/clifuse.c4
-rw-r--r--source3/libsmb/cli_smb2_fnum.c47
-rw-r--r--source3/libsmb/cli_smb2_fnum.h9
-rw-r--r--source3/libsmb/clifile.c11
-rw-r--r--source3/libsmb/pylibsmb.c7
-rw-r--r--source3/torture/test_smb2.c10
6 files changed, 54 insertions, 34 deletions
diff --git a/examples/fuse/clifuse.c b/examples/fuse/clifuse.c
index 75cb72f7f87..94ec3911ef6 100644
--- a/examples/fuse/clifuse.c
+++ b/examples/fuse/clifuse.c
@@ -154,7 +154,7 @@ static void cli_ll_create(fuse_req_t freq, fuse_ino_t parent, const char *name,
state,
mstate->ev,
mstate->cli, state->path,
- 0,
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
FILE_GENERIC_READ|FILE_GENERIC_WRITE,
FILE_ATTRIBUTE_NORMAL,
@@ -853,7 +853,7 @@ static void cli_ll_open(fuse_req_t freq, fuse_ino_t ino,
mstate->ev,
mstate->cli,
istate->path,
- 0,
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
acc,
FILE_ATTRIBUTE_NORMAL,
diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
index 5852f9177fd..2339ca41702 100644
--- a/source3/libsmb/cli_smb2_fnum.c
+++ b/source3/libsmb/cli_smb2_fnum.c
@@ -142,11 +142,11 @@ static NTSTATUS delete_smb2_handle_mapping(struct cli_state *cli,
Oplock mapping code.
***************************************************************/
-static uint8_t flags_to_smb2_oplock(uint32_t create_flags)
+static uint8_t flags_to_smb2_oplock(struct cli_smb2_create_flags create_flags)
{
- if (create_flags & REQUEST_BATCH_OPLOCK) {
+ if (create_flags.batch_oplock) {
return SMB2_OPLOCK_LEVEL_BATCH;
- } else if (create_flags & REQUEST_OPLOCK) {
+ } else if (create_flags.exclusive_oplock) {
return SMB2_OPLOCK_LEVEL_EXCLUSIVE;
}
@@ -212,7 +212,7 @@ struct tevent_req *cli_smb2_create_fnum_send(
struct tevent_context *ev,
struct cli_state *cli,
const char *fname_in,
- uint32_t create_flags,
+ struct cli_smb2_create_flags create_flags,
uint32_t impersonation_level,
uint32_t desired_access,
uint32_t file_attributes,
@@ -392,7 +392,7 @@ NTSTATUS cli_smb2_create_fnum_recv(
NTSTATUS cli_smb2_create_fnum(
struct cli_state *cli,
const char *fname,
- uint32_t create_flags,
+ struct cli_smb2_create_flags create_flags,
uint32_t impersonation_level,
uint32_t desired_access,
uint32_t file_attributes,
@@ -810,7 +810,7 @@ struct tevent_req *cli_smb2_mkdir_send(
ev, /* ev */
cli, /* cli */
dname, /* fname */
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0}, /* create_flags */
SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level */
FILE_READ_ATTRIBUTES, /* desired_access */
FILE_ATTRIBUTE_DIRECTORY, /* file_attributes */
@@ -898,7 +898,7 @@ struct tevent_req *cli_smb2_rmdir_send(
state->ev,
state->cli,
state->dname,
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
DELETE_ACCESS, /* desired_access */
FILE_ATTRIBUTE_DIRECTORY, /* file attributes */
@@ -937,7 +937,7 @@ static void cli_smb2_rmdir_opened1(struct tevent_req *subreq)
state->ev,
state->cli,
state->dname,
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
DELETE_ACCESS, /* desired_access */
FILE_ATTRIBUTE_DIRECTORY, /* file attributes */
@@ -1068,7 +1068,7 @@ struct tevent_req *cli_smb2_unlink_send(
state->ev, /* tevent_context */
state->cli, /* cli_struct */
state->fname, /* filename */
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
DELETE_ACCESS, /* desired_access */
FILE_ATTRIBUTE_NORMAL, /* file attributes */
@@ -1111,7 +1111,7 @@ static void cli_smb2_unlink_opened1(struct tevent_req *subreq)
state->ev, /* tevent_context */
state->cli, /* cli_struct */
state->fname, /* filename */
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
DELETE_ACCESS, /* desired_access */
FILE_ATTRIBUTE_NORMAL, /* file attributes */
@@ -1473,7 +1473,7 @@ struct tevent_req *cli_smb2_list_send(
ev, /* ev */
cli, /* cli */
parent, /* fname */
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0}, /* create_flags */
SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level */
SEC_DIR_LIST|SEC_DIR_READ_ATTRIBUTE, /* desired_access */
FILE_ATTRIBUTE_DIRECTORY, /* file_attributes */
@@ -1722,7 +1722,7 @@ NTSTATUS cli_smb2_qpathinfo_basic(struct cli_state *cli,
status = cli_smb2_create_fnum(cli,
name,
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
FILE_READ_ATTRIBUTES, /* desired_access */
FILE_ATTRIBUTE_DIRECTORY, /* file attributes */
@@ -1739,7 +1739,7 @@ NTSTATUS cli_smb2_qpathinfo_basic(struct cli_state *cli,
/* Maybe a file ? */
status = cli_smb2_create_fnum(cli,
name,
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
FILE_READ_ATTRIBUTES, /* desired_access */
0, /* file attributes */
@@ -1757,7 +1757,7 @@ NTSTATUS cli_smb2_qpathinfo_basic(struct cli_state *cli,
/* Maybe a reparse point ? */
status = cli_smb2_create_fnum(cli,
name,
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
FILE_READ_ATTRIBUTES, /* desired_access */
0, /* file attributes */
@@ -1996,7 +1996,7 @@ static struct tevent_req *get_fnum_from_path_send(
ev, /* ev */
cli, /* cli */
state->name, /* fname */
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0}, /* create_flags */
SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level */
desired_access, /* desired_access */
0, /* file_attributes */
@@ -2037,7 +2037,7 @@ static void get_fnum_from_path_opened_file(struct tevent_req *subreq)
state->ev, /* ev */
state->cli, /* cli */
state->name, /* fname */
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0}, /* create_flags */
SMB2_IMPERSONATION_IMPERSONATION, /* impersonation */
state->desired_access, /* desired_access */
0, /* file_attributes */
@@ -2061,7 +2061,7 @@ static void get_fnum_from_path_opened_file(struct tevent_req *subreq)
state->ev, /* ev */
state->cli, /* cli */
state->name, /* fname */
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0}, /* create_flags */
SMB2_IMPERSONATION_IMPERSONATION, /* impersonation */
state->desired_access, /* desired_access */
0, /* file_attributes */
@@ -2630,7 +2630,7 @@ NTSTATUS cli_smb2_dskattr(struct cli_state *cli, const char *path,
/* First open the top level directory. */
status = cli_smb2_create_fnum(cli,
path,
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
FILE_READ_ATTRIBUTES, /* desired_access */
FILE_ATTRIBUTE_DIRECTORY, /* file attributes */
@@ -2727,7 +2727,8 @@ NTSTATUS cli_smb2_get_fs_full_size_info(struct cli_state *cli,
/* First open the top level directory. */
status =
- cli_smb2_create_fnum(cli, "", 0, /* create_flags */
+ cli_smb2_create_fnum(cli, "",
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
FILE_READ_ATTRIBUTES, /* desired_access */
FILE_ATTRIBUTE_DIRECTORY, /* file attributes */
@@ -2808,7 +2809,8 @@ NTSTATUS cli_smb2_get_fs_attr_info(struct cli_state *cli, uint32_t *fs_attr)
/* First open the top level directory. */
status =
- cli_smb2_create_fnum(cli, "", 0, /* create_flags */
+ cli_smb2_create_fnum(cli, "",
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
FILE_READ_ATTRIBUTES, /* desired_access */
FILE_ATTRIBUTE_DIRECTORY, /* file attributes */
@@ -2888,7 +2890,8 @@ NTSTATUS cli_smb2_get_fs_volume_info(struct cli_state *cli,
/* First open the top level directory. */
status =
- cli_smb2_create_fnum(cli, "", 0, /* create_flags */
+ cli_smb2_create_fnum(cli, "",
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
FILE_READ_ATTRIBUTES, /* desired_access */
FILE_ATTRIBUTE_DIRECTORY, /* file attributes */
@@ -3024,7 +3027,7 @@ struct tevent_req *cli_smb2_query_mxac_send(TALLOC_CTX *mem_ctx,
state->ev,
state->cli,
state->fname,
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
FILE_READ_ATTRIBUTES,
0, /* file attributes */
diff --git a/source3/libsmb/cli_smb2_fnum.h b/source3/libsmb/cli_smb2_fnum.h
index bb1a61ecfd5..4be84db72b0 100644
--- a/source3/libsmb/cli_smb2_fnum.h
+++ b/source3/libsmb/cli_smb2_fnum.h
@@ -26,12 +26,17 @@ struct cli_state;
struct file_info;
struct symlink_reparse_struct;
+struct cli_smb2_create_flags {
+ bool batch_oplock:1;
+ bool exclusive_oplock:1;
+};
+
struct tevent_req *cli_smb2_create_fnum_send(
TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct cli_state *cli,
const char *fname,
- uint32_t create_flags,
+ struct cli_smb2_create_flags create_flags,
uint32_t impersonation_level,
uint32_t desired_access,
uint32_t file_attributes,
@@ -49,7 +54,7 @@ NTSTATUS cli_smb2_create_fnum_recv(
NTSTATUS cli_smb2_create_fnum(
struct cli_state *cli,
const char *fname,
- uint32_t create_flags,
+ struct cli_smb2_create_flags create_flags,
uint32_t impersonation_level,
uint32_t desired_access,
uint32_t file_attributes,
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 5c2e8208d75..ecc652c81e6 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -1746,7 +1746,7 @@ static struct tevent_req *cli_smb2_hardlink_send(
ev,
cli,
fname_src,
- 0, /* create_flags */
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
FILE_WRITE_ATTRIBUTES,
0, /* file attributes */
@@ -2669,16 +2669,23 @@ struct tevent_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
}
if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+ struct cli_smb2_create_flags cflags = {0};
+
if (cli->use_oplocks) {
create_flags |= REQUEST_OPLOCK|REQUEST_BATCH_OPLOCK;
}
+ cflags = (struct cli_smb2_create_flags) {
+ .batch_oplock = (create_flags & REQUEST_BATCH_OPLOCK),
+ .exclusive_oplock = (create_flags & REQUEST_OPLOCK),
+ };
+
subreq = cli_smb2_create_fnum_send(
state,
ev,
cli,
fname,
- create_flags,
+ cflags,
impersonation_level,
desired_access,
file_attributes,
diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c
index 7952a6ec483..0dd5e2583d4 100644
--- a/source3/libsmb/pylibsmb.c
+++ b/source3/libsmb/pylibsmb.c
@@ -1135,12 +1135,17 @@ static PyObject *py_cli_create_ex(
}
if (smbXcli_conn_protocol(self->cli->conn) >= PROTOCOL_SMB2_02) {
+ struct cli_smb2_create_flags cflags = {
+ .batch_oplock = (CreateFlags & REQUEST_BATCH_OPLOCK),
+ .exclusive_oplock = (CreateFlags & REQUEST_OPLOCK),
+ };
+
req = cli_smb2_create_fnum_send(
NULL,
self->ev,
self->cli,
fname,
- CreateFlags,
+ cflags,
ImpersonationLevel,
DesiredAccess,
FileAttributes,
diff --git a/source3/torture/test_smb2.c b/source3/torture/test_smb2.c
index dc249643aa6..ca8cea23a6b 100644
--- a/source3/torture/test_smb2.c
+++ b/source3/torture/test_smb2.c
@@ -2840,7 +2840,7 @@ bool run_smb2_sacl(int dummy)
status = cli_smb2_create_fnum(cli,
fname,
- SMB2_OPLOCK_LEVEL_NONE,
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
SEC_FLAG_SYSTEM_SECURITY, /* desired access */
0, /* file_attributes, */
@@ -2878,7 +2878,7 @@ bool run_smb2_sacl(int dummy)
status = cli_smb2_create_fnum(cli,
fname,
- SMB2_OPLOCK_LEVEL_NONE,
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
SEC_FLAG_SYSTEM_SECURITY|
FILE_WRITE_ATTRIBUTES, /* desired access */
@@ -2947,7 +2947,7 @@ bool run_smb2_sacl(int dummy)
status = cli_smb2_create_fnum(cli,
fname,
- SMB2_OPLOCK_LEVEL_NONE,
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
SEC_FLAG_SYSTEM_SECURITY|
SEC_STD_WRITE_DAC, /* desired access */
@@ -3003,7 +3003,7 @@ bool run_smb2_sacl(int dummy)
status = cli_smb2_create_fnum(cli,
fname,
- SMB2_OPLOCK_LEVEL_NONE,
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
SEC_FLAG_SYSTEM_SECURITY|
FILE_READ_ATTRIBUTES, /* desired access */
@@ -3117,7 +3117,7 @@ bool run_smb2_quota1(int dummy)
status = cli_smb2_create_fnum(
cli,
"\\",
- SMB2_OPLOCK_LEVEL_NONE,
+ (struct cli_smb2_create_flags){0},
SMB2_IMPERSONATION_IMPERSONATION,
SEC_GENERIC_READ, /* desired access */
0, /* file_attributes, */