2 Unix SMB/CIFS implementation.
3 client connect/disconnect routines
4 Copyright (C) Andrew Tridgell 1994-1998
5 Copyright (C) Gerald (Jerry) Carter 2004
6 Copyright (C) Jeremy Allison 2007-2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libsmb/libsmb.h"
24 #include "libsmb/clirap.h"
27 #include "libsmb/nmblib.h"
28 #include "../libcli/smb/smbXcli_base.h"
30 /********************************************************************
33 DFS paths are *always* of the form \server\share\<pathname> (the \ characters
34 are not C escaped here).
36 - but if we're using POSIX paths then <pathname> may contain
37 '/' separators, not '\\' separators. So cope with '\\' or '/'
38 as a separator when looking at the pathname part.... JRA.
39 ********************************************************************/
41 /********************************************************************
42 Ensure a connection is encrypted.
43 ********************************************************************/
45 NTSTATUS
cli_cm_force_encryption(struct cli_state
*c
,
49 const char *sharename
)
51 NTSTATUS status
= cli_force_encryption(c
,
56 if (NT_STATUS_EQUAL(status
,NT_STATUS_NOT_SUPPORTED
)) {
57 d_printf("Encryption required and "
58 "server that doesn't support "
59 "UNIX extensions - failing connect\n");
60 } else if (NT_STATUS_EQUAL(status
,NT_STATUS_UNKNOWN_REVISION
)) {
61 d_printf("Encryption required and "
62 "can't get UNIX CIFS extensions "
63 "version from server.\n");
64 } else if (NT_STATUS_EQUAL(status
,NT_STATUS_UNSUPPORTED_COMPRESSION
)) {
65 d_printf("Encryption required and "
66 "share %s doesn't support "
67 "encryption.\n", sharename
);
68 } else if (!NT_STATUS_IS_OK(status
)) {
69 d_printf("Encryption required and "
70 "setup failed with error %s.\n",
77 /********************************************************************
78 Return a connection to a server.
79 ********************************************************************/
81 static NTSTATUS
do_connect(TALLOC_CTX
*ctx
,
84 const struct user_auth_info
*auth_info
,
90 struct cli_state
**pcli
)
92 struct cli_state
*c
= NULL
;
95 char *newserver
, *newshare
;
101 /* make a copy so we don't modify the global string 'service' */
102 servicename
= talloc_strdup(ctx
,share
);
104 return NT_STATUS_NO_MEMORY
;
106 sharename
= servicename
;
107 if (*sharename
== '\\') {
109 if (server
== NULL
) {
112 sharename
= strchr_m(sharename
,'\\');
114 return NT_STATUS_NO_MEMORY
;
119 if (server
== NULL
) {
120 return NT_STATUS_INVALID_PARAMETER
;
123 if (get_cmdline_auth_info_use_kerberos(auth_info
)) {
124 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
;
126 if (get_cmdline_auth_info_fallback_after_kerberos(auth_info
)) {
127 flags
|= CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS
;
129 if (get_cmdline_auth_info_use_ccache(auth_info
)) {
130 flags
|= CLI_FULL_CONNECTION_USE_CCACHE
;
132 if (get_cmdline_auth_info_use_pw_nt_hash(auth_info
)) {
133 flags
|= CLI_FULL_CONNECTION_USE_NT_HASH
;
136 status
= cli_connect_nb(
137 server
, NULL
, port
, name_type
, NULL
,
138 get_cmdline_auth_info_signing_state(auth_info
),
141 if (!NT_STATUS_IS_OK(status
)) {
142 d_printf("Connection to %s failed (Error %s)\n",
148 if (max_protocol
== 0) {
149 max_protocol
= PROTOCOL_NT1
;
151 DEBUG(4,(" session request ok\n"));
153 status
= smbXcli_negprot(c
->conn
, c
->timeout
, PROTOCOL_CORE
,
156 if (!NT_STATUS_IS_OK(status
)) {
157 d_printf("protocol negotiation failed: %s\n",
163 if (smbXcli_conn_protocol(c
->conn
) >= PROTOCOL_SMB2_02
) {
164 /* Ensure we ask for some initial credits. */
165 smb2cli_conn_set_max_credits(c
->conn
, DEFAULT_SMB2_MAX_CREDITS
);
168 username
= get_cmdline_auth_info_username(auth_info
);
169 password
= get_cmdline_auth_info_password(auth_info
);
171 status
= cli_session_setup(c
, username
,
172 password
, strlen(password
),
173 password
, strlen(password
),
175 if (!NT_STATUS_IS_OK(status
)) {
176 /* If a password was not supplied then
177 * try again with a null username. */
178 if (password
[0] || !username
[0] ||
179 get_cmdline_auth_info_use_kerberos(auth_info
) ||
180 !NT_STATUS_IS_OK(status
= cli_session_setup(c
, "",
184 d_printf("session setup failed: %s\n",
186 if (NT_STATUS_EQUAL(status
,
187 NT_STATUS_MORE_PROCESSING_REQUIRED
))
188 d_printf("did you forget to run kinit?\n");
192 d_printf("Anonymous login successful\n");
193 status
= cli_init_creds(c
, "", lp_workgroup(), "");
195 status
= cli_init_creds(c
, username
, lp_workgroup(), password
);
198 if (!NT_STATUS_IS_OK(status
)) {
199 DEBUG(10,("cli_init_creds() failed: %s\n", nt_errstr(status
)));
204 if ( show_sessetup
) {
205 if (*c
->server_domain
) {
206 DEBUG(0,("Domain=[%s] OS=[%s] Server=[%s]\n",
207 c
->server_domain
,c
->server_os
,c
->server_type
));
208 } else if (*c
->server_os
|| *c
->server_type
) {
209 DEBUG(0,("OS=[%s] Server=[%s]\n",
210 c
->server_os
,c
->server_type
));
213 DEBUG(4,(" session setup ok\n"));
215 /* here's the fun part....to support 'msdfs proxy' shares
216 (on Samba or windows) we have to issues a TRANS_GET_DFS_REFERRAL
217 here before trying to connect to the original share.
218 cli_check_msdfs_proxy() will fail if it is a normal share. */
220 if ((smb1cli_conn_capabilities(c
->conn
) & CAP_DFS
) &&
221 cli_check_msdfs_proxy(ctx
, c
, sharename
,
222 &newserver
, &newshare
,
228 return do_connect(ctx
, newserver
,
229 newshare
, auth_info
, false,
230 force_encrypt
, max_protocol
,
231 port
, name_type
, pcli
);
234 /* must be a normal share */
236 status
= cli_tree_connect(c
, sharename
, "?????",
237 password
, strlen(password
)+1);
238 if (!NT_STATUS_IS_OK(status
)) {
239 d_printf("tree connect failed: %s\n", nt_errstr(status
));
245 status
= cli_cm_force_encryption(c
,
250 if (!NT_STATUS_IS_OK(status
)) {
256 DEBUG(4,(" tconx ok\n"));
261 /****************************************************************************
262 ****************************************************************************/
264 static void cli_set_mntpoint(struct cli_state
*cli
, const char *mnt
)
266 char *name
= clean_name(NULL
, mnt
);
270 TALLOC_FREE(cli
->dfs_mountpoint
);
271 cli
->dfs_mountpoint
= talloc_strdup(cli
, name
);
275 /********************************************************************
276 Add a new connection to the list.
277 referring_cli == NULL means a new initial connection.
278 ********************************************************************/
280 static NTSTATUS
cli_cm_connect(TALLOC_CTX
*ctx
,
281 struct cli_state
*referring_cli
,
284 const struct user_auth_info
*auth_info
,
290 struct cli_state
**pcli
)
292 struct cli_state
*cli
;
295 status
= do_connect(ctx
, server
, share
,
297 show_hdr
, force_encrypt
, max_protocol
,
298 port
, name_type
, &cli
);
300 if (!NT_STATUS_IS_OK(status
)) {
304 /* Enter into the list. */
306 DLIST_ADD_END(referring_cli
, cli
, struct cli_state
*);
309 if (referring_cli
&& referring_cli
->requested_posix_capabilities
) {
311 uint32 caplow
, caphigh
;
312 status
= cli_unix_extensions_version(cli
, &major
, &minor
,
314 if (NT_STATUS_IS_OK(status
)) {
315 cli_set_unix_extensions_capabilities(cli
,
325 /********************************************************************
326 Return a connection to a server on a particular share.
327 ********************************************************************/
329 static struct cli_state
*cli_cm_find(struct cli_state
*cli
,
339 /* Search to the start of the list. */
340 for (p
= cli
; p
; p
= DLIST_PREV(p
)) {
341 const char *remote_name
=
342 smbXcli_conn_remote_name(p
->conn
);
344 if (strequal(server
, remote_name
) &&
345 strequal(share
,p
->share
)) {
350 /* Search to the end of the list. */
351 for (p
= cli
->next
; p
; p
= p
->next
) {
352 const char *remote_name
=
353 smbXcli_conn_remote_name(p
->conn
);
355 if (strequal(server
, remote_name
) &&
356 strequal(share
,p
->share
)) {
364 /****************************************************************************
365 Open a client connection to a \\server\share.
366 ****************************************************************************/
368 NTSTATUS
cli_cm_open(TALLOC_CTX
*ctx
,
369 struct cli_state
*referring_cli
,
372 const struct user_auth_info
*auth_info
,
378 struct cli_state
**pcli
)
380 /* Try to reuse an existing connection in this list. */
381 struct cli_state
*c
= cli_cm_find(referring_cli
, server
, share
);
389 if (auth_info
== NULL
) {
390 /* Can't do a new connection
391 * without auth info. */
392 d_printf("cli_cm_open() Unable to open connection [\\%s\\%s] "
393 "without auth info\n",
395 return NT_STATUS_INVALID_PARAMETER
;
398 status
= cli_cm_connect(ctx
,
409 if (!NT_STATUS_IS_OK(status
)) {
416 /****************************************************************************
417 ****************************************************************************/
419 void cli_cm_display(struct cli_state
*cli
)
423 for (i
=0; cli
; cli
= cli
->next
,i
++ ) {
424 d_printf("%d:\tserver=%s, share=%s\n",
425 i
, smbXcli_conn_remote_name(cli
->conn
), cli
->share
);
429 /****************************************************************************
430 ****************************************************************************/
432 /****************************************************************************
433 ****************************************************************************/
436 void cli_cm_set_credentials(struct user_auth_info
*auth_info
)
438 SAFE_FREE(cm_creds
.username
);
439 cm_creds
.username
= SMB_STRDUP(get_cmdline_auth_info_username(
442 if (get_cmdline_auth_info_got_pass(auth_info
)) {
443 cm_set_password(get_cmdline_auth_info_password(auth_info
));
446 cm_creds
.use_kerberos
= get_cmdline_auth_info_use_kerberos(auth_info
);
447 cm_creds
.fallback_after_kerberos
= false;
448 cm_creds
.signing_state
= get_cmdline_auth_info_signing_state(auth_info
);
452 /**********************************************************************
453 split a dfs path into the server, share name, and extrapath components
454 **********************************************************************/
456 static bool split_dfs_path(TALLOC_CTX
*ctx
,
457 const char *nodepath
,
467 *pp_extrapath
= NULL
;
469 path
= talloc_strdup(ctx
, nodepath
);
474 if ( path
[0] != '\\' ) {
478 p
= strchr_m( path
+ 1, '\\' );
486 /* Look for any extra/deep path */
487 q
= strchr_m(p
, '\\');
491 *pp_extrapath
= talloc_strdup(ctx
, q
);
493 *pp_extrapath
= talloc_strdup(ctx
, "");
495 if (*pp_extrapath
== NULL
) {
499 *pp_share
= talloc_strdup(ctx
, p
);
500 if (*pp_share
== NULL
) {
504 *pp_server
= talloc_strdup(ctx
, &path
[1]);
505 if (*pp_server
== NULL
) {
513 TALLOC_FREE(*pp_share
);
514 TALLOC_FREE(*pp_extrapath
);
519 /****************************************************************************
520 Return the original path truncated at the directory component before
521 the first wildcard character. Trust the caller to provide a NULL
523 ****************************************************************************/
525 static char *clean_path(TALLOC_CTX
*ctx
, const char *path
)
531 /* No absolute paths. */
532 while (IS_DIRECTORY_SEP(*path
)) {
536 path_out
= talloc_strdup(ctx
, path
);
541 p1
= strchr_m(path_out
, '*');
542 p2
= strchr_m(path_out
, '?');
554 /* Now go back to the start of this component. */
555 p1
= strrchr_m(path_out
, '/');
556 p2
= strrchr_m(path_out
, '\\');
563 /* Strip any trailing separator */
565 len
= strlen(path_out
);
566 if ( (len
> 0) && IS_DIRECTORY_SEP(path_out
[len
-1])) {
567 path_out
[len
-1] = '\0';
573 /****************************************************************************
574 ****************************************************************************/
576 static char *cli_dfs_make_full_path(TALLOC_CTX
*ctx
,
577 struct cli_state
*cli
,
580 char path_sep
= '\\';
582 /* Ensure the extrapath doesn't start with a separator. */
583 while (IS_DIRECTORY_SEP(*dir
)) {
587 if (cli
->requested_posix_capabilities
& CIFS_UNIX_POSIX_PATHNAMES_CAP
) {
590 return talloc_asprintf(ctx
, "%c%s%c%s%c%s",
592 smbXcli_conn_remote_name(cli
->conn
),
599 /********************************************************************
600 check for dfs referral
601 ********************************************************************/
603 static bool cli_dfs_check_error(struct cli_state
*cli
, NTSTATUS expected
,
606 /* only deal with DS when we negotiated NT_STATUS codes and UNICODE */
608 if (!(smb1cli_conn_capabilities(cli
->conn
) & CAP_UNICODE
)) {
611 if (!(smb1cli_conn_capabilities(cli
->conn
) & CAP_STATUS32
)) {
614 if (NT_STATUS_EQUAL(status
, expected
)) {
620 /********************************************************************
621 Get the dfs referral link.
622 ********************************************************************/
624 NTSTATUS
cli_dfs_get_referral(TALLOC_CTX
*ctx
,
625 struct cli_state
*cli
,
627 struct client_dfs_referral
**refs
,
631 unsigned int data_len
= 0;
632 unsigned int param_len
= 0;
634 uint16_t recv_flags2
;
635 uint8_t *param
= NULL
;
636 uint8_t *rdata
= NULL
;
639 smb_ucs2_t
*path_ucs
;
640 char *consumed_path
= NULL
;
641 uint16_t consumed_ucs
;
642 uint16 num_referrals
;
643 struct client_dfs_referral
*referrals
= NULL
;
645 TALLOC_CTX
*frame
= talloc_stackframe();
650 SSVAL(setup
, 0, TRANSACT2_GET_DFS_REFERRAL
);
652 param
= talloc_array(talloc_tos(), uint8_t, 2);
654 status
= NT_STATUS_NO_MEMORY
;
657 SSVAL(param
, 0, 0x03); /* max referral level */
659 param
= trans2_bytes_push_str(param
, smbXcli_conn_use_unicode(cli
->conn
),
660 path
, strlen(path
)+1,
663 status
= NT_STATUS_NO_MEMORY
;
666 param_len
= talloc_get_size(param
);
667 path_ucs
= (smb_ucs2_t
*)¶m
[2];
669 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
673 NULL
, 0, CLI_BUFFER_SIZE
,
675 NULL
, 0, NULL
, /* rsetup */
677 &rdata
, 4, &data_len
);
678 if (!NT_STATUS_IS_OK(status
)) {
682 endp
= (char *)rdata
+ data_len
;
684 consumed_ucs
= SVAL(rdata
, 0);
685 num_referrals
= SVAL(rdata
, 2);
687 /* consumed_ucs is the number of bytes
688 * of the UCS2 path consumed not counting any
689 * terminating null. We need to convert
690 * back to unix charset and count again
691 * to get the number of bytes consumed from
692 * the incoming path. */
695 if (pull_string_talloc(talloc_tos(),
703 status
= map_nt_error_from_unix(errno
);
705 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
709 if (consumed_path
== NULL
) {
710 status
= map_nt_error_from_unix(errno
);
713 *consumed
= strlen(consumed_path
);
715 if (num_referrals
!= 0) {
721 referrals
= talloc_array(ctx
, struct client_dfs_referral
,
725 status
= NT_STATUS_NO_MEMORY
;
728 /* start at the referrals array */
731 for (i
=0; i
<num_referrals
&& p
< endp
; i
++) {
735 ref_version
= SVAL(p
, 0);
736 ref_size
= SVAL(p
, 2);
737 node_offset
= SVAL(p
, 16);
739 if (ref_version
!= 3) {
744 referrals
[i
].proximity
= SVAL(p
, 8);
745 referrals
[i
].ttl
= SVAL(p
, 10);
747 if (p
+ node_offset
> endp
) {
748 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
751 clistr_pull_talloc(referrals
,
754 &referrals
[i
].dfspath
,
756 PTR_DIFF(endp
, p
+node_offset
),
757 STR_TERMINATE
|STR_UNICODE
);
759 if (!referrals
[i
].dfspath
) {
760 status
= map_nt_error_from_unix(errno
);
765 if (i
< num_referrals
) {
766 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
771 *num_refs
= num_referrals
;
780 /********************************************************************
781 ********************************************************************/
783 NTSTATUS
cli_resolve_path(TALLOC_CTX
*ctx
,
785 const struct user_auth_info
*dfs_auth_info
,
786 struct cli_state
*rootcli
,
788 struct cli_state
**targetcli
,
789 char **pp_targetpath
)
791 struct client_dfs_referral
*refs
= NULL
;
794 struct cli_state
*cli_ipc
= NULL
;
795 char *dfs_path
= NULL
;
796 char *cleanpath
= NULL
;
797 char *extrapath
= NULL
;
801 struct cli_state
*newcli
= NULL
;
802 char *newpath
= NULL
;
803 char *newmount
= NULL
;
805 SMB_STRUCT_STAT sbuf
;
809 if ( !rootcli
|| !path
|| !targetcli
) {
810 return NT_STATUS_INVALID_PARAMETER
;
813 /* Don't do anything if this is not a DFS root. */
815 if ( !rootcli
->dfsroot
) {
816 *targetcli
= rootcli
;
817 *pp_targetpath
= talloc_strdup(ctx
, path
);
818 if (!*pp_targetpath
) {
819 return NT_STATUS_NO_MEMORY
;
826 /* Send a trans2_query_path_info to check for a referral. */
828 cleanpath
= clean_path(ctx
, path
);
830 return NT_STATUS_NO_MEMORY
;
833 dfs_path
= cli_dfs_make_full_path(ctx
, rootcli
, cleanpath
);
835 return NT_STATUS_NO_MEMORY
;
838 status
= cli_qpathinfo_basic( rootcli
, dfs_path
, &sbuf
, &attributes
);
839 if (NT_STATUS_IS_OK(status
)) {
840 /* This is an ordinary path, just return it. */
841 *targetcli
= rootcli
;
842 *pp_targetpath
= talloc_strdup(ctx
, path
);
843 if (!*pp_targetpath
) {
844 return NT_STATUS_NO_MEMORY
;
849 /* Special case where client asked for a path that does not exist */
851 if (cli_dfs_check_error(rootcli
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
853 *targetcli
= rootcli
;
854 *pp_targetpath
= talloc_strdup(ctx
, path
);
855 if (!*pp_targetpath
) {
856 return NT_STATUS_NO_MEMORY
;
861 /* We got an error, check for DFS referral. */
863 if (!cli_dfs_check_error(rootcli
, NT_STATUS_PATH_NOT_COVERED
,
868 /* Check for the referral. */
870 status
= cli_cm_open(ctx
,
872 smbXcli_conn_remote_name(rootcli
->conn
),
876 smb1cli_conn_encryption_on(rootcli
->conn
),
877 smbXcli_conn_protocol(rootcli
->conn
),
881 if (!NT_STATUS_IS_OK(status
)) {
885 status
= cli_dfs_get_referral(ctx
, cli_ipc
, dfs_path
, &refs
,
886 &num_refs
, &consumed
);
887 if (!NT_STATUS_IS_OK(status
) || !num_refs
) {
891 /* Just store the first referral for now. */
893 if (!refs
[0].dfspath
) {
894 return NT_STATUS_NOT_FOUND
;
896 if (!split_dfs_path(ctx
, refs
[0].dfspath
, &server
, &share
,
898 return NT_STATUS_NOT_FOUND
;
901 /* Make sure to recreate the original string including any wildcards. */
903 dfs_path
= cli_dfs_make_full_path(ctx
, rootcli
, path
);
905 return NT_STATUS_NO_MEMORY
;
907 pathlen
= strlen(dfs_path
);
908 consumed
= MIN(pathlen
, consumed
);
909 *pp_targetpath
= talloc_strdup(ctx
, &dfs_path
[consumed
]);
910 if (!*pp_targetpath
) {
911 return NT_STATUS_NO_MEMORY
;
913 dfs_path
[consumed
] = '\0';
916 * *pp_targetpath is now the unconsumed part of the path.
917 * dfs_path is now the consumed part of the path
918 * (in \server\share\path format).
921 /* Open the connection to the target server & share */
922 status
= cli_cm_open(ctx
, rootcli
,
927 smb1cli_conn_encryption_on(rootcli
->conn
),
928 smbXcli_conn_protocol(rootcli
->conn
),
932 if (!NT_STATUS_IS_OK(status
)) {
933 d_printf("Unable to follow dfs referral [\\%s\\%s]\n",
938 if (extrapath
&& strlen(extrapath
) > 0) {
939 /* EMC Celerra NAS version 5.6.50 (at least) doesn't appear to */
940 /* put the trailing \ on the path, so to be save we put one in if needed */
941 if (extrapath
[strlen(extrapath
)-1] != '\\' && **pp_targetpath
!= '\\') {
942 *pp_targetpath
= talloc_asprintf(ctx
,
947 *pp_targetpath
= talloc_asprintf(ctx
,
952 if (!*pp_targetpath
) {
953 return NT_STATUS_NO_MEMORY
;
957 /* parse out the consumed mount path */
958 /* trim off the \server\share\ */
962 if (*ppath
!= '\\') {
963 d_printf("cli_resolve_path: "
964 "dfs_path (%s) not in correct format.\n",
966 return NT_STATUS_NOT_FOUND
;
969 ppath
++; /* Now pointing at start of server name. */
971 if ((ppath
= strchr_m( dfs_path
, '\\' )) == NULL
) {
972 return NT_STATUS_NOT_FOUND
;
975 ppath
++; /* Now pointing at start of share name. */
977 if ((ppath
= strchr_m( ppath
+1, '\\' )) == NULL
) {
978 return NT_STATUS_NOT_FOUND
;
981 ppath
++; /* Now pointing at path component. */
983 newmount
= talloc_asprintf(ctx
, "%s\\%s", mountpt
, ppath
);
985 return NT_STATUS_NOT_FOUND
;
988 cli_set_mntpoint(*targetcli
, newmount
);
990 /* Check for another dfs referral, note that we are not
991 checking for loops here. */
993 if (!strequal(*pp_targetpath
, "\\") && !strequal(*pp_targetpath
, "/")) {
994 status
= cli_resolve_path(ctx
,
1001 if (NT_STATUS_IS_OK(status
)) {
1003 * When cli_resolve_path returns true here it's always
1004 * returning the complete path in newpath, so we're done
1007 *targetcli
= newcli
;
1008 *pp_targetpath
= newpath
;
1015 /* If returning true ensure we return a dfs root full path. */
1016 if ((*targetcli
)->dfsroot
) {
1017 dfs_path
= talloc_strdup(ctx
, *pp_targetpath
);
1019 return NT_STATUS_NO_MEMORY
;
1021 *pp_targetpath
= cli_dfs_make_full_path(ctx
, *targetcli
, dfs_path
);
1022 if (*pp_targetpath
== NULL
) {
1023 return NT_STATUS_NO_MEMORY
;
1027 return NT_STATUS_OK
;
1030 /********************************************************************
1031 ********************************************************************/
1033 bool cli_check_msdfs_proxy(TALLOC_CTX
*ctx
,
1034 struct cli_state
*cli
,
1035 const char *sharename
,
1036 char **pp_newserver
,
1039 const char *username
,
1040 const char *password
,
1043 struct client_dfs_referral
*refs
= NULL
;
1044 size_t num_refs
= 0;
1045 size_t consumed
= 0;
1046 char *fullpath
= NULL
;
1049 char *newextrapath
= NULL
;
1051 const char *remote_name
;
1053 if (!cli
|| !sharename
) {
1057 remote_name
= smbXcli_conn_remote_name(cli
->conn
);
1058 cnum
= cli_state_get_tid(cli
);
1060 /* special case. never check for a referral on the IPC$ share */
1062 if (strequal(sharename
, "IPC$")) {
1066 /* send a trans2_query_path_info to check for a referral */
1068 fullpath
= talloc_asprintf(ctx
, "\\%s\\%s", remote_name
, sharename
);
1073 /* check for the referral */
1075 if (!NT_STATUS_IS_OK(cli_tree_connect(cli
, "IPC$", "IPC", NULL
, 0))) {
1079 if (force_encrypt
) {
1080 status
= cli_cm_force_encryption(cli
,
1085 if (!NT_STATUS_IS_OK(status
)) {
1090 status
= cli_dfs_get_referral(ctx
, cli
, fullpath
, &refs
,
1091 &num_refs
, &consumed
);
1092 res
= NT_STATUS_IS_OK(status
);
1094 status
= cli_tdis(cli
);
1095 if (!NT_STATUS_IS_OK(status
)) {
1099 cli_state_set_tid(cli
, cnum
);
1101 if (!res
|| !num_refs
) {
1105 if (!refs
[0].dfspath
) {
1109 if (!split_dfs_path(ctx
, refs
[0].dfspath
, pp_newserver
,
1110 pp_newshare
, &newextrapath
)) {
1114 /* check that this is not a self-referral */
1116 if (strequal(remote_name
, *pp_newserver
) &&
1117 strequal(sharename
, *pp_newshare
)) {