2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2005
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 a composite API for making handling a generic async session setup
25 #include "libcli/raw/libcliraw.h"
26 #include "libcli/raw/raw_proto.h"
27 #include "libcli/composite/composite.h"
28 #include "libcli/smb_composite/smb_composite.h"
29 #include "libcli/auth/libcli_auth.h"
30 #include "auth/auth.h"
31 #include "auth/gensec/gensec.h"
32 #include "auth/credentials/credentials.h"
34 #include "param/param.h"
35 #include "libcli/smb/smbXcli_base.h"
37 struct sesssetup_state
{
38 struct smbcli_session
*session
;
39 union smb_sesssetup setup
;
40 const char *chosen_oid
;
41 NTSTATUS remote_status
;
42 NTSTATUS gensec_status
;
43 struct smb_composite_sesssetup
*io
;
44 struct smbcli_request
*req
;
45 struct smbcli_request
*check_req
;
46 unsigned int logon_retries
;
49 static int sesssetup_state_destructor(struct sesssetup_state
*state
)
52 talloc_free(state
->req
);
59 static NTSTATUS
session_setup_old(struct composite_context
*c
,
60 struct smbcli_session
*session
,
61 struct smb_composite_sesssetup
*io
,
62 struct smbcli_request
**req
);
63 static NTSTATUS
session_setup_nt1(struct composite_context
*c
,
64 struct smbcli_session
*session
,
65 struct smb_composite_sesssetup
*io
,
66 struct smbcli_request
**req
);
67 static NTSTATUS
session_setup_spnego_restart(struct composite_context
*c
,
68 struct smbcli_session
*session
,
69 struct smb_composite_sesssetup
*io
);
70 static NTSTATUS
session_setup_spnego(struct composite_context
*c
,
71 struct smbcli_session
*session
,
72 struct smb_composite_sesssetup
*io
,
73 struct smbcli_request
**req
);
74 static void smb_composite_sesssetup_spnego_done1(struct tevent_req
*subreq
);
75 static void smb_composite_sesssetup_spnego_done2(struct tevent_req
*subreq
);
79 handler for completion of a smbcli_request sub-request
81 static void request_handler(struct smbcli_request
*req
)
83 struct composite_context
*c
= (struct composite_context
*)req
->async
.private_data
;
84 struct sesssetup_state
*state
= talloc_get_type(c
->private_data
, struct sesssetup_state
);
85 struct smbcli_session
*session
= req
->session
;
86 DATA_BLOB null_data_blob
= data_blob(NULL
, 0);
87 NTSTATUS session_key_err
, nt_status
;
88 struct smbcli_request
*check_req
= NULL
;
89 const char *os
= NULL
;
90 const char *lanman
= NULL
;
92 if (req
->sign_caller_checks
) {
93 req
->do_not_free
= true;
97 state
->remote_status
= smb_raw_sesssetup_recv(req
, state
, &state
->setup
);
98 c
->status
= state
->remote_status
;
102 * we only need to check the signature if the
103 * NT_STATUS_OK is returned
105 if (!NT_STATUS_IS_OK(state
->remote_status
)) {
106 talloc_free(check_req
);
110 switch (state
->setup
.old
.level
) {
111 case RAW_SESSSETUP_OLD
:
112 state
->io
->out
.vuid
= state
->setup
.old
.out
.vuid
;
113 /* This doesn't work, as this only happens on old
114 * protocols, where this comparison won't match. */
115 if (NT_STATUS_EQUAL(c
->status
, NT_STATUS_LOGON_FAILURE
)) {
116 /* we need to reset the vuid for a new try */
118 if (cli_credentials_wrong_password(state
->io
->in
.credentials
)) {
119 nt_status
= session_setup_old(c
, session
,
122 if (NT_STATUS_IS_OK(nt_status
)) {
123 talloc_free(check_req
);
124 c
->status
= nt_status
;
125 composite_continue_smb(c
, state
->req
, request_handler
, c
);
130 if (!NT_STATUS_IS_OK(c
->status
)) {
131 composite_error(c
, c
->status
);
134 os
= state
->setup
.old
.out
.os
;
135 lanman
= state
->setup
.old
.out
.lanman
;
138 case RAW_SESSSETUP_NT1
:
139 state
->io
->out
.vuid
= state
->setup
.nt1
.out
.vuid
;
140 if (NT_STATUS_EQUAL(c
->status
, NT_STATUS_LOGON_FAILURE
)) {
141 /* we need to reset the vuid for a new try */
143 if (cli_credentials_wrong_password(state
->io
->in
.credentials
)) {
144 nt_status
= session_setup_nt1(c
, session
,
147 if (NT_STATUS_IS_OK(nt_status
)) {
148 talloc_free(check_req
);
149 c
->status
= nt_status
;
150 composite_continue_smb(c
, state
->req
, request_handler
, c
);
155 if (!NT_STATUS_IS_OK(c
->status
)) {
156 composite_error(c
, c
->status
);
159 os
= state
->setup
.nt1
.out
.os
;
160 lanman
= state
->setup
.nt1
.out
.lanman
;
163 case RAW_SESSSETUP_SPNEGO
:
164 state
->io
->out
.vuid
= state
->setup
.spnego
.out
.vuid
;
165 if (NT_STATUS_EQUAL(c
->status
, NT_STATUS_LOGON_FAILURE
)) {
166 const char *principal
;
168 /* we need to reset the vuid for a new try */
171 principal
= gensec_get_target_principal(session
->gensec
);
172 if (principal
== NULL
) {
173 const char *hostname
= gensec_get_target_hostname(session
->gensec
);
174 const char *service
= gensec_get_target_service(session
->gensec
);
175 if (hostname
!= NULL
&& service
!= NULL
) {
176 principal
= talloc_asprintf(state
, "%s/%s", service
, hostname
);
179 if (cli_credentials_failed_kerberos_login(state
->io
->in
.credentials
, principal
, &state
->logon_retries
) ||
180 cli_credentials_wrong_password(state
->io
->in
.credentials
)) {
181 struct tevent_req
*subreq
= NULL
;
183 nt_status
= session_setup_spnego_restart(c
, session
, state
->io
);
184 if (!NT_STATUS_IS_OK(nt_status
)) {
185 DEBUG(1, ("session_setup_spnego_restart() failed: %s\n",
186 nt_errstr(nt_status
)));
187 c
->status
= nt_status
;
188 composite_error(c
, c
->status
);
192 subreq
= gensec_update_send(state
, c
->event_ctx
,
194 state
->setup
.spnego
.out
.secblob
);
195 if (composite_nomem(subreq
, c
)) {
198 tevent_req_set_callback(subreq
,
199 smb_composite_sesssetup_spnego_done1
,
204 if (GENSEC_UPDATE_IS_NTERROR(c
->status
)) {
205 composite_error(c
, c
->status
);
208 if (NT_STATUS_EQUAL(state
->gensec_status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
209 struct tevent_req
*subreq
= NULL
;
211 /* The status value here, from the earlier pass at GENSEC is
212 * vital to the security of the system. Even if the other end
213 * accepts, if GENSEC claims 'MORE_PROCESSING_REQUIRED' then
214 * you must keep feeding it blobs, or else the remote
215 * host/attacker might avoid mutual authentication
218 subreq
= gensec_update_send(state
, c
->event_ctx
,
220 state
->setup
.spnego
.out
.secblob
);
221 if (composite_nomem(subreq
, c
)) {
224 tevent_req_set_callback(subreq
,
225 smb_composite_sesssetup_spnego_done2
,
227 if (NT_STATUS_IS_OK(state
->remote_status
)) {
228 state
->check_req
= check_req
;
230 TALLOC_FREE(check_req
);
234 state
->setup
.spnego
.in
.secblob
= data_blob(NULL
, 0);
237 if (cli_credentials_is_anonymous(state
->io
->in
.credentials
)) {
239 * anonymous => no signing
241 } else if (NT_STATUS_IS_OK(state
->remote_status
)) {
242 DATA_BLOB session_key
;
244 if (state
->setup
.spnego
.in
.secblob
.length
) {
245 c
->status
= NT_STATUS_INTERNAL_ERROR
;
246 composite_error(c
, c
->status
);
249 session_key_err
= gensec_session_key(session
->gensec
, session
, &session_key
);
250 if (NT_STATUS_IS_OK(session_key_err
)) {
251 smb1cli_conn_activate_signing(session
->transport
->conn
,
256 c
->status
= smb1cli_session_set_session_key(session
->smbXcli
,
258 data_blob_free(&session_key
);
259 if (!NT_STATUS_IS_OK(c
->status
)) {
260 composite_error(c
, c
->status
);
265 os
= state
->setup
.spnego
.out
.os
;
266 lanman
= state
->setup
.spnego
.out
.lanman
;
269 case RAW_SESSSETUP_SMB2
:
270 c
->status
= NT_STATUS_INTERNAL_ERROR
;
271 composite_error(c
, c
->status
);
278 check_req
->sign_caller_checks
= false;
280 ok
= smb1cli_conn_check_signing(check_req
->transport
->conn
,
281 check_req
->in
.buffer
, 1);
282 TALLOC_FREE(check_req
);
284 c
->status
= NT_STATUS_ACCESS_DENIED
;
285 composite_error(c
, c
->status
);
290 if (!NT_STATUS_IS_OK(c
->status
)) {
291 composite_error(c
, c
->status
);
296 session
->os
= talloc_strdup(session
, os
);
297 if (composite_nomem(session
->os
, c
)) return;
302 session
->lanman
= talloc_strdup(session
, lanman
);
303 if (composite_nomem(session
->lanman
, c
)) return;
305 session
->lanman
= NULL
;
313 send a nt1 style session setup
315 static NTSTATUS
session_setup_nt1(struct composite_context
*c
,
316 struct smbcli_session
*session
,
317 struct smb_composite_sesssetup
*io
,
318 struct smbcli_request
**req
)
320 NTSTATUS nt_status
= NT_STATUS_INTERNAL_ERROR
;
321 struct sesssetup_state
*state
= talloc_get_type(c
->private_data
,
322 struct sesssetup_state
);
323 const char *domain
= cli_credentials_get_domain(io
->in
.credentials
);
326 * domain controllers tend to reject the NTLM v2 blob
327 * if the netbiosname is not valid (e.g. IP address or FQDN)
328 * so just leave it away (as Windows client do)
330 DATA_BLOB names_blob
= NTLMv2_generate_names_blob(state
, NULL
, domain
);
332 DATA_BLOB session_key
= data_blob(NULL
, 0);
333 int flags
= CLI_CRED_NTLM_AUTH
;
335 if (session
->options
.lanman_auth
) {
336 flags
|= CLI_CRED_LANMAN_AUTH
;
339 if (session
->options
.ntlmv2_auth
) {
340 flags
|= CLI_CRED_NTLMv2_AUTH
;
343 state
->setup
.nt1
.level
= RAW_SESSSETUP_NT1
;
344 state
->setup
.nt1
.in
.bufsize
= session
->transport
->options
.max_xmit
;
345 state
->setup
.nt1
.in
.mpx_max
= session
->transport
->options
.max_mux
;
346 state
->setup
.nt1
.in
.vc_num
= 1;
347 state
->setup
.nt1
.in
.sesskey
= io
->in
.sesskey
;
348 state
->setup
.nt1
.in
.capabilities
= io
->in
.capabilities
;
349 state
->setup
.nt1
.in
.os
= "Unix";
350 state
->setup
.nt1
.in
.lanman
= talloc_asprintf(state
, "Samba %s", SAMBA_VERSION_STRING
);
352 cli_credentials_get_ntlm_username_domain(io
->in
.credentials
, state
,
353 &state
->setup
.nt1
.in
.user
,
354 &state
->setup
.nt1
.in
.domain
);
357 if (session
->transport
->negotiate
.sec_mode
& NEGOTIATE_SECURITY_CHALLENGE_RESPONSE
) {
358 if (!cli_credentials_is_anonymous(io
->in
.credentials
) &&
359 session
->options
.ntlmv2_auth
&&
360 session
->transport
->options
.use_spnego
)
363 * Don't send an NTLMv2_RESPONSE without NTLMSSP
364 * if we want to use spnego
366 return NT_STATUS_INVALID_PARAMETER
;
369 nt_status
= cli_credentials_get_ntlm_response(io
->in
.credentials
, state
,
371 session
->transport
->negotiate
.secblob
,
372 NULL
, /* server_timestamp */
374 &state
->setup
.nt1
.in
.password1
,
375 &state
->setup
.nt1
.in
.password2
,
377 NT_STATUS_NOT_OK_RETURN(nt_status
);
378 } else if (session
->options
.plaintext_auth
) {
379 const char *password
= cli_credentials_get_password(io
->in
.credentials
);
380 state
->setup
.nt1
.in
.password1
= data_blob_talloc(state
, password
, strlen(password
));
381 state
->setup
.nt1
.in
.password2
= data_blob(NULL
, 0);
383 /* could match windows client and return 'cannot logon from this workstation', but it just confuses everybody */
384 return NT_STATUS_INVALID_PARAMETER
;
387 *req
= smb_raw_sesssetup_send(session
, &state
->setup
);
389 return NT_STATUS_NO_MEMORY
;
392 if (!NT_STATUS_IS_OK(nt_status
)) {
394 * plain text => no signing
396 return (*req
)->status
;
399 if (cli_credentials_is_anonymous(io
->in
.credentials
)) {
401 * anonymous => no signing
403 return (*req
)->status
;
406 smb1cli_conn_activate_signing(session
->transport
->conn
,
408 state
->setup
.nt1
.in
.password2
);
410 nt_status
= smb1cli_session_set_session_key(session
->smbXcli
,
412 data_blob_free(&session_key
);
413 if (!NT_STATUS_IS_OK(nt_status
)) {
417 return (*req
)->status
;
422 old style session setup (pre NT1 protocol level)
424 static NTSTATUS
session_setup_old(struct composite_context
*c
,
425 struct smbcli_session
*session
,
426 struct smb_composite_sesssetup
*io
,
427 struct smbcli_request
**req
)
430 struct sesssetup_state
*state
= talloc_get_type(c
->private_data
,
431 struct sesssetup_state
);
432 const char *password
= cli_credentials_get_password(io
->in
.credentials
);
435 * domain controllers tend to reject the NTLM v2 blob
436 * if the netbiosname is not valid (e.g. IP address or FQDN)
437 * so just leave it away (as Windows client do)
439 DATA_BLOB session_key
;
441 state
->setup
.old
.level
= RAW_SESSSETUP_OLD
;
442 state
->setup
.old
.in
.bufsize
= session
->transport
->options
.max_xmit
;
443 state
->setup
.old
.in
.mpx_max
= session
->transport
->options
.max_mux
;
444 state
->setup
.old
.in
.vc_num
= 1;
445 state
->setup
.old
.in
.sesskey
= io
->in
.sesskey
;
446 state
->setup
.old
.in
.os
= "Unix";
447 state
->setup
.old
.in
.lanman
= talloc_asprintf(state
, "Samba %s", SAMBA_VERSION_STRING
);
448 cli_credentials_get_ntlm_username_domain(io
->in
.credentials
, state
,
449 &state
->setup
.old
.in
.user
,
450 &state
->setup
.old
.in
.domain
);
452 if (session
->transport
->negotiate
.sec_mode
& NEGOTIATE_SECURITY_CHALLENGE_RESPONSE
) {
453 DATA_BLOB names_blob
= data_blob_null
;
456 if (!cli_credentials_is_anonymous(io
->in
.credentials
) &&
457 !session
->options
.lanman_auth
)
459 return NT_STATUS_INVALID_PARAMETER
;
462 flags
|= CLI_CRED_LANMAN_AUTH
;
464 nt_status
= cli_credentials_get_ntlm_response(io
->in
.credentials
, state
,
466 session
->transport
->negotiate
.secblob
,
467 NULL
, /* server_timestamp */
469 &state
->setup
.old
.in
.password
,
472 NT_STATUS_NOT_OK_RETURN(nt_status
);
474 nt_status
= smb1cli_session_set_session_key(session
->smbXcli
,
476 data_blob_free(&session_key
);
477 if (!NT_STATUS_IS_OK(nt_status
)) {
480 } else if (session
->options
.plaintext_auth
) {
481 state
->setup
.old
.in
.password
= data_blob_talloc(state
, password
, strlen(password
));
483 /* could match windows client and return 'cannot logon from this workstation', but it just confuses everybody */
484 return NT_STATUS_INVALID_PARAMETER
;
487 *req
= smb_raw_sesssetup_send(session
, &state
->setup
);
489 return NT_STATUS_NO_MEMORY
;
491 return (*req
)->status
;
494 static NTSTATUS
session_setup_spnego_restart(struct composite_context
*c
,
495 struct smbcli_session
*session
,
496 struct smb_composite_sesssetup
*io
)
498 struct sesssetup_state
*state
= talloc_get_type(c
->private_data
, struct sesssetup_state
);
501 status
= gensec_client_start(session
, &session
->gensec
,
502 io
->in
.gensec_settings
);
503 if (!NT_STATUS_IS_OK(status
)) {
504 DEBUG(1, ("Failed to start GENSEC client mode: %s\n", nt_errstr(status
)));
508 gensec_want_feature(session
->gensec
, GENSEC_FEATURE_SESSION_KEY
);
510 status
= gensec_set_credentials(session
->gensec
, io
->in
.credentials
);
511 if (!NT_STATUS_IS_OK(status
)) {
512 DEBUG(1, ("Failed to start set GENSEC client credentials: %s\n",
517 status
= gensec_set_target_hostname(session
->gensec
,
518 smbXcli_conn_remote_name(session
->transport
->conn
));
519 if (!NT_STATUS_IS_OK(status
)) {
520 DEBUG(1, ("Failed to start set GENSEC target hostname: %s\n",
525 status
= gensec_set_target_service(session
->gensec
, "cifs");
526 if (!NT_STATUS_IS_OK(status
)) {
527 DEBUG(1, ("Failed to start set GENSEC target service: %s\n",
532 state
->setup
.spnego
.out
.secblob
=
533 session
->transport
->negotiate
.secblob
;
534 if (session
->transport
->negotiate
.secblob
.length
) {
535 state
->chosen_oid
= GENSEC_OID_SPNEGO
;
536 status
= gensec_start_mech_by_oid(session
->gensec
,
538 if (!NT_STATUS_IS_OK(status
)) {
539 DEBUG(1, ("Failed to start set GENSEC client mechanism %s: %s\n",
540 gensec_get_name_by_oid(session
->gensec
,
543 state
->setup
.spnego
.out
.secblob
= data_blob_null
;
544 state
->chosen_oid
= GENSEC_OID_NTLMSSP
;
545 status
= gensec_start_mech_by_oid(session
->gensec
,
547 if (!NT_STATUS_IS_OK(status
)) {
548 DEBUG(1, ("Failed to start set (fallback) GENSEC client mechanism %s: %s\n",
549 gensec_get_name_by_oid(session
->gensec
,
556 /* without a sec blob, means raw NTLMSSP */
557 state
->chosen_oid
= GENSEC_OID_NTLMSSP
;
558 status
= gensec_start_mech_by_oid(session
->gensec
,
560 if (!NT_STATUS_IS_OK(status
)) {
561 DEBUG(1, ("Failed to start set GENSEC client mechanism %s: %s\n",
562 gensec_get_name_by_oid(session
->gensec
,
569 state
->gensec_status
= NT_STATUS_MORE_PROCESSING_REQUIRED
;
570 state
->remote_status
= NT_STATUS_MORE_PROCESSING_REQUIRED
;
575 Modern, all singing, all dancing extended security (and possibly SPNEGO) request
577 static NTSTATUS
session_setup_spnego(struct composite_context
*c
,
578 struct smbcli_session
*session
,
579 struct smb_composite_sesssetup
*io
,
580 struct smbcli_request
**req
)
582 struct sesssetup_state
*state
= talloc_get_type(c
->private_data
, struct sesssetup_state
);
584 state
->setup
.spnego
.level
= RAW_SESSSETUP_SPNEGO
;
585 state
->setup
.spnego
.in
.bufsize
= session
->transport
->options
.max_xmit
;
586 state
->setup
.spnego
.in
.mpx_max
= session
->transport
->options
.max_mux
;
587 state
->setup
.spnego
.in
.vc_num
= 1;
588 state
->setup
.spnego
.in
.sesskey
= io
->in
.sesskey
;
589 state
->setup
.spnego
.in
.capabilities
= io
->in
.capabilities
;
590 state
->setup
.spnego
.in
.os
= "Unix";
591 state
->setup
.spnego
.in
.lanman
= talloc_asprintf(state
, "Samba %s", SAMBA_VERSION_STRING
);
592 state
->setup
.spnego
.in
.workgroup
= io
->in
.workgroup
;
594 *req
= smb_raw_sesssetup_send(session
, &state
->setup
);
596 return NT_STATUS_NO_MEMORY
;
600 * we need to check the signature ourself
601 * as the session key might be the acceptor subkey
602 * which comes within the response itself
604 if (!smb1cli_conn_signing_is_active((*req
)->transport
->conn
)) {
605 (*req
)->sign_caller_checks
= true;
608 return (*req
)->status
;
613 composite session setup function that hides the details of all the
614 different session setup variants, including the multi-pass nature of
617 struct composite_context
*smb_composite_sesssetup_send(struct smbcli_session
*session
,
618 struct smb_composite_sesssetup
*io
)
620 struct composite_context
*c
;
621 struct sesssetup_state
*state
;
623 enum smb_encryption_setting encryption_state
=
624 cli_credentials_get_smb_encryption(io
->in
.credentials
);
625 enum credentials_use_kerberos krb5_state
=
626 cli_credentials_get_kerberos_state(io
->in
.credentials
);
628 c
= composite_create(session
, session
->transport
->ev
);
629 if (c
== NULL
) return NULL
;
631 if (encryption_state
> SMB_ENCRYPTION_DESIRED
) {
632 composite_error(c
, NT_STATUS_PROTOCOL_NOT_SUPPORTED
);
636 state
= talloc_zero(c
, struct sesssetup_state
);
637 if (composite_nomem(state
, c
)) return c
;
638 c
->private_data
= state
;
640 state
->session
= session
;
643 talloc_set_destructor(state
, sesssetup_state_destructor
);
645 /* no session setup at all in earliest protocol variants */
646 if (session
->transport
->negotiate
.protocol
< PROTOCOL_LANMAN1
) {
647 if (krb5_state
== CRED_USE_KERBEROS_REQUIRED
) {
648 composite_error(c
, NT_STATUS_NETWORK_CREDENTIAL_CONFLICT
);
651 ZERO_STRUCT(io
->out
);
656 /* see what session setup interface we will use */
657 if (session
->transport
->negotiate
.protocol
< PROTOCOL_NT1
) {
658 if (krb5_state
== CRED_USE_KERBEROS_REQUIRED
) {
659 composite_error(c
, NT_STATUS_NETWORK_CREDENTIAL_CONFLICT
);
662 status
= session_setup_old(c
, session
, io
, &state
->req
);
663 } else if (!session
->transport
->options
.use_spnego
||
664 !(io
->in
.capabilities
& CAP_EXTENDED_SECURITY
)) {
665 if (krb5_state
== CRED_USE_KERBEROS_REQUIRED
) {
666 composite_error(c
, NT_STATUS_NETWORK_CREDENTIAL_CONFLICT
);
669 status
= session_setup_nt1(c
, session
, io
, &state
->req
);
671 struct tevent_req
*subreq
= NULL
;
673 status
= session_setup_spnego_restart(c
, session
, io
);
674 if (!NT_STATUS_IS_OK(status
)) {
675 DEBUG(1, ("session_setup_spnego_restart() failed: %s\n",
678 composite_error(c
, c
->status
);
682 subreq
= gensec_update_send(state
, c
->event_ctx
,
684 state
->setup
.spnego
.out
.secblob
);
685 if (composite_nomem(subreq
, c
)) {
688 tevent_req_set_callback(subreq
,
689 smb_composite_sesssetup_spnego_done1
,
694 if (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
) ||
695 NT_STATUS_IS_OK(status
)) {
696 composite_continue_smb(c
, state
->req
, request_handler
, c
);
700 composite_error(c
, status
);
704 static void smb_composite_sesssetup_spnego_done1(struct tevent_req
*subreq
)
706 struct composite_context
*c
=
707 tevent_req_callback_data(subreq
,
708 struct composite_context
);
709 struct sesssetup_state
*state
=
710 talloc_get_type_abort(c
->private_data
,
711 struct sesssetup_state
);
714 status
= gensec_update_recv(subreq
, state
,
715 &state
->setup
.spnego
.in
.secblob
);
717 if (GENSEC_UPDATE_IS_NTERROR(status
)) {
718 DEBUG(1, ("Failed initial gensec_update with mechanism %s: %s\n",
719 gensec_get_name_by_oid(state
->session
->gensec
,
723 composite_error(c
, c
->status
);
726 state
->gensec_status
= status
;
728 status
= session_setup_spnego(c
, state
->session
, state
->io
, &state
->req
);
729 if (!NT_STATUS_IS_OK(status
)) {
731 composite_error(c
, c
->status
);
735 composite_continue_smb(c
, state
->req
, request_handler
, c
);
738 static void smb_composite_sesssetup_spnego_done2(struct tevent_req
*subreq
)
740 struct composite_context
*c
=
741 tevent_req_callback_data(subreq
,
742 struct composite_context
);
743 struct sesssetup_state
*state
=
744 talloc_get_type_abort(c
->private_data
,
745 struct sesssetup_state
);
746 struct smbcli_session
*session
= state
->session
;
748 const char *os
= NULL
;
749 const char *lanman
= NULL
;
751 status
= gensec_update_recv(subreq
, state
,
752 &state
->setup
.spnego
.in
.secblob
);
754 if (GENSEC_UPDATE_IS_NTERROR(status
)) {
755 DEBUG(1, ("Failed initial gensec_update with mechanism %s: %s\n",
756 gensec_get_name_by_oid(state
->session
->gensec
,
760 composite_error(c
, c
->status
);
763 state
->gensec_status
= status
;
765 if (NT_STATUS_IS_OK(state
->remote_status
)) {
766 if (state
->setup
.spnego
.in
.secblob
.length
) {
767 c
->status
= NT_STATUS_INTERNAL_ERROR
;
768 composite_error(c
, c
->status
);
773 if (state
->setup
.spnego
.in
.secblob
.length
) {
775 * set the session->vuid value only for calling
776 * smb_raw_sesssetup_send()
778 uint16_t vuid
= session
->vuid
;
779 session
->vuid
= state
->io
->out
.vuid
;
780 state
->req
= smb_raw_sesssetup_send(session
, &state
->setup
);
781 session
->vuid
= vuid
;
783 !smb1cli_conn_signing_is_active(state
->req
->transport
->conn
)) {
784 state
->req
->sign_caller_checks
= true;
786 composite_continue_smb(c
, state
->req
, request_handler
, c
);
790 if (cli_credentials_is_anonymous(state
->io
->in
.credentials
)) {
792 * anonymous => no signing
794 } else if (NT_STATUS_IS_OK(state
->remote_status
)) {
795 NTSTATUS session_key_err
;
796 DATA_BLOB session_key
;
798 session_key_err
= gensec_session_key(session
->gensec
, session
, &session_key
);
799 if (NT_STATUS_IS_OK(session_key_err
)) {
800 smb1cli_conn_activate_signing(session
->transport
->conn
,
805 c
->status
= smb1cli_session_set_session_key(session
->smbXcli
,
807 data_blob_free(&session_key
);
808 if (!NT_STATUS_IS_OK(c
->status
)) {
809 composite_error(c
, c
->status
);
814 os
= state
->setup
.spnego
.out
.os
;
815 lanman
= state
->setup
.spnego
.out
.lanman
;
817 if (state
->check_req
) {
818 struct smbcli_request
*check_req
= state
->check_req
;
821 check_req
->sign_caller_checks
= false;
823 ok
= smb1cli_conn_check_signing(check_req
->transport
->conn
,
824 check_req
->in
.buffer
, 1);
825 TALLOC_FREE(check_req
);
827 c
->status
= NT_STATUS_ACCESS_DENIED
;
828 composite_error(c
, c
->status
);
834 session
->os
= talloc_strdup(session
, os
);
835 if (composite_nomem(session
->os
, c
)) return;
840 session
->lanman
= talloc_strdup(session
, lanman
);
841 if (composite_nomem(session
->lanman
, c
)) return;
843 session
->lanman
= NULL
;
850 receive a composite session setup reply
852 NTSTATUS
smb_composite_sesssetup_recv(struct composite_context
*c
)
855 status
= composite_wait(c
);
861 sync version of smb_composite_sesssetup
863 NTSTATUS
smb_composite_sesssetup(struct smbcli_session
*session
, struct smb_composite_sesssetup
*io
)
865 struct composite_context
*c
= smb_composite_sesssetup_send(session
, io
);
866 return smb_composite_sesssetup_recv(c
);