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"
25 /****************************************************************************
26 Get UNIX extensions version info.
27 ****************************************************************************/
29 struct cli_unix_extensions_version_state
{
32 uint16_t major
, minor
;
33 uint32_t caplow
, caphigh
;
36 static void cli_unix_extensions_version_done(struct tevent_req
*subreq
);
38 struct tevent_req
*cli_unix_extensions_version_send(TALLOC_CTX
*mem_ctx
,
39 struct tevent_context
*ev
,
40 struct cli_state
*cli
)
42 struct tevent_req
*req
, *subreq
;
43 struct cli_unix_extensions_version_state
*state
;
45 req
= tevent_req_create(mem_ctx
, &state
,
46 struct cli_unix_extensions_version_state
);
50 SSVAL(state
->setup
, 0, TRANSACT2_QFSINFO
);
51 SSVAL(state
->param
, 0, SMB_QUERY_CIFS_UNIX_INFO
);
53 subreq
= cli_trans_send(state
, ev
, cli
, SMBtrans2
,
58 if (tevent_req_nomem(subreq
, req
)) {
59 return tevent_req_post(req
, ev
);
61 tevent_req_set_callback(subreq
, cli_unix_extensions_version_done
, req
);
65 static void cli_unix_extensions_version_done(struct tevent_req
*subreq
)
67 struct tevent_req
*req
= tevent_req_callback_data(
68 subreq
, struct tevent_req
);
69 struct cli_unix_extensions_version_state
*state
= tevent_req_data(
70 req
, struct cli_unix_extensions_version_state
);
75 status
= cli_trans_recv(subreq
, state
, NULL
, 0, NULL
, NULL
, 0, NULL
,
76 &data
, 12, &num_data
);
78 if (!NT_STATUS_IS_OK(status
)) {
79 tevent_req_nterror(req
, status
);
83 state
->major
= SVAL(data
, 0);
84 state
->minor
= SVAL(data
, 2);
85 state
->caplow
= IVAL(data
, 4);
86 state
->caphigh
= IVAL(data
, 8);
91 NTSTATUS
cli_unix_extensions_version_recv(struct tevent_req
*req
,
92 uint16_t *pmajor
, uint16_t *pminor
,
96 struct cli_unix_extensions_version_state
*state
= tevent_req_data(
97 req
, struct cli_unix_extensions_version_state
);
100 if (tevent_req_is_nterror(req
, &status
)) {
103 *pmajor
= state
->major
;
104 *pminor
= state
->minor
;
105 *pcaplow
= state
->caplow
;
106 *pcaphigh
= state
->caphigh
;
110 NTSTATUS
cli_unix_extensions_version(struct cli_state
*cli
, uint16
*pmajor
,
111 uint16
*pminor
, uint32
*pcaplow
,
114 TALLOC_CTX
*frame
= talloc_stackframe();
115 struct event_context
*ev
;
116 struct tevent_req
*req
;
117 NTSTATUS status
= NT_STATUS_OK
;
119 if (cli_has_async_calls(cli
)) {
121 * Can't use sync call while an async call is in flight
123 status
= NT_STATUS_INVALID_PARAMETER
;
127 ev
= event_context_init(frame
);
129 status
= NT_STATUS_NO_MEMORY
;
133 req
= cli_unix_extensions_version_send(frame
, ev
, cli
);
135 status
= NT_STATUS_NO_MEMORY
;
139 if (!tevent_req_poll(req
, ev
)) {
140 status
= map_nt_error_from_unix(errno
);
144 status
= cli_unix_extensions_version_recv(req
, pmajor
, pminor
, pcaplow
,
146 if (NT_STATUS_IS_OK(status
)) {
147 cli
->posix_capabilities
= *pcaplow
;
151 if (!NT_STATUS_IS_OK(status
)) {
152 cli_set_error(cli
, status
);
157 /****************************************************************************
158 Set UNIX extensions capabilities.
159 ****************************************************************************/
161 struct cli_set_unix_extensions_capabilities_state
{
167 static void cli_set_unix_extensions_capabilities_done(
168 struct tevent_req
*subreq
);
170 struct tevent_req
*cli_set_unix_extensions_capabilities_send(
171 TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev
, struct cli_state
*cli
,
172 uint16_t major
, uint16_t minor
, uint32_t caplow
, uint32_t caphigh
)
174 struct tevent_req
*req
, *subreq
;
175 struct cli_set_unix_extensions_capabilities_state
*state
;
177 req
= tevent_req_create(
179 struct cli_set_unix_extensions_capabilities_state
);
184 SSVAL(state
->setup
+0, 0, TRANSACT2_SETFSINFO
);
186 SSVAL(state
->param
, 0, 0);
187 SSVAL(state
->param
, 2, SMB_SET_CIFS_UNIX_INFO
);
189 SSVAL(state
->data
, 0, major
);
190 SSVAL(state
->data
, 2, minor
);
191 SIVAL(state
->data
, 4, caplow
);
192 SIVAL(state
->data
, 8, caphigh
);
194 subreq
= cli_trans_send(state
, ev
, cli
, SMBtrans2
,
198 state
->data
, 12, 560);
199 if (tevent_req_nomem(subreq
, req
)) {
200 return tevent_req_post(req
, ev
);
202 tevent_req_set_callback(
203 subreq
, cli_set_unix_extensions_capabilities_done
, req
);
207 static void cli_set_unix_extensions_capabilities_done(
208 struct tevent_req
*subreq
)
210 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, 0, NULL
,
211 NULL
, 0, NULL
, NULL
, 0, NULL
);
212 tevent_req_simple_finish_ntstatus(subreq
, status
);
215 NTSTATUS
cli_set_unix_extensions_capabilities_recv(struct tevent_req
*req
)
217 return tevent_req_simple_recv_ntstatus(req
);
220 NTSTATUS
cli_set_unix_extensions_capabilities(struct cli_state
*cli
,
221 uint16 major
, uint16 minor
,
222 uint32 caplow
, uint32 caphigh
)
224 struct tevent_context
*ev
;
225 struct tevent_req
*req
;
226 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
228 if (cli_has_async_calls(cli
)) {
229 return NT_STATUS_INVALID_PARAMETER
;
231 ev
= tevent_context_init(talloc_tos());
235 req
= cli_set_unix_extensions_capabilities_send(
236 ev
, ev
, cli
, major
, minor
, caplow
, caphigh
);
240 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
243 status
= cli_set_unix_extensions_capabilities_recv(req
);
246 if (!NT_STATUS_IS_OK(status
)) {
247 cli_set_error(cli
, status
);
252 struct cli_get_fs_attr_info_state
{
258 static void cli_get_fs_attr_info_done(struct tevent_req
*subreq
);
260 struct tevent_req
*cli_get_fs_attr_info_send(TALLOC_CTX
*mem_ctx
,
261 struct tevent_context
*ev
,
262 struct cli_state
*cli
)
264 struct tevent_req
*subreq
, *req
;
265 struct cli_get_fs_attr_info_state
*state
;
267 req
= tevent_req_create(mem_ctx
, &state
,
268 struct cli_get_fs_attr_info_state
);
272 SSVAL(state
->setup
+0, 0, TRANSACT2_QFSINFO
);
273 SSVAL(state
->param
+0, 0, SMB_QUERY_FS_ATTRIBUTE_INFO
);
275 subreq
= cli_trans_send(state
, ev
, cli
, SMBtrans2
,
280 if (tevent_req_nomem(subreq
, req
)) {
281 return tevent_req_post(req
, ev
);
283 tevent_req_set_callback(subreq
, cli_get_fs_attr_info_done
, req
);
287 static void cli_get_fs_attr_info_done(struct tevent_req
*subreq
)
289 struct tevent_req
*req
= tevent_req_callback_data(
290 subreq
, struct tevent_req
);
291 struct cli_get_fs_attr_info_state
*state
= tevent_req_data(
292 req
, struct cli_get_fs_attr_info_state
);
297 status
= cli_trans_recv(subreq
, talloc_tos(), NULL
, 0, NULL
,
298 NULL
, 0, NULL
, &data
, 12, &num_data
);
300 if (!NT_STATUS_IS_OK(status
)) {
301 tevent_req_nterror(req
, status
);
304 state
->fs_attr
= IVAL(data
, 0);
306 tevent_req_done(req
);
309 NTSTATUS
cli_get_fs_attr_info_recv(struct tevent_req
*req
, uint32_t *fs_attr
)
311 struct cli_get_fs_attr_info_state
*state
= tevent_req_data(
312 req
, struct cli_get_fs_attr_info_state
);
315 if (tevent_req_is_nterror(req
, &status
)) {
318 *fs_attr
= state
->fs_attr
;
322 NTSTATUS
cli_get_fs_attr_info(struct cli_state
*cli
, uint32_t *fs_attr
)
324 struct tevent_context
*ev
;
325 struct tevent_req
*req
;
326 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
328 if (cli_has_async_calls(cli
)) {
329 return NT_STATUS_INVALID_PARAMETER
;
331 ev
= tevent_context_init(talloc_tos());
335 req
= cli_get_fs_attr_info_send(ev
, ev
, cli
);
339 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
342 status
= cli_get_fs_attr_info_recv(req
, fs_attr
);
345 if (!NT_STATUS_IS_OK(status
)) {
346 cli_set_error(cli
, status
);
351 bool cli_get_fs_volume_info(struct cli_state
*cli
, fstring volume_name
, uint32
*pserial_number
, time_t *pdate
)
356 char *rparam
=NULL
, *rdata
=NULL
;
357 unsigned int rparam_count
=0, rdata_count
=0;
360 setup
= TRANSACT2_QFSINFO
;
362 SSVAL(param
,0,SMB_QUERY_FS_VOLUME_INFO
);
364 if (!cli_send_trans(cli
, SMBtrans2
,
373 if (!cli_receive_trans(cli
, SMBtrans2
,
374 &rparam
, &rparam_count
,
375 &rdata
, &rdata_count
)) {
379 if (cli_is_error(cli
)) {
386 if (rdata_count
< 19) {
392 ts
= interpret_long_date(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
413 bool cli_get_fs_full_size_info(struct cli_state
*cli
,
414 uint64_t *total_allocation_units
,
415 uint64_t *caller_allocation_units
,
416 uint64_t *actual_allocation_units
,
417 uint64_t *sectors_per_allocation_unit
,
418 uint64_t *bytes_per_sector
)
423 char *rparam
=NULL
, *rdata
=NULL
;
424 unsigned int rparam_count
=0, rdata_count
=0;
426 setup
= TRANSACT2_QFSINFO
;
428 SSVAL(param
,0,SMB_FS_FULL_SIZE_INFORMATION
);
430 if (!cli_send_trans(cli
, SMBtrans2
,
439 if (!cli_receive_trans(cli
, SMBtrans2
,
440 &rparam
, &rparam_count
,
441 &rdata
, &rdata_count
)) {
445 if (cli_is_error(cli
)) {
452 if (rdata_count
!= 32) {
456 if (total_allocation_units
) {
457 *total_allocation_units
= BIG_UINT(rdata
, 0);
459 if (caller_allocation_units
) {
460 *caller_allocation_units
= BIG_UINT(rdata
,8);
462 if (actual_allocation_units
) {
463 *actual_allocation_units
= BIG_UINT(rdata
,16);
465 if (sectors_per_allocation_unit
) {
466 *sectors_per_allocation_unit
= IVAL(rdata
,24);
468 if (bytes_per_sector
) {
469 *bytes_per_sector
= IVAL(rdata
,28);
479 bool cli_get_posix_fs_info(struct cli_state
*cli
,
480 uint32
*optimal_transfer_size
,
482 uint64_t *total_blocks
,
483 uint64_t *blocks_available
,
484 uint64_t *user_blocks_available
,
485 uint64_t *total_file_nodes
,
486 uint64_t *free_file_nodes
,
487 uint64_t *fs_identifier
)
492 char *rparam
=NULL
, *rdata
=NULL
;
493 unsigned int rparam_count
=0, rdata_count
=0;
495 setup
= TRANSACT2_QFSINFO
;
497 SSVAL(param
,0,SMB_QUERY_POSIX_FS_INFO
);
499 if (!cli_send_trans(cli
, SMBtrans2
,
508 if (!cli_receive_trans(cli
, SMBtrans2
,
509 &rparam
, &rparam_count
,
510 &rdata
, &rdata_count
)) {
514 if (cli_is_error(cli
)) {
521 if (rdata_count
!= 56) {
525 if (optimal_transfer_size
) {
526 *optimal_transfer_size
= IVAL(rdata
, 0);
529 *block_size
= IVAL(rdata
,4);
532 *total_blocks
= BIG_UINT(rdata
,8);
534 if (blocks_available
) {
535 *blocks_available
= BIG_UINT(rdata
,16);
537 if (user_blocks_available
) {
538 *user_blocks_available
= BIG_UINT(rdata
,24);
540 if (total_file_nodes
) {
541 *total_file_nodes
= BIG_UINT(rdata
,32);
543 if (free_file_nodes
) {
544 *free_file_nodes
= BIG_UINT(rdata
,40);
547 *fs_identifier
= BIG_UINT(rdata
,48);
558 /******************************************************************************
559 Send/receive the request encryption blob.
560 ******************************************************************************/
562 static NTSTATUS
enc_blob_send_receive(struct cli_state
*cli
, DATA_BLOB
*in
, DATA_BLOB
*out
, DATA_BLOB
*param_out
)
566 char *rparam
=NULL
, *rdata
=NULL
;
567 unsigned int rparam_count
=0, rdata_count
=0;
568 NTSTATUS status
= NT_STATUS_OK
;
570 setup
= TRANSACT2_SETFSINFO
;
573 SSVAL(param
,2,SMB_REQUEST_TRANSPORT_ENCRYPTION
);
575 if (!cli_send_trans(cli
, SMBtrans2
,
580 (char *)in
->data
, in
->length
, CLI_BUFFER_SIZE
)) {
581 status
= cli_nt_error(cli
);
585 if (!cli_receive_trans(cli
, SMBtrans2
,
586 &rparam
, &rparam_count
,
587 &rdata
, &rdata_count
)) {
588 status
= cli_nt_error(cli
);
592 if (cli_is_error(cli
)) {
593 status
= cli_nt_error(cli
);
594 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
599 *out
= data_blob(rdata
, rdata_count
);
600 *param_out
= data_blob(rparam
, rparam_count
);
609 /******************************************************************************
610 Make a client state struct.
611 ******************************************************************************/
613 static struct smb_trans_enc_state
*make_cli_enc_state(enum smb_trans_enc_type smb_enc_type
)
615 struct smb_trans_enc_state
*es
= NULL
;
616 es
= SMB_MALLOC_P(struct smb_trans_enc_state
);
621 es
->smb_enc_type
= smb_enc_type
;
623 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
624 if (smb_enc_type
== SMB_TRANS_ENC_GSS
) {
625 es
->s
.gss_state
= SMB_MALLOC_P(struct smb_tran_enc_state_gss
);
626 if (!es
->s
.gss_state
) {
630 ZERO_STRUCTP(es
->s
.gss_state
);
636 /******************************************************************************
637 Start a raw ntlmssp encryption.
638 ******************************************************************************/
640 NTSTATUS
cli_raw_ntlm_smb_encryption_start(struct cli_state
*cli
,
645 DATA_BLOB blob_in
= data_blob_null
;
646 DATA_BLOB blob_out
= data_blob_null
;
647 DATA_BLOB param_out
= data_blob_null
;
648 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
649 struct smb_trans_enc_state
*es
= make_cli_enc_state(SMB_TRANS_ENC_NTLM
);
652 return NT_STATUS_NO_MEMORY
;
654 status
= ntlmssp_client_start(&es
->s
.ntlmssp_state
);
655 if (!NT_STATUS_IS_OK(status
)) {
659 ntlmssp_want_feature(es
->s
.ntlmssp_state
, NTLMSSP_FEATURE_SESSION_KEY
);
660 es
->s
.ntlmssp_state
->neg_flags
|= (NTLMSSP_NEGOTIATE_SIGN
|NTLMSSP_NEGOTIATE_SEAL
);
662 if (!NT_STATUS_IS_OK(status
= ntlmssp_set_username(es
->s
.ntlmssp_state
, user
))) {
665 if (!NT_STATUS_IS_OK(status
= ntlmssp_set_domain(es
->s
.ntlmssp_state
, domain
))) {
668 if (!NT_STATUS_IS_OK(status
= ntlmssp_set_password(es
->s
.ntlmssp_state
, pass
))) {
673 status
= ntlmssp_update(es
->s
.ntlmssp_state
, blob_in
, &blob_out
);
674 data_blob_free(&blob_in
);
675 data_blob_free(¶m_out
);
676 if (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
) || NT_STATUS_IS_OK(status
)) {
677 NTSTATUS trans_status
= enc_blob_send_receive(cli
,
681 if (!NT_STATUS_EQUAL(trans_status
,
682 NT_STATUS_MORE_PROCESSING_REQUIRED
) &&
683 !NT_STATUS_IS_OK(trans_status
)) {
684 status
= trans_status
;
686 if (param_out
.length
== 2) {
687 es
->enc_ctx_num
= SVAL(param_out
.data
, 0);
691 data_blob_free(&blob_out
);
692 } while (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
));
694 data_blob_free(&blob_in
);
696 if (NT_STATUS_IS_OK(status
)) {
697 /* Replace the old state, if any. */
698 if (cli
->trans_enc_state
) {
699 common_free_encryption_state(&cli
->trans_enc_state
);
701 cli
->trans_enc_state
= es
;
702 cli
->trans_enc_state
->enc_on
= True
;
708 common_free_encryption_state(&es
);
712 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
714 #ifndef SMB_GSS_REQUIRED_FLAGS
715 #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)
718 /******************************************************************************
719 Get client gss blob to send to a server.
720 ******************************************************************************/
722 static NTSTATUS
make_cli_gss_blob(struct smb_trans_enc_state
*es
,
726 DATA_BLOB spnego_blob_in
,
727 DATA_BLOB
*p_blob_out
)
729 const char *krb_mechs
[] = {OID_KERBEROS5
, NULL
};
733 gss_buffer_desc input_name
;
734 gss_buffer_desc
*p_tok_in
;
735 gss_buffer_desc tok_out
, tok_in
;
736 DATA_BLOB blob_out
= data_blob_null
;
737 DATA_BLOB blob_in
= data_blob_null
;
738 char *host_princ_s
= NULL
;
739 OM_uint32 ret_flags
= 0;
740 NTSTATUS status
= NT_STATUS_OK
;
742 gss_OID_desc nt_hostbased_service
=
743 {10, CONST_DISCARD(char *,"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04")};
745 memset(&tok_out
, '\0', sizeof(tok_out
));
747 /* Get a ticket for the service@host */
748 if (asprintf(&host_princ_s
, "%s@%s", service
, host
) == -1) {
749 return NT_STATUS_NO_MEMORY
;
752 input_name
.value
= host_princ_s
;
753 input_name
.length
= strlen(host_princ_s
) + 1;
755 ret
= gss_import_name(&min
,
757 &nt_hostbased_service
,
760 if (ret
!= GSS_S_COMPLETE
) {
761 SAFE_FREE(host_princ_s
);
762 return map_nt_error_from_gss(ret
, min
);
765 if (spnego_blob_in
.length
== 0) {
766 p_tok_in
= GSS_C_NO_BUFFER
;
768 /* Remove the SPNEGO wrapper */
769 if (!spnego_parse_auth_response(spnego_blob_in
, status_in
, OID_KERBEROS5
, &blob_in
)) {
770 status
= NT_STATUS_UNSUCCESSFUL
;
773 tok_in
.value
= blob_in
.data
;
774 tok_in
.length
= blob_in
.length
;
778 ret
= gss_init_sec_context(&min
,
779 GSS_C_NO_CREDENTIAL
, /* Use our default cred. */
780 &es
->s
.gss_state
->gss_ctx
,
782 GSS_C_NO_OID
, /* default OID. */
783 GSS_C_MUTUAL_FLAG
| GSS_C_REPLAY_FLAG
| GSS_C_SEQUENCE_FLAG
| GSS_C_DELEG_FLAG
,
784 GSS_C_INDEFINITE
, /* requested ticket lifetime. */
785 NULL
, /* no channel bindings */
787 NULL
, /* ignore mech type */
790 NULL
); /* ignore time_rec */
792 status
= map_nt_error_from_gss(ret
, min
);
793 if (!NT_STATUS_IS_OK(status
) && !NT_STATUS_EQUAL(status
,NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
794 ADS_STATUS adss
= ADS_ERROR_GSS(ret
, min
);
795 DEBUG(10,("make_cli_gss_blob: gss_init_sec_context failed with %s\n",
800 if ((ret_flags
& SMB_GSS_REQUIRED_FLAGS
) != SMB_GSS_REQUIRED_FLAGS
) {
801 status
= NT_STATUS_ACCESS_DENIED
;
804 blob_out
= data_blob(tok_out
.value
, tok_out
.length
);
806 /* Wrap in an SPNEGO wrapper */
807 *p_blob_out
= gen_negTokenTarg(krb_mechs
, blob_out
);
811 data_blob_free(&blob_out
);
812 data_blob_free(&blob_in
);
813 SAFE_FREE(host_princ_s
);
814 gss_release_name(&min
, &srv_name
);
816 gss_release_buffer(&min
, &tok_out
);
821 /******************************************************************************
822 Start a SPNEGO gssapi encryption context.
823 ******************************************************************************/
825 NTSTATUS
cli_gss_smb_encryption_start(struct cli_state
*cli
)
827 DATA_BLOB blob_recv
= data_blob_null
;
828 DATA_BLOB blob_send
= data_blob_null
;
829 DATA_BLOB param_out
= data_blob_null
;
830 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
832 const char *servicename
;
833 struct smb_trans_enc_state
*es
= make_cli_enc_state(SMB_TRANS_ENC_GSS
);
836 return NT_STATUS_NO_MEMORY
;
839 name_to_fqdn(fqdn
, cli
->desthost
);
842 servicename
= "cifs";
843 status
= make_cli_gss_blob(es
, servicename
, fqdn
, NT_STATUS_OK
, blob_recv
, &blob_send
);
844 if (!NT_STATUS_EQUAL(status
,NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
845 servicename
= "host";
846 status
= make_cli_gss_blob(es
, servicename
, fqdn
, NT_STATUS_OK
, blob_recv
, &blob_send
);
847 if (!NT_STATUS_EQUAL(status
,NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
853 data_blob_free(&blob_recv
);
854 status
= enc_blob_send_receive(cli
, &blob_send
, &blob_recv
, ¶m_out
);
855 if (param_out
.length
== 2) {
856 es
->enc_ctx_num
= SVAL(param_out
.data
, 0);
858 data_blob_free(&blob_send
);
859 status
= make_cli_gss_blob(es
, servicename
, fqdn
, status
, blob_recv
, &blob_send
);
860 } while (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
));
861 data_blob_free(&blob_recv
);
863 if (NT_STATUS_IS_OK(status
)) {
864 /* Replace the old state, if any. */
865 if (cli
->trans_enc_state
) {
866 common_free_encryption_state(&cli
->trans_enc_state
);
868 cli
->trans_enc_state
= es
;
869 cli
->trans_enc_state
->enc_on
= True
;
875 common_free_encryption_state(&es
);
879 NTSTATUS
cli_gss_smb_encryption_start(struct cli_state
*cli
)
881 return NT_STATUS_NOT_SUPPORTED
;
885 /********************************************************************
886 Ensure a connection is encrypted.
887 ********************************************************************/
889 NTSTATUS
cli_force_encryption(struct cli_state
*c
,
890 const char *username
,
891 const char *password
,
895 uint32 caplow
, caphigh
;
898 if (!SERVER_HAS_UNIX_CIFS(c
)) {
899 return NT_STATUS_NOT_SUPPORTED
;
902 status
= cli_unix_extensions_version(c
, &major
, &minor
, &caplow
,
904 if (!NT_STATUS_IS_OK(status
)) {
905 DEBUG(10, ("cli_force_encryption: cli_unix_extensions_version "
906 "returned %s\n", nt_errstr(status
)));
907 return NT_STATUS_UNKNOWN_REVISION
;
910 if (!(caplow
& CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
)) {
911 return NT_STATUS_UNSUPPORTED_COMPRESSION
;
914 if (c
->use_kerberos
) {
915 return cli_gss_smb_encryption_start(c
);
917 return cli_raw_ntlm_smb_encryption_start(c
,