s4:smb_server/smb: make use of _smb_setlen_nbt()
[rusty/samba.git] / source4 / smb_server / smb / request.c
index 241c2628572c2fdd1acb9fa8ab41bac92fc302b2..41854a1f0f1bd307af8902ecd09d464bc3a17d8d 100644 (file)
 
 #include "includes.h"
 #include "smb_server/smb_server.h"
-#include "smb_server/service_smb_proto.h"
 #include "smbd/service_stream.h"
 #include "lib/stream/packet.h"
 #include "ntvfs/ntvfs.h"
-#include "param/param.h"
 
 
 /* we over allocate the data buffer to prevent too many realloc calls */
@@ -78,7 +76,7 @@ struct smbsrv_request *smbsrv_init_request(struct smbsrv_connection *smb_conn)
 /*
   setup a chained reply in req->out with the given word count and initial data buffer size. 
 */
-static void req_setup_chain_reply(struct smbsrv_request *req, uint_t wct, uint_t buflen)
+static void req_setup_chain_reply(struct smbsrv_request *req, unsigned int wct, unsigned int buflen)
 {
        uint32_t chain_base_size = req->out.size;
 
@@ -112,7 +110,7 @@ static void req_setup_chain_reply(struct smbsrv_request *req, uint_t wct, uint_t
   the caller will then fill in the command words and data before calling req_send_reply() to 
   send the reply on its way
 */
-void smbsrv_setup_reply(struct smbsrv_request *req, uint_t wct, size_t buflen)
+void smbsrv_setup_reply(struct smbsrv_request *req, unsigned int wct, size_t buflen)
 {
        uint16_t flags2;
 
@@ -235,7 +233,7 @@ int req_max_data(struct smbsrv_request *req)
   To cope with this req->out.ptr is supplied. This will be updated to
   point at the same offset into the packet as before this call
 */
-static void req_grow_allocation(struct smbsrv_request *req, uint_t new_size)
+static void req_grow_allocation(struct smbsrv_request *req, unsigned int new_size)
 {
        int delta;
        uint8_t *buf2;
@@ -313,7 +311,7 @@ void smbsrv_send_reply_nosign(struct smbsrv_request *req)
        }
 
        if (req->out.size > NBT_HDR_SIZE) {
-               _smb_setlen(req->out.buffer, req->out.size - NBT_HDR_SIZE);
+               _smb_setlen_nbt(req->out.buffer, req->out.size - NBT_HDR_SIZE);
        }
 
        blob = data_blob_const(req->out.buffer, req->out.size);
@@ -401,7 +399,7 @@ void smbsrv_send_error(struct smbsrv_request *req, NTSTATUS status)
 size_t req_push_str(struct smbsrv_request *req, uint8_t *dest, const char *str, int dest_len, size_t flags)
 {
        size_t len;
-       uint_t grow_size;
+       unsigned int grow_size;
        uint8_t *buf0;
        const int max_bytes_per_char = 3;
 
@@ -428,7 +426,7 @@ size_t req_push_str(struct smbsrv_request *req, uint8_t *dest, const char *str,
                dest = req->out.buffer + PTR_DIFF(dest, buf0);
        }
 
-       len = push_string(lp_iconv_convenience(req->smb_conn->lp_ctx), dest, str, len, flags);
+       len = push_string(dest, str, len, flags);
 
        grow_size = len + PTR_DIFF(dest, req->out.data);
 
@@ -480,11 +478,12 @@ size_t req_append_var_block(struct smbsrv_request *req,
   on failure zero is returned and *dest is set to NULL, otherwise the number
   of bytes consumed in the packet is returned
 */
-static size_t req_pull_ucs2(struct request_bufinfo *bufinfo, const char **dest, const uint8_t *src, int byte_len, uint_t flags)
+static size_t req_pull_ucs2(struct request_bufinfo *bufinfo, const char **dest, const uint8_t *src, int byte_len, unsigned int flags)
 {
        int src_len, src_len2, alignment=0;
-       ssize_t ret;
+       bool ret;
        char *dest2;
+       size_t converted_size = 0;
 
        if (!(flags & STR_NOALIGN) && ucs2_align(bufinfo->align_base, src, flags)) {
                src++;
@@ -514,9 +513,9 @@ static size_t req_pull_ucs2(struct request_bufinfo *bufinfo, const char **dest,
                return src_len2 + alignment;
        }
 
-       ret = convert_string_talloc(bufinfo->mem_ctx, lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2);
+       ret = convert_string_talloc(bufinfo->mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2, &converted_size);
 
-       if (ret == -1) {
+       if (!ret) {
                *dest = NULL;
                return 0;
        }
@@ -538,11 +537,12 @@ static size_t req_pull_ucs2(struct request_bufinfo *bufinfo, const char **dest,
   on failure zero is returned and *dest is set to NULL, otherwise the number
   of bytes consumed in the packet is returned
 */
-static size_t req_pull_ascii(struct request_bufinfo *bufinfo, const char **dest, const uint8_t *src, int byte_len, uint_t flags)
+static size_t req_pull_ascii(struct request_bufinfo *bufinfo, const char **dest, const uint8_t *src, int byte_len, unsigned int flags)
 {
        int src_len, src_len2;
-       ssize_t ret;
+       bool ret;
        char *dest2;
+       size_t converted_size = 0;
 
        if (flags & STR_NO_RANGE_CHECK) {
                src_len = byte_len;
@@ -563,9 +563,9 @@ static size_t req_pull_ascii(struct request_bufinfo *bufinfo, const char **dest,
                src_len2++;
        }
 
-       ret = convert_string_talloc(bufinfo->mem_ctx, lp_iconv_convenience(global_loadparm), CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2);
+       ret = convert_string_talloc(bufinfo->mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2, &converted_size);
 
-       if (ret == -1) {
+       if (!ret) {
                *dest = NULL;
                return 0;
        }
@@ -587,7 +587,7 @@ static size_t req_pull_ascii(struct request_bufinfo *bufinfo, const char **dest,
   on failure zero is returned and *dest is set to NULL, otherwise the number
   of bytes consumed in the packet is returned
 */
-size_t req_pull_string(struct request_bufinfo *bufinfo, const char **dest, const uint8_t *src, int byte_len, uint_t flags)
+size_t req_pull_string(struct request_bufinfo *bufinfo, const char **dest, const uint8_t *src, int byte_len, unsigned int flags)
 {
        if (!(flags & STR_ASCII) && 
            (((flags & STR_UNICODE) || (bufinfo->flags & BUFINFO_FLAG_UNICODE)))) {
@@ -607,7 +607,7 @@ size_t req_pull_string(struct request_bufinfo *bufinfo, const char **dest, const
   on failure *dest is set to the zero length string. This seems to
   match win2000 behaviour
 */
-size_t req_pull_ascii4(struct request_bufinfo *bufinfo, const char **dest, const uint8_t *src, uint_t flags)
+size_t req_pull_ascii4(struct request_bufinfo *bufinfo, const char **dest, const uint8_t *src, unsigned int flags)
 {
        ssize_t ret;
 
@@ -669,7 +669,7 @@ bool req_data_oob(struct request_bufinfo *bufinfo, const uint8_t *ptr, uint32_t
 /* 
    pull an open file handle from a packet, taking account of the chained_fnum
 */
-static uint16_t req_fnum(struct smbsrv_request *req, const uint8_t *base, uint_t offset)
+static uint16_t req_fnum(struct smbsrv_request *req, const uint8_t *base, unsigned int offset)
 {
        if (req->chained_fnum != -1) {
                return req->chained_fnum;
@@ -677,7 +677,7 @@ static uint16_t req_fnum(struct smbsrv_request *req, const uint8_t *base, uint_t
        return SVAL(base, offset);
 }
 
-struct ntvfs_handle *smbsrv_pull_fnum(struct smbsrv_request *req, const uint8_t *base, uint_t offset)
+struct ntvfs_handle *smbsrv_pull_fnum(struct smbsrv_request *req, const uint8_t *base, unsigned int offset)
 {
        struct smbsrv_handle *handle;
        uint16_t fnum = req_fnum(req, base, offset);
@@ -701,7 +701,7 @@ struct ntvfs_handle *smbsrv_pull_fnum(struct smbsrv_request *req, const uint8_t
        return handle->ntvfs;
 }
 
-void smbsrv_push_fnum(uint8_t *base, uint_t offset, struct ntvfs_handle *ntvfs)
+void smbsrv_push_fnum(uint8_t *base, unsigned int offset, struct ntvfs_handle *ntvfs)
 {
        struct smbsrv_handle *handle = talloc_get_type(ntvfs->frontend_data.private_data,
                                       struct smbsrv_handle);