2 Unix SMB/CIFS implementation.
5 Copyright (C) Stefan Metzmacher 2009
6 Copyright (C) Jeremy Allison 2010
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "smbd/smbd.h"
24 #include "smbd/globals.h"
25 #include "../libcli/smb/smb_common.h"
26 #include "../libcli/auth/spnego.h"
27 #include "../libcli/auth/ntlmssp.h"
28 #include "ntlmssp_wrap.h"
29 #include "../librpc/gen_ndr/krb5pac.h"
30 #include "libads/kerberos_proto.h"
31 #include "../lib/util/asn1.h"
33 #include "../lib/tsocket/tsocket.h"
34 #include "../libcli/security/security.h"
36 static NTSTATUS
smbd_smb2_session_setup(struct smbd_smb2_request
*smb2req
,
37 uint64_t in_session_id
,
38 uint8_t in_security_mode
,
39 DATA_BLOB in_security_buffer
,
40 uint16_t *out_session_flags
,
41 DATA_BLOB
*out_security_buffer
,
42 uint64_t *out_session_id
);
44 NTSTATUS
smbd_smb2_request_process_sesssetup(struct smbd_smb2_request
*smb2req
)
47 const uint8_t *inbody
;
48 int i
= smb2req
->current_idx
;
52 size_t expected_body_size
= 0x19;
54 uint64_t in_session_id
;
55 uint8_t in_security_mode
;
56 uint16_t in_security_offset
;
57 uint16_t in_security_length
;
58 DATA_BLOB in_security_buffer
;
59 uint16_t out_session_flags
;
60 uint64_t out_session_id
;
61 uint16_t out_security_offset
;
62 DATA_BLOB out_security_buffer
;
65 inhdr
= (const uint8_t *)smb2req
->in
.vector
[i
+0].iov_base
;
67 if (smb2req
->in
.vector
[i
+1].iov_len
!= (expected_body_size
& 0xFFFFFFFE)) {
68 return smbd_smb2_request_error(smb2req
, NT_STATUS_INVALID_PARAMETER
);
71 inbody
= (const uint8_t *)smb2req
->in
.vector
[i
+1].iov_base
;
73 body_size
= SVAL(inbody
, 0x00);
74 if (body_size
!= expected_body_size
) {
75 return smbd_smb2_request_error(smb2req
, NT_STATUS_INVALID_PARAMETER
);
78 in_security_offset
= SVAL(inbody
, 0x0C);
79 in_security_length
= SVAL(inbody
, 0x0E);
81 if (in_security_offset
!= (SMB2_HDR_BODY
+ (body_size
& 0xFFFFFFFE))) {
82 return smbd_smb2_request_error(smb2req
, NT_STATUS_INVALID_PARAMETER
);
85 if (in_security_length
> smb2req
->in
.vector
[i
+2].iov_len
) {
86 return smbd_smb2_request_error(smb2req
, NT_STATUS_INVALID_PARAMETER
);
89 in_session_id
= BVAL(inhdr
, SMB2_HDR_SESSION_ID
);
90 in_security_mode
= CVAL(inbody
, 0x03);
91 in_security_buffer
.data
= (uint8_t *)smb2req
->in
.vector
[i
+2].iov_base
;
92 in_security_buffer
.length
= in_security_length
;
94 status
= smbd_smb2_session_setup(smb2req
,
101 if (!NT_STATUS_IS_OK(status
) &&
102 !NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
103 status
= nt_status_squash(status
);
104 return smbd_smb2_request_error(smb2req
, status
);
107 out_security_offset
= SMB2_HDR_BODY
+ 0x08;
109 outhdr
= (uint8_t *)smb2req
->out
.vector
[i
].iov_base
;
111 outbody
= data_blob_talloc(smb2req
->out
.vector
, NULL
, 0x08);
112 if (outbody
.data
== NULL
) {
113 return smbd_smb2_request_error(smb2req
, NT_STATUS_NO_MEMORY
);
116 SBVAL(outhdr
, SMB2_HDR_SESSION_ID
, out_session_id
);
118 SSVAL(outbody
.data
, 0x00, 0x08 + 1); /* struct size */
119 SSVAL(outbody
.data
, 0x02,
120 out_session_flags
); /* session flags */
121 SSVAL(outbody
.data
, 0x04,
122 out_security_offset
); /* security buffer offset */
123 SSVAL(outbody
.data
, 0x06,
124 out_security_buffer
.length
); /* security buffer length */
126 outdyn
= out_security_buffer
;
128 return smbd_smb2_request_done_ex(smb2req
, status
, outbody
, &outdyn
,
132 static int smbd_smb2_session_destructor(struct smbd_smb2_session
*session
)
134 if (session
->sconn
== NULL
) {
138 /* first free all tcons */
139 while (session
->tcons
.list
) {
140 talloc_free(session
->tcons
.list
);
143 idr_remove(session
->sconn
->smb2
.sessions
.idtree
, session
->vuid
);
144 DLIST_REMOVE(session
->sconn
->smb2
.sessions
.list
, session
);
145 invalidate_vuid(session
->sconn
, session
->vuid
);
148 session
->status
= NT_STATUS_USER_SESSION_DELETED
;
149 session
->sconn
= NULL
;
154 static NTSTATUS
setup_ntlmssp_session_info(struct smbd_smb2_session
*session
,
157 if (NT_STATUS_IS_OK(status
)) {
158 status
= auth_ntlmssp_steal_session_info(session
,
159 session
->auth_ntlmssp_state
,
160 &session
->session_info
);
162 /* Note that this session_info won't have a session
163 * key. But for map to guest, that's exactly the right
164 * thing - we can't reasonably guess the key the
165 * client wants, as the password was wrong */
166 status
= do_map_to_guest(status
,
167 &session
->session_info
,
168 auth_ntlmssp_get_username(session
->auth_ntlmssp_state
),
169 auth_ntlmssp_get_domain(session
->auth_ntlmssp_state
));
175 static NTSTATUS
smbd_smb2_session_setup_krb5(struct smbd_smb2_session
*session
,
176 struct smbd_smb2_request
*smb2req
,
177 uint8_t in_security_mode
,
178 const DATA_BLOB
*secblob
,
180 uint16_t *out_session_flags
,
181 DATA_BLOB
*out_security_buffer
,
182 uint64_t *out_session_id
)
184 DATA_BLOB ap_rep
= data_blob_null
;
185 DATA_BLOB ap_rep_wrapped
= data_blob_null
;
186 DATA_BLOB ticket
= data_blob_null
;
187 DATA_BLOB session_key
= data_blob_null
;
188 DATA_BLOB secblob_out
= data_blob_null
;
190 struct PAC_LOGON_INFO
*logon_info
= NULL
;
191 char *principal
= NULL
;
194 struct passwd
*pw
= NULL
;
198 bool username_was_mapped
= false;
199 bool map_domainuser_to_guest
= false;
201 if (!spnego_parse_krb5_wrap(talloc_tos(), *secblob
, &ticket
, tok_id
)) {
202 status
= NT_STATUS_LOGON_FAILURE
;
206 status
= ads_verify_ticket(smb2req
, lp_realm(), 0, &ticket
,
207 &principal
, &logon_info
, &ap_rep
,
210 if (!NT_STATUS_IS_OK(status
)) {
211 DEBUG(1,("smb2: Failed to verify incoming ticket with error %s!\n",
213 if (!NT_STATUS_EQUAL(status
, NT_STATUS_TIME_DIFFERENCE_AT_DC
)) {
214 status
= NT_STATUS_LOGON_FAILURE
;
219 status
= get_user_from_kerberos_info(talloc_tos(),
220 session
->sconn
->remote_hostname
,
221 principal
, logon_info
,
222 &username_was_mapped
,
223 &map_domainuser_to_guest
,
225 &real_username
, &pw
);
226 if (!NT_STATUS_IS_OK(status
)) {
230 /* save the PAC data if we have it */
232 netsamlogon_cache_store(user
, &logon_info
->info3
);
235 /* setup the string used by %U */
236 sub_set_smb_name(real_username
);
238 /* reload services so that the new %U is taken into account */
239 reload_services(smb2req
->sconn
->msg_ctx
, smb2req
->sconn
->sock
, true);
241 status
= make_session_info_krb5(session
,
242 user
, domain
, real_username
, pw
,
243 logon_info
, map_domainuser_to_guest
,
246 &session
->session_info
);
247 if (!NT_STATUS_IS_OK(status
)) {
248 DEBUG(1, ("smb2: make_server_info_krb5 failed\n"));
252 if ((in_security_mode
& SMB2_NEGOTIATE_SIGNING_REQUIRED
) ||
253 lp_server_signing() == Required
) {
254 session
->do_signing
= true;
257 if (security_session_user_level(session
->session_info
, NULL
) < SECURITY_USER
) {
258 /* we map anonymous to guest internally */
259 *out_session_flags
|= SMB2_SESSION_FLAG_IS_GUEST
;
260 *out_session_flags
|= SMB2_SESSION_FLAG_IS_NULL
;
261 /* force no signing */
262 session
->do_signing
= false;
265 session
->session_key
= session
->session_info
->session_key
;
267 session
->compat_vuser
= talloc_zero(session
, user_struct
);
268 if (session
->compat_vuser
== NULL
) {
269 status
= NT_STATUS_NO_MEMORY
;
272 session
->compat_vuser
->auth_ntlmssp_state
= NULL
;
273 session
->compat_vuser
->homes_snum
= -1;
274 session
->compat_vuser
->session_info
= session
->session_info
;
275 session
->compat_vuser
->session_keystr
= NULL
;
276 session
->compat_vuser
->vuid
= session
->vuid
;
277 DLIST_ADD(session
->sconn
->smb1
.sessions
.validated_users
, session
->compat_vuser
);
279 /* This is a potentially untrusted username */
280 alpha_strcpy(tmp
, user
, ". _-$", sizeof(tmp
));
281 session
->session_info
->unix_info
->sanitized_username
=
282 talloc_strdup(session
->session_info
, tmp
);
284 if (security_session_user_level(session
->session_info
, NULL
) >= SECURITY_USER
) {
285 session
->compat_vuser
->homes_snum
=
286 register_homes_share(session
->session_info
->unix_info
->unix_name
);
289 if (!session_claim(session
->sconn
, session
->compat_vuser
)) {
290 DEBUG(1, ("smb2: Failed to claim session "
292 session
->compat_vuser
->vuid
));
296 session
->status
= NT_STATUS_OK
;
299 * we attach the session to the request
300 * so that the response can be signed
302 smb2req
->session
= session
;
303 if (session
->do_signing
) {
304 smb2req
->do_signing
= true;
307 global_client_caps
|= (CAP_LEVEL_II_OPLOCKS
|CAP_STATUS32
);
308 status
= NT_STATUS_OK
;
310 /* wrap that up in a nice GSS-API wrapping */
311 ap_rep_wrapped
= spnego_gen_krb5_wrap(talloc_tos(), ap_rep
,
314 secblob_out
= spnego_gen_auth_response(
320 *out_security_buffer
= data_blob_talloc(smb2req
,
323 if (secblob_out
.data
&& out_security_buffer
->data
== NULL
) {
324 status
= NT_STATUS_NO_MEMORY
;
328 data_blob_free(&ap_rep
);
329 data_blob_free(&ap_rep_wrapped
);
330 data_blob_free(&ticket
);
331 data_blob_free(&session_key
);
332 data_blob_free(&secblob_out
);
334 *out_session_id
= session
->vuid
;
340 data_blob_free(&ap_rep
);
341 data_blob_free(&ap_rep_wrapped
);
342 data_blob_free(&ticket
);
343 data_blob_free(&session_key
);
344 data_blob_free(&secblob_out
);
346 ap_rep_wrapped
= data_blob_null
;
347 secblob_out
= spnego_gen_auth_response(
353 *out_security_buffer
= data_blob_talloc(smb2req
,
356 data_blob_free(&secblob_out
);
361 static NTSTATUS
smbd_smb2_spnego_negotiate(struct smbd_smb2_session
*session
,
362 struct smbd_smb2_request
*smb2req
,
363 uint8_t in_security_mode
,
364 DATA_BLOB in_security_buffer
,
365 uint16_t *out_session_flags
,
366 DATA_BLOB
*out_security_buffer
,
367 uint64_t *out_session_id
)
369 DATA_BLOB secblob_in
= data_blob_null
;
370 DATA_BLOB chal_out
= data_blob_null
;
371 char *kerb_mech
= NULL
;
374 /* Ensure we have no old NTLM state around. */
375 TALLOC_FREE(session
->auth_ntlmssp_state
);
377 status
= parse_spnego_mechanisms(talloc_tos(), in_security_buffer
,
378 &secblob_in
, &kerb_mech
);
379 if (!NT_STATUS_IS_OK(status
)) {
384 if (kerb_mech
&& ((lp_security()==SEC_ADS
) ||
385 USE_KERBEROS_KEYTAB
) ) {
386 status
= smbd_smb2_session_setup_krb5(session
,
400 /* The mechtoken is a krb5 ticket, but
401 * we need to fall back to NTLM. */
403 DEBUG(3,("smb2: Got krb5 ticket in SPNEGO "
404 "but set to downgrade to NTLMSSP\n"));
406 status
= NT_STATUS_MORE_PROCESSING_REQUIRED
;
408 /* Fall back to NTLMSSP. */
409 status
= auth_ntlmssp_start(session
->sconn
->remote_address
,
410 &session
->auth_ntlmssp_state
);
411 if (!NT_STATUS_IS_OK(status
)) {
415 status
= auth_ntlmssp_update(session
->auth_ntlmssp_state
,
420 if (!NT_STATUS_IS_OK(status
) &&
421 !NT_STATUS_EQUAL(status
,
422 NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
426 *out_security_buffer
= spnego_gen_auth_response(smb2req
,
430 if (out_security_buffer
->data
== NULL
) {
431 status
= NT_STATUS_NO_MEMORY
;
434 *out_session_id
= session
->vuid
;
438 data_blob_free(&secblob_in
);
439 data_blob_free(&chal_out
);
440 TALLOC_FREE(kerb_mech
);
441 if (!NT_STATUS_IS_OK(status
) &&
442 !NT_STATUS_EQUAL(status
,
443 NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
444 TALLOC_FREE(session
->auth_ntlmssp_state
);
445 TALLOC_FREE(session
);
450 static NTSTATUS
smbd_smb2_common_ntlmssp_auth_return(struct smbd_smb2_session
*session
,
451 struct smbd_smb2_request
*smb2req
,
452 uint8_t in_security_mode
,
453 DATA_BLOB in_security_buffer
,
454 uint16_t *out_session_flags
,
455 uint64_t *out_session_id
)
459 if ((in_security_mode
& SMB2_NEGOTIATE_SIGNING_REQUIRED
) ||
460 lp_server_signing() == Required
) {
461 session
->do_signing
= true;
464 if (security_session_user_level(session
->session_info
, NULL
) < SECURITY_USER
) {
465 /* we map anonymous to guest internally */
466 *out_session_flags
|= SMB2_SESSION_FLAG_IS_GUEST
;
467 *out_session_flags
|= SMB2_SESSION_FLAG_IS_NULL
;
468 /* force no signing */
469 session
->do_signing
= false;
472 session
->session_key
= session
->session_info
->session_key
;
474 session
->compat_vuser
= talloc_zero(session
, user_struct
);
475 if (session
->compat_vuser
== NULL
) {
476 TALLOC_FREE(session
->auth_ntlmssp_state
);
477 TALLOC_FREE(session
);
478 return NT_STATUS_NO_MEMORY
;
480 session
->compat_vuser
->auth_ntlmssp_state
= session
->auth_ntlmssp_state
;
481 session
->compat_vuser
->homes_snum
= -1;
482 session
->compat_vuser
->session_info
= session
->session_info
;
483 session
->compat_vuser
->session_keystr
= NULL
;
484 session
->compat_vuser
->vuid
= session
->vuid
;
485 DLIST_ADD(session
->sconn
->smb1
.sessions
.validated_users
, session
->compat_vuser
);
487 /* This is a potentially untrusted username */
489 auth_ntlmssp_get_username(session
->auth_ntlmssp_state
),
492 session
->session_info
->unix_info
->sanitized_username
= talloc_strdup(
493 session
->session_info
, tmp
);
495 if (security_session_user_level(session
->session_info
, NULL
) >= SECURITY_USER
) {
496 session
->compat_vuser
->homes_snum
=
497 register_homes_share(session
->session_info
->unix_info
->unix_name
);
500 if (!session_claim(session
->sconn
, session
->compat_vuser
)) {
501 DEBUG(1, ("smb2: Failed to claim session "
503 session
->compat_vuser
->vuid
));
504 TALLOC_FREE(session
->auth_ntlmssp_state
);
505 TALLOC_FREE(session
);
506 return NT_STATUS_LOGON_FAILURE
;
510 session
->status
= NT_STATUS_OK
;
513 * we attach the session to the request
514 * so that the response can be signed
516 smb2req
->session
= session
;
517 if (session
->do_signing
) {
518 smb2req
->do_signing
= true;
521 global_client_caps
|= (CAP_LEVEL_II_OPLOCKS
|CAP_STATUS32
);
523 *out_session_id
= session
->vuid
;
528 static NTSTATUS
smbd_smb2_spnego_auth(struct smbd_smb2_session
*session
,
529 struct smbd_smb2_request
*smb2req
,
530 uint8_t in_security_mode
,
531 DATA_BLOB in_security_buffer
,
532 uint16_t *out_session_flags
,
533 DATA_BLOB
*out_security_buffer
,
534 uint64_t *out_session_id
)
536 DATA_BLOB auth
= data_blob_null
;
537 DATA_BLOB auth_out
= data_blob_null
;
540 if (!spnego_parse_auth(talloc_tos(), in_security_buffer
, &auth
)) {
541 TALLOC_FREE(session
);
542 return NT_STATUS_LOGON_FAILURE
;
545 if (auth
.data
[0] == ASN1_APPLICATION(0)) {
546 /* Might be a second negTokenTarg packet */
547 DATA_BLOB secblob_in
= data_blob_null
;
548 char *kerb_mech
= NULL
;
550 status
= parse_spnego_mechanisms(talloc_tos(),
552 &secblob_in
, &kerb_mech
);
553 if (!NT_STATUS_IS_OK(status
)) {
554 TALLOC_FREE(session
);
559 if (kerb_mech
&& ((lp_security()==SEC_ADS
) ||
560 USE_KERBEROS_KEYTAB
) ) {
561 status
= smbd_smb2_session_setup_krb5(session
,
570 data_blob_free(&secblob_in
);
571 TALLOC_FREE(kerb_mech
);
572 if (!NT_STATUS_IS_OK(status
)) {
573 TALLOC_FREE(session
);
579 /* Can't blunder into NTLMSSP auth if we have
583 DEBUG(3,("smb2: network "
584 "misconfiguration, client sent us a "
585 "krb5 ticket and kerberos security "
587 TALLOC_FREE(session
);
588 data_blob_free(&secblob_in
);
589 TALLOC_FREE(kerb_mech
);
590 return NT_STATUS_LOGON_FAILURE
;
593 data_blob_free(&secblob_in
);
596 if (session
->auth_ntlmssp_state
== NULL
) {
597 status
= auth_ntlmssp_start(session
->sconn
->remote_address
,
598 &session
->auth_ntlmssp_state
);
599 if (!NT_STATUS_IS_OK(status
)) {
600 data_blob_free(&auth
);
601 TALLOC_FREE(session
);
606 status
= auth_ntlmssp_update(session
->auth_ntlmssp_state
,
609 /* We need to call setup_ntlmssp_session_info() if status==NT_STATUS_OK,
610 or if status is anything except NT_STATUS_MORE_PROCESSING_REQUIRED,
611 as this can trigger map to guest. */
612 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
613 status
= setup_ntlmssp_session_info(session
, status
);
616 if (!NT_STATUS_IS_OK(status
) &&
617 !NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
618 TALLOC_FREE(session
->auth_ntlmssp_state
);
619 data_blob_free(&auth
);
620 TALLOC_FREE(session
);
624 data_blob_free(&auth
);
626 *out_security_buffer
= spnego_gen_auth_response(smb2req
,
627 &auth_out
, status
, NULL
);
629 if (out_security_buffer
->data
== NULL
) {
630 TALLOC_FREE(session
->auth_ntlmssp_state
);
631 TALLOC_FREE(session
);
632 return NT_STATUS_NO_MEMORY
;
635 *out_session_id
= session
->vuid
;
637 if (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
638 return NT_STATUS_MORE_PROCESSING_REQUIRED
;
641 /* We're done - claim the session. */
642 return smbd_smb2_common_ntlmssp_auth_return(session
,
650 static NTSTATUS
smbd_smb2_raw_ntlmssp_auth(struct smbd_smb2_session
*session
,
651 struct smbd_smb2_request
*smb2req
,
652 uint8_t in_security_mode
,
653 DATA_BLOB in_security_buffer
,
654 uint16_t *out_session_flags
,
655 DATA_BLOB
*out_security_buffer
,
656 uint64_t *out_session_id
)
659 DATA_BLOB secblob_out
= data_blob_null
;
661 if (session
->auth_ntlmssp_state
== NULL
) {
662 status
= auth_ntlmssp_start(session
->sconn
->remote_address
,
663 &session
->auth_ntlmssp_state
);
664 if (!NT_STATUS_IS_OK(status
)) {
665 TALLOC_FREE(session
);
671 status
= auth_ntlmssp_update(session
->auth_ntlmssp_state
,
675 if (NT_STATUS_IS_OK(status
) ||
676 NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
677 *out_security_buffer
= data_blob_talloc(smb2req
,
680 if (secblob_out
.data
&& out_security_buffer
->data
== NULL
) {
681 TALLOC_FREE(session
->auth_ntlmssp_state
);
682 TALLOC_FREE(session
);
683 return NT_STATUS_NO_MEMORY
;
687 if (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
688 *out_session_id
= session
->vuid
;
692 status
= setup_ntlmssp_session_info(session
, status
);
694 if (!NT_STATUS_IS_OK(status
)) {
695 TALLOC_FREE(session
->auth_ntlmssp_state
);
696 TALLOC_FREE(session
);
699 *out_session_id
= session
->vuid
;
701 return smbd_smb2_common_ntlmssp_auth_return(session
,
709 static NTSTATUS
smbd_smb2_session_setup(struct smbd_smb2_request
*smb2req
,
710 uint64_t in_session_id
,
711 uint8_t in_security_mode
,
712 DATA_BLOB in_security_buffer
,
713 uint16_t *out_session_flags
,
714 DATA_BLOB
*out_security_buffer
,
715 uint64_t *out_session_id
)
717 struct smbd_smb2_session
*session
;
719 *out_session_flags
= 0;
722 if (in_session_id
== 0) {
725 /* create a new session */
726 session
= talloc_zero(smb2req
->sconn
, struct smbd_smb2_session
);
727 if (session
== NULL
) {
728 return NT_STATUS_NO_MEMORY
;
730 session
->status
= NT_STATUS_MORE_PROCESSING_REQUIRED
;
731 id
= idr_get_new_random(smb2req
->sconn
->smb2
.sessions
.idtree
,
733 smb2req
->sconn
->smb2
.sessions
.limit
);
735 return NT_STATUS_INSUFFICIENT_RESOURCES
;
739 session
->tcons
.idtree
= idr_init(session
);
740 if (session
->tcons
.idtree
== NULL
) {
741 return NT_STATUS_NO_MEMORY
;
743 session
->tcons
.limit
= 0x0000FFFE;
744 session
->tcons
.list
= NULL
;
746 DLIST_ADD_END(smb2req
->sconn
->smb2
.sessions
.list
, session
,
747 struct smbd_smb2_session
*);
748 session
->sconn
= smb2req
->sconn
;
749 talloc_set_destructor(session
, smbd_smb2_session_destructor
);
753 /* lookup an existing session */
754 p
= idr_find(smb2req
->sconn
->smb2
.sessions
.idtree
, in_session_id
);
756 return NT_STATUS_USER_SESSION_DELETED
;
758 session
= talloc_get_type_abort(p
, struct smbd_smb2_session
);
761 if (NT_STATUS_IS_OK(session
->status
)) {
762 return NT_STATUS_REQUEST_NOT_ACCEPTED
;
765 if (in_security_buffer
.data
[0] == ASN1_APPLICATION(0)) {
766 return smbd_smb2_spnego_negotiate(session
,
773 } else if (in_security_buffer
.data
[0] == ASN1_CONTEXT(1)) {
774 return smbd_smb2_spnego_auth(session
,
781 } else if (strncmp((char *)(in_security_buffer
.data
), "NTLMSSP", 7) == 0) {
782 return smbd_smb2_raw_ntlmssp_auth(session
,
791 /* Unknown packet type. */
792 DEBUG(1,("Unknown packet type %u in smb2 sessionsetup\n",
793 (unsigned int)in_security_buffer
.data
[0] ));
794 TALLOC_FREE(session
->auth_ntlmssp_state
);
795 TALLOC_FREE(session
);
796 return NT_STATUS_LOGON_FAILURE
;
799 NTSTATUS
smbd_smb2_request_process_logoff(struct smbd_smb2_request
*req
)
801 const uint8_t *inbody
;
802 int i
= req
->current_idx
;
804 size_t expected_body_size
= 0x04;
807 if (req
->in
.vector
[i
+1].iov_len
!= (expected_body_size
& 0xFFFFFFFE)) {
808 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
811 inbody
= (const uint8_t *)req
->in
.vector
[i
+1].iov_base
;
813 body_size
= SVAL(inbody
, 0x00);
814 if (body_size
!= expected_body_size
) {
815 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
819 * TODO: cancel all outstanding requests on the session
820 * and delete all tree connections.
822 smbd_smb2_session_destructor(req
->session
);
824 * we may need to sign the response, so we need to keep
825 * the session until the response is sent to the wire.
827 talloc_steal(req
, req
->session
);
829 outbody
= data_blob_talloc(req
->out
.vector
, NULL
, 0x04);
830 if (outbody
.data
== NULL
) {
831 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
834 SSVAL(outbody
.data
, 0x00, 0x04); /* struct size */
835 SSVAL(outbody
.data
, 0x02, 0); /* reserved */
837 return smbd_smb2_request_done(req
, outbody
, NULL
);