samba-cvs.cvs
[Top] [All Lists]

[SCM] Samba Shared Repository - branch v3-3-test updated - release-3-2-0

Subject: [SCM] Samba Shared Repository - branch v3-3-test updated - release-3-2-0pre2-3044-gd3facf4
From: Volker Lendecke
Date: Sat, 28 Jun 2008 03:55:12 -0500 CDT
The branch, v3-3-test has been updated
       via  d3facf4cbdb2915168e91d64c2d8320f67524df8 (commit)
       via  50427cbf6345d3f671e9ea321089c4b4244df972 (commit)
      from  242077f714c738642edd125449ab5c89748bcecd (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-3-test


- Log -----------------------------------------------------------------
commit d3facf4cbdb2915168e91d64c2d8320f67524df8
Author: Volker Lendecke <vl@xxxxxxxxx>
Date:   Wed Apr 2 15:55:10 2008 +0200

    Let send_trans_reply work on only the inbuf
    
    It does not really need the whole smb_request

commit 50427cbf6345d3f671e9ea321089c4b4244df972
Author: Volker Lendecke <vl@xxxxxxxxx>
Date:   Wed Apr 2 15:34:29 2008 +0200

    Factor out create_outbuf, creating an outbuf just given an inbuf

-----------------------------------------------------------------------

Summary of changes:
 source/include/proto.h |    4 +-
 source/smbd/ipc.c      |  107 ++++++++++++++++++++++++-----------------------
 source/smbd/lanman.c   |    2 +-
 source/smbd/process.c  |   29 +++++++++----
 4 files changed, 79 insertions(+), 63 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/include/proto.h b/source/include/proto.h
index 81cf2db..13f392d 100644
--- a/source/include/proto.h
+++ b/source/include/proto.h
@@ -9727,7 +9727,7 @@ NTSTATUS dup_file_fsp(files_struct *fsp,
 /* The following definitions come from smbd/ipc.c  */
 
 void send_trans_reply(connection_struct *conn,
-                       struct smb_request *req,
+                     const uint8_t *inbuf,
                      char *rparam, int rparam_len,
                      char *rdata, int rdata_len,
                      bool buffer_too_large);
@@ -10066,6 +10066,8 @@ struct idle_event *event_add_idle(struct event_context 
*event_ctx,
                                  void *private_data);
 NTSTATUS allow_new_trans(struct trans_state *list, int mid);
 void respond_to_all_remaining_local_messages(void);
+bool create_outbuf(TALLOC_CTX *mem_ctx, const char *inbuf, char **outbuf,
+                  uint8_t num_words, uint32_t num_bytes);
 void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes);
 const char *smb_fn_name(int type);
 void add_to_common_flags2(uint32 v);
diff --git a/source/smbd/ipc.c b/source/smbd/ipc.c
index 59a5dfd..f4c4599 100644
--- a/source/smbd/ipc.c
+++ b/source/smbd/ipc.c
@@ -81,8 +81,7 @@ static void copy_trans_params_and_data(char *outbuf, int 
align,
  Send a trans reply.
  ****************************************************************************/
 
-void send_trans_reply(connection_struct *conn,
-                       struct smb_request *req,
+void send_trans_reply(connection_struct *conn, const uint8_t *inbuf,
                      char *rparam, int rparam_len,
                      char *rdata, int rdata_len,
                      bool buffer_too_large)
@@ -91,6 +90,7 @@ void send_trans_reply(connection_struct *conn,
        int tot_data_sent = 0;
        int tot_param_sent = 0;
        int align;
+       char *outbuf;
 
        int ldata  = rdata  ? rdata_len : 0;
        int lparam = rparam ? rparam_len : 0;
@@ -103,47 +103,48 @@ void send_trans_reply(connection_struct *conn,
 
        align = ((this_lparam)%4);
 
-       reply_outbuf(req, 10, 1+align+this_ldata+this_lparam);
+       if (!create_outbuf(talloc_tos(), (char *)inbuf, &outbuf,
+                          10, 1+align+this_ldata+this_lparam)) {
+               smb_panic("could not allocate outbuf");
+       }
 
-       copy_trans_params_and_data((char *)req->outbuf, align,
+       copy_trans_params_and_data(outbuf, align,
                                rparam, tot_param_sent, this_lparam,
                                rdata, tot_data_sent, this_ldata);
 
-       SSVAL(req->outbuf,smb_vwv0,lparam);
-       SSVAL(req->outbuf,smb_vwv1,ldata);
-       SSVAL(req->outbuf,smb_vwv3,this_lparam);
-       SSVAL(req->outbuf,smb_vwv4,smb_offset(smb_buf(req->outbuf)+1,
-                                             req->outbuf));
-       SSVAL(req->outbuf,smb_vwv5,0);
-       SSVAL(req->outbuf,smb_vwv6,this_ldata);
-       SSVAL(req->outbuf,smb_vwv7,smb_offset(smb_buf(req->outbuf)+1+
-                                             this_lparam+align,
-                                             req->outbuf));
-       SSVAL(req->outbuf,smb_vwv8,0);
-       SSVAL(req->outbuf,smb_vwv9,0);
+       SSVAL(outbuf,smb_vwv0,lparam);
+       SSVAL(outbuf,smb_vwv1,ldata);
+       SSVAL(outbuf,smb_vwv3,this_lparam);
+       SSVAL(outbuf,smb_vwv4,smb_offset(smb_buf(outbuf)+1,outbuf));
+       SSVAL(outbuf,smb_vwv5,0);
+       SSVAL(outbuf,smb_vwv6,this_ldata);
+       SSVAL(outbuf,smb_vwv7,smb_offset(smb_buf(outbuf)+1+this_lparam+align,
+                                        outbuf));
+       SSVAL(outbuf,smb_vwv8,0);
+       SSVAL(outbuf,smb_vwv9,0);
 
        if (buffer_too_large) {
-               error_packet_set((char *)req->outbuf,
-                                ERRDOS, ERRmoredata,
-                                STATUS_BUFFER_OVERFLOW,
-                                __LINE__, __FILE__);
+               error_packet_set((char *)outbuf, ERRDOS, ERRmoredata,
+                                STATUS_BUFFER_OVERFLOW, __LINE__, __FILE__);
        }
 
-       show_msg((char *)req->outbuf);
-       if (!srv_send_smb(smbd_server_fd(),
-                       (char *)req->outbuf,
-                       IS_CONN_ENCRYPTED(conn)))
+       show_msg(outbuf);
+       if (!srv_send_smb(smbd_server_fd(), (char *)outbuf,
+                         IS_CONN_ENCRYPTED(conn))) {
                exit_server_cleanly("send_trans_reply: srv_send_smb failed.");
+       }
 
-       TALLOC_FREE(req->outbuf);
+       TALLOC_FREE(outbuf);
 
        tot_data_sent = this_ldata;
        tot_param_sent = this_lparam;
 
        while (tot_data_sent < ldata || tot_param_sent < lparam)
        {
-               this_lparam = MIN(lparam-tot_param_sent, max_send - 500); /* 
hack */
-               this_ldata  = MIN(ldata -tot_data_sent, max_send - 
(500+this_lparam));
+               this_lparam = MIN(lparam-tot_param_sent,
+                                 max_send - 500); /* hack */
+               this_ldata  = MIN(ldata -tot_data_sent,
+                                 max_send - (500+this_lparam));
 
                if(this_lparam < 0)
                        this_lparam = 0;
@@ -153,39 +154,39 @@ void send_trans_reply(connection_struct *conn,
 
                align = (this_lparam%4);
 
-               reply_outbuf(req, 10, 1+this_ldata+this_lparam+align);
+               if (!create_outbuf(talloc_tos(), (char *)inbuf, &outbuf,
+                                  10, 1+align+this_ldata+this_lparam)) {
+                       smb_panic("could not allocate outbuf");
+               }
 
-               copy_trans_params_and_data((char *)req->outbuf, align,
+               copy_trans_params_and_data(outbuf, align,
                                           rparam, tot_param_sent, this_lparam,
                                           rdata, tot_data_sent, this_ldata);
                
-               SSVAL(req->outbuf,smb_vwv3,this_lparam);
-               SSVAL(req->outbuf,smb_vwv4,smb_offset(smb_buf(req->outbuf)+1,
-                                                     req->outbuf));
-               SSVAL(req->outbuf,smb_vwv5,tot_param_sent);
-               SSVAL(req->outbuf,smb_vwv6,this_ldata);
-               SSVAL(req->outbuf,smb_vwv7,smb_offset(smb_buf(req->outbuf)+1+
-                                                     this_lparam+align,
-                                                     req->outbuf));
-               SSVAL(req->outbuf,smb_vwv8,tot_data_sent);
-               SSVAL(req->outbuf,smb_vwv9,0);
+               SSVAL(outbuf,smb_vwv3,this_lparam);
+               SSVAL(outbuf,smb_vwv4,smb_offset(smb_buf(outbuf)+1,outbuf));
+               SSVAL(outbuf,smb_vwv5,tot_param_sent);
+               SSVAL(outbuf,smb_vwv6,this_ldata);
+               SSVAL(outbuf,smb_vwv7,
+                     smb_offset(smb_buf(outbuf)+1+this_lparam+align, outbuf));
+               SSVAL(outbuf,smb_vwv8,tot_data_sent);
+               SSVAL(outbuf,smb_vwv9,0);
 
                if (buffer_too_large) {
-                       error_packet_set((char *)req->outbuf,
-                                        ERRDOS, ERRmoredata,
+                       error_packet_set(outbuf, ERRDOS, ERRmoredata,
                                         STATUS_BUFFER_OVERFLOW,
                                         __LINE__, __FILE__);
                }
 
-               show_msg((char *)req->outbuf);
-               if (!srv_send_smb(smbd_server_fd(),
-                               (char *)req->outbuf,
-                               IS_CONN_ENCRYPTED(conn)))
-                       exit_server_cleanly("send_trans_reply: srv_send_smb 
failed.");
+               show_msg(outbuf);
+               if (!srv_send_smb(smbd_server_fd(), outbuf,
+                                 IS_CONN_ENCRYPTED(conn)))
+                       exit_server_cleanly("send_trans_reply: srv_send_smb "
+                                           "failed.");
 
                tot_data_sent  += this_ldata;
                tot_param_sent += this_lparam;
-               TALLOC_FREE(req->outbuf);
+               TALLOC_FREE(outbuf);
        }
 }
 
@@ -212,7 +213,8 @@ static void api_rpc_trans_reply(connection_struct *conn, 
struct smb_request *req
                return;
        }
 
-       send_trans_reply(conn, req, NULL, 0, rdata, data_len, 
is_data_outstanding);
+       send_trans_reply(conn, req->inbuf, NULL, 0, rdata, data_len,
+                        is_data_outstanding);
        SAFE_FREE(rdata);
        return;
 }
@@ -236,7 +238,7 @@ static void api_WNPHS(connection_struct *conn, struct 
smb_request *req, smb_np_s
 
        if (wait_rpc_pipe_hnd_state(p, priority)) {
                /* now send the reply */
-               send_trans_reply(conn, req, NULL, 0, NULL, 0, False);
+               send_trans_reply(conn, req->inbuf, NULL, 0, NULL, 0, False);
                return;
        }
        api_no_reply(conn,req);
@@ -262,7 +264,7 @@ static void api_SNPHS(connection_struct *conn, struct 
smb_request *req, smb_np_s
 
        if (set_rpc_pipe_hnd_state(p, id)) {
                /* now send the reply */
-               send_trans_reply(conn, req, NULL, 0, NULL, 0, False);
+               send_trans_reply(conn, req->inbuf, NULL, 0, NULL, 0, False);
                return;
        }
        api_no_reply(conn,req);
@@ -284,7 +286,7 @@ static void api_no_reply(connection_struct *conn, struct 
smb_request *req)
        DEBUG(3,("Unsupported API fd command\n"));
 
        /* now send the reply */
-       send_trans_reply(conn, req, rparam, 4, NULL, 0, False);
+       send_trans_reply(conn, req->inbuf, rparam, 4, NULL, 0, False);
 
        return;
 }
@@ -326,7 +328,8 @@ static void api_fd_reply(connection_struct *conn, uint16 
vuid,
                        /* Win9x does this call with a unicode pipe name, not a 
pnum. */
                        /* Just return success for now... */
                        DEBUG(3,("Got TRANSACT_WAITNAMEDPIPEHANDLESTATE on text 
pipe name\n"));
-                       send_trans_reply(conn, req, NULL, 0, NULL, 0, False);
+                       send_trans_reply(conn, req->inbuf, NULL, 0, NULL, 0,
+                                        False);
                        return;
                }
 
diff --git a/source/smbd/lanman.c b/source/smbd/lanman.c
index 03a48f5..fe1d766 100644
--- a/source/smbd/lanman.c
+++ b/source/smbd/lanman.c
@@ -4632,7 +4632,7 @@ void api_reply(connection_struct *conn, uint16 vuid,
 
        /* If api_Unsupported returns false we can't return anything. */
        if (reply) {
-               send_trans_reply(conn, req, rparam, rparam_len,
+               send_trans_reply(conn, req->inbuf, rparam, rparam_len,
                                 rdata, rdata_len, False);
        }
 
diff --git a/source/smbd/process.c b/source/smbd/process.c
index 71e3863..da11652 100644
--- a/source/smbd/process.c
+++ b/source/smbd/process.c
@@ -1245,7 +1245,8 @@ static const struct smb_message_struct {
  allocate and initialize a reply packet
 ********************************************************************/
 
-void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes)
+bool create_outbuf(TALLOC_CTX *mem_ctx, const char *inbuf, char **outbuf,
+                  uint8_t num_words, uint32_t num_bytes)
 {
        /*
          * Protect against integer wrap
@@ -1260,23 +1261,33 @@ void reply_outbuf(struct smb_request *req, uint8 
num_words, uint32 num_bytes)
                smb_panic(msg);
        }
 
-       if (!(req->outbuf = TALLOC_ARRAY(
-                     req, uint8,
-                     smb_size + num_words*2 + num_bytes))) {
-               smb_panic("could not allocate output buffer\n");
+       *outbuf = TALLOC_ARRAY(mem_ctx, char,
+                              smb_size + num_words*2 + num_bytes);
+       if (*outbuf == NULL) {
+               return false;
        }
 
-       construct_reply_common((char *)req->inbuf, (char *)req->outbuf);
-       srv_set_message((char *)req->outbuf, num_words, num_bytes, false);
+       construct_reply_common(inbuf, *outbuf);
+       srv_set_message(*outbuf, num_words, num_bytes, false);
        /*
         * Zero out the word area, the caller has to take care of the bcc area
         * himself
         */
        if (num_words != 0) {
-               memset(req->outbuf + smb_vwv0, 0, num_words*2);
+               memset(*outbuf + smb_vwv0, 0, num_words*2);
        }
 
-       return;
+       return true;
+}
+
+void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes)
+{
+       char *outbuf;
+       if (!create_outbuf(req, (char *)req->inbuf, &outbuf, num_words,
+                          num_bytes)) {
+               smb_panic("could not allocate output buffer\n");
+       }
+       req->outbuf = (uint8_t *)outbuf;
 }
 
 


-- 
Samba Shared Repository

<Prev in Thread] Current Thread [Next in Thread>
  • [SCM] Samba Shared Repository - branch v3-3-test updated - release-3-2-0pre2-3044-gd3facf4, Volker Lendecke <=