Add the strlen to push to smb_bytes_push_str, return the converted size
authorVolker Lendecke <vl@samba.org>
Mon, 26 Jan 2009 19:45:09 +0000 (20:45 +0100)
committerVolker Lendecke <vl@samba.org>
Thu, 29 Jan 2009 20:38:06 +0000 (21:38 +0100)
The pushed strlen replaces the STR_TERMINATE flag which I personally always
find very confusing.

source3/include/proto.h
source3/libsmb/cliconnect.c
source3/libsmb/clifile.c
source3/libsmb/clitrans.c

index e2aeb197d087a504c867ad8e977376eef7bfe83c..e00d644852a070bdda0e8b91b043aef4a4b54360 100644 (file)
@@ -2501,7 +2501,8 @@ int cli_nt_create_full(struct cli_state *cli, const char *fname,
                 uint32 CreateDisposition, uint32 CreateOptions,
                 uint8 SecuityFlags);
 int cli_nt_create(struct cli_state *cli, const char *fname, uint32 DesiredAccess);
-uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2, const char *str);
+uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2, const char *str,
+                           size_t strlen, size_t *pconverted_size);
 struct async_req *cli_open_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
                                struct cli_state *cli,
                                const char *fname, int flags, int share_mode);
index bc690f2e02be44fdc1e4763f15b7db7a73f4211b..5778e7f6a39b3d68de446d5704e8fbb4d256d9d0 100644 (file)
@@ -1294,7 +1294,10 @@ struct async_req *cli_negprot_send(TALLOC_CTX *mem_ctx,
                if (bytes == NULL) {
                        return NULL;
                }
-               bytes = smb_bytes_push_str(bytes, false, prots[numprots].name);
+               bytes = smb_bytes_push_str(bytes, false,
+                                          prots[numprots].name,
+                                          strlen(prots[numprots].name)+1,
+                                          NULL);
                if (bytes == NULL) {
                        return NULL;
                }
index 02cd2108bf2878af1a314720bb87617fa048860d..3b6585b7e79875e88386949f8165f24856e1aede 100644 (file)
@@ -781,7 +781,9 @@ int cli_nt_create(struct cli_state *cli, const char *fname, uint32 DesiredAccess
                                FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0);
 }
 
-uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2, const char *str)
+uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2,
+                           const char *str, size_t str_len,
+                           size_t *pconverted_size)
 {
        size_t buflen;
        char *converted;
@@ -806,7 +808,7 @@ uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2, const char *str)
 
        if (!convert_string_allocate(talloc_tos(), CH_UNIX,
                                     ucs2 ? CH_UTF16LE : CH_DOS,
-                                    str, strlen(str)+1, &converted,
+                                    str, str_len, &converted,
                                     &converted_size, true)) {
                return NULL;
        }
@@ -821,6 +823,11 @@ uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2, const char *str)
        memcpy(buf + buflen, converted, converted_size);
 
        TALLOC_FREE(converted);
+
+       if (pconverted_size) {
+               *pconverted_size = converted_size;
+       }
+
        return buf;
 }
 
@@ -890,12 +897,8 @@ struct async_req *cli_open_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
        }
 
        bytes = talloc_array(talloc_tos(), uint8_t, 0);
-       if (bytes == NULL) {
-               return NULL;
-       }
-
-       bytes = smb_bytes_push_str(
-               bytes, (cli->capabilities & CAP_UNICODE) != 0, fname);
+       bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,
+                                  strlen(fname)+1, NULL);
        if (bytes == NULL) {
                return NULL;
        }
index baa73aeb14e199c03754d028b14af30558ed9f1b..4a0fc5f6e91f4f1979d28479ff956229984ace60 100644 (file)
@@ -765,9 +765,9 @@ static struct async_req *cli_ship_trans(TALLOC_CTX *mem_ctx,
                if (bytes == NULL) {
                        goto fail;
                }
-               bytes = smb_bytes_push_str(
-                       bytes, (state->cli->capabilities & CAP_UNICODE) != 0,
-                       state->pipe_name);
+               bytes = smb_bytes_push_str(bytes, cli_ucs2(state->cli),
+                                          state->pipe_name,
+                                          strlen(state->pipe_name)+1, NULL);
                if (bytes == NULL) {
                        goto fail;
                }