Skip to content

Commit e0ad56a

Browse files
author
Ronnie Sahlberg
committed
cifs: Add helper function to check smb1+ server
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2151418 commit d291e70 SMB1 server's header_preamble_size is not 0, add use is_smb1 function to simplify the code, no actual functional changes. Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz> Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com> Signed-off-by: Steve French <stfrench@microsoft.com> (cherry picked from commit d291e70) Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
1 parent c8d1dc3 commit e0ad56a

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

fs/cifs/cifsencrypt.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ int __cifs_calc_signature(struct smb_rqst *rqst,
3232
int rc;
3333
struct kvec *iov = rqst->rq_iov;
3434
int n_vec = rqst->rq_nvec;
35-
bool is_smb2 = HEADER_PREAMBLE_SIZE(server) == 0;
3635

3736
/* iov[0] is actual data and not the rfc1002 length for SMB2+ */
38-
if (is_smb2) {
37+
if (!is_smb1(server)) {
3938
if (iov[0].iov_len <= 4)
4039
return -EIO;
4140
i = 0;

fs/cifs/cifsglob.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,11 @@ struct TCP_Server_Info {
749749
#endif
750750
};
751751

752+
static inline bool is_smb1(struct TCP_Server_Info *server)
753+
{
754+
return HEADER_PREAMBLE_SIZE(server) != 0;
755+
}
756+
752757
static inline void cifs_server_lock(struct TCP_Server_Info *server)
753758
{
754759
unsigned int nofs_flag = memalloc_nofs_save();

fs/cifs/connect.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ smb2_get_credits_from_hdr(char *buffer, struct TCP_Server_Info *server)
848848
/*
849849
* SMB1 does not use credits.
850850
*/
851-
if (HEADER_PREAMBLE_SIZE(server))
851+
if (is_smb1(server))
852852
return 0;
853853

854854
return le16_to_cpu(shdr->CreditRequest);
@@ -1098,7 +1098,7 @@ smb2_add_credits_from_hdr(char *buffer, struct TCP_Server_Info *server)
10981098
/*
10991099
* SMB1 does not use credits.
11001100
*/
1101-
if (HEADER_PREAMBLE_SIZE(server))
1101+
if (is_smb1(server))
11021102
return;
11031103

11041104
if (shdr->CreditRequest) {
@@ -1156,10 +1156,10 @@ cifs_demultiplex_thread(void *p)
11561156
if (length < 0)
11571157
continue;
11581158

1159-
if (HEADER_PREAMBLE_SIZE(server) == 0)
1160-
server->total_read = 0;
1161-
else
1159+
if (is_smb1(server))
11621160
server->total_read = length;
1161+
else
1162+
server->total_read = 0;
11631163

11641164
/*
11651165
* The right amount was read from socket - 4 bytes,

fs/cifs/transport.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ smb_rqst_len(struct TCP_Server_Info *server, struct smb_rqst *rqst)
266266
int nvec;
267267
unsigned long buflen = 0;
268268

269-
if (HEADER_PREAMBLE_SIZE(server) == 0 && rqst->rq_nvec >= 2 &&
269+
if (!is_smb1(server) && rqst->rq_nvec >= 2 &&
270270
rqst->rq_iov[0].iov_len == 4) {
271271
iov = &rqst->rq_iov[1];
272272
nvec = rqst->rq_nvec - 1;
@@ -351,7 +351,7 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
351351
sigprocmask(SIG_BLOCK, &mask, &oldmask);
352352

353353
/* Generate a rfc1002 marker for SMB2+ */
354-
if (HEADER_PREAMBLE_SIZE(server) == 0) {
354+
if (!is_smb1(server)) {
355355
struct kvec hiov = {
356356
.iov_base = &rfc1002_marker,
357357
.iov_len = 4

0 commit comments

Comments
 (0)