ntlmssp: Add ntlmssp_blob_matches_magic()
authorAndrew Bartlett <abartlet@samba.org>
Tue, 2 Aug 2011 23:33:29 +0000 (09:33 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 3 Aug 2011 10:45:04 +0000 (12:45 +0200)
This avoids having the same check in 3 different parts of the code

Andrew Bartlett

Autobuild-User: Andrew Bartlett <abartlet@samba.org>
Autobuild-Date: Wed Aug  3 12:45:04 CEST 2011 on sn-devel-104

libcli/auth/ntlmssp.c
libcli/auth/ntlmssp.h
source3/smbd/sesssetup.c
source3/smbd/smb2_sesssetup.c
source4/auth/ntlmssp/ntlmssp.c

index b7f14c153cc94ebec261cdbcd0c246e72a42e011..4817329314af347bdef99874c1ae46d211efee41 100644 (file)
@@ -132,3 +132,13 @@ void ntlmssp_handle_neg_flags(struct ntlmssp_state *ntlmssp_state,
                ntlmssp_state->neg_flags |= NTLMSSP_REQUEST_TARGET;
        }
 }
+
+/* Does this blob looks like it could be NTLMSSP? */
+bool ntlmssp_blob_matches_magic(const DATA_BLOB *blob)
+{
+       if (blob->length > 8 && memcmp("NTLMSSP\0", blob->data, 8) == 0) {
+               return true;
+       } else {
+               return false;
+       }
+}
index 495d94f6a038e2cfe9fb14cda3483ed08c988ff6..cf8bb8dd301cc1e63fc9d973274ef88901620acf 100644 (file)
@@ -169,3 +169,5 @@ NTSTATUS ntlmssp_unwrap(struct ntlmssp_state *ntlmssp_stae,
                        const DATA_BLOB *in,
                        DATA_BLOB *out);
 NTSTATUS ntlmssp_sign_init(struct ntlmssp_state *ntlmssp_state);
+
+bool ntlmssp_blob_matches_magic(const DATA_BLOB *blob);
index 8b133b4a541e1c2df708c21a3b9e7d8ba4dfcb69..6dc8609071d0f3bae3f2541a83baee0a6e53ea80 100644 (file)
@@ -1140,7 +1140,7 @@ static void reply_sesssetup_and_X_spnego(struct smb_request *req)
         * identical regardless.  In particular, both rely only on the
         * status code (not the contents of the packet) and do not
         * wrap the result */
-       if (sconn->use_gensec_hook || (blob1.length > 7 && strncmp((char *)(blob1.data), "NTLMSSP", 7) == 0)) {
+       if (sconn->use_gensec_hook || ntlmssp_blob_matches_magic(&blob1)) {
                DATA_BLOB chal;
 
                if (!vuser->auth_ntlmssp_state) {
index 6517fb6d004c4f53917d9795015bf5acd8692983..30e65c21371e2ef044c6cb72573e0150cafff580 100644 (file)
@@ -753,7 +753,7 @@ static NTSTATUS smbd_smb2_session_setup(struct smbd_smb2_request *smb2req,
         * status code (not the contents of the packet) and do not
         * wrap the result */
        if (session->sconn->use_gensec_hook
-           || (in_security_buffer.length > 7 && strncmp((char *)(in_security_buffer.data), "NTLMSSP", 7) == 0)) {
+           || ntlmssp_blob_matches_magic(&in_security_buffer)) {
                return smbd_smb2_raw_ntlmssp_auth(session,
                                                smb2req,
                                                in_security_mode,
index a53e5547ab21b7f13cfec6ab99d36b425e2ca9bd..d90c908d8d63ba893f76f838daa1da7b080eefc1 100644 (file)
@@ -63,7 +63,7 @@ static const struct ntlmssp_callbacks {
 static NTSTATUS gensec_ntlmssp_magic(struct gensec_security *gensec_security, 
                                     const DATA_BLOB *first_packet) 
 {
-       if (first_packet->length > 8 && memcmp("NTLMSSP\0", first_packet->data, 8) == 0) {
+       if (ntlmssp_blob_matches_magic(first_packet)) {
                return NT_STATUS_OK;
        } else {
                return NT_STATUS_INVALID_PARAMETER;