Add the strlen to push to smb_bytes_push_str, return the converted size
[metze/samba/wip.git] / source3 / libsmb / clifile.c
index 733abb6510ce6f2523005440b5c236ba3b51fc83..3b6585b7e79875e88386949f8165f24856e1aede 100644 (file)
@@ -781,12 +781,19 @@ 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 = talloc_get_size(buf);
+       size_t buflen;
        char *converted;
        size_t converted_size;
 
+       if (buf == NULL) {
+               return NULL;
+       }
+
+       buflen = talloc_get_size(buf);
        /*
         * We're pushing into an SMB buffer, align odd
         */
@@ -801,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;
        }
@@ -809,12 +816,18 @@ uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2, const char *str)
        buf = TALLOC_REALLOC_ARRAY(NULL, buf, uint8_t,
                                   buflen + converted_size);
        if (buf == NULL) {
+               TALLOC_FREE(converted);
                return NULL;
        }
 
        memcpy(buf + buflen, converted, converted_size);
 
        TALLOC_FREE(converted);
+
+       if (pconverted_size) {
+               *pconverted_size = converted_size;
+       }
+
        return buf;
 }
 
@@ -884,18 +897,14 @@ 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;
        }
 
        result = cli_request_send(mem_ctx, ev, cli, SMBopenX, additional_flags,
-                                 15, vwv, talloc_get_size(bytes), bytes);
+                                 15, vwv, 0, talloc_get_size(bytes), bytes);
        TALLOC_FREE(bytes);
        return result;
 }
@@ -974,7 +983,7 @@ struct async_req *cli_close_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
        SSVAL(vwv+0, 0, fnum);
        SIVALS(vwv+1, 0, -1);
 
-       return cli_request_send(mem_ctx, ev, cli, SMBclose, 0, 3, vwv,
+       return cli_request_send(mem_ctx, ev, cli, SMBclose, 0, 3, vwv, 0,
                                0, NULL);
 }
 
@@ -1745,7 +1754,7 @@ int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path)
                if (!path2) {
                        return -1;
                }
-               clistr_pull(cli, path2, p,
+               clistr_pull(cli->inbuf, path2, p,
                            len+1, len, STR_ASCII);
                *tmp_path = path2;
        }