s3:libsmb/cli*: use CLI_BUFFER_SIZE instead of cli->max_xmit
[metze/samba/wip.git] / source3 / libsmb / clirap.c
index 141db7131e019c317da65dbff02adb4d96fc7019..8e7dc68534792b9d8f0c40d94fee3e879ad08d8e 100644 (file)
 #include "../libcli/auth/libcli_auth.h"
 #include "../librpc/gen_ndr/rap.h"
 #include "../lib/crypto/arcfour.h"
+#include "../lib/util/tevent_ntstatus.h"
 #include "async_smb.h"
+#include "libsmb/libsmb.h"
 #include "libsmb/clirap.h"
+#include "trans2.h"
 
 #define PIPE_LANMAN   "\\PIPE\\LANMAN"
 
@@ -137,7 +140,10 @@ bool cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
 
                if (cli->rap_error == 0) {
                        DEBUG(4,("NetWkstaUserLogon success\n"));
-                       cli->privileges = SVAL(p, 24);
+                       /*
+                        * The cli->privileges = SVAL(p, 24); field was set here
+                        * but it was not use anywhere else.
+                        */
                        /* The cli->eff_name field used to be set here
                           but it wasn't used anywhere else. */
                } else {
@@ -584,7 +590,7 @@ struct tevent_req *cli_qpathinfo1_send(TALLOC_CTX *mem_ctx,
        }
        state->cli = cli;
        subreq = cli_qpathinfo_send(state, ev, cli, fname, SMB_INFO_STANDARD,
-                                   22, cli->max_xmit);
+                                   22, CLI_BUFFER_SIZE);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -686,9 +692,6 @@ NTSTATUS cli_qpathinfo1(struct cli_state *cli,
                                     write_time, size, mode);
  fail:
        TALLOC_FREE(frame);
-       if (!NT_STATUS_IS_OK(status)) {
-               cli_set_error(cli, status);
-       }
        return status;
 }
 
@@ -763,7 +766,7 @@ struct tevent_req *cli_qpathinfo2_send(TALLOC_CTX *mem_ctx,
        }
        subreq = cli_qpathinfo_send(state, ev, cli, fname,
                                    SMB_QUERY_FILE_ALL_INFO,
-                                   68, cli->max_xmit);
+                                   68, CLI_BUFFER_SIZE);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -864,9 +867,6 @@ NTSTATUS cli_qpathinfo2(struct cli_state *cli, const char *fname,
                                     write_time, change_time, size, mode, ino);
  fail:
        TALLOC_FREE(frame);
-       if (!NT_STATUS_IS_OK(status)) {
-               cli_set_error(cli, status);
-       }
        return status;
 }
 
@@ -901,7 +901,7 @@ struct tevent_req *cli_qpathinfo_streams_send(TALLOC_CTX *mem_ctx,
        }
        subreq = cli_qpathinfo_send(state, ev, cli, fname,
                                    SMB_FILE_STREAM_INFORMATION,
-                                   0, cli->max_xmit);
+                                   0, CLI_BUFFER_SIZE);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -978,9 +978,6 @@ NTSTATUS cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
                                            pstreams);
  fail:
        TALLOC_FREE(frame);
-       if (!NT_STATUS_IS_OK(status)) {
-               cli_set_error(cli, status);
-       }
        return status;
 }
 
@@ -1004,7 +1001,7 @@ static bool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *rdata,
                struct stream_struct *tmp;
                uint8_t *tmp_buf;
 
-               tmp = TALLOC_REALLOC_ARRAY(mem_ctx, streams,
+               tmp = talloc_realloc(mem_ctx, streams,
                                           struct stream_struct,
                                           num_streams+1);
 
@@ -1029,7 +1026,7 @@ static bool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *rdata,
                 * convert_string_talloc??
                 */
 
-               tmp_buf = TALLOC_ARRAY(streams, uint8_t, nlen+2);
+               tmp_buf = talloc_array(streams, uint8_t, nlen+2);
                if (tmp_buf == NULL) {
                        goto fail;
                }
@@ -1070,23 +1067,44 @@ static bool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *rdata,
  Send a qfileinfo QUERY_FILE_NAME_INFO call.
 ****************************************************************************/
 
-NTSTATUS cli_qfilename(struct cli_state *cli, uint16_t fnum, char *name,
-                      size_t namelen)
+NTSTATUS cli_qfilename(struct cli_state *cli, uint16_t fnum,
+                      TALLOC_CTX *mem_ctx, char **_name)
 {
+       uint16_t recv_flags2;
        uint8_t *rdata;
        uint32_t num_rdata;
        NTSTATUS status;
+       char *name = NULL;
+       uint32_t namelen;
 
        status = cli_qfileinfo(talloc_tos(), cli, fnum,
                               SMB_QUERY_FILE_NAME_INFO,
-                              4, cli->max_xmit,
+                              4, CLI_BUFFER_SIZE, &recv_flags2,
                               &rdata, &num_rdata);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
 
-       clistr_pull(cli->inbuf, name, rdata+4, namelen, IVAL(rdata, 0),
-                   STR_UNICODE);
+       namelen = IVAL(rdata, 0);
+       if (namelen > (num_rdata - 4)) {
+               TALLOC_FREE(rdata);
+               return NT_STATUS_INVALID_NETWORK_RESPONSE;
+       }
+
+       clistr_pull_talloc(mem_ctx,
+                          (const char *)rdata,
+                          recv_flags2,
+                          &name,
+                          rdata + 4,
+                          namelen,
+                          STR_UNICODE);
+       if (name == NULL) {
+               status = map_nt_error_from_unix(errno);
+               TALLOC_FREE(rdata);
+               return status;
+       }
+
+       *_name = name;
        TALLOC_FREE(rdata);
        return NT_STATUS_OK;
 }
@@ -1115,7 +1133,8 @@ NTSTATUS cli_qfileinfo_basic(struct cli_state *cli, uint16_t fnum,
 
        status = cli_qfileinfo(talloc_tos(), cli, fnum,
                               SMB_QUERY_FILE_ALL_INFO,
-                              68, MIN(cli->max_xmit, 0xffff),
+                              68, CLI_BUFFER_SIZE,
+                              NULL,
                               &rdata, &num_rdata);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -1173,7 +1192,7 @@ struct tevent_req *cli_qpathinfo_basic_send(TALLOC_CTX *mem_ctx,
        }
        subreq = cli_qpathinfo_send(state, ev, cli, fname,
                                    SMB_QUERY_FILE_BASIC_INFO,
-                                   36, cli->max_xmit);
+                                   36, CLI_BUFFER_SIZE);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -1246,9 +1265,6 @@ NTSTATUS cli_qpathinfo_basic(struct cli_state *cli, const char *name,
        status = cli_qpathinfo_basic_recv(req, sbuf, attributes);
  fail:
        TALLOC_FREE(frame);
-       if (!NT_STATUS_IS_OK(status)) {
-               cli_set_error(cli, status);
-       }
        return status;
 }
 
@@ -1267,7 +1283,7 @@ NTSTATUS cli_qpathinfo_alt_name(struct cli_state *cli, const char *fname, fstrin
 
        status = cli_qpathinfo(talloc_tos(), cli, fname,
                               SMB_QUERY_FILE_ALT_NAME_INFO,
-                              4, cli->max_xmit, &rdata, &num_rdata);
+                              4, CLI_BUFFER_SIZE, &rdata, &num_rdata);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }