smbd: Fix error return for STREAM_INFO
[Samba.git] / auth / ntlmssp / ntlmssp_util.c
blob96793abfda1dc8199abfa3979202c091a4298ee5
1 /*
2 Unix SMB/Netbios implementation.
3 Version 3.0
4 handle NLTMSSP, server side
6 Copyright (C) Andrew Tridgell 2001
7 Copyright (C) Andrew Bartlett 2001-2003
8 Copyright (C) Andrew Bartlett 2005 (Updated from gensec).
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "../auth/ntlmssp/ntlmssp.h"
26 #include "../auth/ntlmssp/ntlmssp_private.h"
28 /**
29 * Print out the NTLMSSP flags for debugging
30 * @param neg_flags The flags from the packet
32 void debug_ntlmssp_flags(uint32_t neg_flags)
34 DEBUG(3,("Got NTLMSSP neg_flags=0x%08x\n", neg_flags));
36 if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE)
37 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_UNICODE\n"));
38 if (neg_flags & NTLMSSP_NEGOTIATE_OEM)
39 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_OEM\n"));
40 if (neg_flags & NTLMSSP_REQUEST_TARGET)
41 DEBUGADD(4, (" NTLMSSP_REQUEST_TARGET\n"));
42 if (neg_flags & NTLMSSP_NEGOTIATE_SIGN)
43 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_SIGN\n"));
44 if (neg_flags & NTLMSSP_NEGOTIATE_SEAL)
45 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_SEAL\n"));
46 if (neg_flags & NTLMSSP_NEGOTIATE_DATAGRAM)
47 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_DATAGRAM\n"));
48 if (neg_flags & NTLMSSP_NEGOTIATE_LM_KEY)
49 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_LM_KEY\n"));
50 if (neg_flags & NTLMSSP_NEGOTIATE_NETWARE)
51 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_NETWARE\n"));
52 if (neg_flags & NTLMSSP_NEGOTIATE_NTLM)
53 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_NTLM\n"));
54 if (neg_flags & NTLMSSP_NEGOTIATE_OEM_DOMAIN_SUPPLIED)
55 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_OEM_DOMAIN_SUPPLIED\n"));
56 if (neg_flags & NTLMSSP_NEGOTIATE_OEM_WORKSTATION_SUPPLIED)
57 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_OEM_WORKSTATION_SUPPLIED\n"));
58 if (neg_flags & NTLMSSP_NEGOTIATE_THIS_IS_LOCAL_CALL)
59 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_THIS_IS_LOCAL_CALL\n"));
60 if (neg_flags & NTLMSSP_NEGOTIATE_ALWAYS_SIGN)
61 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_ALWAYS_SIGN\n"));
62 if (neg_flags & NTLMSSP_REQUEST_NON_NT_SESSION_KEY)
63 DEBUGADD(4, (" NTLMSSP_REQUEST_NON_NT_SESSION_KEY\n"));
64 if (neg_flags & NTLMSSP_NEGOTIATE_NTLM2)
65 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_NTLM2\n"));
66 if (neg_flags & NTLMSSP_NEGOTIATE_TARGET_INFO)
67 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_TARGET_INFO\n"));
68 if (neg_flags & NTLMSSP_NEGOTIATE_VERSION)
69 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_VERSION\n"));
70 if (neg_flags & NTLMSSP_NEGOTIATE_128)
71 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_128\n"));
72 if (neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH)
73 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_KEY_EXCH\n"));
74 if (neg_flags & NTLMSSP_NEGOTIATE_56)
75 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_56\n"));
78 void ntlmssp_handle_neg_flags(struct ntlmssp_state *ntlmssp_state,
79 uint32_t neg_flags, bool allow_lm)
81 if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
82 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_UNICODE;
83 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_OEM;
84 ntlmssp_state->unicode = true;
85 } else {
86 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_UNICODE;
87 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_OEM;
88 ntlmssp_state->unicode = false;
91 if ((neg_flags & NTLMSSP_NEGOTIATE_LM_KEY) && allow_lm) {
92 /* other end forcing us to use LM */
93 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_LM_KEY;
94 ntlmssp_state->use_ntlmv2 = false;
95 } else {
96 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
99 if (!(neg_flags & NTLMSSP_NEGOTIATE_ALWAYS_SIGN)) {
100 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
103 if (!(neg_flags & NTLMSSP_NEGOTIATE_NTLM2)) {
104 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2;
107 if (!(neg_flags & NTLMSSP_NEGOTIATE_128)) {
108 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_128;
111 if (!(neg_flags & NTLMSSP_NEGOTIATE_56)) {
112 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_56;
115 if (!(neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH)) {
116 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_KEY_EXCH;
119 if (!(neg_flags & NTLMSSP_NEGOTIATE_SIGN)) {
120 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_SIGN;
123 if (!(neg_flags & NTLMSSP_NEGOTIATE_SEAL)) {
124 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_SEAL;
127 if (!(neg_flags & NTLMSSP_NEGOTIATE_VERSION)) {
128 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_VERSION;
131 if ((neg_flags & NTLMSSP_REQUEST_TARGET)) {
132 ntlmssp_state->neg_flags |= NTLMSSP_REQUEST_TARGET;
136 /* Does this blob looks like it could be NTLMSSP? */
137 bool ntlmssp_blob_matches_magic(const DATA_BLOB *blob)
139 if (blob->length > 8 && memcmp("NTLMSSP\0", blob->data, 8) == 0) {
140 return true;
141 } else {
142 return false;