s3-ntlmssp use gensec_{seal,unseal,sign,check}_packet
[rusty/samba.git] / source3 / libsmb / smb_seal.c
index d930523f864eae308497cac31964215a8254397f..f767f16be50d8a80502988570aee3e18fa1ca844 100644 (file)
@@ -23,7 +23,9 @@
 #include "libsmb/libsmb.h"
 #include "ntlmssp_wrap.h"
 #include "libcli/auth/krb5_wrap.h"
+#include "auth/gensec/gensec.h"
 
+#undef malloc
 
 /******************************************************************************
  Pull out the encryption context for this packet. 0 means global context.
@@ -98,7 +100,7 @@ static NTSTATUS common_ntlm_decrypt_buffer(struct auth_ntlmssp_state *auth_ntlms
        /* Point at the signature. */
        sig = data_blob_const(inbuf+8, NTLMSSP_SIG_SIZE);
 
-       status = auth_ntlmssp_unseal_packet(auth_ntlmssp_state,
+       status = gensec_unseal_packet(auth_ntlmssp_state->gensec_security,
                (unsigned char *)inbuf + 8 + NTLMSSP_SIG_SIZE, /* 4 byte len + 0xFF 'E' <enc> <ctx> */
                data_len,
                (unsigned char *)inbuf + 8 + NTLMSSP_SIG_SIZE,
@@ -148,7 +150,11 @@ static NTSTATUS common_ntlm_encrypt_buffer(struct auth_ntlmssp_state *auth_ntlms
         * check needed.
         */
 
-       buf_out = SMB_XMALLOC_ARRAY(char, 8 + NTLMSSP_SIG_SIZE + data_len);
+       buf_out = (char *)malloc(8 + NTLMSSP_SIG_SIZE + data_len);
+       if (buf_out == NULL) {
+               TALLOC_FREE(frame);
+               return NT_STATUS_NO_MEMORY;
+       }
 
        /* Copy the data from the original buffer. */
 
@@ -158,8 +164,8 @@ static NTSTATUS common_ntlm_encrypt_buffer(struct auth_ntlmssp_state *auth_ntlms
 
        ZERO_STRUCT(sig);
 
-       status = auth_ntlmssp_seal_packet(auth_ntlmssp_state,
-                                    frame,
+       status = gensec_seal_packet(auth_ntlmssp_state->gensec_security,
+                                   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,
@@ -309,7 +315,7 @@ static NTSTATUS common_gss_encrypt_buffer(struct smb_tran_enc_state_gss *gss_sta
         * bother :-*(. JRA.
         */
 
-       *ppbuf_out = (char *)SMB_MALLOC(out_buf.length + 8); /* We know this can't wrap. */
+       *ppbuf_out = (char *)malloc(out_buf.length + 8); /* We know this can't wrap. */
        if (!*ppbuf_out) {
                gss_release_buffer(&minor, &out_buf);
                return NT_STATUS_NO_MEMORY;
@@ -439,18 +445,5 @@ void common_free_enc_buffer(struct smb_trans_enc_state *es, char *buf)
                return;
        }
 
-       if (es->smb_enc_type == SMB_TRANS_ENC_NTLM) {
-               SAFE_FREE(buf);
-               return;
-       }
-
-#if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
-       if (es->smb_enc_type == SMB_TRANS_ENC_GSS) {
-               OM_uint32 min;
-               gss_buffer_desc rel_buf;
-               rel_buf.value = buf;
-               rel_buf.length = smb_len_nbt(buf) + 4;
-               gss_release_buffer(&min, &rel_buf);
-       }
-#endif
+       SAFE_FREE(buf);
 }