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 "libsmb/libsmb.h"
23 #include "../libcli/auth/spnego.h"
24 #include "../libcli/auth/ntlmssp.h"
25 #include "../lib/util/tevent_ntstatus.h"
26 #include "async_smb.h"
27 #include "smb_crypt.h"
29 #include "ntlmssp_wrap.h"
31 /****************************************************************************
32 Get UNIX extensions version info.
33 ****************************************************************************/
35 struct cli_unix_extensions_version_state
{
36 struct cli_state
*cli
;
39 uint16_t major
, minor
;
40 uint32_t caplow
, caphigh
;
43 static void cli_unix_extensions_version_done(struct tevent_req
*subreq
);
45 struct tevent_req
*cli_unix_extensions_version_send(TALLOC_CTX
*mem_ctx
,
46 struct tevent_context
*ev
,
47 struct cli_state
*cli
)
49 struct tevent_req
*req
, *subreq
;
50 struct cli_unix_extensions_version_state
*state
;
52 req
= tevent_req_create(mem_ctx
, &state
,
53 struct cli_unix_extensions_version_state
);
58 SSVAL(state
->setup
, 0, TRANSACT2_QFSINFO
);
59 SSVAL(state
->param
, 0, SMB_QUERY_CIFS_UNIX_INFO
);
61 subreq
= cli_trans_send(state
, ev
, cli
, SMBtrans2
,
66 if (tevent_req_nomem(subreq
, req
)) {
67 return tevent_req_post(req
, ev
);
69 tevent_req_set_callback(subreq
, cli_unix_extensions_version_done
, req
);
73 static void cli_unix_extensions_version_done(struct tevent_req
*subreq
)
75 struct tevent_req
*req
= tevent_req_callback_data(
76 subreq
, struct tevent_req
);
77 struct cli_unix_extensions_version_state
*state
= tevent_req_data(
78 req
, struct cli_unix_extensions_version_state
);
83 status
= cli_trans_recv(subreq
, state
, NULL
, NULL
, 0, NULL
,
84 NULL
, 0, NULL
, &data
, 12, &num_data
);
86 if (!NT_STATUS_IS_OK(status
)) {
87 tevent_req_nterror(req
, status
);
91 state
->major
= SVAL(data
, 0);
92 state
->minor
= SVAL(data
, 2);
93 state
->caplow
= IVAL(data
, 4);
94 state
->caphigh
= IVAL(data
, 8);
99 NTSTATUS
cli_unix_extensions_version_recv(struct tevent_req
*req
,
100 uint16_t *pmajor
, uint16_t *pminor
,
104 struct cli_unix_extensions_version_state
*state
= tevent_req_data(
105 req
, struct cli_unix_extensions_version_state
);
108 if (tevent_req_is_nterror(req
, &status
)) {
111 *pmajor
= state
->major
;
112 *pminor
= state
->minor
;
113 *pcaplow
= state
->caplow
;
114 *pcaphigh
= state
->caphigh
;
115 state
->cli
->server_posix_capabilities
= *pcaplow
;
119 NTSTATUS
cli_unix_extensions_version(struct cli_state
*cli
, uint16
*pmajor
,
120 uint16
*pminor
, uint32
*pcaplow
,
123 TALLOC_CTX
*frame
= talloc_stackframe();
124 struct event_context
*ev
;
125 struct tevent_req
*req
;
126 NTSTATUS status
= NT_STATUS_OK
;
128 if (cli_has_async_calls(cli
)) {
130 * Can't use sync call while an async call is in flight
132 status
= NT_STATUS_INVALID_PARAMETER
;
136 ev
= event_context_init(frame
);
138 status
= NT_STATUS_NO_MEMORY
;
142 req
= cli_unix_extensions_version_send(frame
, ev
, cli
);
144 status
= NT_STATUS_NO_MEMORY
;
148 if (!tevent_req_poll(req
, ev
)) {
149 status
= map_nt_error_from_unix(errno
);
153 status
= cli_unix_extensions_version_recv(req
, pmajor
, pminor
, pcaplow
,
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
);
262 struct cli_get_fs_attr_info_state
{
268 static void cli_get_fs_attr_info_done(struct tevent_req
*subreq
);
270 struct tevent_req
*cli_get_fs_attr_info_send(TALLOC_CTX
*mem_ctx
,
271 struct tevent_context
*ev
,
272 struct cli_state
*cli
)
274 struct tevent_req
*subreq
, *req
;
275 struct cli_get_fs_attr_info_state
*state
;
277 req
= tevent_req_create(mem_ctx
, &state
,
278 struct cli_get_fs_attr_info_state
);
282 SSVAL(state
->setup
+0, 0, TRANSACT2_QFSINFO
);
283 SSVAL(state
->param
+0, 0, SMB_QUERY_FS_ATTRIBUTE_INFO
);
285 subreq
= cli_trans_send(state
, ev
, cli
, SMBtrans2
,
290 if (tevent_req_nomem(subreq
, req
)) {
291 return tevent_req_post(req
, ev
);
293 tevent_req_set_callback(subreq
, cli_get_fs_attr_info_done
, req
);
297 static void cli_get_fs_attr_info_done(struct tevent_req
*subreq
)
299 struct tevent_req
*req
= tevent_req_callback_data(
300 subreq
, struct tevent_req
);
301 struct cli_get_fs_attr_info_state
*state
= tevent_req_data(
302 req
, struct cli_get_fs_attr_info_state
);
307 status
= cli_trans_recv(subreq
, talloc_tos(), NULL
, NULL
, 0, NULL
,
308 NULL
, 0, NULL
, &data
, 12, &num_data
);
310 if (!NT_STATUS_IS_OK(status
)) {
311 tevent_req_nterror(req
, status
);
314 state
->fs_attr
= IVAL(data
, 0);
316 tevent_req_done(req
);
319 NTSTATUS
cli_get_fs_attr_info_recv(struct tevent_req
*req
, uint32_t *fs_attr
)
321 struct cli_get_fs_attr_info_state
*state
= tevent_req_data(
322 req
, struct cli_get_fs_attr_info_state
);
325 if (tevent_req_is_nterror(req
, &status
)) {
328 *fs_attr
= state
->fs_attr
;
332 NTSTATUS
cli_get_fs_attr_info(struct cli_state
*cli
, uint32_t *fs_attr
)
334 struct tevent_context
*ev
;
335 struct tevent_req
*req
;
336 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
338 if (cli_has_async_calls(cli
)) {
339 return NT_STATUS_INVALID_PARAMETER
;
341 ev
= tevent_context_init(talloc_tos());
345 req
= cli_get_fs_attr_info_send(ev
, ev
, cli
);
349 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
352 status
= cli_get_fs_attr_info_recv(req
, fs_attr
);
358 NTSTATUS
cli_get_fs_volume_info(struct cli_state
*cli
,
361 uint32_t *pserial_number
,
365 uint16_t recv_flags2
;
369 uint32_t rdata_count
;
371 char *volume_name
= NULL
;
373 SSVAL(setup
, 0, TRANSACT2_QFSINFO
);
374 SSVAL(param
,0,SMB_QUERY_FS_VOLUME_INFO
);
376 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
384 &rdata
, 18, &rdata_count
);
385 if (!NT_STATUS_IS_OK(status
)) {
391 ts
= interpret_long_date((char *)rdata
);
394 if (pserial_number
) {
395 *pserial_number
= IVAL(rdata
,8);
397 nlen
= IVAL(rdata
,12);
398 if (nlen
> (rdata_count
- 18)) {
400 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
403 clistr_pull_talloc(mem_ctx
,
409 if (volume_name
== NULL
) {
410 status
= map_nt_error_from_unix(errno
);
415 /* todo: but not yet needed
416 * return the other stuff
419 *_volume_name
= volume_name
;
424 NTSTATUS
cli_get_fs_full_size_info(struct cli_state
*cli
,
425 uint64_t *total_allocation_units
,
426 uint64_t *caller_allocation_units
,
427 uint64_t *actual_allocation_units
,
428 uint64_t *sectors_per_allocation_unit
,
429 uint64_t *bytes_per_sector
)
433 uint8_t *rdata
= NULL
;
434 uint32_t rdata_count
;
437 SSVAL(setup
, 0, TRANSACT2_QFSINFO
);
438 SSVAL(param
, 0, SMB_FS_FULL_SIZE_INFORMATION
);
440 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
442 setup
, 1, 0, /* setup */
443 param
, 2, 0, /* param */
444 NULL
, 0, 560, /* data */
446 NULL
, 0, NULL
, /* rsetup */
447 NULL
, 0, NULL
, /* rparam */
448 &rdata
, 32, &rdata_count
); /* rdata */
449 if (!NT_STATUS_IS_OK(status
)) {
453 if (total_allocation_units
) {
454 *total_allocation_units
= BIG_UINT(rdata
, 0);
456 if (caller_allocation_units
) {
457 *caller_allocation_units
= BIG_UINT(rdata
,8);
459 if (actual_allocation_units
) {
460 *actual_allocation_units
= BIG_UINT(rdata
,16);
462 if (sectors_per_allocation_unit
) {
463 *sectors_per_allocation_unit
= IVAL(rdata
,24);
465 if (bytes_per_sector
) {
466 *bytes_per_sector
= IVAL(rdata
,28);
474 NTSTATUS
cli_get_posix_fs_info(struct cli_state
*cli
,
475 uint32
*optimal_transfer_size
,
477 uint64_t *total_blocks
,
478 uint64_t *blocks_available
,
479 uint64_t *user_blocks_available
,
480 uint64_t *total_file_nodes
,
481 uint64_t *free_file_nodes
,
482 uint64_t *fs_identifier
)
486 uint8_t *rdata
= NULL
;
487 uint32_t rdata_count
;
490 SSVAL(setup
, 0, TRANSACT2_QFSINFO
);
491 SSVAL(param
,0,SMB_QUERY_POSIX_FS_INFO
);
493 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
, NULL
, 0, 0, 0,
498 NULL
, 0, NULL
, /* rsetup */
499 NULL
, 0, NULL
, /* rparam */
500 &rdata
, 56, &rdata_count
);
501 if (!NT_STATUS_IS_OK(status
)) {
505 if (optimal_transfer_size
) {
506 *optimal_transfer_size
= IVAL(rdata
, 0);
509 *block_size
= IVAL(rdata
,4);
512 *total_blocks
= BIG_UINT(rdata
,8);
514 if (blocks_available
) {
515 *blocks_available
= BIG_UINT(rdata
,16);
517 if (user_blocks_available
) {
518 *user_blocks_available
= BIG_UINT(rdata
,24);
520 if (total_file_nodes
) {
521 *total_file_nodes
= BIG_UINT(rdata
,32);
523 if (free_file_nodes
) {
524 *free_file_nodes
= BIG_UINT(rdata
,40);
527 *fs_identifier
= BIG_UINT(rdata
,48);
533 /******************************************************************************
534 Send/receive the request encryption blob.
535 ******************************************************************************/
537 static NTSTATUS
enc_blob_send_receive(struct cli_state
*cli
, DATA_BLOB
*in
, DATA_BLOB
*out
, DATA_BLOB
*param_out
)
541 uint8_t *rparam
=NULL
, *rdata
=NULL
;
542 uint32_t num_rparam
, num_rdata
;
545 SSVAL(setup
+0, 0, TRANSACT2_SETFSINFO
);
547 SSVAL(param
,2,SMB_REQUEST_TRANSPORT_ENCRYPTION
);
549 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
, NULL
, 0, 0, 0,
552 (uint8_t *)in
->data
, in
->length
, CLI_BUFFER_SIZE
,
553 NULL
, /* recv_flags */
554 NULL
, 0, NULL
, /* rsetup */
555 &rparam
, 0, &num_rparam
,
556 &rdata
, 0, &num_rdata
);
558 if (!NT_STATUS_IS_OK(status
) &&
559 !NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
563 *out
= data_blob(rdata
, num_rdata
);
564 *param_out
= data_blob(rparam
, num_rparam
);
571 /******************************************************************************
572 Make a client state struct.
573 ******************************************************************************/
575 static struct smb_trans_enc_state
*make_cli_enc_state(enum smb_trans_enc_type smb_enc_type
)
577 struct smb_trans_enc_state
*es
= NULL
;
578 es
= SMB_MALLOC_P(struct smb_trans_enc_state
);
583 es
->smb_enc_type
= smb_enc_type
;
585 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
586 if (smb_enc_type
== SMB_TRANS_ENC_GSS
) {
587 es
->s
.gss_state
= SMB_MALLOC_P(struct smb_tran_enc_state_gss
);
588 if (!es
->s
.gss_state
) {
592 ZERO_STRUCTP(es
->s
.gss_state
);
598 /******************************************************************************
599 Start a raw ntlmssp encryption.
600 ******************************************************************************/
602 NTSTATUS
cli_raw_ntlm_smb_encryption_start(struct cli_state
*cli
,
607 DATA_BLOB blob_in
= data_blob_null
;
608 DATA_BLOB blob_out
= data_blob_null
;
609 DATA_BLOB param_out
= data_blob_null
;
610 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
611 struct smb_trans_enc_state
*es
= make_cli_enc_state(SMB_TRANS_ENC_NTLM
);
614 return NT_STATUS_NO_MEMORY
;
616 status
= auth_ntlmssp_client_start(NULL
,
619 lp_client_ntlmv2_auth(),
620 &es
->s
.auth_ntlmssp_state
);
621 if (!NT_STATUS_IS_OK(status
)) {
625 auth_ntlmssp_want_feature(es
->s
.auth_ntlmssp_state
, NTLMSSP_FEATURE_SESSION_KEY
);
626 auth_ntlmssp_want_feature(es
->s
.auth_ntlmssp_state
, NTLMSSP_FEATURE_SEAL
);
628 if (!NT_STATUS_IS_OK(status
= auth_ntlmssp_set_username(es
->s
.auth_ntlmssp_state
, user
))) {
631 if (!NT_STATUS_IS_OK(status
= auth_ntlmssp_set_domain(es
->s
.auth_ntlmssp_state
, domain
))) {
634 if (!NT_STATUS_IS_OK(status
= auth_ntlmssp_set_password(es
->s
.auth_ntlmssp_state
, pass
))) {
639 status
= auth_ntlmssp_update(es
->s
.auth_ntlmssp_state
, es
->s
.auth_ntlmssp_state
,
641 data_blob_free(&blob_in
);
642 data_blob_free(¶m_out
);
643 if (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
) || NT_STATUS_IS_OK(status
)) {
644 NTSTATUS trans_status
= enc_blob_send_receive(cli
,
648 if (!NT_STATUS_EQUAL(trans_status
,
649 NT_STATUS_MORE_PROCESSING_REQUIRED
) &&
650 !NT_STATUS_IS_OK(trans_status
)) {
651 status
= trans_status
;
653 if (param_out
.length
== 2) {
654 es
->enc_ctx_num
= SVAL(param_out
.data
, 0);
658 data_blob_free(&blob_out
);
659 } while (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
));
661 data_blob_free(&blob_in
);
663 if (NT_STATUS_IS_OK(status
)) {
664 /* Replace the old state, if any. */
665 if (cli
->trans_enc_state
) {
666 common_free_encryption_state(&cli
->trans_enc_state
);
668 cli
->trans_enc_state
= es
;
669 cli
->trans_enc_state
->enc_on
= True
;
675 common_free_encryption_state(&es
);
679 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
681 #ifndef SMB_GSS_REQUIRED_FLAGS
682 #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)
685 /******************************************************************************
686 Get client gss blob to send to a server.
687 ******************************************************************************/
689 static NTSTATUS
make_cli_gss_blob(TALLOC_CTX
*ctx
,
690 struct smb_trans_enc_state
*es
,
694 DATA_BLOB spnego_blob_in
,
695 DATA_BLOB
*p_blob_out
)
697 const char *krb_mechs
[] = {OID_KERBEROS5
, NULL
};
701 gss_buffer_desc input_name
;
702 gss_buffer_desc
*p_tok_in
;
703 gss_buffer_desc tok_out
, tok_in
;
704 DATA_BLOB blob_out
= data_blob_null
;
705 DATA_BLOB blob_in
= data_blob_null
;
706 char *host_princ_s
= NULL
;
707 OM_uint32 ret_flags
= 0;
708 NTSTATUS status
= NT_STATUS_OK
;
710 gss_OID_desc nt_hostbased_service
=
711 {10, discard_const_p(char, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04")};
713 memset(&tok_out
, '\0', sizeof(tok_out
));
715 /* Get a ticket for the service@host */
716 if (asprintf(&host_princ_s
, "%s@%s", service
, host
) == -1) {
717 return NT_STATUS_NO_MEMORY
;
720 input_name
.value
= host_princ_s
;
721 input_name
.length
= strlen(host_princ_s
) + 1;
723 ret
= gss_import_name(&min
,
725 &nt_hostbased_service
,
728 if (ret
!= GSS_S_COMPLETE
) {
729 SAFE_FREE(host_princ_s
);
730 return map_nt_error_from_gss(ret
, min
);
733 if (spnego_blob_in
.length
== 0) {
734 p_tok_in
= GSS_C_NO_BUFFER
;
736 /* Remove the SPNEGO wrapper */
737 if (!spnego_parse_auth_response(ctx
, spnego_blob_in
, status_in
, OID_KERBEROS5
, &blob_in
)) {
738 status
= NT_STATUS_UNSUCCESSFUL
;
741 tok_in
.value
= blob_in
.data
;
742 tok_in
.length
= blob_in
.length
;
746 ret
= gss_init_sec_context(&min
,
747 GSS_C_NO_CREDENTIAL
, /* Use our default cred. */
748 &es
->s
.gss_state
->gss_ctx
,
750 GSS_C_NO_OID
, /* default OID. */
751 GSS_C_MUTUAL_FLAG
| GSS_C_REPLAY_FLAG
| GSS_C_SEQUENCE_FLAG
| GSS_C_DELEG_FLAG
,
752 GSS_C_INDEFINITE
, /* requested ticket lifetime. */
753 NULL
, /* no channel bindings */
755 NULL
, /* ignore mech type */
758 NULL
); /* ignore time_rec */
760 status
= map_nt_error_from_gss(ret
, min
);
761 if (!NT_STATUS_IS_OK(status
) && !NT_STATUS_EQUAL(status
,NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
762 ADS_STATUS adss
= ADS_ERROR_GSS(ret
, min
);
763 DEBUG(10,("make_cli_gss_blob: gss_init_sec_context failed with %s\n",
768 if ((ret_flags
& SMB_GSS_REQUIRED_FLAGS
) != SMB_GSS_REQUIRED_FLAGS
) {
769 status
= NT_STATUS_ACCESS_DENIED
;
772 blob_out
= data_blob_talloc(ctx
, tok_out
.value
, tok_out
.length
);
774 /* Wrap in an SPNEGO wrapper */
775 *p_blob_out
= spnego_gen_negTokenInit(ctx
, krb_mechs
, &blob_out
, NULL
);
779 data_blob_free(&blob_out
);
780 data_blob_free(&blob_in
);
781 SAFE_FREE(host_princ_s
);
782 gss_release_name(&min
, &srv_name
);
784 gss_release_buffer(&min
, &tok_out
);
789 /******************************************************************************
790 Start a SPNEGO gssapi encryption context.
791 ******************************************************************************/
793 NTSTATUS
cli_gss_smb_encryption_start(struct cli_state
*cli
)
795 DATA_BLOB blob_recv
= data_blob_null
;
796 DATA_BLOB blob_send
= data_blob_null
;
797 DATA_BLOB param_out
= data_blob_null
;
798 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
800 const char *servicename
;
801 struct smb_trans_enc_state
*es
= make_cli_enc_state(SMB_TRANS_ENC_GSS
);
804 return NT_STATUS_NO_MEMORY
;
807 name_to_fqdn(fqdn
, cli_state_remote_name(cli
));
810 servicename
= "cifs";
811 status
= make_cli_gss_blob(talloc_tos(), es
, servicename
, fqdn
, NT_STATUS_OK
, blob_recv
, &blob_send
);
812 if (!NT_STATUS_EQUAL(status
,NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
813 servicename
= "host";
814 status
= make_cli_gss_blob(talloc_tos(), es
, servicename
, fqdn
, NT_STATUS_OK
, blob_recv
, &blob_send
);
815 if (!NT_STATUS_EQUAL(status
,NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
821 data_blob_free(&blob_recv
);
822 status
= enc_blob_send_receive(cli
, &blob_send
, &blob_recv
, ¶m_out
);
823 if (param_out
.length
== 2) {
824 es
->enc_ctx_num
= SVAL(param_out
.data
, 0);
826 data_blob_free(&blob_send
);
827 status
= make_cli_gss_blob(talloc_tos(), es
, servicename
, fqdn
, status
, blob_recv
, &blob_send
);
828 } while (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
));
829 data_blob_free(&blob_recv
);
831 if (NT_STATUS_IS_OK(status
)) {
832 /* Replace the old state, if any. */
833 if (cli
->trans_enc_state
) {
834 common_free_encryption_state(&cli
->trans_enc_state
);
836 cli
->trans_enc_state
= es
;
837 cli
->trans_enc_state
->enc_on
= True
;
843 common_free_encryption_state(&es
);
847 NTSTATUS
cli_gss_smb_encryption_start(struct cli_state
*cli
)
849 return NT_STATUS_NOT_SUPPORTED
;
853 /********************************************************************
854 Ensure a connection is encrypted.
855 ********************************************************************/
857 NTSTATUS
cli_force_encryption(struct cli_state
*c
,
858 const char *username
,
859 const char *password
,
863 uint32 caplow
, caphigh
;
866 if (!SERVER_HAS_UNIX_CIFS(c
)) {
867 return NT_STATUS_NOT_SUPPORTED
;
870 status
= cli_unix_extensions_version(c
, &major
, &minor
, &caplow
,
872 if (!NT_STATUS_IS_OK(status
)) {
873 DEBUG(10, ("cli_force_encryption: cli_unix_extensions_version "
874 "returned %s\n", nt_errstr(status
)));
875 return NT_STATUS_UNKNOWN_REVISION
;
878 if (!(caplow
& CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
)) {
879 return NT_STATUS_UNSUPPORTED_COMPRESSION
;
882 if (c
->use_kerberos
) {
883 return cli_gss_smb_encryption_start(c
);
885 return cli_raw_ntlm_smb_encryption_start(c
,