libcli/smb: move smb_seal.c to the toplevel
[rusty/samba.git] / source3 / libsmb / clifsinfo.c
index 4b3383a1d2488b35bf70c38485e78f0fab966661..a5b7838b2a2620878832b462c8f2024187a9f6ac 100644 (file)
 */
 
 #include "includes.h"
+#include "libsmb/libsmb.h"
 #include "../libcli/auth/spnego.h"
-#include "../libcli/auth/ntlmssp.h"
+#include "../auth/ntlmssp/ntlmssp.h"
 #include "../lib/util/tevent_ntstatus.h"
 #include "async_smb.h"
-#include "smb_crypt.h"
+#include "../libcli/smb/smb_seal.h"
 #include "trans2.h"
+#include "ntlmssp_wrap.h"
+#include "auth/gensec/gensec.h"
 
 /****************************************************************************
  Get UNIX extensions version info.
@@ -152,9 +155,6 @@ NTSTATUS cli_unix_extensions_version(struct cli_state *cli, uint16 *pmajor,
                                                  pcaphigh);
  fail:
        TALLOC_FREE(frame);
-       if (!NT_STATUS_IS_OK(status)) {
-               cli_set_error(cli, status);
-       }
        return status;
 }
 
@@ -257,9 +257,6 @@ NTSTATUS cli_set_unix_extensions_capabilities(struct cli_state *cli,
        status = cli_set_unix_extensions_capabilities_recv(req);
 fail:
        TALLOC_FREE(ev);
-       if (!NT_STATUS_IS_OK(status)) {
-               cli_set_error(cli, status);
-       }
        return status;
 }
 
@@ -356,21 +353,23 @@ NTSTATUS cli_get_fs_attr_info(struct cli_state *cli, uint32_t *fs_attr)
        status = cli_get_fs_attr_info_recv(req, fs_attr);
 fail:
        TALLOC_FREE(ev);
-       if (!NT_STATUS_IS_OK(status)) {
-               cli_set_error(cli, status);
-       }
        return status;
 }
 
-NTSTATUS cli_get_fs_volume_info(struct cli_state *cli, fstring volume_name,
-                               uint32 *pserial_number, time_t *pdate)
+NTSTATUS cli_get_fs_volume_info(struct cli_state *cli,
+                               TALLOC_CTX *mem_ctx,
+                               char **_volume_name,
+                               uint32_t *pserial_number,
+                               time_t *pdate)
 {
        NTSTATUS status;
-       uint16 setup[1];
+       uint16_t recv_flags2;
+       uint16_t setup[1];
        uint8_t param[2];
        uint8_t *rdata;
        uint32_t rdata_count;
        unsigned int nlen;
+       char *volume_name = NULL;
 
        SSVAL(setup, 0, TRANSACT2_QFSINFO);
        SSVAL(param,0,SMB_QUERY_FS_VOLUME_INFO);
@@ -380,10 +379,10 @@ NTSTATUS cli_get_fs_volume_info(struct cli_state *cli, fstring volume_name,
                           setup, 1, 0,
                           param, 2, 0,
                           NULL, 0, 560,
-                          NULL,
+                          &recv_flags2,
                           NULL, 0, NULL,
                           NULL, 0, NULL,
-                          &rdata, 10, &rdata_count);
+                          &rdata, 18, &rdata_count);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -397,13 +396,28 @@ NTSTATUS cli_get_fs_volume_info(struct cli_state *cli, fstring volume_name,
                *pserial_number = IVAL(rdata,8);
        }
        nlen = IVAL(rdata,12);
-       clistr_pull(cli->inbuf, volume_name, rdata + 18, sizeof(fstring),
-                   nlen, STR_UNICODE);
+       if (nlen > (rdata_count - 18)) {
+               TALLOC_FREE(rdata);
+               return NT_STATUS_INVALID_NETWORK_RESPONSE;
+       }
+
+       clistr_pull_talloc(mem_ctx,
+                          (const char *)rdata,
+                          recv_flags2,
+                          &volume_name,
+                          rdata + 18,
+                          nlen, STR_UNICODE);
+       if (volume_name == NULL) {
+               status = map_nt_error_from_unix(errno);
+               TALLOC_FREE(rdata);
+               return status;
+       }
 
        /* todo: but not yet needed
         *       return the other stuff
         */
 
+       *_volume_name = volume_name;
        TALLOC_FREE(rdata);
        return NT_STATUS_OK;
 }
@@ -471,6 +485,7 @@ NTSTATUS cli_get_posix_fs_info(struct cli_state *cli,
        uint16 setup[1];
        uint8_t param[2];
        uint8_t *rdata = NULL;
+       uint32_t rdata_count;
        NTSTATUS status;
 
        SSVAL(setup, 0, TRANSACT2_QFSINFO);
@@ -483,7 +498,7 @@ NTSTATUS cli_get_posix_fs_info(struct cli_state *cli,
                           NULL,
                           NULL, 0, NULL, /* rsetup */
                           NULL, 0, NULL, /* rparam */
-                          &rdata, 56, NULL);
+                          &rdata, 56, &rdata_count);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -594,35 +609,38 @@ NTSTATUS cli_raw_ntlm_smb_encryption_start(struct cli_state *cli,
        DATA_BLOB blob_out = data_blob_null;
        DATA_BLOB param_out = data_blob_null;
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+       struct auth_ntlmssp_state *auth_ntlmssp_state;
        struct smb_trans_enc_state *es = make_cli_enc_state(SMB_TRANS_ENC_NTLM);
 
        if (!es) {
                return NT_STATUS_NO_MEMORY;
        }
-       status = ntlmssp_client_start(NULL,
-                                     global_myname(),
-                                     lp_workgroup(),
-                                     lp_client_ntlmv2_auth(),
-                                     &es->s.ntlmssp_state);
+       status = auth_ntlmssp_client_prepare(NULL,
+                                            &auth_ntlmssp_state);
        if (!NT_STATUS_IS_OK(status)) {
                goto fail;
        }
 
-       ntlmssp_want_feature(es->s.ntlmssp_state, NTLMSSP_FEATURE_SESSION_KEY);
-       es->s.ntlmssp_state->neg_flags |= (NTLMSSP_NEGOTIATE_SIGN|NTLMSSP_NEGOTIATE_SEAL);
+       gensec_want_feature(auth_ntlmssp_state->gensec_security, GENSEC_FEATURE_SESSION_KEY);
+       gensec_want_feature(auth_ntlmssp_state->gensec_security, GENSEC_FEATURE_SEAL);
 
-       if (!NT_STATUS_IS_OK(status = ntlmssp_set_username(es->s.ntlmssp_state, user))) {
+       if (!NT_STATUS_IS_OK(status = auth_ntlmssp_set_username(auth_ntlmssp_state, user))) {
                goto fail;
        }
-       if (!NT_STATUS_IS_OK(status = ntlmssp_set_domain(es->s.ntlmssp_state, domain))) {
+       if (!NT_STATUS_IS_OK(status = auth_ntlmssp_set_domain(auth_ntlmssp_state, domain))) {
                goto fail;
        }
-       if (!NT_STATUS_IS_OK(status = ntlmssp_set_password(es->s.ntlmssp_state, pass))) {
+       if (!NT_STATUS_IS_OK(status = auth_ntlmssp_set_password(auth_ntlmssp_state, pass))) {
+               goto fail;
+       }
+
+       if (!NT_STATUS_IS_OK(status = auth_ntlmssp_client_start(auth_ntlmssp_state))) {
                goto fail;
        }
 
        do {
-               status = ntlmssp_update(es->s.ntlmssp_state, blob_in, &blob_out);
+               status = gensec_update(auth_ntlmssp_state->gensec_security, auth_ntlmssp_state,
+                                      NULL, blob_in, &blob_out);
                data_blob_free(&blob_in);
                data_blob_free(&param_out);
                if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED) || NT_STATUS_IS_OK(status)) {
@@ -650,13 +668,18 @@ NTSTATUS cli_raw_ntlm_smb_encryption_start(struct cli_state *cli,
                if (cli->trans_enc_state) {
                        common_free_encryption_state(&cli->trans_enc_state);
                }
+               /* We only need the gensec_security part from here.
+                * es is a malloc()ed pointer, so we cannot make
+                * gensec_security a talloc child */
+               es->s.gensec_security = talloc_move(NULL,
+                                       &auth_ntlmssp_state->gensec_security);
                cli->trans_enc_state = es;
                cli->trans_enc_state->enc_on = True;
                es = NULL;
        }
 
   fail:
-
+       TALLOC_FREE(auth_ntlmssp_state);
        common_free_encryption_state(&es);
        return status;
 }
@@ -693,7 +716,7 @@ static NTSTATUS make_cli_gss_blob(TALLOC_CTX *ctx,
        NTSTATUS status = NT_STATUS_OK;
 
        gss_OID_desc nt_hostbased_service =
-       {10, CONST_DISCARD(char *,"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04")};
+       {10, discard_const_p(char, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04")};
 
        memset(&tok_out, '\0', sizeof(tok_out));
 
@@ -789,7 +812,7 @@ NTSTATUS cli_gss_smb_encryption_start(struct cli_state *cli)
                return NT_STATUS_NO_MEMORY;
        }
 
-       name_to_fqdn(fqdn, cli->desthost);
+       name_to_fqdn(fqdn, cli_state_remote_name(cli));
        strlower_m(fqdn);
 
        servicename = "cifs";