dce/rpc thing

Ronan Waide waider at waider.ie
Wed Apr 16 09:51:45 GMT 2003


On April 16, jra at dp.samba.org said:
> This code and the schannel stuff is actively being worked on at the
> SambaXP hack-fest in Germany.... Please keep cvs updating, some
> things will change.

Cool... here, let me contribute!

whitespace-ignorant diff against CVS as of about 5 minutes ago; the
whitespace ignorance is because I accidentally reindented an entire
function that I'd only changed one or two lines in. patch -l should
cope. Changes:

* Adds a 'remain' parameter to cli_issue_write. Having spent too much
  time watching packet traces, it appears that this field is the
  max_xmit_frag size minus however much data we've sent of the current
  PDU.

* Sets one of the "reserved" fields to 0xFFFFFFFF rather than
  0x00000000. This is entirely cosmetic; 0xFFFFFFFF was observed in
  WinNT4 and Win2K, and I haven't seen 0x0 for the same field in any
  traces just yet. Can be safely disregarded (it's in the second block
  of the patch below, but watch out for the 'remain' patch also in
  that block

* Adds some PIPE_RAW_MODE handling in cli_write. This can be
  disregarded, it just happens to be in my codebase right now. All it
  does is tweaks the first block in appropriate ways to cater for the
  two-byte PDU-length header

* Calculates and adds the 'remain' parameter to the call to cli_write

* Switches off the PIPE_START_MESSAGE bit after the first block of the
  PDU has been sent, since that's what it's flagging.

* Moves the cli_receive_smb() inside the cli_issue_write loop, so that
  the code waits for a WriteAndX response for each WriteAndX request
  it sends, rather than sending an entire PDU in several WriteAndX
  requests and then collecting a bunch of replies. This also turns up
  errors a little faster.

Cheers,
Waider.

Index: source/libsmb/clireadwrite.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/clireadwrite.c,v
retrieving revision 1.24
diff -u -B -b -t -w -r1.24 clireadwrite.c
--- source/libsmb/clireadwrite.c	2 Jan 2003 09:07:04 -0000	1.24
+++ source/libsmb/clireadwrite.c	16 Apr 2003 08:42:09 -0000
@@ -250,7 +250,7 @@
 
 static BOOL cli_issue_write(struct cli_state *cli, int fnum, off_t offset, 
                             uint16 mode, const char *buf,
-                            size_t size, int i)
+                            size_t size, int i, size_t remain)
 {
         char *p;
         BOOL bigoffset = False;
@@ -282,10 +282,11 @@
         SSVAL(cli->outbuf,smb_vwv2,fnum);
 
         SIVAL(cli->outbuf,smb_vwv3,offset);
-        SIVAL(cli->outbuf,smb_vwv5,0);
+        SIVAL(cli->outbuf,smb_vwv5,0xFFFFFFFF);
         SSVAL(cli->outbuf,smb_vwv7,mode);
 
-        SSVAL(cli->outbuf,smb_vwv8,(mode & 0x0008) ? size : 0);
+     SSVAL(cli->outbuf,smb_vwv8,remain);
+
         /*
          * According to CIFS-TR-1p00, this following field should only
          * be set if CAP_LARGE_WRITEX is set. We should check this
@@ -328,9 +329,9 @@
         int mpx = MAX(cli->max_mux-1, 1);
         int block = (cli->max_xmit - (smb_size+32)) & ~1023;
         int blocks = (size + (block-1)) / block;
+        size_t remain = cli->max_xmit_frag;
 
         while (received < blocks) {
-
                 while ((issued - received < mpx) && (issued < blocks)) {
                         int bsent = issued * block;
                         int size1 = MIN(block, size - bsent);
@@ -335,12 +336,24 @@
                         int bsent = issued * block;
                         int size1 = MIN(block, size - bsent);
 
-                        if (!cli_issue_write(cli, fnum, offset + bsent,
+                        if ( write_mode & PIPE_RAW_MODE ) {
+                                if ( bsent )
+                                        bsent += 2;
+                                else
+                                        size1 += 2;
+                        }
+                        
+                        if (!cli_issue_write(cli, fnum, offset + (block * issued),
                                         write_mode,
                                         buf + bsent,
-                                        size1, issued))
+                                             size1, issued, remain))
                                 return -1;
                         issued++;
+                        remain -= block;
+                        
+                        /* PIPE_START_MESSAGE should only be set in first packet */
+                        if ( write_mode & PIPE_START_MESSAGE ) {
+                                write_mode &= ~PIPE_START_MESSAGE;
                 }
 
                 if (!cli_receive_smb(cli))
@@ -354,6 +367,7 @@
                 bwritten += SVAL(cli->inbuf, smb_vwv2);
                 bwritten += (((int)(SVAL(cli->inbuf, smb_vwv4)))>>16);
         }
+        }
 
         while (received < issued && cli_receive_smb(cli))
                 received++;

-- 
waider at waider.ie / Yes, it /is/ very personal of me.

"i *have* to purchase more memory. every time someone tells me a new joke,
 i forget where i live." - Nikolai Kingsley


More information about the samba-technical mailing list