Skip to content

Commit

Permalink
libsmb: Centralize the SMB2 protocol check
Browse files Browse the repository at this point in the history
Instead of checking protocol correctness in every highlevel routine,
we should rely on the lowerlevel one in smbXcli_base.c to give the
INVALID_PARAMETER error return when running on SMB1

Signed-off-by: Volker Lendecke <[email protected]>
Reviewed-by: Jeremy Allison <[email protected]>
  • Loading branch information
vlendec authored and jrasamba committed Oct 3, 2022
1 parent 36bd73e commit 4388ba4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 153 deletions.
6 changes: 6 additions & 0 deletions libcli/smb/smbXcli_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -2997,13 +2997,19 @@ struct tevent_req *smb2cli_req_create(TALLOC_CTX *mem_ctx,
bool use_channel_sequence = conn->smb2.force_channel_sequence;
uint16_t channel_sequence = 0;
bool use_replay_flag = false;
enum protocol_types proto = smbXcli_conn_protocol(conn);

req = tevent_req_create(mem_ctx, &state,
struct smbXcli_req_state);
if (req == NULL) {
return NULL;
}

if ((proto > PROTOCOL_NONE) && (proto < PROTOCOL_SMB2_02)) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return req;
}

state->ev = ev;
state->conn = conn;
state->session = session;
Expand Down
153 changes: 0 additions & 153 deletions source3/libsmb/cli_smb2_fnum.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,6 @@ struct tevent_req *cli_smb2_create_fnum_send(
}
state->cli = cli;

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return tevent_req_post(req, ev);
}

if (cli->backup_intent) {
create_options |= FILE_OPEN_FOR_BACKUP_INTENT;
}
Expand Down Expand Up @@ -486,11 +481,6 @@ struct tevent_req *cli_smb2_close_fnum_send(TALLOC_CTX *mem_ctx,
state->cli = cli;
state->fnum = fnum;

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return tevent_req_post(req, ev);
}

status = map_fnum_to_smb2_handle(cli, fnum, &state->ph);
if (tevent_req_nterror(req, status)) {
return tevent_req_post(req, ev);
Expand Down Expand Up @@ -710,11 +700,6 @@ struct tevent_req *cli_smb2_delete_on_close_send(TALLOC_CTX *mem_ctx,
}
state->cli = cli;

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return tevent_req_post(req, ev);
}

/*
* setinfo on the handle with info_type SMB2_SETINFO_FILE (1),
* level 13 (SMB_FILE_DISPOSITION_INFORMATION - 1000).
Expand Down Expand Up @@ -912,11 +897,6 @@ struct tevent_req *cli_smb2_rmdir_send(
state->dname = dname;
state->in_cblobs = in_cblobs;

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return tevent_req_post(req, ev);
}

subreq = cli_smb2_create_fnum_send(
state,
state->ev,
Expand Down Expand Up @@ -1087,11 +1067,6 @@ struct tevent_req *cli_smb2_unlink_send(
state->fname = fname;
state->in_cblobs = in_cblobs;

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return tevent_req_post(req, ev);
}

subreq = cli_smb2_create_fnum_send(
state, /* mem_ctx */
state->ev, /* tevent_context */
Expand Down Expand Up @@ -1357,11 +1332,6 @@ struct tevent_req *cli_smb2_list_send(
state->cli = cli;
state->status = NT_STATUS_OK;

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return tevent_req_post(req, ev);
}

ok = windows_parent_dirname(state, pathname, &parent, &state->mask);
if (!ok) {
tevent_req_oom(req);
Expand Down Expand Up @@ -1598,10 +1568,6 @@ NTSTATUS cli_smb2_qpathinfo_basic(struct cli_state *cli,
return NT_STATUS_INVALID_PARAMETER;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
return NT_STATUS_INVALID_PARAMETER;
}

/* SMB2 is pickier about pathnames. Ensure it doesn't
end in a '\' */
if (namelen > 0 && name[namelen-1] == '\\') {
Expand Down Expand Up @@ -2047,11 +2013,6 @@ NTSTATUS cli_smb2_qpathinfo_alt_name(struct cli_state *cli,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

status = get_fnum_from_path(cli,
name,
FILE_READ_ATTRIBUTES,
Expand Down Expand Up @@ -2148,11 +2109,6 @@ NTSTATUS cli_smb2_getatr(struct cli_state *cli,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

status = get_fnum_from_path(cli,
name,
FILE_READ_ATTRIBUTES,
Expand Down Expand Up @@ -2219,11 +2175,6 @@ NTSTATUS cli_smb2_qpathinfo2(struct cli_state *cli,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

status = get_fnum_from_path(cli,
name,
FILE_READ_ATTRIBUTES,
Expand Down Expand Up @@ -2280,11 +2231,6 @@ NTSTATUS cli_smb2_qpathinfo_streams(struct cli_state *cli,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

status = get_fnum_from_path(cli,
name,
FILE_READ_ATTRIBUTES,
Expand Down Expand Up @@ -2359,11 +2305,6 @@ NTSTATUS cli_smb2_setpathinfo(struct cli_state *cli,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

status = get_fnum_from_path(cli,
name,
FILE_WRITE_ATTRIBUTES,
Expand Down Expand Up @@ -2475,10 +2416,6 @@ NTSTATUS cli_smb2_setattrE(struct cli_state *cli,
return NT_STATUS_INVALID_PARAMETER;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
return NT_STATUS_INVALID_PARAMETER;
}

/* setinfo on the handle with info_type SMB2_SETINFO_FILE (1),
level 4 (SMB_FILE_BASIC_INFORMATION - 1000). */

Expand Down Expand Up @@ -2533,11 +2470,6 @@ NTSTATUS cli_smb2_dskattr(struct cli_state *cli, const char *path,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

/* First open the top level directory. */
status = cli_smb2_create_fnum(cli,
path,
Expand Down Expand Up @@ -2636,11 +2568,6 @@ NTSTATUS cli_smb2_get_fs_full_size_info(struct cli_state *cli,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

/* First open the top level directory. */
status =
cli_smb2_create_fnum(cli, "", 0, /* create_flags */
Expand Down Expand Up @@ -2722,11 +2649,6 @@ NTSTATUS cli_smb2_get_fs_attr_info(struct cli_state *cli, uint32_t *fs_attr)
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

/* First open the top level directory. */
status =
cli_smb2_create_fnum(cli, "", 0, /* create_flags */
Expand Down Expand Up @@ -2807,11 +2729,6 @@ NTSTATUS cli_smb2_get_fs_volume_info(struct cli_state *cli,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

/* First open the top level directory. */
status =
cli_smb2_create_fnum(cli, "", 0, /* create_flags */
Expand Down Expand Up @@ -2937,11 +2854,6 @@ struct tevent_req *cli_smb2_query_mxac_send(TALLOC_CTX *mem_ctx,
.fname = fname,
};

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return tevent_req_post(req, ev);
}

status = smb2_create_blob_add(state,
&state->in_cblobs,
SMB2_CREATE_TAG_MXAC,
Expand Down Expand Up @@ -3361,11 +3273,6 @@ NTSTATUS cli_smb2_set_ea_fnum(struct cli_state *cli,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

/* Marshall the SMB2 EA data. */
if (ea_len > 0xFFFF) {
status = NT_STATUS_INVALID_PARAMETER;
Expand Down Expand Up @@ -3441,11 +3348,6 @@ NTSTATUS cli_smb2_set_ea_path(struct cli_state *cli,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

status = get_fnum_from_path(cli,
name,
FILE_WRITE_EA,
Expand Down Expand Up @@ -3505,11 +3407,6 @@ NTSTATUS cli_smb2_get_ea_list_path(struct cli_state *cli,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

status = get_fnum_from_path(cli,
name,
FILE_READ_EA,
Expand Down Expand Up @@ -3606,11 +3503,6 @@ NTSTATUS cli_smb2_get_user_quota(struct cli_state *cli,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

sid_len = ndr_size_dom_sid(&pqt->sid, 0);

query.return_single = 1;
Expand Down Expand Up @@ -3711,11 +3603,6 @@ NTSTATUS cli_smb2_list_user_quota_step(struct cli_state *cli,
goto cleanup;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto cleanup;
}

info.restart_scan = first ? 1 : 0;

err = ndr_push_struct_blob(
Expand Down Expand Up @@ -3784,11 +3671,6 @@ NTSTATUS cli_smb2_get_fs_quota_info(struct cli_state *cli,
goto cleanup;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto cleanup;
}

status = cli_smb2_query_info_fnum(
cli,
quota_fnum,
Expand Down Expand Up @@ -3835,11 +3717,6 @@ NTSTATUS cli_smb2_set_user_quota(struct cli_state *cli,
goto cleanup;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto cleanup;
}

status = build_user_quota_buffer(qtl, 0, talloc_tos(), &inbuf, NULL);
if (!NT_STATUS_IS_OK(status)) {
goto cleanup;
Expand Down Expand Up @@ -3877,11 +3754,6 @@ NTSTATUS cli_smb2_set_fs_quota_info(struct cli_state *cli,
goto cleanup;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto cleanup;
}

status = build_fs_quota_buffer(talloc_tos(), pqt, &inbuf, 0);
if (!NT_STATUS_IS_OK(status)) {
goto cleanup;
Expand Down Expand Up @@ -4578,11 +4450,6 @@ static struct tevent_req *cli_smb2_shadow_copy_data_fnum_send(
return NULL;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return tevent_req_post(req, ev);
}

state->cli = cli;
state->fnum = fnum;

Expand Down Expand Up @@ -4795,11 +4662,6 @@ NTSTATUS cli_smb2_ftruncate(struct cli_state *cli,
goto fail;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
status = NT_STATUS_INVALID_PARAMETER;
goto fail;
}

SBVAL(buf, 0, newsize);

/* setinfo on the handle with info_type SMB2_SETINFO_FILE (1),
Expand Down Expand Up @@ -4850,11 +4712,6 @@ struct tevent_req *cli_smb2_notify_send(
return NULL;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return tevent_req_post(req, ev);
}

status = map_fnum_to_smb2_handle(cli, fnum, &ph);
if (tevent_req_nterror(req, status)) {
return tevent_req_post(req, ev);
Expand Down Expand Up @@ -5051,11 +4908,6 @@ struct tevent_req *cli_smb2_set_reparse_point_fnum_send(
return NULL;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return tevent_req_post(req, ev);
}

state->cli = cli;
state->fnum = fnum;

Expand Down Expand Up @@ -5143,11 +4995,6 @@ struct tevent_req *cli_smb2_get_reparse_point_fnum_send(
return NULL;
}

if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
return tevent_req_post(req, ev);
}

state->cli = cli;
state->fnum = fnum;

Expand Down

0 comments on commit 4388ba4

Please sign in to comment.