Clean up assignments to iov_base, ensure it's always cast to void *. This should...
[samba.git] / source3 / libsmb / cliconnect.c
index 34c0825c079f6546b67d6ddd4c03de2d4b020cc1..38985363c2e67846193293e1a8f7ada53daf5922 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "includes.h"
+#include "../libcli/auth/libcli_auth.h"
 
 static const struct {
        int prot;
@@ -168,13 +169,15 @@ static uint32 cli_session_setup_capabilities(struct cli_state *cli)
 struct cli_session_setup_guest_state {
        struct cli_state *cli;
        uint16_t vwv[16];
+       struct iovec bytes;
 };
 
 static void cli_session_setup_guest_done(struct tevent_req *subreq);
 
-struct tevent_req *cli_session_setup_guest_send(TALLOC_CTX *mem_ctx,
-                                               struct event_context *ev,
-                                               struct cli_state *cli)
+struct tevent_req *cli_session_setup_guest_create(TALLOC_CTX *mem_ctx,
+                                                 struct event_context *ev,
+                                                 struct cli_state *cli,
+                                                 struct tevent_req **psmbreq)
 {
        struct tevent_req *req, *subreq;
        struct cli_session_setup_guest_state *state;
@@ -211,16 +214,36 @@ struct tevent_req *cli_session_setup_guest_send(TALLOC_CTX *mem_ctx,
        bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), "Unix", 5, NULL);
        bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), "Samba", 6, NULL);
 
-       if (tevent_req_nomem(bytes, req)) {
-               return tevent_req_post(req, ev);
+       if (bytes == NULL) {
+               TALLOC_FREE(req);
+               return NULL;
        }
 
-       subreq = cli_smb_send(state, ev, cli, SMBsesssetupX, 0, 13, vwv,
-                             talloc_get_size(bytes), bytes);
-       if (tevent_req_nomem(subreq, req)) {
-               return tevent_req_post(req, ev);
+       state->bytes.iov_base = (void *)bytes;
+       state->bytes.iov_len = talloc_get_size(bytes);
+
+       subreq = cli_smb_req_create(state, ev, cli, SMBsesssetupX, 0, 13, vwv,
+                                   1, &state->bytes);
+       if (subreq == NULL) {
+               TALLOC_FREE(req);
+               return NULL;
        }
        tevent_req_set_callback(subreq, cli_session_setup_guest_done, req);
+       *psmbreq = subreq;
+       return req;
+}
+
+struct tevent_req *cli_session_setup_guest_send(TALLOC_CTX *mem_ctx,
+                                               struct event_context *ev,
+                                               struct cli_state *cli)
+{
+       struct tevent_req *req, *subreq;
+
+       req = cli_session_setup_guest_create(mem_ctx, ev, cli, &subreq);
+       if ((req == NULL) || !cli_smb_req_send(subreq)) {
+               TALLOC_FREE(req);
+               return NULL;
+       }
        return req;
 }
 
@@ -433,11 +456,11 @@ static NTSTATUS cli_session_setup_nt1(struct cli_state *cli, const char *user,
                           the server's domain at this point.  The 'server name' is also
                           dodgy... 
                        */
-                       names_blob = NTLMv2_generate_names_blob(cli->called.name, workgroup);
+                       names_blob = NTLMv2_generate_names_blob(NULL, cli->called.name, workgroup);
 
-                       if (!SMBNTLMv2encrypt(user, workgroup, pass, &server_chal, 
+                       if (!SMBNTLMv2encrypt(NULL, user, workgroup, pass, &server_chal, 
                                              &names_blob,
-                                             &lm_response, &nt_response, &session_key)) {
+                                             &lm_response, &nt_response, NULL, &session_key)) {
                                data_blob_free(&names_blob);
                                data_blob_free(&server_chal);
                                return NT_STATUS_ACCESS_DENIED;
@@ -474,7 +497,7 @@ static NTSTATUS cli_session_setup_nt1(struct cli_state *cli, const char *user,
                        E_deshash(pass, session_key.data);
                        memset(&session_key.data[8], '\0', 8);
 #else
-                       SMBsesskeygen_ntv1(nt_hash, NULL, session_key.data);
+                       SMBsesskeygen_ntv1(nt_hash, session_key.data);
 #endif
                }
                cli_temp_set_signing(cli);
@@ -1211,7 +1234,7 @@ bool cli_ulogoff(struct cli_state *cli)
                return False;
        }
 
-        cli->cnum = -1;
+        cli->vuid = -1;
         return True;
 }
 
@@ -1222,15 +1245,17 @@ bool cli_ulogoff(struct cli_state *cli)
 struct cli_tcon_andx_state {
        struct cli_state *cli;
        uint16_t vwv[4];
+       struct iovec bytes;
 };
 
 static void cli_tcon_andx_done(struct tevent_req *subreq);
 
-struct tevent_req *cli_tcon_andx_send(TALLOC_CTX *mem_ctx,
-                                     struct event_context *ev,
-                                     struct cli_state *cli,
-                                     const char *share, const char *dev,
-                                     const char *pass, int passlen)
+struct tevent_req *cli_tcon_andx_create(TALLOC_CTX *mem_ctx,
+                                       struct event_context *ev,
+                                       struct cli_state *cli,
+                                       const char *share, const char *dev,
+                                       const char *pass, int passlen,
+                                       struct tevent_req **psmbreq)
 {
        struct tevent_req *req, *subreq;
        struct cli_tcon_andx_state *state;
@@ -1318,8 +1343,9 @@ struct tevent_req *cli_tcon_andx_send(TALLOC_CTX *mem_ctx,
         */
        tmp = talloc_asprintf_strupper_m(talloc_tos(), "\\\\%s\\%s",
                                         cli->desthost, share);
-       if (tevent_req_nomem(tmp, req)) {
-               return tevent_req_post(req, ev);
+       if (tmp == NULL) {
+               TALLOC_FREE(req);
+               return NULL;
        }
        bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), tmp, strlen(tmp)+1,
                                   NULL);
@@ -1329,22 +1355,29 @@ struct tevent_req *cli_tcon_andx_send(TALLOC_CTX *mem_ctx,
         * Add the devicetype
         */
        tmp = talloc_strdup_upper(talloc_tos(), dev);
-       if (tevent_req_nomem(tmp, req)) {
-               return tevent_req_post(req, ev);
+       if (tmp == NULL) {
+               TALLOC_FREE(req);
+               return NULL;
        }
        bytes = smb_bytes_push_str(bytes, false, tmp, strlen(tmp)+1, NULL);
        TALLOC_FREE(tmp);
 
-       if (tevent_req_nomem(bytes, req)) {
-               return tevent_req_post(req, ev);
+       if (bytes == NULL) {
+               TALLOC_FREE(req);
+               return NULL;
        }
 
-       subreq = cli_smb_send(state, ev, cli, SMBtconX, 0, 4, vwv,
-                             talloc_get_size(bytes), bytes);
-       if (tevent_req_nomem(subreq, req)) {
-               return tevent_req_post(req, ev);
+       state->bytes.iov_base = (void *)bytes;
+       state->bytes.iov_len = talloc_get_size(bytes);
+
+       subreq = cli_smb_req_create(state, ev, cli, SMBtconX, 0, 4, vwv,
+                                   1, &state->bytes);
+       if (subreq == NULL) {
+               TALLOC_FREE(req);
+               return NULL;
        }
        tevent_req_set_callback(subreq, cli_tcon_andx_done, req);
+       *psmbreq = subreq;
        return req;
 
  access_denied:
@@ -1352,6 +1385,23 @@ struct tevent_req *cli_tcon_andx_send(TALLOC_CTX *mem_ctx,
        return tevent_req_post(req, ev);
 }
 
+struct tevent_req *cli_tcon_andx_send(TALLOC_CTX *mem_ctx,
+                                     struct event_context *ev,
+                                     struct cli_state *cli,
+                                     const char *share, const char *dev,
+                                     const char *pass, int passlen)
+{
+       struct tevent_req *req, *subreq;
+
+       req = cli_tcon_andx_create(mem_ctx, ev, cli, share, dev, pass, passlen,
+                                  &subreq);
+       if ((req == NULL) || !cli_smb_req_send(subreq)) {
+               TALLOC_FREE(req);
+               return NULL;
+       }
+       return req;
+}
+
 static void cli_tcon_andx_done(struct tevent_req *subreq)
 {
        struct tevent_req *req = tevent_req_callback_data(
@@ -2169,6 +2219,10 @@ NTSTATUS cli_full_connection(struct cli_state **output_cli,
                return nt_status;
        }
 
+       cli->use_oplocks = ((flags & CLI_FULL_CONNECTION_OPLOCKS) != 0);
+       cli->use_level_II_oplocks =
+               ((flags & CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS) != 0);
+
        nt_status = cli_session_setup(cli, user, password, pw_len, password,
                                      pw_len, domain);
        if (!NT_STATUS_IS_OK(nt_status)) {