r22389: Start preparing for multiple encryption contexts in the
authorJeremy Allison <jra@samba.org>
Thu, 19 Apr 2007 20:50:49 +0000 (20:50 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:19:30 +0000 (12:19 -0500)
server. Allow server to reflect back to calling client
the encryption context that was sent.
Jeremy.
(This used to be commit b49e90335d1e589916b5ab4992e3c4a2d221ca7e)

source3/lib/util.c
source3/libsmb/smb_seal.c
source3/smbd/aio.c
source3/smbd/blocking.c
source3/smbd/process.c
source3/smbd/reply.c

index b1db36c2504f560eae218701c0fa80c2e3c24624..bb92466a05b041986b511d5ebcdd63cc01b51bf6 100644 (file)
@@ -533,14 +533,20 @@ void smb_set_enclen(char *buf,int len,uint16 enc_ctx_num)
  Set the length and marker of an smb packet.
 ********************************************************************/
 
-void smb_setlen(char *buf,int len)
+void smb_setlen(char *buf,int len,const char *frombuf)
 {
        _smb_setlen(buf,len);
 
-       SCVAL(buf,4,0xFF);
-       SCVAL(buf,5,'S');
-       SCVAL(buf,6,'M');
-       SCVAL(buf,7,'B');
+       if (frombuf) {
+               if (buf != frombuf) {
+                       memcpy(buf+4, frombuf+4, 4);
+               }
+       } else {
+               SCVAL(buf,4,0xFF);
+               SCVAL(buf,5,'S');
+               SCVAL(buf,6,'M');
+               SCVAL(buf,7,'B');
+       }
 }
 
 /*******************************************************************
@@ -554,7 +560,7 @@ int set_message(char *buf,int num_words,int num_bytes,BOOL zero)
        }
        SCVAL(buf,smb_wct,num_words);
        SSVAL(buf,smb_vwv + num_words*SIZEOFWORD,num_bytes);  
-       smb_setlen(buf,smb_size + num_words*2 + num_bytes - 4);
+       smb_setlen(buf,smb_size + num_words*2 + num_bytes - 4, NULL);
        return (smb_size + num_words*2 + num_bytes);
 }
 
@@ -566,7 +572,7 @@ int set_message_bcc(char *buf,int num_bytes)
 {
        int num_words = CVAL(buf,smb_wct);
        SSVAL(buf,smb_vwv + num_words*SIZEOFWORD,num_bytes);  
-       smb_setlen(buf,smb_size + num_words*2 + num_bytes - 4);
+       smb_setlen(buf,smb_size + num_words*2 + num_bytes - 4, NULL);
        return (smb_size + num_words*2 + num_bytes);
 }
 
index 19092bd8c84aaf42d253cc27342270bb89e1a981..2e3e2f4ce3c8ee249dada475260527cf2c2dc3bd 100644 (file)
@@ -93,10 +93,11 @@ NTSTATUS common_ntlm_decrypt_buffer(NTLMSSP_STATE *ntlmssp_state, char *buf)
        }
 
        memcpy(buf + 8, inbuf + 8 + NTLMSSP_SIG_SIZE, data_len);
-       SAFE_FREE(inbuf);
 
        /* Reset the length. */
-       smb_setlen(buf, data_len + 4);
+       smb_setlen(buf, data_len + 4, inbuf);
+
+       SAFE_FREE(inbuf);
        return NT_STATUS_OK;
 }
 
@@ -203,7 +204,7 @@ static NTSTATUS common_gss_decrypt_buffer(struct smb_tran_enc_state_gss *gss_sta
        }
 
        memcpy(buf + 8, out_buf.value, out_buf.length);
-       smb_setlen(buf, out_buf.length + 4);
+       smb_setlen(buf, out_buf.length + 4, out_buf.value);
 
        gss_release_buffer(&minor, &out_buf);
        return NT_STATUS_OK;
index a85cf901ae2e3bb2832dc650c05015f654523575..6b403e1e365bc0105935db9d7f6ec29082eb4c2f 100644 (file)
@@ -49,8 +49,10 @@ static struct aio_extra *aio_list_head;
  of the aio_read call.
 *****************************************************************************/
 
-static struct aio_extra *create_aio_ex_read(files_struct *fsp, size_t buflen,
-                                           uint16 mid)
+static struct aio_extra *create_aio_ex_read(files_struct *fsp,
+                                               size_t buflen,
+                                               uint16 mid,
+                                               const char *inbuf)
 {
        struct aio_extra *aio_ex = SMB_MALLOC_P(struct aio_extra);
 
@@ -66,6 +68,14 @@ static struct aio_extra *create_aio_ex_read(files_struct *fsp, size_t buflen,
                SAFE_FREE(aio_ex);
                return NULL;
        }
+       /* Save the first 8 bytes of inbuf for possible enc data. */
+       aio_ex->inbuf = SMB_MALLOC_ARRAY(char, 8);
+       if (!aio_ex->inbuf) {
+               SAFE_FREE(aio_ex->outbuf);
+               SAFE_FREE(aio_ex);
+               return NULL;
+       }
+       memcpy(aio_ex->inbuf, inbuf, 8);
        DLIST_ADD(aio_list_head, aio_ex);
        aio_ex->fsp = fsp;
        aio_ex->read_req = True;
@@ -408,7 +418,7 @@ static int handle_aio_read_complete(struct aio_extra *aio_ex)
                            aio_ex->acb.aio_nbytes, (int)nread ) );
 
        }
-       smb_setlen(outbuf,outsize - 4);
+       smb_setlen(outbuf,outsize - 4,aio_ex->inbuf);
        show_msg(outbuf);
        if (!send_smb(smbd_server_fd(),outbuf)) {
                exit_server_cleanly("handle_aio_read_complete: send_smb "
index 101f16bb9dcdce5f0f5f8f4eb1799da9eddcd222..58953bac11deb19aea2baed076e01df81025d6b7 100644 (file)
@@ -237,13 +237,15 @@ BOOL push_blocking_lock_request( struct byte_range_lock *br_lck,
  Return a smd with a given size.
 *****************************************************************************/
 
-static void send_blocking_reply(char *outbuf, int outsize)
+static void send_blocking_reply(char *outbuf, int outsize, const char *inbuf)
 {
-       if(outsize > 4)
-               smb_setlen(outbuf,outsize - 4);
+       if(outsize > 4) {
+               smb_setlen(outbuf,outsize - 4, inbuf);
+       }
 
-       if (!send_smb(smbd_server_fd(),outbuf))
+       if (!send_smb(smbd_server_fd(),outbuf)) {
                exit_server_cleanly("send_blocking_reply: send_smb failed.");
+       }
 }
 
 /****************************************************************************
@@ -272,7 +274,7 @@ static void reply_lockingX_success(blocking_lock_record *blr)
 
        outsize += chain_size;
 
-       send_blocking_reply(outbuf,outsize);
+       send_blocking_reply(outbuf,outsize,inbuf);
 }
 
 /****************************************************************************
index 6f3ad9884c1ecbc8a998e4f704a82f8198a3ef13..c6bcfb73946eba3cc811887e1b9af238ebb6ac76 100644 (file)
@@ -1039,8 +1039,9 @@ static int construct_reply(char *inbuf,char *outbuf,int size,int bufsize)
 
        outsize += chain_size;
 
-       if(outsize > 4)
-               smb_setlen(outbuf,outsize - 4);
+       if(outsize > 4) {
+               smb_setlen(outbuf,outsize - 4, inbuf);
+       }
        return(outsize);
 }
 
@@ -1219,7 +1220,7 @@ int chain_reply(char *inbuf,char *outbuf,int size,int bufsize)
        }
 
        /* And set it in the header. */
-       smb_setlen(inbuf2, new_size);
+       smb_setlen(inbuf2, new_size, inbuf);
 
        /* create the out buffer */
        construct_reply_common(inbuf2, outbuf2);
index 3d0f8a3ca84c7b514ce99a1ed7648ea8574236aa..1b6f861cb8a156edc7ec9613ca76c794ea590f2b 100644 (file)
@@ -303,7 +303,7 @@ int reply_special(char *inbuf,char *outbuf)
        
        memset(outbuf,'\0',smb_size);
 
-       smb_setlen(outbuf,0);
+       smb_setlen(outbuf,0,inbuf);
        
        switch (msg_type) {
        case 0x81: /* session request */
@@ -1182,7 +1182,7 @@ int reply_search(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
        SSVAL(outbuf,smb_flg2, (SVAL(outbuf, smb_flg2) & (~FLAGS2_UNICODE_STRINGS)));
          
        outsize += DIR_STRUCT_SIZE*numentries;
-       smb_setlen(outbuf,outsize - 4);
+       smb_setlen(outbuf,outsize - 4,inbuf);
   
        if ((! *directory) && dptr_path(dptr_num))
                slprintf(directory, sizeof(directory)-1, "(%s)",dptr_path(dptr_num));
@@ -3538,7 +3538,7 @@ int reply_echo(connection_struct *conn,
        for (seq_num =1 ; seq_num <= smb_reverb ; seq_num++) {
                SSVAL(outbuf,smb_vwv0,seq_num);
 
-               smb_setlen(outbuf,outsize - 4);
+               smb_setlen(outbuf,outsize - 4,inbuf);
 
                show_msg(outbuf);
                if (!send_smb(smbd_server_fd(),outbuf))
@@ -5846,7 +5846,7 @@ int reply_writebmpx(connection_struct *conn, char *inbuf,char *outbuf, int size,
 
        if (write_through && tcount==nwritten) {
                /* We need to send both a primary and a secondary response */
-               smb_setlen(outbuf,outsize - 4);
+               smb_setlen(outbuf,outsize - 4,inbuf);
                show_msg(outbuf);
                if (!send_smb(smbd_server_fd(),outbuf))
                        exit_server_cleanly("reply_writebmpx: send_smb failed.");