]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Factor out create_outbuf, creating an outbuf just given an inbuf
authorVolker Lendecke <vl@samba.org>
Wed, 2 Apr 2008 13:34:29 +0000 (15:34 +0200)
committerVolker Lendecke <vl@samba.org>
Sat, 28 Jun 2008 08:38:51 +0000 (10:38 +0200)
source/include/proto.h
source/smbd/process.c

index 81cf2dbf4f6f58e7d469477e884e69d521be4796..783688e48663f07f3961d7fbaf96b2bd30df8427 100644 (file)
@@ -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);
index 71e38634b70ace96f0212d74f9bc56b242d86c9b..da1165219b52c537f29a6c6bbeff3a65822e3448 100644 (file)
@@ -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;
 }