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, */