2faac72e6fef8ed2a192807811cdf3ae34b619ac
[samba.git] / auth / ntlmssp / ntlmssp_server.c
1 /*
2    Unix SMB/Netbios implementation.
3    Version 3.0
4    handle NTLMSSP, server side
5
6    Copyright (C) Andrew Tridgell      2001
7    Copyright (C) Andrew Bartlett 2001-2010
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "includes.h"
24 #include "auth/ntlmssp/ntlmssp.h"
25 #include "auth/ntlmssp/ntlmssp_private.h"
26 #include "../librpc/gen_ndr/ndr_ntlmssp.h"
27 #include "auth/ntlmssp/ntlmssp_ndr.h"
28 #include "../libcli/auth/libcli_auth.h"
29 #include "../lib/crypto/crypto.h"
30 #include "auth/gensec/gensec.h"
31
32 /**
33  * Determine correct target name flags for reply, given server role
34  * and negotiated flags
35  *
36  * @param ntlmssp_state NTLMSSP State
37  * @param neg_flags The flags from the packet
38  * @param chal_flags The flags to be set in the reply packet
39  * @return The 'target name' string.
40  */
41
42 const char *ntlmssp_target_name(struct ntlmssp_state *ntlmssp_state,
43                                 uint32_t neg_flags, uint32_t *chal_flags)
44 {
45         if (neg_flags & NTLMSSP_REQUEST_TARGET) {
46                 *chal_flags |= NTLMSSP_NEGOTIATE_TARGET_INFO;
47                 *chal_flags |= NTLMSSP_REQUEST_TARGET;
48                 if (ntlmssp_state->server.is_standalone) {
49                         *chal_flags |= NTLMSSP_TARGET_TYPE_SERVER;
50                         return ntlmssp_state->server.netbios_name;
51                 } else {
52                         *chal_flags |= NTLMSSP_TARGET_TYPE_DOMAIN;
53                         return ntlmssp_state->server.netbios_domain;
54                 };
55         } else {
56                 return "";
57         }
58 }
59
60 /**
61  * Next state function for the NTLMSSP Negotiate packet
62  *
63  * @param gensec_security GENSEC state
64  * @param out_mem_ctx Memory context for *out
65  * @param in The request, as a DATA_BLOB.  reply.data must be NULL
66  * @param out The reply, as an allocated DATA_BLOB, caller to free.
67  * @return Errors or MORE_PROCESSING_REQUIRED if (normal) a reply is required.
68  */
69
70 NTSTATUS gensec_ntlmssp_server_negotiate(struct gensec_security *gensec_security,
71                                          TALLOC_CTX *out_mem_ctx,
72                                          const DATA_BLOB request, DATA_BLOB *reply)
73 {
74         struct gensec_ntlmssp_context *gensec_ntlmssp =
75                 talloc_get_type_abort(gensec_security->private_data,
76                                       struct gensec_ntlmssp_context);
77         struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
78         DATA_BLOB struct_blob;
79         uint32_t neg_flags = 0;
80         uint32_t ntlmssp_command, chal_flags;
81         uint8_t cryptkey[8];
82         const char *target_name;
83         NTSTATUS status;
84
85         /* parse the NTLMSSP packet */
86 #if 0
87         file_save("ntlmssp_negotiate.dat", request.data, request.length);
88 #endif
89
90         if (request.length) {
91                 if ((request.length < 16) || !msrpc_parse(ntlmssp_state, &request, "Cdd",
92                                                           "NTLMSSP",
93                                                           &ntlmssp_command,
94                                                           &neg_flags)) {
95                         DEBUG(1, ("ntlmssp_server_negotiate: failed to parse NTLMSSP Negotiate of length %u\n",
96                                 (unsigned int)request.length));
97                         dump_data(2, request.data, request.length);
98                         return NT_STATUS_INVALID_PARAMETER;
99                 }
100                 debug_ntlmssp_flags(neg_flags);
101
102                 if (DEBUGLEVEL >= 10) {
103                         struct NEGOTIATE_MESSAGE *negotiate = talloc(
104                                 ntlmssp_state, struct NEGOTIATE_MESSAGE);
105                         if (negotiate != NULL) {
106                                 status = ntlmssp_pull_NEGOTIATE_MESSAGE(
107                                         &request, negotiate, negotiate);
108                                 if (NT_STATUS_IS_OK(status)) {
109                                         NDR_PRINT_DEBUG(NEGOTIATE_MESSAGE,
110                                                         negotiate);
111                                 }
112                                 TALLOC_FREE(negotiate);
113                         }
114                 }
115         }
116
117         ntlmssp_handle_neg_flags(ntlmssp_state, neg_flags, ntlmssp_state->allow_lm_key);
118
119         /* Ask our caller what challenge they would like in the packet */
120         status = ntlmssp_state->get_challenge(ntlmssp_state, cryptkey);
121         if (!NT_STATUS_IS_OK(status)) {
122                 DEBUG(1, ("ntlmssp_server_negotiate: backend doesn't give a challenge: %s\n",
123                           nt_errstr(status)));
124                 return status;
125         }
126
127         /* Check if we may set the challenge */
128         if (!ntlmssp_state->may_set_challenge(ntlmssp_state)) {
129                 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2;
130         }
131
132         /* The flags we send back are not just the negotiated flags,
133          * they are also 'what is in this packet'.  Therfore, we
134          * operate on 'chal_flags' from here on
135          */
136
137         chal_flags = ntlmssp_state->neg_flags;
138
139         /* get the right name to fill in as 'target' */
140         target_name = ntlmssp_target_name(ntlmssp_state,
141                                           neg_flags, &chal_flags);
142         if (target_name == NULL)
143                 return NT_STATUS_INVALID_PARAMETER;
144
145         ntlmssp_state->chal = data_blob_talloc(ntlmssp_state, cryptkey, 8);
146         ntlmssp_state->internal_chal = data_blob_talloc(ntlmssp_state,
147                                                         cryptkey, 8);
148
149         /* This creates the 'blob' of names that appears at the end of the packet */
150         if (chal_flags & NTLMSSP_NEGOTIATE_TARGET_INFO)
151         {
152                 status = msrpc_gen(ntlmssp_state, &struct_blob, "aaaaa",
153                           MsvAvNbDomainName, target_name,
154                           MsvAvNbComputerName, ntlmssp_state->server.netbios_name,
155                           MsvAvDnsDomainName, ntlmssp_state->server.dns_domain,
156                           MsvAvDnsComputerName, ntlmssp_state->server.dns_name,
157                           MsvAvEOL, "");
158                 if (!NT_STATUS_IS_OK(status)) {
159                         return status;
160                 }
161         } else {
162                 struct_blob = data_blob_null;
163         }
164
165         {
166                 /* Marshal the packet in the right format, be it unicode or ASCII */
167                 const char *gen_string;
168                 DATA_BLOB version_blob = data_blob_null;
169
170                 if (chal_flags & NTLMSSP_NEGOTIATE_VERSION) {
171                         enum ndr_err_code err;
172                         struct ntlmssp_VERSION vers;
173
174                         /* "What Windows returns" as a version number. */
175                         ZERO_STRUCT(vers);
176                         vers.ProductMajorVersion = NTLMSSP_WINDOWS_MAJOR_VERSION_6;
177                         vers.ProductMinorVersion = NTLMSSP_WINDOWS_MINOR_VERSION_1;
178                         vers.ProductBuild = 0;
179                         vers.NTLMRevisionCurrent = NTLMSSP_REVISION_W2K3;
180
181                         err = ndr_push_struct_blob(&version_blob,
182                                                 ntlmssp_state,
183                                                 &vers,
184                                                 (ndr_push_flags_fn_t)ndr_push_ntlmssp_VERSION);
185
186                         if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
187                                 data_blob_free(&struct_blob);
188                                 return NT_STATUS_NO_MEMORY;
189                         }
190                 }
191
192                 if (ntlmssp_state->unicode) {
193                         gen_string = "CdUdbddBb";
194                 } else {
195                         gen_string = "CdAdbddBb";
196                 }
197
198                 status = msrpc_gen(out_mem_ctx, reply, gen_string,
199                         "NTLMSSP",
200                         NTLMSSP_CHALLENGE,
201                         target_name,
202                         chal_flags,
203                         cryptkey, 8,
204                         0, 0,
205                         struct_blob.data, struct_blob.length,
206                         version_blob.data, version_blob.length);
207
208                 if (!NT_STATUS_IS_OK(status)) {
209                         data_blob_free(&version_blob);
210                         data_blob_free(&struct_blob);
211                         return status;
212                 }
213
214                 data_blob_free(&version_blob);
215
216                 if (DEBUGLEVEL >= 10) {
217                         struct CHALLENGE_MESSAGE *challenge = talloc(
218                                 ntlmssp_state, struct CHALLENGE_MESSAGE);
219                         if (challenge != NULL) {
220                                 challenge->NegotiateFlags = chal_flags;
221                                 status = ntlmssp_pull_CHALLENGE_MESSAGE(
222                                         reply, challenge, challenge);
223                                 if (NT_STATUS_IS_OK(status)) {
224                                         NDR_PRINT_DEBUG(CHALLENGE_MESSAGE,
225                                                         challenge);
226                                 }
227                                 TALLOC_FREE(challenge);
228                         }
229                 }
230         }
231
232         data_blob_free(&struct_blob);
233
234         ntlmssp_state->expected_state = NTLMSSP_AUTH;
235
236         return NT_STATUS_MORE_PROCESSING_REQUIRED;
237 }
238
239 struct ntlmssp_server_auth_state {
240         DATA_BLOB user_session_key;
241         DATA_BLOB lm_session_key;
242         /* internal variables used by KEY_EXCH (client-supplied user session key */
243         DATA_BLOB encrypted_session_key;
244         bool doing_ntlm2;
245         /* internal variables used by NTLM2 */
246         uint8_t session_nonce[16];
247 };
248
249 /**
250  * Next state function for the Authenticate packet
251  *
252  * @param ntlmssp_state NTLMSSP State
253  * @param request The request, as a DATA_BLOB
254  * @return Errors or NT_STATUS_OK.
255  */
256
257 static NTSTATUS ntlmssp_server_preauth(struct ntlmssp_state *ntlmssp_state,
258                                        struct ntlmssp_server_auth_state *state,
259                                        const DATA_BLOB request)
260 {
261         uint32_t ntlmssp_command, auth_flags;
262         NTSTATUS nt_status;
263
264         uint8_t session_nonce_hash[16];
265
266         const char *parse_string;
267
268 #if 0
269         file_save("ntlmssp_auth.dat", request.data, request.length);
270 #endif
271
272         if (ntlmssp_state->unicode) {
273                 parse_string = "CdBBUUUBd";
274         } else {
275                 parse_string = "CdBBAAABd";
276         }
277
278         /* zero these out */
279         data_blob_free(&ntlmssp_state->session_key);
280         data_blob_free(&ntlmssp_state->lm_resp);
281         data_blob_free(&ntlmssp_state->nt_resp);
282
283         ntlmssp_state->user = NULL;
284         ntlmssp_state->domain = NULL;
285         ntlmssp_state->client.netbios_name = NULL;
286
287         /* now the NTLMSSP encoded auth hashes */
288         if (!msrpc_parse(ntlmssp_state, &request, parse_string,
289                          "NTLMSSP",
290                          &ntlmssp_command,
291                          &ntlmssp_state->lm_resp,
292                          &ntlmssp_state->nt_resp,
293                          &ntlmssp_state->domain,
294                          &ntlmssp_state->user,
295                          &ntlmssp_state->client.netbios_name,
296                          &state->encrypted_session_key,
297                          &auth_flags)) {
298                 DEBUG(10, ("ntlmssp_server_auth: failed to parse NTLMSSP (nonfatal):\n"));
299                 dump_data(10, request.data, request.length);
300
301                 /* zero this out */
302                 data_blob_free(&state->encrypted_session_key);
303                 auth_flags = 0;
304
305                 /* Try again with a shorter string (Win9X truncates this packet) */
306                 if (ntlmssp_state->unicode) {
307                         parse_string = "CdBBUUU";
308                 } else {
309                         parse_string = "CdBBAAA";
310                 }
311
312                 /* now the NTLMSSP encoded auth hashes */
313                 if (!msrpc_parse(ntlmssp_state, &request, parse_string,
314                                  "NTLMSSP",
315                                  &ntlmssp_command,
316                                  &ntlmssp_state->lm_resp,
317                                  &ntlmssp_state->nt_resp,
318                                  &ntlmssp_state->domain,
319                                  &ntlmssp_state->user,
320                                  &ntlmssp_state->client.netbios_name)) {
321                         DEBUG(1, ("ntlmssp_server_auth: failed to parse NTLMSSP (tried both formats):\n"));
322                         dump_data(2, request.data, request.length);
323
324                         return NT_STATUS_INVALID_PARAMETER;
325                 }
326         }
327
328         talloc_steal(state, state->encrypted_session_key.data);
329
330         if (auth_flags)
331                 ntlmssp_handle_neg_flags(ntlmssp_state, auth_flags, ntlmssp_state->allow_lm_key);
332
333         if (DEBUGLEVEL >= 10) {
334                 struct AUTHENTICATE_MESSAGE *authenticate = talloc(
335                         ntlmssp_state, struct AUTHENTICATE_MESSAGE);
336                 if (authenticate != NULL) {
337                         NTSTATUS status;
338                         authenticate->NegotiateFlags = auth_flags;
339                         status = ntlmssp_pull_AUTHENTICATE_MESSAGE(
340                                 &request, authenticate, authenticate);
341                         if (NT_STATUS_IS_OK(status)) {
342                                 NDR_PRINT_DEBUG(AUTHENTICATE_MESSAGE,
343                                                 authenticate);
344                         }
345                         TALLOC_FREE(authenticate);
346                 }
347         }
348
349         DEBUG(3,("Got user=[%s] domain=[%s] workstation=[%s] len1=%lu len2=%lu\n",
350                  ntlmssp_state->user, ntlmssp_state->domain,
351                  ntlmssp_state->client.netbios_name,
352                  (unsigned long)ntlmssp_state->lm_resp.length,
353                  (unsigned long)ntlmssp_state->nt_resp.length));
354
355 #if 0
356         file_save("nthash1.dat",  &ntlmssp_state->nt_resp.data,  &ntlmssp_state->nt_resp.length);
357         file_save("lmhash1.dat",  &ntlmssp_state->lm_resp.data,  &ntlmssp_state->lm_resp.length);
358 #endif
359
360         /* NTLM2 uses a 'challenge' that is made of up both the server challenge, and a
361            client challenge
362
363            However, the NTLM2 flag may still be set for the real NTLMv2 logins, be careful.
364         */
365         if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) {
366                 if (ntlmssp_state->nt_resp.length == 24 && ntlmssp_state->lm_resp.length == 24) {
367                         struct MD5Context md5_session_nonce_ctx;
368                         state->doing_ntlm2 = true;
369
370                         memcpy(state->session_nonce, ntlmssp_state->internal_chal.data, 8);
371                         memcpy(&state->session_nonce[8], ntlmssp_state->lm_resp.data, 8);
372
373                         SMB_ASSERT(ntlmssp_state->internal_chal.data && ntlmssp_state->internal_chal.length == 8);
374
375                         MD5Init(&md5_session_nonce_ctx);
376                         MD5Update(&md5_session_nonce_ctx, state->session_nonce, 16);
377                         MD5Final(session_nonce_hash, &md5_session_nonce_ctx);
378
379                         ntlmssp_state->chal = data_blob_talloc(
380                                 ntlmssp_state, session_nonce_hash, 8);
381
382                         /* LM response is no longer useful */
383                         data_blob_free(&ntlmssp_state->lm_resp);
384
385                         /* We changed the effective challenge - set it */
386                         if (!NT_STATUS_IS_OK(nt_status = ntlmssp_state->set_challenge(ntlmssp_state, &ntlmssp_state->chal))) {
387                                 return nt_status;
388                         }
389
390                         /* LM Key is incompatible. */
391                         ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
392                 }
393         }
394         return NT_STATUS_OK;
395 }
396
397 /**
398  * Next state function for the Authenticate packet
399  * (after authentication - figures out the session keys etc)
400  *
401  * @param ntlmssp_state NTLMSSP State
402  * @return Errors or NT_STATUS_OK.
403  */
404
405 static NTSTATUS ntlmssp_server_postauth(struct ntlmssp_state *ntlmssp_state,
406                                         struct ntlmssp_server_auth_state *state)
407 {
408         DATA_BLOB user_session_key = state->user_session_key;
409         DATA_BLOB lm_session_key = state->lm_session_key;
410         NTSTATUS nt_status = NT_STATUS_OK;
411         DATA_BLOB session_key = data_blob(NULL, 0);
412
413         dump_data_pw("NT session key:\n", user_session_key.data, user_session_key.length);
414         dump_data_pw("LM first-8:\n", lm_session_key.data, lm_session_key.length);
415
416         /* Handle the different session key derivation for NTLM2 */
417         if (state->doing_ntlm2) {
418                 if (user_session_key.data && user_session_key.length == 16) {
419                         session_key = data_blob_talloc(ntlmssp_state,
420                                                        NULL, 16);
421                         hmac_md5(user_session_key.data, state->session_nonce,
422                                  sizeof(state->session_nonce), session_key.data);
423                         DEBUG(10,("ntlmssp_server_auth: Created NTLM2 session key.\n"));
424                         dump_data_pw("NTLM2 session key:\n", session_key.data, session_key.length);
425
426                 } else {
427                         DEBUG(10,("ntlmssp_server_auth: Failed to create NTLM2 session key.\n"));
428                         session_key = data_blob_null;
429                 }
430         } else if ((ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY)
431                 /* Ensure we can never get here on NTLMv2 */
432                 && (ntlmssp_state->nt_resp.length == 0 || ntlmssp_state->nt_resp.length == 24)) {
433
434                 if (lm_session_key.data && lm_session_key.length >= 8) {
435                         if (ntlmssp_state->lm_resp.data && ntlmssp_state->lm_resp.length == 24) {
436                                 session_key = data_blob_talloc(ntlmssp_state,
437                                                                NULL, 16);
438                                 if (session_key.data == NULL) {
439                                         return NT_STATUS_NO_MEMORY;
440                                 }
441                                 SMBsesskeygen_lm_sess_key(lm_session_key.data, ntlmssp_state->lm_resp.data,
442                                                           session_key.data);
443                                 DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n"));
444                         } else {
445                                 static const uint8_t zeros[24] = {0, };
446                                 session_key = data_blob_talloc(
447                                         ntlmssp_state, NULL, 16);
448                                 if (session_key.data == NULL) {
449                                         return NT_STATUS_NO_MEMORY;
450                                 }
451                                 SMBsesskeygen_lm_sess_key(zeros, zeros,
452                                                           session_key.data);
453                                 DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n"));
454                         }
455                         dump_data_pw("LM session key:\n", session_key.data,
456                                      session_key.length);
457                 } else {
458                         /* LM Key not selected */
459                         ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
460
461                         DEBUG(10,("ntlmssp_server_auth: Failed to create NTLM session key.\n"));
462                         session_key = data_blob_null;
463                 }
464
465         } else if (user_session_key.data) {
466                 session_key = user_session_key;
467                 DEBUG(10,("ntlmssp_server_auth: Using unmodified nt session key.\n"));
468                 dump_data_pw("unmodified session key:\n", session_key.data, session_key.length);
469
470                 /* LM Key not selected */
471                 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
472
473         } else if (lm_session_key.data) {
474                 /* Very weird to have LM key, but no user session key, but anyway.. */
475                 session_key = lm_session_key;
476                 DEBUG(10,("ntlmssp_server_auth: Using unmodified lm session key.\n"));
477                 dump_data_pw("unmodified session key:\n", session_key.data, session_key.length);
478
479                 /* LM Key not selected */
480                 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
481
482         } else {
483                 DEBUG(10,("ntlmssp_server_auth: Failed to create unmodified session key.\n"));
484                 session_key = data_blob_null;
485
486                 /* LM Key not selected */
487                 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
488         }
489
490         /* With KEY_EXCH, the client supplies the proposed session key,
491            but encrypts it with the long-term key */
492         if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH) {
493                 if (!state->encrypted_session_key.data
494                     || state->encrypted_session_key.length != 16) {
495                         DEBUG(1, ("Client-supplied KEY_EXCH session key was of invalid length (%u)!\n",
496                                   (unsigned)state->encrypted_session_key.length));
497                         return NT_STATUS_INVALID_PARAMETER;
498                 } else if (!session_key.data || session_key.length != 16) {
499                         DEBUG(5, ("server session key is invalid (len == %u), cannot do KEY_EXCH!\n",
500                                   (unsigned int)session_key.length));
501                         ntlmssp_state->session_key = session_key;
502                         talloc_steal(ntlmssp_state, session_key.data);
503                 } else {
504                         dump_data_pw("KEY_EXCH session key (enc):\n",
505                                      state->encrypted_session_key.data,
506                                      state->encrypted_session_key.length);
507                         arcfour_crypt(state->encrypted_session_key.data,
508                                       session_key.data,
509                                       state->encrypted_session_key.length);
510                         ntlmssp_state->session_key = data_blob_talloc(ntlmssp_state,
511                                                                       state->encrypted_session_key.data,
512                                                                       state->encrypted_session_key.length);
513                         dump_data_pw("KEY_EXCH session key:\n",
514                                      state->encrypted_session_key.data,
515                                      state->encrypted_session_key.length);
516                 }
517         } else {
518                 ntlmssp_state->session_key = session_key;
519                 talloc_steal(ntlmssp_state, session_key.data);
520         }
521
522         if (ntlmssp_state->session_key.length) {
523                 nt_status = ntlmssp_sign_init(ntlmssp_state);
524         }
525
526         ntlmssp_state->expected_state = NTLMSSP_DONE;
527
528         return nt_status;
529 }
530
531
532 /**
533  * Next state function for the NTLMSSP Authenticate packet
534  *
535  * @param gensec_security GENSEC state
536  * @param out_mem_ctx Memory context for *out
537  * @param in The request, as a DATA_BLOB.  reply.data must be NULL
538  * @param out The reply, as an allocated DATA_BLOB, caller to free.
539  * @return Errors or NT_STATUS_OK if authentication sucessful
540  */
541
542 NTSTATUS gensec_ntlmssp_server_auth(struct gensec_security *gensec_security,
543                                     TALLOC_CTX *out_mem_ctx,
544                                     const DATA_BLOB in, DATA_BLOB *out)
545 {
546         struct gensec_ntlmssp_context *gensec_ntlmssp =
547                 talloc_get_type_abort(gensec_security->private_data,
548                                       struct gensec_ntlmssp_context);
549         struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
550         struct ntlmssp_server_auth_state *state;
551         NTSTATUS nt_status;
552
553         /* zero the outbound NTLMSSP packet */
554         *out = data_blob_null;
555
556         state = talloc_zero(ntlmssp_state, struct ntlmssp_server_auth_state);
557         if (state == NULL) {
558                 return NT_STATUS_NO_MEMORY;
559         }
560
561         nt_status = ntlmssp_server_preauth(ntlmssp_state, state, in);
562         if (!NT_STATUS_IS_OK(nt_status)) {
563                 TALLOC_FREE(state);
564                 return nt_status;
565         }
566
567         /*
568          * Note we don't check here for NTLMv2 auth settings. If NTLMv2 auth
569          * is required (by "ntlm auth = no" and "lm auth = no" being set in the
570          * smb.conf file) and no NTLMv2 response was sent then the password check
571          * will fail here. JRA.
572          */
573
574         /* Finally, actually ask if the password is OK */
575         nt_status = ntlmssp_state->check_password(ntlmssp_state,
576                                                   state,
577                                                   &state->user_session_key,
578                                                   &state->lm_session_key);
579         if (!NT_STATUS_IS_OK(nt_status)) {
580                 DEBUG(5,("%s: Checking NTLMSSP password for %s\\%s failed: %s\n",
581                          __location__,
582                          ntlmssp_state->domain, ntlmssp_state->user,
583                          nt_errstr(nt_status)));
584                 TALLOC_FREE(state);
585                 return nt_status;
586         }
587
588         /* When we get more async in the auth code behind
589            ntlmssp_state->check_password, the ntlmssp_server_postpath
590            can be done in a callback */
591
592         nt_status = ntlmssp_server_postauth(ntlmssp_state, state);
593         TALLOC_FREE(state);
594         return nt_status;
595 }