More recvfile optimizations

Jeremy Allison jra at samba.org
Thu Apr 10 15:59:08 MDT 2014


On Thu, Apr 10, 2014 at 02:24:42PM -0700, Jeremy Allison wrote:
> On Thu, Apr 10, 2014 at 11:05:14PM +0200, Stefan (metze) Metzmacher wrote:
> > 
> > I don't have a fix.
> > 
> > But we would need such check in is_smb2_recvfile_write(), correct?
> 
> Well, there are two ways of doing it.
> 
> First one is to add the :
> 
> smbd_smb2_request_check_session()
> smbd_smb2_request_check_tcon()
> 
> calls into is_smb2_recvfile_write(), which is
> the same way the SMB1 code does it.

And here is that patch.

Compiles but not yet tested....

I'll have a look at it tomorrow.

Cheers,

	Jeremy.
-------------- next part --------------
diff --git a/source3/smbd/smb2_server.c b/source3/smbd/smb2_server.c
index 3c46efd..b12db9a 100644
--- a/source3/smbd/smb2_server.c
+++ b/source3/smbd/smb2_server.c
@@ -2841,8 +2841,18 @@ static size_t get_min_receive_file_size(struct smbd_smb2_request *smb2_req)
 
 static bool is_smb2_recvfile_write(struct smbd_smb2_request_read_state *state)
 {
+	NTSTATUS status;
+	struct smbXsrv_session *session;
+	struct smbXsrv_tcon *tcon;
+	struct timeval curr;
+	NTTIME now;
+	const uint8_t *inhdr;
 	uint32_t flags;
 
+	if (state->hdr.nbt[0] != 0x00) {
+		/* Not a standard NBT packet. Ignore. */
+		return false;
+	}
 	if (IVAL(state->pktbuf, 0) == SMB2_TF_MAGIC) {
 		/* Transform header. Cannot recvfile. */
 		return false;
@@ -2873,6 +2883,33 @@ static bool is_smb2_recvfile_write(struct smbd_smb2_request_read_state *state)
 		return false;
 	}
 
+	inhdr = SMBD_SMB2_IN_HDR_PTR(state->req);
+	curr = timeval_current();
+	now = timeval_to_nttime(&curr);
+
+	/* Lookup an existing session */
+	status = smb2srv_session_lookup(state->req->sconn->conn,
+					BVAL(inhdr, SMB2_HDR_SESSION_ID),
+					now,
+					&session);
+	if (!NT_STATUS_IS_OK(status)) {
+		return false;
+	}
+
+	/* Now get the tcon. */
+	status = smb2srv_tcon_lookup(session,
+				IVAL(inhdr, SMB2_HDR_TID),
+				now,
+				&tcon);
+	if (!NT_STATUS_IS_OK(status)) {
+		return false;
+	}
+
+	if (IS_IPC(tcon->compat) || IS_PRINT(tcon->compat)) {
+		/* No recvfile on IPC or print. */
+		return false;
+	}
+
 	DEBUG(10,("Doing recvfile write len = %u\n",
 		(unsigned int)(state->pktlen -
 		SMBD_SMB2_SHORT_RECEIVEFILE_WRITE_LEN)));


More information about the samba-technical mailing list