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"
26 /****************************************************************************
27 Get UNIX extensions version info.
28 ****************************************************************************/
30 struct cli_unix_extensions_version_state
{
31 struct cli_state
*cli
;
34 uint16_t major
, minor
;
35 uint32_t caplow
, caphigh
;
38 static void cli_unix_extensions_version_done(struct tevent_req
*subreq
);
40 struct tevent_req
*cli_unix_extensions_version_send(TALLOC_CTX
*mem_ctx
,
41 struct tevent_context
*ev
,
42 struct cli_state
*cli
)
44 struct tevent_req
*req
, *subreq
;
45 struct cli_unix_extensions_version_state
*state
;
47 req
= tevent_req_create(mem_ctx
, &state
,
48 struct cli_unix_extensions_version_state
);
53 SSVAL(state
->setup
, 0, TRANSACT2_QFSINFO
);
54 SSVAL(state
->param
, 0, SMB_QUERY_CIFS_UNIX_INFO
);
56 subreq
= cli_trans_send(state
, ev
, cli
, SMBtrans2
,
61 if (tevent_req_nomem(subreq
, req
)) {
62 return tevent_req_post(req
, ev
);
64 tevent_req_set_callback(subreq
, cli_unix_extensions_version_done
, req
);
68 static void cli_unix_extensions_version_done(struct tevent_req
*subreq
)
70 struct tevent_req
*req
= tevent_req_callback_data(
71 subreq
, struct tevent_req
);
72 struct cli_unix_extensions_version_state
*state
= tevent_req_data(
73 req
, struct cli_unix_extensions_version_state
);
78 status
= cli_trans_recv(subreq
, state
, NULL
, NULL
, 0, NULL
,
79 NULL
, 0, NULL
, &data
, 12, &num_data
);
81 if (!NT_STATUS_IS_OK(status
)) {
82 tevent_req_nterror(req
, status
);
86 state
->major
= SVAL(data
, 0);
87 state
->minor
= SVAL(data
, 2);
88 state
->caplow
= IVAL(data
, 4);
89 state
->caphigh
= IVAL(data
, 8);
94 NTSTATUS
cli_unix_extensions_version_recv(struct tevent_req
*req
,
95 uint16_t *pmajor
, uint16_t *pminor
,
99 struct cli_unix_extensions_version_state
*state
= tevent_req_data(
100 req
, struct cli_unix_extensions_version_state
);
103 if (tevent_req_is_nterror(req
, &status
)) {
106 *pmajor
= state
->major
;
107 *pminor
= state
->minor
;
108 *pcaplow
= state
->caplow
;
109 *pcaphigh
= state
->caphigh
;
110 state
->cli
->server_posix_capabilities
= *pcaplow
;
114 NTSTATUS
cli_unix_extensions_version(struct cli_state
*cli
, uint16
*pmajor
,
115 uint16
*pminor
, uint32
*pcaplow
,
118 TALLOC_CTX
*frame
= talloc_stackframe();
119 struct event_context
*ev
;
120 struct tevent_req
*req
;
121 NTSTATUS status
= NT_STATUS_OK
;
123 if (cli_has_async_calls(cli
)) {
125 * Can't use sync call while an async call is in flight
127 status
= NT_STATUS_INVALID_PARAMETER
;
131 ev
= event_context_init(frame
);
133 status
= NT_STATUS_NO_MEMORY
;
137 req
= cli_unix_extensions_version_send(frame
, ev
, cli
);
139 status
= NT_STATUS_NO_MEMORY
;
143 if (!tevent_req_poll(req
, ev
)) {
144 status
= map_nt_error_from_unix(errno
);
148 status
= cli_unix_extensions_version_recv(req
, pmajor
, pminor
, pcaplow
,
152 if (!NT_STATUS_IS_OK(status
)) {
153 cli_set_error(cli
, status
);
158 /****************************************************************************
159 Set UNIX extensions capabilities.
160 ****************************************************************************/
162 struct cli_set_unix_extensions_capabilities_state
{
163 struct cli_state
*cli
;
169 static void cli_set_unix_extensions_capabilities_done(
170 struct tevent_req
*subreq
);
172 struct tevent_req
*cli_set_unix_extensions_capabilities_send(
173 TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev
, struct cli_state
*cli
,
174 uint16_t major
, uint16_t minor
, uint32_t caplow
, uint32_t caphigh
)
176 struct tevent_req
*req
, *subreq
;
177 struct cli_set_unix_extensions_capabilities_state
*state
;
179 req
= tevent_req_create(
181 struct cli_set_unix_extensions_capabilities_state
);
187 SSVAL(state
->setup
+0, 0, TRANSACT2_SETFSINFO
);
189 SSVAL(state
->param
, 0, 0);
190 SSVAL(state
->param
, 2, SMB_SET_CIFS_UNIX_INFO
);
192 SSVAL(state
->data
, 0, major
);
193 SSVAL(state
->data
, 2, minor
);
194 SIVAL(state
->data
, 4, caplow
);
195 SIVAL(state
->data
, 8, caphigh
);
197 subreq
= cli_trans_send(state
, ev
, cli
, SMBtrans2
,
201 state
->data
, 12, 560);
202 if (tevent_req_nomem(subreq
, req
)) {
203 return tevent_req_post(req
, ev
);
205 tevent_req_set_callback(
206 subreq
, cli_set_unix_extensions_capabilities_done
, req
);
210 static void cli_set_unix_extensions_capabilities_done(
211 struct tevent_req
*subreq
)
213 struct tevent_req
*req
= tevent_req_callback_data(
214 subreq
, struct tevent_req
);
215 struct cli_set_unix_extensions_capabilities_state
*state
= tevent_req_data(
216 req
, struct cli_set_unix_extensions_capabilities_state
);
218 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
219 NULL
, 0, NULL
, NULL
, 0, NULL
);
220 if (NT_STATUS_IS_OK(status
)) {
221 state
->cli
->requested_posix_capabilities
= IVAL(state
->data
, 4);
223 tevent_req_simple_finish_ntstatus(subreq
, status
);
226 NTSTATUS
cli_set_unix_extensions_capabilities_recv(struct tevent_req
*req
)
228 return tevent_req_simple_recv_ntstatus(req
);
231 NTSTATUS
cli_set_unix_extensions_capabilities(struct cli_state
*cli
,
232 uint16 major
, uint16 minor
,
233 uint32 caplow
, uint32 caphigh
)
235 struct tevent_context
*ev
;
236 struct tevent_req
*req
;
237 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
239 if (cli_has_async_calls(cli
)) {
240 return NT_STATUS_INVALID_PARAMETER
;
242 ev
= tevent_context_init(talloc_tos());
246 req
= cli_set_unix_extensions_capabilities_send(
247 ev
, ev
, cli
, major
, minor
, caplow
, caphigh
);
251 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
254 status
= cli_set_unix_extensions_capabilities_recv(req
);
257 if (!NT_STATUS_IS_OK(status
)) {
258 cli_set_error(cli
, status
);
263 struct cli_get_fs_attr_info_state
{
269 static void cli_get_fs_attr_info_done(struct tevent_req
*subreq
);
271 struct tevent_req
*cli_get_fs_attr_info_send(TALLOC_CTX
*mem_ctx
,
272 struct tevent_context
*ev
,
273 struct cli_state
*cli
)
275 struct tevent_req
*subreq
, *req
;
276 struct cli_get_fs_attr_info_state
*state
;
278 req
= tevent_req_create(mem_ctx
, &state
,
279 struct cli_get_fs_attr_info_state
);
283 SSVAL(state
->setup
+0, 0, TRANSACT2_QFSINFO
);
284 SSVAL(state
->param
+0, 0, SMB_QUERY_FS_ATTRIBUTE_INFO
);
286 subreq
= cli_trans_send(state
, ev
, cli
, SMBtrans2
,
291 if (tevent_req_nomem(subreq
, req
)) {
292 return tevent_req_post(req
, ev
);
294 tevent_req_set_callback(subreq
, cli_get_fs_attr_info_done
, req
);
298 static void cli_get_fs_attr_info_done(struct tevent_req
*subreq
)
300 struct tevent_req
*req
= tevent_req_callback_data(
301 subreq
, struct tevent_req
);
302 struct cli_get_fs_attr_info_state
*state
= tevent_req_data(
303 req
, struct cli_get_fs_attr_info_state
);
308 status
= cli_trans_recv(subreq
, talloc_tos(), NULL
, NULL
, 0, NULL
,
309 NULL
, 0, NULL
, &data
, 12, &num_data
);
311 if (!NT_STATUS_IS_OK(status
)) {
312 tevent_req_nterror(req
, status
);
315 state
->fs_attr
= IVAL(data
, 0);
317 tevent_req_done(req
);
320 NTSTATUS
cli_get_fs_attr_info_recv(struct tevent_req
*req
, uint32_t *fs_attr
)
322 struct cli_get_fs_attr_info_state
*state
= tevent_req_data(
323 req
, struct cli_get_fs_attr_info_state
);
326 if (tevent_req_is_nterror(req
, &status
)) {
329 *fs_attr
= state
->fs_attr
;
333 NTSTATUS
cli_get_fs_attr_info(struct cli_state
*cli
, uint32_t *fs_attr
)
335 struct tevent_context
*ev
;
336 struct tevent_req
*req
;
337 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
339 if (cli_has_async_calls(cli
)) {
340 return NT_STATUS_INVALID_PARAMETER
;
342 ev
= tevent_context_init(talloc_tos());
346 req
= cli_get_fs_attr_info_send(ev
, ev
, cli
);
350 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
353 status
= cli_get_fs_attr_info_recv(req
, fs_attr
);
356 if (!NT_STATUS_IS_OK(status
)) {
357 cli_set_error(cli
, status
);
362 NTSTATUS
cli_get_fs_volume_info(struct cli_state
*cli
, fstring volume_name
,
363 uint32
*pserial_number
, time_t *pdate
)
369 uint32_t rdata_count
;
372 SSVAL(setup
, 0, TRANSACT2_QFSINFO
);
373 SSVAL(param
,0,SMB_QUERY_FS_VOLUME_INFO
);
375 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
383 &rdata
, 10, &rdata_count
);
384 if (!NT_STATUS_IS_OK(status
)) {
390 ts
= interpret_long_date((char *)rdata
);
393 if (pserial_number
) {
394 *pserial_number
= IVAL(rdata
,8);
396 nlen
= IVAL(rdata
,12);
397 clistr_pull(cli
->inbuf
, volume_name
, rdata
+ 18, sizeof(fstring
),
400 /* todo: but not yet needed
401 * return the other stuff
408 NTSTATUS
cli_get_fs_full_size_info(struct cli_state
*cli
,
409 uint64_t *total_allocation_units
,
410 uint64_t *caller_allocation_units
,
411 uint64_t *actual_allocation_units
,
412 uint64_t *sectors_per_allocation_unit
,
413 uint64_t *bytes_per_sector
)
417 uint8_t *rdata
= NULL
;
418 uint32_t rdata_count
;
421 SSVAL(setup
, 0, TRANSACT2_QFSINFO
);
422 SSVAL(param
, 0, SMB_FS_FULL_SIZE_INFORMATION
);
424 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
426 setup
, 1, 0, /* setup */
427 param
, 2, 0, /* param */
428 NULL
, 0, 560, /* data */
430 NULL
, 0, NULL
, /* rsetup */
431 NULL
, 0, NULL
, /* rparam */
432 &rdata
, 32, &rdata_count
); /* rdata */
433 if (!NT_STATUS_IS_OK(status
)) {
437 if (total_allocation_units
) {
438 *total_allocation_units
= BIG_UINT(rdata
, 0);
440 if (caller_allocation_units
) {
441 *caller_allocation_units
= BIG_UINT(rdata
,8);
443 if (actual_allocation_units
) {
444 *actual_allocation_units
= BIG_UINT(rdata
,16);
446 if (sectors_per_allocation_unit
) {
447 *sectors_per_allocation_unit
= IVAL(rdata
,24);
449 if (bytes_per_sector
) {
450 *bytes_per_sector
= IVAL(rdata
,28);
458 NTSTATUS
cli_get_posix_fs_info(struct cli_state
*cli
,
459 uint32
*optimal_transfer_size
,
461 uint64_t *total_blocks
,
462 uint64_t *blocks_available
,
463 uint64_t *user_blocks_available
,
464 uint64_t *total_file_nodes
,
465 uint64_t *free_file_nodes
,
466 uint64_t *fs_identifier
)
470 uint8_t *rdata
= NULL
;
473 SSVAL(setup
, 0, TRANSACT2_QFSINFO
);
474 SSVAL(param
,0,SMB_QUERY_POSIX_FS_INFO
);
476 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
, NULL
, 0, 0, 0,
481 NULL
, 0, NULL
, /* rsetup */
482 NULL
, 0, NULL
, /* rparam */
484 if (!NT_STATUS_IS_OK(status
)) {
488 if (optimal_transfer_size
) {
489 *optimal_transfer_size
= IVAL(rdata
, 0);
492 *block_size
= IVAL(rdata
,4);
495 *total_blocks
= BIG_UINT(rdata
,8);
497 if (blocks_available
) {
498 *blocks_available
= BIG_UINT(rdata
,16);
500 if (user_blocks_available
) {
501 *user_blocks_available
= BIG_UINT(rdata
,24);
503 if (total_file_nodes
) {
504 *total_file_nodes
= BIG_UINT(rdata
,32);
506 if (free_file_nodes
) {
507 *free_file_nodes
= BIG_UINT(rdata
,40);
510 *fs_identifier
= BIG_UINT(rdata
,48);
516 /******************************************************************************
517 Send/receive the request encryption blob.
518 ******************************************************************************/
520 static NTSTATUS
enc_blob_send_receive(struct cli_state
*cli
, DATA_BLOB
*in
, DATA_BLOB
*out
, DATA_BLOB
*param_out
)
524 uint8_t *rparam
=NULL
, *rdata
=NULL
;
525 uint32_t num_rparam
, num_rdata
;
528 SSVAL(setup
+0, 0, TRANSACT2_SETFSINFO
);
530 SSVAL(param
,2,SMB_REQUEST_TRANSPORT_ENCRYPTION
);
532 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
, NULL
, 0, 0, 0,
535 (uint8_t *)in
->data
, in
->length
, CLI_BUFFER_SIZE
,
536 NULL
, /* recv_flags */
537 NULL
, 0, NULL
, /* rsetup */
538 &rparam
, 0, &num_rparam
,
539 &rdata
, 0, &num_rdata
);
541 if (!NT_STATUS_IS_OK(status
) &&
542 !NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
546 *out
= data_blob(rdata
, num_rdata
);
547 *param_out
= data_blob(rparam
, num_rparam
);
554 /******************************************************************************
555 Make a client state struct.
556 ******************************************************************************/
558 static struct smb_trans_enc_state
*make_cli_enc_state(enum smb_trans_enc_type smb_enc_type
)
560 struct smb_trans_enc_state
*es
= NULL
;
561 es
= SMB_MALLOC_P(struct smb_trans_enc_state
);
566 es
->smb_enc_type
= smb_enc_type
;
568 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
569 if (smb_enc_type
== SMB_TRANS_ENC_GSS
) {
570 es
->s
.gss_state
= SMB_MALLOC_P(struct smb_tran_enc_state_gss
);
571 if (!es
->s
.gss_state
) {
575 ZERO_STRUCTP(es
->s
.gss_state
);
581 /******************************************************************************
582 Start a raw ntlmssp encryption.
583 ******************************************************************************/
585 NTSTATUS
cli_raw_ntlm_smb_encryption_start(struct cli_state
*cli
,
590 DATA_BLOB blob_in
= data_blob_null
;
591 DATA_BLOB blob_out
= data_blob_null
;
592 DATA_BLOB param_out
= data_blob_null
;
593 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
594 struct smb_trans_enc_state
*es
= make_cli_enc_state(SMB_TRANS_ENC_NTLM
);
597 return NT_STATUS_NO_MEMORY
;
599 status
= ntlmssp_client_start(NULL
,
602 lp_client_ntlmv2_auth(),
603 &es
->s
.ntlmssp_state
);
604 if (!NT_STATUS_IS_OK(status
)) {
608 ntlmssp_want_feature(es
->s
.ntlmssp_state
, NTLMSSP_FEATURE_SESSION_KEY
);
609 es
->s
.ntlmssp_state
->neg_flags
|= (NTLMSSP_NEGOTIATE_SIGN
|NTLMSSP_NEGOTIATE_SEAL
);
611 if (!NT_STATUS_IS_OK(status
= ntlmssp_set_username(es
->s
.ntlmssp_state
, user
))) {
614 if (!NT_STATUS_IS_OK(status
= ntlmssp_set_domain(es
->s
.ntlmssp_state
, domain
))) {
617 if (!NT_STATUS_IS_OK(status
= ntlmssp_set_password(es
->s
.ntlmssp_state
, pass
))) {
622 status
= ntlmssp_update(es
->s
.ntlmssp_state
, blob_in
, &blob_out
);
623 data_blob_free(&blob_in
);
624 data_blob_free(¶m_out
);
625 if (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
) || NT_STATUS_IS_OK(status
)) {
626 NTSTATUS trans_status
= enc_blob_send_receive(cli
,
630 if (!NT_STATUS_EQUAL(trans_status
,
631 NT_STATUS_MORE_PROCESSING_REQUIRED
) &&
632 !NT_STATUS_IS_OK(trans_status
)) {
633 status
= trans_status
;
635 if (param_out
.length
== 2) {
636 es
->enc_ctx_num
= SVAL(param_out
.data
, 0);
640 data_blob_free(&blob_out
);
641 } while (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
));
643 data_blob_free(&blob_in
);
645 if (NT_STATUS_IS_OK(status
)) {
646 /* Replace the old state, if any. */
647 if (cli
->trans_enc_state
) {
648 common_free_encryption_state(&cli
->trans_enc_state
);
650 cli
->trans_enc_state
= es
;
651 cli
->trans_enc_state
->enc_on
= True
;
657 common_free_encryption_state(&es
);
661 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
663 #ifndef SMB_GSS_REQUIRED_FLAGS
664 #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)
667 /******************************************************************************
668 Get client gss blob to send to a server.
669 ******************************************************************************/
671 static NTSTATUS
make_cli_gss_blob(TALLOC_CTX
*ctx
,
672 struct smb_trans_enc_state
*es
,
676 DATA_BLOB spnego_blob_in
,
677 DATA_BLOB
*p_blob_out
)
679 const char *krb_mechs
[] = {OID_KERBEROS5
, NULL
};
683 gss_buffer_desc input_name
;
684 gss_buffer_desc
*p_tok_in
;
685 gss_buffer_desc tok_out
, tok_in
;
686 DATA_BLOB blob_out
= data_blob_null
;
687 DATA_BLOB blob_in
= data_blob_null
;
688 char *host_princ_s
= NULL
;
689 OM_uint32 ret_flags
= 0;
690 NTSTATUS status
= NT_STATUS_OK
;
692 gss_OID_desc nt_hostbased_service
=
693 {10, CONST_DISCARD(char *,"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04")};
695 memset(&tok_out
, '\0', sizeof(tok_out
));
697 /* Get a ticket for the service@host */
698 if (asprintf(&host_princ_s
, "%s@%s", service
, host
) == -1) {
699 return NT_STATUS_NO_MEMORY
;
702 input_name
.value
= host_princ_s
;
703 input_name
.length
= strlen(host_princ_s
) + 1;
705 ret
= gss_import_name(&min
,
707 &nt_hostbased_service
,
710 if (ret
!= GSS_S_COMPLETE
) {
711 SAFE_FREE(host_princ_s
);
712 return map_nt_error_from_gss(ret
, min
);
715 if (spnego_blob_in
.length
== 0) {
716 p_tok_in
= GSS_C_NO_BUFFER
;
718 /* Remove the SPNEGO wrapper */
719 if (!spnego_parse_auth_response(ctx
, spnego_blob_in
, status_in
, OID_KERBEROS5
, &blob_in
)) {
720 status
= NT_STATUS_UNSUCCESSFUL
;
723 tok_in
.value
= blob_in
.data
;
724 tok_in
.length
= blob_in
.length
;
728 ret
= gss_init_sec_context(&min
,
729 GSS_C_NO_CREDENTIAL
, /* Use our default cred. */
730 &es
->s
.gss_state
->gss_ctx
,
732 GSS_C_NO_OID
, /* default OID. */
733 GSS_C_MUTUAL_FLAG
| GSS_C_REPLAY_FLAG
| GSS_C_SEQUENCE_FLAG
| GSS_C_DELEG_FLAG
,
734 GSS_C_INDEFINITE
, /* requested ticket lifetime. */
735 NULL
, /* no channel bindings */
737 NULL
, /* ignore mech type */
740 NULL
); /* ignore time_rec */
742 status
= map_nt_error_from_gss(ret
, min
);
743 if (!NT_STATUS_IS_OK(status
) && !NT_STATUS_EQUAL(status
,NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
744 ADS_STATUS adss
= ADS_ERROR_GSS(ret
, min
);
745 DEBUG(10,("make_cli_gss_blob: gss_init_sec_context failed with %s\n",
750 if ((ret_flags
& SMB_GSS_REQUIRED_FLAGS
) != SMB_GSS_REQUIRED_FLAGS
) {
751 status
= NT_STATUS_ACCESS_DENIED
;
754 blob_out
= data_blob_talloc(ctx
, tok_out
.value
, tok_out
.length
);
756 /* Wrap in an SPNEGO wrapper */
757 *p_blob_out
= spnego_gen_negTokenInit(ctx
, krb_mechs
, &blob_out
, NULL
);
761 data_blob_free(&blob_out
);
762 data_blob_free(&blob_in
);
763 SAFE_FREE(host_princ_s
);
764 gss_release_name(&min
, &srv_name
);
766 gss_release_buffer(&min
, &tok_out
);
771 /******************************************************************************
772 Start a SPNEGO gssapi encryption context.
773 ******************************************************************************/
775 NTSTATUS
cli_gss_smb_encryption_start(struct cli_state
*cli
)
777 DATA_BLOB blob_recv
= data_blob_null
;
778 DATA_BLOB blob_send
= data_blob_null
;
779 DATA_BLOB param_out
= data_blob_null
;
780 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
782 const char *servicename
;
783 struct smb_trans_enc_state
*es
= make_cli_enc_state(SMB_TRANS_ENC_GSS
);
786 return NT_STATUS_NO_MEMORY
;
789 name_to_fqdn(fqdn
, cli
->desthost
);
792 servicename
= "cifs";
793 status
= make_cli_gss_blob(talloc_tos(), es
, servicename
, fqdn
, NT_STATUS_OK
, blob_recv
, &blob_send
);
794 if (!NT_STATUS_EQUAL(status
,NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
795 servicename
= "host";
796 status
= make_cli_gss_blob(talloc_tos(), es
, servicename
, fqdn
, NT_STATUS_OK
, blob_recv
, &blob_send
);
797 if (!NT_STATUS_EQUAL(status
,NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
803 data_blob_free(&blob_recv
);
804 status
= enc_blob_send_receive(cli
, &blob_send
, &blob_recv
, ¶m_out
);
805 if (param_out
.length
== 2) {
806 es
->enc_ctx_num
= SVAL(param_out
.data
, 0);
808 data_blob_free(&blob_send
);
809 status
= make_cli_gss_blob(talloc_tos(), es
, servicename
, fqdn
, status
, blob_recv
, &blob_send
);
810 } while (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
));
811 data_blob_free(&blob_recv
);
813 if (NT_STATUS_IS_OK(status
)) {
814 /* Replace the old state, if any. */
815 if (cli
->trans_enc_state
) {
816 common_free_encryption_state(&cli
->trans_enc_state
);
818 cli
->trans_enc_state
= es
;
819 cli
->trans_enc_state
->enc_on
= True
;
825 common_free_encryption_state(&es
);
829 NTSTATUS
cli_gss_smb_encryption_start(struct cli_state
*cli
)
831 return NT_STATUS_NOT_SUPPORTED
;
835 /********************************************************************
836 Ensure a connection is encrypted.
837 ********************************************************************/
839 NTSTATUS
cli_force_encryption(struct cli_state
*c
,
840 const char *username
,
841 const char *password
,
845 uint32 caplow
, caphigh
;
848 if (!SERVER_HAS_UNIX_CIFS(c
)) {
849 return NT_STATUS_NOT_SUPPORTED
;
852 status
= cli_unix_extensions_version(c
, &major
, &minor
, &caplow
,
854 if (!NT_STATUS_IS_OK(status
)) {
855 DEBUG(10, ("cli_force_encryption: cli_unix_extensions_version "
856 "returned %s\n", nt_errstr(status
)));
857 return NT_STATUS_UNKNOWN_REVISION
;
860 if (!(caplow
& CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
)) {
861 return NT_STATUS_UNSUPPORTED_COMPRESSION
;
864 if (c
->use_kerberos
) {
865 return cli_gss_smb_encryption_start(c
);
867 return cli_raw_ntlm_smb_encryption_start(c
,