Commit 4276d496 authored by Pavel Shilovsky's avatar Pavel Shilovsky Committed by Thadeu Lima de Souza Cascardo

CIFS: Add capability to transform requests before sending

BugLink: http://bugs.launchpad.net/bugs/1670508

This will allow us to do protocol specific tranformations of packets
before sending to the server. For SMB3 it can be used to support
encryption.
Signed-off-by: default avatarPavel Shilovsky <pshilov@microsoft.com>
(cherry picked from commit 7fb8986e)
Signed-off-by: default avatarJoseph Salisbury <joseph.salisbury@canonical.com>
parent cc85b775
...@@ -431,6 +431,11 @@ struct smb_version_operations { ...@@ -431,6 +431,11 @@ struct smb_version_operations {
bool (*dir_needs_close)(struct cifsFileInfo *); bool (*dir_needs_close)(struct cifsFileInfo *);
long (*fallocate)(struct file *, struct cifs_tcon *, int, loff_t, long (*fallocate)(struct file *, struct cifs_tcon *, int, loff_t,
loff_t); loff_t);
/* init transform request - used for encryption for now */
int (*init_transform_rq)(struct TCP_Server_Info *, struct smb_rqst *,
struct smb_rqst *);
/* free transform request */
void (*free_transform_rq)(struct smb_rqst *);
}; };
struct smb_version_values { struct smb_version_values {
...@@ -1467,7 +1472,9 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param, ...@@ -1467,7 +1472,9 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param,
#define CIFS_OBREAK_OP 0x0100 /* oplock break request */ #define CIFS_OBREAK_OP 0x0100 /* oplock break request */
#define CIFS_NEG_OP 0x0200 /* negotiate request */ #define CIFS_NEG_OP 0x0200 /* negotiate request */
#define CIFS_OP_MASK 0x0380 /* mask request type */ #define CIFS_OP_MASK 0x0380 /* mask request type */
#define CIFS_HAS_CREDITS 0x0400 /* already has credits */ #define CIFS_HAS_CREDITS 0x0400 /* already has credits */
#define CIFS_TRANSFORM_REQ 0x0800 /* transform request before sending */
/* Security Flags: indicate type of session setup needed */ /* Security Flags: indicate type of session setup needed */
#define CIFSSEC_MAY_SIGN 0x00001 #define CIFSSEC_MAY_SIGN 0x00001
......
This diff is collapsed.
...@@ -291,7 +291,7 @@ rqst_len(struct smb_rqst *rqst) ...@@ -291,7 +291,7 @@ rqst_len(struct smb_rqst *rqst)
} }
static int static int
smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst) __smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
{ {
int rc; int rc;
struct kvec *iov = rqst->rq_iov; struct kvec *iov = rqst->rq_iov;
...@@ -371,12 +371,27 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst) ...@@ -371,12 +371,27 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
} }
static int static int
smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst, int flags)
{ {
struct smb_rqst rqst = { .rq_iov = iov, struct smb_rqst cur_rqst;
.rq_nvec = n_vec }; int rc;
if (!(flags & CIFS_TRANSFORM_REQ))
return __smb_send_rqst(server, rqst);
if (!server->ops->init_transform_rq ||
!server->ops->free_transform_rq) {
cifs_dbg(VFS, "Encryption requested but transform callbacks are missed\n");
return -EIO;
}
return smb_send_rqst(server, &rqst); rc = server->ops->init_transform_rq(server, &cur_rqst, rqst);
if (rc)
return rc;
rc = __smb_send_rqst(server, &cur_rqst);
server->ops->free_transform_rq(&cur_rqst);
return rc;
} }
int int
...@@ -384,13 +399,15 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, ...@@ -384,13 +399,15 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer,
unsigned int smb_buf_length) unsigned int smb_buf_length)
{ {
struct kvec iov[2]; struct kvec iov[2];
struct smb_rqst rqst = { .rq_iov = iov,
.rq_nvec = 2 };
iov[0].iov_base = smb_buffer; iov[0].iov_base = smb_buffer;
iov[0].iov_len = 4; iov[0].iov_len = 4;
iov[1].iov_base = (char *)smb_buffer + 4; iov[1].iov_base = (char *)smb_buffer + 4;
iov[1].iov_len = smb_buf_length; iov[1].iov_len = smb_buf_length;
return smb_sendv(server, iov, 2); return __smb_send_rqst(server, &rqst);
} }
static int static int
...@@ -582,7 +599,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, ...@@ -582,7 +599,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst,
cifs_in_send_inc(server); cifs_in_send_inc(server);
rc = smb_send_rqst(server, rqst); rc = smb_send_rqst(server, rqst, flags);
cifs_in_send_dec(server); cifs_in_send_dec(server);
cifs_save_when_sent(mid); cifs_save_when_sent(mid);
...@@ -776,7 +793,7 @@ cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, ...@@ -776,7 +793,7 @@ cifs_send_recv(const unsigned int xid, struct cifs_ses *ses,
midQ->mid_state = MID_REQUEST_SUBMITTED; midQ->mid_state = MID_REQUEST_SUBMITTED;
cifs_in_send_inc(ses->server); cifs_in_send_inc(ses->server);
rc = smb_send_rqst(ses->server, rqst); rc = smb_send_rqst(ses->server, rqst, flags);
cifs_in_send_dec(ses->server); cifs_in_send_dec(ses->server);
cifs_save_when_sent(midQ); cifs_save_when_sent(midQ);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment