s3:libsmb/smb_seal: make common_ntlm_[en|de]crypt_buffer static
[rusty/samba.git] / source3 / libsmb / smb_seal.c
index 2f7305c5b65466c95439391b227fda70e12d18c8..c5541107ab923b0c0d2e44556223d2ab4bac8860 100644 (file)
 */
 
 #include "includes.h"
+#include "../auth/ntlmssp/ntlmssp.h"
+#include "smb_crypt.h"
+#include "libsmb/libsmb.h"
+#include "ntlmssp_wrap.h"
+
 
 /******************************************************************************
  Pull out the encryption context for this packet. 0 means global context.
@@ -59,7 +64,7 @@ bool common_encryption_on(struct smb_trans_enc_state *es)
  output, so cope with the same for compatibility.
 ******************************************************************************/
 
-NTSTATUS common_ntlm_decrypt_buffer(NTLMSSP_STATE *ntlmssp_state, char *buf)
+static NTSTATUS common_ntlm_decrypt_buffer(struct auth_ntlmssp_state *auth_ntlmssp_state, char *buf)
 {
        NTSTATUS status;
        size_t buf_len = smb_len(buf) + 4; /* Don't forget the 4 length bytes. */
@@ -79,7 +84,7 @@ NTSTATUS common_ntlm_decrypt_buffer(NTLMSSP_STATE *ntlmssp_state, char *buf)
        /* Point at the signature. */
        sig = data_blob_const(inbuf+8, NTLMSSP_SIG_SIZE);
 
-       status = ntlmssp_unseal_packet(ntlmssp_state,
+       status = auth_ntlmssp_unseal_packet(auth_ntlmssp_state,
                (unsigned char *)inbuf + 8 + NTLMSSP_SIG_SIZE, /* 4 byte len + 0xFF 'E' <enc> <ctx> */
                data_len,
                (unsigned char *)inbuf + 8 + NTLMSSP_SIG_SIZE,
@@ -107,7 +112,7 @@ NTSTATUS common_ntlm_decrypt_buffer(NTLMSSP_STATE *ntlmssp_state, char *buf)
  output, so do the same for compatibility.
 ******************************************************************************/
 
-NTSTATUS common_ntlm_encrypt_buffer(NTLMSSP_STATE *ntlmssp_state,
+static NTSTATUS common_ntlm_encrypt_buffer(struct auth_ntlmssp_state *auth_ntlmssp_state,
                                uint16 enc_ctx_num,
                                char *buf,
                                char **ppbuf_out)
@@ -116,13 +121,14 @@ NTSTATUS common_ntlm_encrypt_buffer(NTLMSSP_STATE *ntlmssp_state,
        char *buf_out;
        size_t data_len = smb_len(buf) - 4; /* Ignore the 0xFF SMB bytes. */
        DATA_BLOB sig;
-
+       TALLOC_CTX *frame;
        *ppbuf_out = NULL;
 
        if (data_len == 0) {
                return NT_STATUS_BUFFER_TOO_SMALL;
        }
 
+       frame = talloc_stackframe();
        /* 
         * We know smb_len can't return a value > 128k, so no int overflow
         * check needed.
@@ -138,7 +144,8 @@ NTSTATUS common_ntlm_encrypt_buffer(NTLMSSP_STATE *ntlmssp_state,
 
        ZERO_STRUCT(sig);
 
-       status = ntlmssp_seal_packet(ntlmssp_state,
+       status = auth_ntlmssp_seal_packet(auth_ntlmssp_state,
+                                    frame,
                (unsigned char *)buf_out + 8 + NTLMSSP_SIG_SIZE, /* 4 byte len + 0xFF 'S' <enc> <ctx> */
                data_len,
                (unsigned char *)buf_out + 8 + NTLMSSP_SIG_SIZE,
@@ -146,14 +153,14 @@ NTSTATUS common_ntlm_encrypt_buffer(NTLMSSP_STATE *ntlmssp_state,
                &sig);
 
        if (!NT_STATUS_IS_OK(status)) {
-               data_blob_free(&sig);
+               talloc_free(frame);
                SAFE_FREE(buf_out);
                return status;
        }
 
        /* First 16 data bytes are signature for SSPI compatibility. */
        memcpy(buf_out + 8, sig.data, NTLMSSP_SIG_SIZE);
-       data_blob_free(&sig);
+       talloc_free(frame);
        *ppbuf_out = buf_out;
        return NT_STATUS_OK;
 }
@@ -299,7 +306,7 @@ NTSTATUS common_encrypt_buffer(struct smb_trans_enc_state *es, char *buffer, cha
 
        switch (es->smb_enc_type) {
                case SMB_TRANS_ENC_NTLM:
-                       return common_ntlm_encrypt_buffer(es->s.ntlmssp_state, es->enc_ctx_num, buffer, buf_out);
+                       return common_ntlm_encrypt_buffer(es->s.auth_ntlmssp_state, es->enc_ctx_num, buffer, buf_out);
 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
                case SMB_TRANS_ENC_GSS:
                        return common_gss_encrypt_buffer(es->s.gss_state, es->enc_ctx_num, buffer, buf_out);
@@ -324,7 +331,7 @@ NTSTATUS common_decrypt_buffer(struct smb_trans_enc_state *es, char *buf)
 
        switch (es->smb_enc_type) {
                case SMB_TRANS_ENC_NTLM:
-                       return common_ntlm_decrypt_buffer(es->s.ntlmssp_state, buf);
+                       return common_ntlm_decrypt_buffer(es->s.auth_ntlmssp_state, buf);
 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
                case SMB_TRANS_ENC_GSS:
                        return common_gss_decrypt_buffer(es->s.gss_state, buf);
@@ -367,8 +374,8 @@ void common_free_encryption_state(struct smb_trans_enc_state **pp_es)
        }
 
        if (es->smb_enc_type == SMB_TRANS_ENC_NTLM) {
-               if (es->s.ntlmssp_state) {
-                       ntlmssp_end(&es->s.ntlmssp_state);
+               if (es->s.auth_ntlmssp_state) {
+                       TALLOC_FREE(es->s.auth_ntlmssp_state);
                }
        }
 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
@@ -415,91 +422,3 @@ void common_free_enc_buffer(struct smb_trans_enc_state *es, char *buf)
        }
 #endif
 }
-
-/******************************************************************************
- Client side encryption.
-******************************************************************************/
-
-/******************************************************************************
- Is client encryption on ?
-******************************************************************************/
-
-bool cli_encryption_on(struct cli_state *cli)
-{
-       /* If we supported multiple encrytion contexts
-        * here we'd look up based on tid.
-        */
-       return common_encryption_on(cli->trans_enc_state);
-}
-
-/******************************************************************************
- Shutdown a client encryption state.
-******************************************************************************/
-
-void cli_free_encryption_context(struct cli_state *cli)
-{
-       common_free_encryption_state(&cli->trans_enc_state);
-}
-
-/******************************************************************************
- Free an encryption-allocated buffer.
-******************************************************************************/
-
-void cli_free_enc_buffer(struct cli_state *cli, char *buf)
-{
-       /* We know this is an smb buffer, and we
-        * didn't malloc, only copy, for a keepalive,
-        * so ignore non-session messages. */
-
-       if(CVAL(buf,0)) {
-               return;
-       }
-
-       /* If we supported multiple encrytion contexts
-        * here we'd look up based on tid.
-        */
-       common_free_enc_buffer(cli->trans_enc_state, buf);
-}
-
-/******************************************************************************
- Decrypt an incoming buffer.
-******************************************************************************/
-
-NTSTATUS cli_decrypt_message(struct cli_state *cli)
-{
-       NTSTATUS status;
-       uint16 enc_ctx_num;
-
-       /* Ignore non-session messages. */
-       if(CVAL(cli->inbuf,0)) {
-               return NT_STATUS_OK;
-       }
-
-       status = get_enc_ctx_num((const uint8_t *)cli->inbuf, &enc_ctx_num);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
-       if (enc_ctx_num != cli->trans_enc_state->enc_ctx_num) {
-               return NT_STATUS_INVALID_HANDLE;
-       }
-
-       return common_decrypt_buffer(cli->trans_enc_state, cli->inbuf);
-}
-
-/******************************************************************************
- Encrypt an outgoing buffer. Return the encrypted pointer in buf_out.
-******************************************************************************/
-
-NTSTATUS cli_encrypt_message(struct cli_state *cli, char *buf, char **buf_out)
-{
-       /* Ignore non-session messages. */
-       if (CVAL(buf,0)) {
-               return NT_STATUS_OK;
-       }
-
-       /* If we supported multiple encrytion contexts
-        * here we'd look up based on tid.
-        */
-       return common_encrypt_buffer(cli->trans_enc_state, buf, buf_out);
-}