2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan (metze) Metzmacher 2003
5 Copyright (C) Jeremy Allison 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "../libcli/auth/spnego.h"
23 #include "../libcli/auth/ntlmssp.h"
24 #include "async_smb.h"
25 #include "smb_crypt.h"
28 /****************************************************************************
29 Get UNIX extensions version info.
30 ****************************************************************************/
32 struct cli_unix_extensions_version_state
{
33 struct cli_state
*cli
;
36 uint16_t major
, minor
;
37 uint32_t caplow
, caphigh
;
40 static void cli_unix_extensions_version_done(struct tevent_req
*subreq
);
42 struct tevent_req
*cli_unix_extensions_version_send(TALLOC_CTX
*mem_ctx
,
43 struct tevent_context
*ev
,
44 struct cli_state
*cli
)
46 struct tevent_req
*req
, *subreq
;
47 struct cli_unix_extensions_version_state
*state
;
49 req
= tevent_req_create(mem_ctx
, &state
,
50 struct cli_unix_extensions_version_state
);
55 SSVAL(state
->setup
, 0, TRANSACT2_QFSINFO
);
56 SSVAL(state
->param
, 0, SMB_QUERY_CIFS_UNIX_INFO
);
58 subreq
= cli_trans_send(state
, ev
, cli
, SMBtrans2
,
63 if (tevent_req_nomem(subreq
, req
)) {
64 return tevent_req_post(req
, ev
);
66 tevent_req_set_callback(subreq
, cli_unix_extensions_version_done
, req
);
70 static void cli_unix_extensions_version_done(struct tevent_req
*subreq
)
72 struct tevent_req
*req
= tevent_req_callback_data(
73 subreq
, struct tevent_req
);
74 struct cli_unix_extensions_version_state
*state
= tevent_req_data(
75 req
, struct cli_unix_extensions_version_state
);
80 status
= cli_trans_recv(subreq
, state
, NULL
, NULL
, 0, NULL
,
81 NULL
, 0, NULL
, &data
, 12, &num_data
);
83 if (!NT_STATUS_IS_OK(status
)) {
84 tevent_req_nterror(req
, status
);
88 state
->major
= SVAL(data
, 0);
89 state
->minor
= SVAL(data
, 2);
90 state
->caplow
= IVAL(data
, 4);
91 state
->caphigh
= IVAL(data
, 8);
96 NTSTATUS
cli_unix_extensions_version_recv(struct tevent_req
*req
,
97 uint16_t *pmajor
, uint16_t *pminor
,
101 struct cli_unix_extensions_version_state
*state
= tevent_req_data(
102 req
, struct cli_unix_extensions_version_state
);
105 if (tevent_req_is_nterror(req
, &status
)) {
108 *pmajor
= state
->major
;
109 *pminor
= state
->minor
;
110 *pcaplow
= state
->caplow
;
111 *pcaphigh
= state
->caphigh
;
112 state
->cli
->server_posix_capabilities
= *pcaplow
;
116 NTSTATUS
cli_unix_extensions_version(struct cli_state
*cli
, uint16
*pmajor
,
117 uint16
*pminor
, uint32
*pcaplow
,
120 TALLOC_CTX
*frame
= talloc_stackframe();
121 struct event_context
*ev
;
122 struct tevent_req
*req
;
123 NTSTATUS status
= NT_STATUS_OK
;
125 if (cli_has_async_calls(cli
)) {
127 * Can't use sync call while an async call is in flight
129 status
= NT_STATUS_INVALID_PARAMETER
;
133 ev
= event_context_init(frame
);
135 status
= NT_STATUS_NO_MEMORY
;
139 req
= cli_unix_extensions_version_send(frame
, ev
, cli
);
141 status
= NT_STATUS_NO_MEMORY
;
145 if (!tevent_req_poll(req
, ev
)) {
146 status
= map_nt_error_from_unix(errno
);
150 status
= cli_unix_extensions_version_recv(req
, pmajor
, pminor
, pcaplow
,
154 if (!NT_STATUS_IS_OK(status
)) {
155 cli_set_error(cli
, status
);
160 /****************************************************************************
161 Set UNIX extensions capabilities.
162 ****************************************************************************/
164 struct cli_set_unix_extensions_capabilities_state
{
165 struct cli_state
*cli
;
171 static void cli_set_unix_extensions_capabilities_done(
172 struct tevent_req
*subreq
);
174 struct tevent_req
*cli_set_unix_extensions_capabilities_send(
175 TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev
, struct cli_state
*cli
,
176 uint16_t major
, uint16_t minor
, uint32_t caplow
, uint32_t caphigh
)
178 struct tevent_req
*req
, *subreq
;
179 struct cli_set_unix_extensions_capabilities_state
*state
;
181 req
= tevent_req_create(
183 struct cli_set_unix_extensions_capabilities_state
);
189 SSVAL(state
->setup
+0, 0, TRANSACT2_SETFSINFO
);
191 SSVAL(state
->param
, 0, 0);
192 SSVAL(state
->param
, 2, SMB_SET_CIFS_UNIX_INFO
);
194 SSVAL(state
->data
, 0, major
);
195 SSVAL(state
->data
, 2, minor
);
196 SIVAL(state
->data
, 4, caplow
);
197 SIVAL(state
->data
, 8, caphigh
);
199 subreq
= cli_trans_send(state
, ev
, cli
, SMBtrans2
,
203 state
->data
, 12, 560);
204 if (tevent_req_nomem(subreq
, req
)) {
205 return tevent_req_post(req
, ev
);
207 tevent_req_set_callback(
208 subreq
, cli_set_unix_extensions_capabilities_done
, req
);
212 static void cli_set_unix_extensions_capabilities_done(
213 struct tevent_req
*subreq
)
215 struct tevent_req
*req
= tevent_req_callback_data(
216 subreq
, struct tevent_req
);
217 struct cli_set_unix_extensions_capabilities_state
*state
= tevent_req_data(
218 req
, struct cli_set_unix_extensions_capabilities_state
);
220 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
221 NULL
, 0, NULL
, NULL
, 0, NULL
);
222 if (NT_STATUS_IS_OK(status
)) {
223 state
->cli
->requested_posix_capabilities
= IVAL(state
->data
, 4);
225 tevent_req_simple_finish_ntstatus(subreq
, status
);
228 NTSTATUS
cli_set_unix_extensions_capabilities_recv(struct tevent_req
*req
)
230 return tevent_req_simple_recv_ntstatus(req
);
233 NTSTATUS
cli_set_unix_extensions_capabilities(struct cli_state
*cli
,
234 uint16 major
, uint16 minor
,
235 uint32 caplow
, uint32 caphigh
)
237 struct tevent_context
*ev
;
238 struct tevent_req
*req
;
239 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
241 if (cli_has_async_calls(cli
)) {
242 return NT_STATUS_INVALID_PARAMETER
;
244 ev
= tevent_context_init(talloc_tos());
248 req
= cli_set_unix_extensions_capabilities_send(
249 ev
, ev
, cli
, major
, minor
, caplow
, caphigh
);
253 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
256 status
= cli_set_unix_extensions_capabilities_recv(req
);
259 if (!NT_STATUS_IS_OK(status
)) {
260 cli_set_error(cli
, status
);
265 struct cli_get_fs_attr_info_state
{
271 static void cli_get_fs_attr_info_done(struct tevent_req
*subreq
);
273 struct tevent_req
*cli_get_fs_attr_info_send(TALLOC_CTX
*mem_ctx
,
274 struct tevent_context
*ev
,
275 struct cli_state
*cli
)
277 struct tevent_req
*subreq
, *req
;
278 struct cli_get_fs_attr_info_state
*state
;
280 req
= tevent_req_create(mem_ctx
, &state
,
281 struct cli_get_fs_attr_info_state
);
285 SSVAL(state
->setup
+0, 0, TRANSACT2_QFSINFO
);
286 SSVAL(state
->param
+0, 0, SMB_QUERY_FS_ATTRIBUTE_INFO
);
288 subreq
= cli_trans_send(state
, ev
, cli
, SMBtrans2
,
293 if (tevent_req_nomem(subreq
, req
)) {
294 return tevent_req_post(req
, ev
);
296 tevent_req_set_callback(subreq
, cli_get_fs_attr_info_done
, req
);
300 static void cli_get_fs_attr_info_done(struct tevent_req
*subreq
)
302 struct tevent_req
*req
= tevent_req_callback_data(
303 subreq
, struct tevent_req
);
304 struct cli_get_fs_attr_info_state
*state
= tevent_req_data(
305 req
, struct cli_get_fs_attr_info_state
);
310 status
= cli_trans_recv(subreq
, talloc_tos(), NULL
, NULL
, 0, NULL
,
311 NULL
, 0, NULL
, &data
, 12, &num_data
);
313 if (!NT_STATUS_IS_OK(status
)) {
314 tevent_req_nterror(req
, status
);
317 state
->fs_attr
= IVAL(data
, 0);
319 tevent_req_done(req
);
322 NTSTATUS
cli_get_fs_attr_info_recv(struct tevent_req
*req
, uint32_t *fs_attr
)
324 struct cli_get_fs_attr_info_state
*state
= tevent_req_data(
325 req
, struct cli_get_fs_attr_info_state
);
328 if (tevent_req_is_nterror(req
, &status
)) {
331 *fs_attr
= state
->fs_attr
;
335 NTSTATUS
cli_get_fs_attr_info(struct cli_state
*cli
, uint32_t *fs_attr
)
337 struct tevent_context
*ev
;
338 struct tevent_req
*req
;
339 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
341 if (cli_has_async_calls(cli
)) {
342 return NT_STATUS_INVALID_PARAMETER
;
344 ev
= tevent_context_init(talloc_tos());
348 req
= cli_get_fs_attr_info_send(ev
, ev
, cli
);
352 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
355 status
= cli_get_fs_attr_info_recv(req
, fs_attr
);
358 if (!NT_STATUS_IS_OK(status
)) {
359 cli_set_error(cli
, status
);
364 NTSTATUS
cli_get_fs_volume_info(struct cli_state
*cli
, fstring volume_name
,
365 uint32
*pserial_number
, time_t *pdate
)
371 uint32_t rdata_count
;
374 SSVAL(setup
, 0, TRANSACT2_QFSINFO
);
375 SSVAL(param
,0,SMB_QUERY_FS_VOLUME_INFO
);
377 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
385 &rdata
, 10, &rdata_count
);
386 if (!NT_STATUS_IS_OK(status
)) {
392 ts
= interpret_long_date((char *)rdata
);
395 if (pserial_number
) {
396 *pserial_number
= IVAL(rdata
,8);
398 nlen
= IVAL(rdata
,12);
399 clistr_pull(cli
->inbuf
, volume_name
, rdata
+ 18, sizeof(fstring
),
402 /* todo: but not yet needed
403 * return the other stuff
410 NTSTATUS
cli_get_fs_full_size_info(struct cli_state
*cli
,
411 uint64_t *total_allocation_units
,
412 uint64_t *caller_allocation_units
,
413 uint64_t *actual_allocation_units
,
414 uint64_t *sectors_per_allocation_unit
,
415 uint64_t *bytes_per_sector
)
419 uint8_t *rdata
= NULL
;
420 uint32_t rdata_count
;
423 SSVAL(setup
, 0, TRANSACT2_QFSINFO
);
424 SSVAL(param
, 0, SMB_FS_FULL_SIZE_INFORMATION
);
426 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
428 setup
, 1, 0, /* setup */
429 param
, 2, 0, /* param */
430 NULL
, 0, 560, /* data */
432 NULL
, 0, NULL
, /* rsetup */
433 NULL
, 0, NULL
, /* rparam */
434 &rdata
, 32, &rdata_count
); /* rdata */
435 if (!NT_STATUS_IS_OK(status
)) {
439 if (total_allocation_units
) {
440 *total_allocation_units
= BIG_UINT(rdata
, 0);
442 if (caller_allocation_units
) {
443 *caller_allocation_units
= BIG_UINT(rdata
,8);
445 if (actual_allocation_units
) {
446 *actual_allocation_units
= BIG_UINT(rdata
,16);
448 if (sectors_per_allocation_unit
) {
449 *sectors_per_allocation_unit
= IVAL(rdata
,24);
451 if (bytes_per_sector
) {
452 *bytes_per_sector
= IVAL(rdata
,28);
460 NTSTATUS
cli_get_posix_fs_info(struct cli_state
*cli
,
461 uint32
*optimal_transfer_size
,
463 uint64_t *total_blocks
,
464 uint64_t *blocks_available
,
465 uint64_t *user_blocks_available
,
466 uint64_t *total_file_nodes
,
467 uint64_t *free_file_nodes
,
468 uint64_t *fs_identifier
)
472 uint8_t *rdata
= NULL
;
475 SSVAL(setup
, 0, TRANSACT2_QFSINFO
);
476 SSVAL(param
,0,SMB_QUERY_POSIX_FS_INFO
);
478 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
, NULL
, 0, 0, 0,
483 NULL
, 0, NULL
, /* rsetup */
484 NULL
, 0, NULL
, /* rparam */
486 if (!NT_STATUS_IS_OK(status
)) {
490 if (optimal_transfer_size
) {
491 *optimal_transfer_size
= IVAL(rdata
, 0);
494 *block_size
= IVAL(rdata
,4);
497 *total_blocks
= BIG_UINT(rdata
,8);
499 if (blocks_available
) {
500 *blocks_available
= BIG_UINT(rdata
,16);
502 if (user_blocks_available
) {
503 *user_blocks_available
= BIG_UINT(rdata
,24);
505 if (total_file_nodes
) {
506 *total_file_nodes
= BIG_UINT(rdata
,32);
508 if (free_file_nodes
) {
509 *free_file_nodes
= BIG_UINT(rdata
,40);
512 *fs_identifier
= BIG_UINT(rdata
,48);
518 /******************************************************************************
519 Send/receive the request encryption blob.
520 ******************************************************************************/
522 static NTSTATUS
enc_blob_send_receive(struct cli_state
*cli
, DATA_BLOB
*in
, DATA_BLOB
*out
, DATA_BLOB
*param_out
)
526 uint8_t *rparam
=NULL
, *rdata
=NULL
;
527 uint32_t num_rparam
, num_rdata
;
530 SSVAL(setup
+0, 0, TRANSACT2_SETFSINFO
);
532 SSVAL(param
,2,SMB_REQUEST_TRANSPORT_ENCRYPTION
);
534 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
, NULL
, 0, 0, 0,
537 (uint8_t *)in
->data
, in
->length
, CLI_BUFFER_SIZE
,
538 NULL
, /* recv_flags */
539 NULL
, 0, NULL
, /* rsetup */
540 &rparam
, 0, &num_rparam
,
541 &rdata
, 0, &num_rdata
);
543 if (!NT_STATUS_IS_OK(status
) &&
544 !NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
548 *out
= data_blob(rdata
, num_rdata
);
549 *param_out
= data_blob(rparam
, num_rparam
);
556 /******************************************************************************
557 Make a client state struct.
558 ******************************************************************************/
560 static struct smb_trans_enc_state
*make_cli_enc_state(enum smb_trans_enc_type smb_enc_type
)
562 struct smb_trans_enc_state
*es
= NULL
;
563 es
= SMB_MALLOC_P(struct smb_trans_enc_state
);
568 es
->smb_enc_type
= smb_enc_type
;
570 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
571 if (smb_enc_type
== SMB_TRANS_ENC_GSS
) {
572 es
->s
.gss_state
= SMB_MALLOC_P(struct smb_tran_enc_state_gss
);
573 if (!es
->s
.gss_state
) {
577 ZERO_STRUCTP(es
->s
.gss_state
);
583 /******************************************************************************
584 Start a raw ntlmssp encryption.
585 ******************************************************************************/
587 NTSTATUS
cli_raw_ntlm_smb_encryption_start(struct cli_state
*cli
,
592 DATA_BLOB blob_in
= data_blob_null
;
593 DATA_BLOB blob_out
= data_blob_null
;
594 DATA_BLOB param_out
= data_blob_null
;
595 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
596 struct smb_trans_enc_state
*es
= make_cli_enc_state(SMB_TRANS_ENC_NTLM
);
599 return NT_STATUS_NO_MEMORY
;
601 status
= ntlmssp_client_start(NULL
,
604 lp_client_ntlmv2_auth(),
605 &es
->s
.ntlmssp_state
);
606 if (!NT_STATUS_IS_OK(status
)) {
610 ntlmssp_want_feature(es
->s
.ntlmssp_state
, NTLMSSP_FEATURE_SESSION_KEY
);
611 es
->s
.ntlmssp_state
->neg_flags
|= (NTLMSSP_NEGOTIATE_SIGN
|NTLMSSP_NEGOTIATE_SEAL
);
613 if (!NT_STATUS_IS_OK(status
= ntlmssp_set_username(es
->s
.ntlmssp_state
, user
))) {
616 if (!NT_STATUS_IS_OK(status
= ntlmssp_set_domain(es
->s
.ntlmssp_state
, domain
))) {
619 if (!NT_STATUS_IS_OK(status
= ntlmssp_set_password(es
->s
.ntlmssp_state
, pass
))) {
624 status
= ntlmssp_update(es
->s
.ntlmssp_state
, blob_in
, &blob_out
);
625 data_blob_free(&blob_in
);
626 data_blob_free(¶m_out
);
627 if (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
) || NT_STATUS_IS_OK(status
)) {
628 NTSTATUS trans_status
= enc_blob_send_receive(cli
,
632 if (!NT_STATUS_EQUAL(trans_status
,
633 NT_STATUS_MORE_PROCESSING_REQUIRED
) &&
634 !NT_STATUS_IS_OK(trans_status
)) {
635 status
= trans_status
;
637 if (param_out
.length
== 2) {
638 es
->enc_ctx_num
= SVAL(param_out
.data
, 0);
642 data_blob_free(&blob_out
);
643 } while (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
));
645 data_blob_free(&blob_in
);
647 if (NT_STATUS_IS_OK(status
)) {
648 /* Replace the old state, if any. */
649 if (cli
->trans_enc_state
) {
650 common_free_encryption_state(&cli
->trans_enc_state
);
652 cli
->trans_enc_state
= es
;
653 cli
->trans_enc_state
->enc_on
= True
;
659 common_free_encryption_state(&es
);
663 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
665 #ifndef SMB_GSS_REQUIRED_FLAGS
666 #define SMB_GSS_REQUIRED_FLAGS (GSS_C_CONF_FLAG|GSS_C_INTEG_FLAG|GSS_C_MUTUAL_FLAG|GSS_C_REPLAY_FLAG|GSS_C_SEQUENCE_FLAG)
669 /******************************************************************************
670 Get client gss blob to send to a server.
671 ******************************************************************************/
673 static NTSTATUS
make_cli_gss_blob(TALLOC_CTX
*ctx
,
674 struct smb_trans_enc_state
*es
,
678 DATA_BLOB spnego_blob_in
,
679 DATA_BLOB
*p_blob_out
)
681 const char *krb_mechs
[] = {OID_KERBEROS5
, NULL
};
685 gss_buffer_desc input_name
;
686 gss_buffer_desc
*p_tok_in
;
687 gss_buffer_desc tok_out
, tok_in
;
688 DATA_BLOB blob_out
= data_blob_null
;
689 DATA_BLOB blob_in
= data_blob_null
;
690 char *host_princ_s
= NULL
;
691 OM_uint32 ret_flags
= 0;
692 NTSTATUS status
= NT_STATUS_OK
;
694 gss_OID_desc nt_hostbased_service
=
695 {10, CONST_DISCARD(char *,"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04")};
697 memset(&tok_out
, '\0', sizeof(tok_out
));
699 /* Get a ticket for the service@host */
700 if (asprintf(&host_princ_s
, "%s@%s", service
, host
) == -1) {
701 return NT_STATUS_NO_MEMORY
;
704 input_name
.value
= host_princ_s
;
705 input_name
.length
= strlen(host_princ_s
) + 1;
707 ret
= gss_import_name(&min
,
709 &nt_hostbased_service
,
712 if (ret
!= GSS_S_COMPLETE
) {
713 SAFE_FREE(host_princ_s
);
714 return map_nt_error_from_gss(ret
, min
);
717 if (spnego_blob_in
.length
== 0) {
718 p_tok_in
= GSS_C_NO_BUFFER
;
720 /* Remove the SPNEGO wrapper */
721 if (!spnego_parse_auth_response(ctx
, spnego_blob_in
, status_in
, OID_KERBEROS5
, &blob_in
)) {
722 status
= NT_STATUS_UNSUCCESSFUL
;
725 tok_in
.value
= blob_in
.data
;
726 tok_in
.length
= blob_in
.length
;
730 ret
= gss_init_sec_context(&min
,
731 GSS_C_NO_CREDENTIAL
, /* Use our default cred. */
732 &es
->s
.gss_state
->gss_ctx
,
734 GSS_C_NO_OID
, /* default OID. */
735 GSS_C_MUTUAL_FLAG
| GSS_C_REPLAY_FLAG
| GSS_C_SEQUENCE_FLAG
| GSS_C_DELEG_FLAG
,
736 GSS_C_INDEFINITE
, /* requested ticket lifetime. */
737 NULL
, /* no channel bindings */
739 NULL
, /* ignore mech type */
742 NULL
); /* ignore time_rec */
744 status
= map_nt_error_from_gss(ret
, min
);
745 if (!NT_STATUS_IS_OK(status
) && !NT_STATUS_EQUAL(status
,NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
746 ADS_STATUS adss
= ADS_ERROR_GSS(ret
, min
);
747 DEBUG(10,("make_cli_gss_blob: gss_init_sec_context failed with %s\n",
752 if ((ret_flags
& SMB_GSS_REQUIRED_FLAGS
) != SMB_GSS_REQUIRED_FLAGS
) {
753 status
= NT_STATUS_ACCESS_DENIED
;
756 blob_out
= data_blob_talloc(ctx
, tok_out
.value
, tok_out
.length
);
758 /* Wrap in an SPNEGO wrapper */
759 *p_blob_out
= spnego_gen_negTokenInit(ctx
, krb_mechs
, &blob_out
, NULL
);
763 data_blob_free(&blob_out
);
764 data_blob_free(&blob_in
);
765 SAFE_FREE(host_princ_s
);
766 gss_release_name(&min
, &srv_name
);
768 gss_release_buffer(&min
, &tok_out
);
773 /******************************************************************************
774 Start a SPNEGO gssapi encryption context.
775 ******************************************************************************/
777 NTSTATUS
cli_gss_smb_encryption_start(struct cli_state
*cli
)
779 DATA_BLOB blob_recv
= data_blob_null
;
780 DATA_BLOB blob_send
= data_blob_null
;
781 DATA_BLOB param_out
= data_blob_null
;
782 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
784 const char *servicename
;
785 struct smb_trans_enc_state
*es
= make_cli_enc_state(SMB_TRANS_ENC_GSS
);
788 return NT_STATUS_NO_MEMORY
;
791 name_to_fqdn(fqdn
, cli
->desthost
);
794 servicename
= "cifs";
795 status
= make_cli_gss_blob(talloc_tos(), es
, servicename
, fqdn
, NT_STATUS_OK
, blob_recv
, &blob_send
);
796 if (!NT_STATUS_EQUAL(status
,NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
797 servicename
= "host";
798 status
= make_cli_gss_blob(talloc_tos(), es
, servicename
, fqdn
, NT_STATUS_OK
, blob_recv
, &blob_send
);
799 if (!NT_STATUS_EQUAL(status
,NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
805 data_blob_free(&blob_recv
);
806 status
= enc_blob_send_receive(cli
, &blob_send
, &blob_recv
, ¶m_out
);
807 if (param_out
.length
== 2) {
808 es
->enc_ctx_num
= SVAL(param_out
.data
, 0);
810 data_blob_free(&blob_send
);
811 status
= make_cli_gss_blob(talloc_tos(), es
, servicename
, fqdn
, status
, blob_recv
, &blob_send
);
812 } while (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
));
813 data_blob_free(&blob_recv
);
815 if (NT_STATUS_IS_OK(status
)) {
816 /* Replace the old state, if any. */
817 if (cli
->trans_enc_state
) {
818 common_free_encryption_state(&cli
->trans_enc_state
);
820 cli
->trans_enc_state
= es
;
821 cli
->trans_enc_state
->enc_on
= True
;
827 common_free_encryption_state(&es
);
831 NTSTATUS
cli_gss_smb_encryption_start(struct cli_state
*cli
)
833 return NT_STATUS_NOT_SUPPORTED
;
837 /********************************************************************
838 Ensure a connection is encrypted.
839 ********************************************************************/
841 NTSTATUS
cli_force_encryption(struct cli_state
*c
,
842 const char *username
,
843 const char *password
,
847 uint32 caplow
, caphigh
;
850 if (!SERVER_HAS_UNIX_CIFS(c
)) {
851 return NT_STATUS_NOT_SUPPORTED
;
854 status
= cli_unix_extensions_version(c
, &major
, &minor
, &caplow
,
856 if (!NT_STATUS_IS_OK(status
)) {
857 DEBUG(10, ("cli_force_encryption: cli_unix_extensions_version "
858 "returned %s\n", nt_errstr(status
)));
859 return NT_STATUS_UNKNOWN_REVISION
;
862 if (!(caplow
& CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
)) {
863 return NT_STATUS_UNSUPPORTED_COMPRESSION
;
866 if (c
->use_kerberos
) {
867 return cli_gss_smb_encryption_start(c
);
869 return cli_raw_ntlm_smb_encryption_start(c
,