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
,
154 lp_cli_minprotocol(),
157 if (!NT_STATUS_IS_OK(status
)) {
158 d_printf("protocol negotiation failed: %s\n",
164 if (smbXcli_conn_protocol(c
->conn
) >= PROTOCOL_SMB2_02
) {
165 /* Ensure we ask for some initial credits. */
166 smb2cli_conn_set_max_credits(c
->conn
, DEFAULT_SMB2_MAX_CREDITS
);
169 username
= get_cmdline_auth_info_username(auth_info
);
170 password
= get_cmdline_auth_info_password(auth_info
);
172 status
= cli_session_setup(c
, username
,
173 password
, strlen(password
),
174 password
, strlen(password
),
176 if (!NT_STATUS_IS_OK(status
)) {
177 /* If a password was not supplied then
178 * try again with a null username. */
179 if (password
[0] || !username
[0] ||
180 get_cmdline_auth_info_use_kerberos(auth_info
) ||
181 !NT_STATUS_IS_OK(status
= cli_session_setup(c
, "",
185 d_printf("session setup failed: %s\n",
187 if (NT_STATUS_EQUAL(status
,
188 NT_STATUS_MORE_PROCESSING_REQUIRED
))
189 d_printf("did you forget to run kinit?\n");
193 d_printf("Anonymous login successful\n");
194 status
= cli_init_creds(c
, "", lp_workgroup(), "");
196 status
= cli_init_creds(c
, username
, lp_workgroup(), password
);
199 if (!NT_STATUS_IS_OK(status
)) {
200 DEBUG(10,("cli_init_creds() failed: %s\n", nt_errstr(status
)));
205 if ( show_sessetup
) {
206 if (*c
->server_domain
) {
207 DEBUG(0,("Domain=[%s] OS=[%s] Server=[%s]\n",
208 c
->server_domain
,c
->server_os
,c
->server_type
));
209 } else if (*c
->server_os
|| *c
->server_type
) {
210 DEBUG(0,("OS=[%s] Server=[%s]\n",
211 c
->server_os
,c
->server_type
));
214 DEBUG(4,(" session setup ok\n"));
216 /* here's the fun part....to support 'msdfs proxy' shares
217 (on Samba or windows) we have to issues a TRANS_GET_DFS_REFERRAL
218 here before trying to connect to the original share.
219 cli_check_msdfs_proxy() will fail if it is a normal share. */
221 if ((smb1cli_conn_capabilities(c
->conn
) & CAP_DFS
) &&
222 cli_check_msdfs_proxy(ctx
, c
, sharename
,
223 &newserver
, &newshare
,
229 return do_connect(ctx
, newserver
,
230 newshare
, auth_info
, false,
231 force_encrypt
, max_protocol
,
232 port
, name_type
, pcli
);
235 /* must be a normal share */
237 status
= cli_tree_connect(c
, sharename
, "?????",
238 password
, strlen(password
)+1);
239 if (!NT_STATUS_IS_OK(status
)) {
240 d_printf("tree connect failed: %s\n", nt_errstr(status
));
246 status
= cli_cm_force_encryption(c
,
251 if (!NT_STATUS_IS_OK(status
)) {
257 DEBUG(4,(" tconx ok\n"));
262 /****************************************************************************
263 ****************************************************************************/
265 static void cli_set_mntpoint(struct cli_state
*cli
, const char *mnt
)
267 char *name
= clean_name(NULL
, mnt
);
271 TALLOC_FREE(cli
->dfs_mountpoint
);
272 cli
->dfs_mountpoint
= talloc_strdup(cli
, name
);
276 /********************************************************************
277 Add a new connection to the list.
278 referring_cli == NULL means a new initial connection.
279 ********************************************************************/
281 static NTSTATUS
cli_cm_connect(TALLOC_CTX
*ctx
,
282 struct cli_state
*referring_cli
,
285 const struct user_auth_info
*auth_info
,
291 struct cli_state
**pcli
)
293 struct cli_state
*cli
;
296 status
= do_connect(ctx
, server
, share
,
298 show_hdr
, force_encrypt
, max_protocol
,
299 port
, name_type
, &cli
);
301 if (!NT_STATUS_IS_OK(status
)) {
305 /* Enter into the list. */
307 DLIST_ADD_END(referring_cli
, cli
, struct cli_state
*);
310 if (referring_cli
&& referring_cli
->requested_posix_capabilities
) {
312 uint32 caplow
, caphigh
;
313 status
= cli_unix_extensions_version(cli
, &major
, &minor
,
315 if (NT_STATUS_IS_OK(status
)) {
316 cli_set_unix_extensions_capabilities(cli
,
326 /********************************************************************
327 Return a connection to a server on a particular share.
328 ********************************************************************/
330 static struct cli_state
*cli_cm_find(struct cli_state
*cli
,
340 /* Search to the start of the list. */
341 for (p
= cli
; p
; p
= DLIST_PREV(p
)) {
342 const char *remote_name
=
343 smbXcli_conn_remote_name(p
->conn
);
345 if (strequal(server
, remote_name
) &&
346 strequal(share
,p
->share
)) {
351 /* Search to the end of the list. */
352 for (p
= cli
->next
; p
; p
= p
->next
) {
353 const char *remote_name
=
354 smbXcli_conn_remote_name(p
->conn
);
356 if (strequal(server
, remote_name
) &&
357 strequal(share
,p
->share
)) {
365 /****************************************************************************
366 Open a client connection to a \\server\share.
367 ****************************************************************************/
369 NTSTATUS
cli_cm_open(TALLOC_CTX
*ctx
,
370 struct cli_state
*referring_cli
,
373 const struct user_auth_info
*auth_info
,
379 struct cli_state
**pcli
)
381 /* Try to reuse an existing connection in this list. */
382 struct cli_state
*c
= cli_cm_find(referring_cli
, server
, share
);
390 if (auth_info
== NULL
) {
391 /* Can't do a new connection
392 * without auth info. */
393 d_printf("cli_cm_open() Unable to open connection [\\%s\\%s] "
394 "without auth info\n",
396 return NT_STATUS_INVALID_PARAMETER
;
399 status
= cli_cm_connect(ctx
,
410 if (!NT_STATUS_IS_OK(status
)) {
417 /****************************************************************************
418 ****************************************************************************/
420 void cli_cm_display(struct cli_state
*cli
)
424 for (i
=0; cli
; cli
= cli
->next
,i
++ ) {
425 d_printf("%d:\tserver=%s, share=%s\n",
426 i
, smbXcli_conn_remote_name(cli
->conn
), cli
->share
);
430 /****************************************************************************
431 ****************************************************************************/
433 /****************************************************************************
434 ****************************************************************************/
437 void cli_cm_set_credentials(struct user_auth_info
*auth_info
)
439 SAFE_FREE(cm_creds
.username
);
440 cm_creds
.username
= SMB_STRDUP(get_cmdline_auth_info_username(
443 if (get_cmdline_auth_info_got_pass(auth_info
)) {
444 cm_set_password(get_cmdline_auth_info_password(auth_info
));
447 cm_creds
.use_kerberos
= get_cmdline_auth_info_use_kerberos(auth_info
);
448 cm_creds
.fallback_after_kerberos
= false;
449 cm_creds
.signing_state
= get_cmdline_auth_info_signing_state(auth_info
);
453 /**********************************************************************
454 split a dfs path into the server, share name, and extrapath components
455 **********************************************************************/
457 static bool split_dfs_path(TALLOC_CTX
*ctx
,
458 const char *nodepath
,
468 *pp_extrapath
= NULL
;
470 path
= talloc_strdup(ctx
, nodepath
);
475 if ( path
[0] != '\\' ) {
479 p
= strchr_m( path
+ 1, '\\' );
487 /* Look for any extra/deep path */
488 q
= strchr_m(p
, '\\');
492 *pp_extrapath
= talloc_strdup(ctx
, q
);
494 *pp_extrapath
= talloc_strdup(ctx
, "");
496 if (*pp_extrapath
== NULL
) {
500 *pp_share
= talloc_strdup(ctx
, p
);
501 if (*pp_share
== NULL
) {
505 *pp_server
= talloc_strdup(ctx
, &path
[1]);
506 if (*pp_server
== NULL
) {
514 TALLOC_FREE(*pp_share
);
515 TALLOC_FREE(*pp_extrapath
);
520 /****************************************************************************
521 Return the original path truncated at the directory component before
522 the first wildcard character. Trust the caller to provide a NULL
524 ****************************************************************************/
526 static char *clean_path(TALLOC_CTX
*ctx
, const char *path
)
532 /* No absolute paths. */
533 while (IS_DIRECTORY_SEP(*path
)) {
537 path_out
= talloc_strdup(ctx
, path
);
542 p1
= strchr_m(path_out
, '*');
543 p2
= strchr_m(path_out
, '?');
555 /* Now go back to the start of this component. */
556 p1
= strrchr_m(path_out
, '/');
557 p2
= strrchr_m(path_out
, '\\');
564 /* Strip any trailing separator */
566 len
= strlen(path_out
);
567 if ( (len
> 0) && IS_DIRECTORY_SEP(path_out
[len
-1])) {
568 path_out
[len
-1] = '\0';
574 /****************************************************************************
575 ****************************************************************************/
577 static char *cli_dfs_make_full_path(TALLOC_CTX
*ctx
,
578 struct cli_state
*cli
,
581 char path_sep
= '\\';
583 /* Ensure the extrapath doesn't start with a separator. */
584 while (IS_DIRECTORY_SEP(*dir
)) {
588 if (cli
->requested_posix_capabilities
& CIFS_UNIX_POSIX_PATHNAMES_CAP
) {
591 return talloc_asprintf(ctx
, "%c%s%c%s%c%s",
593 smbXcli_conn_remote_name(cli
->conn
),
600 /********************************************************************
601 check for dfs referral
602 ********************************************************************/
604 static bool cli_dfs_check_error(struct cli_state
*cli
, NTSTATUS expected
,
607 /* only deal with DS when we negotiated NT_STATUS codes and UNICODE */
609 if (!(smb1cli_conn_capabilities(cli
->conn
) & CAP_UNICODE
)) {
612 if (!(smb1cli_conn_capabilities(cli
->conn
) & CAP_STATUS32
)) {
615 if (NT_STATUS_EQUAL(status
, expected
)) {
621 /********************************************************************
622 Get the dfs referral link.
623 ********************************************************************/
625 NTSTATUS
cli_dfs_get_referral(TALLOC_CTX
*ctx
,
626 struct cli_state
*cli
,
628 struct client_dfs_referral
**refs
,
632 unsigned int data_len
= 0;
633 unsigned int param_len
= 0;
635 uint16_t recv_flags2
;
636 uint8_t *param
= NULL
;
637 uint8_t *rdata
= NULL
;
640 smb_ucs2_t
*path_ucs
;
641 char *consumed_path
= NULL
;
642 uint16_t consumed_ucs
;
643 uint16 num_referrals
;
644 struct client_dfs_referral
*referrals
= NULL
;
646 TALLOC_CTX
*frame
= talloc_stackframe();
651 SSVAL(setup
, 0, TRANSACT2_GET_DFS_REFERRAL
);
653 param
= talloc_array(talloc_tos(), uint8_t, 2);
655 status
= NT_STATUS_NO_MEMORY
;
658 SSVAL(param
, 0, 0x03); /* max referral level */
660 param
= trans2_bytes_push_str(param
, smbXcli_conn_use_unicode(cli
->conn
),
661 path
, strlen(path
)+1,
664 status
= NT_STATUS_NO_MEMORY
;
667 param_len
= talloc_get_size(param
);
668 path_ucs
= (smb_ucs2_t
*)¶m
[2];
670 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
674 NULL
, 0, CLI_BUFFER_SIZE
,
676 NULL
, 0, NULL
, /* rsetup */
678 &rdata
, 4, &data_len
);
679 if (!NT_STATUS_IS_OK(status
)) {
683 endp
= (char *)rdata
+ data_len
;
685 consumed_ucs
= SVAL(rdata
, 0);
686 num_referrals
= SVAL(rdata
, 2);
688 /* consumed_ucs is the number of bytes
689 * of the UCS2 path consumed not counting any
690 * terminating null. We need to convert
691 * back to unix charset and count again
692 * to get the number of bytes consumed from
693 * the incoming path. */
696 if (pull_string_talloc(talloc_tos(),
704 status
= map_nt_error_from_unix(errno
);
706 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
710 if (consumed_path
== NULL
) {
711 status
= map_nt_error_from_unix(errno
);
714 *consumed
= strlen(consumed_path
);
716 if (num_referrals
!= 0) {
722 referrals
= talloc_array(ctx
, struct client_dfs_referral
,
726 status
= NT_STATUS_NO_MEMORY
;
729 /* start at the referrals array */
732 for (i
=0; i
<num_referrals
&& p
< endp
; i
++) {
736 ref_version
= SVAL(p
, 0);
737 ref_size
= SVAL(p
, 2);
738 node_offset
= SVAL(p
, 16);
740 if (ref_version
!= 3) {
745 referrals
[i
].proximity
= SVAL(p
, 8);
746 referrals
[i
].ttl
= SVAL(p
, 10);
748 if (p
+ node_offset
> endp
) {
749 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
752 clistr_pull_talloc(referrals
,
755 &referrals
[i
].dfspath
,
757 PTR_DIFF(endp
, p
+node_offset
),
758 STR_TERMINATE
|STR_UNICODE
);
760 if (!referrals
[i
].dfspath
) {
761 status
= map_nt_error_from_unix(errno
);
766 if (i
< num_referrals
) {
767 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
772 *num_refs
= num_referrals
;
781 /********************************************************************
782 ********************************************************************/
784 NTSTATUS
cli_resolve_path(TALLOC_CTX
*ctx
,
786 const struct user_auth_info
*dfs_auth_info
,
787 struct cli_state
*rootcli
,
789 struct cli_state
**targetcli
,
790 char **pp_targetpath
)
792 struct client_dfs_referral
*refs
= NULL
;
795 struct cli_state
*cli_ipc
= NULL
;
796 char *dfs_path
= NULL
;
797 char *cleanpath
= NULL
;
798 char *extrapath
= NULL
;
802 struct cli_state
*newcli
= NULL
;
803 char *newpath
= NULL
;
804 char *newmount
= NULL
;
806 SMB_STRUCT_STAT sbuf
;
810 if ( !rootcli
|| !path
|| !targetcli
) {
811 return NT_STATUS_INVALID_PARAMETER
;
814 /* Don't do anything if this is not a DFS root. */
816 if ( !rootcli
->dfsroot
) {
817 *targetcli
= rootcli
;
818 *pp_targetpath
= talloc_strdup(ctx
, path
);
819 if (!*pp_targetpath
) {
820 return NT_STATUS_NO_MEMORY
;
827 /* Send a trans2_query_path_info to check for a referral. */
829 cleanpath
= clean_path(ctx
, path
);
831 return NT_STATUS_NO_MEMORY
;
834 dfs_path
= cli_dfs_make_full_path(ctx
, rootcli
, cleanpath
);
836 return NT_STATUS_NO_MEMORY
;
839 status
= cli_qpathinfo_basic( rootcli
, dfs_path
, &sbuf
, &attributes
);
840 if (NT_STATUS_IS_OK(status
)) {
841 /* This is an ordinary path, just return it. */
842 *targetcli
= rootcli
;
843 *pp_targetpath
= talloc_strdup(ctx
, path
);
844 if (!*pp_targetpath
) {
845 return NT_STATUS_NO_MEMORY
;
850 /* Special case where client asked for a path that does not exist */
852 if (cli_dfs_check_error(rootcli
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
854 *targetcli
= rootcli
;
855 *pp_targetpath
= talloc_strdup(ctx
, path
);
856 if (!*pp_targetpath
) {
857 return NT_STATUS_NO_MEMORY
;
862 /* We got an error, check for DFS referral. */
864 if (!cli_dfs_check_error(rootcli
, NT_STATUS_PATH_NOT_COVERED
,
869 /* Check for the referral. */
871 status
= cli_cm_open(ctx
,
873 smbXcli_conn_remote_name(rootcli
->conn
),
877 smb1cli_conn_encryption_on(rootcli
->conn
),
878 smbXcli_conn_protocol(rootcli
->conn
),
882 if (!NT_STATUS_IS_OK(status
)) {
886 status
= cli_dfs_get_referral(ctx
, cli_ipc
, dfs_path
, &refs
,
887 &num_refs
, &consumed
);
888 if (!NT_STATUS_IS_OK(status
) || !num_refs
) {
892 /* Just store the first referral for now. */
894 if (!refs
[0].dfspath
) {
895 return NT_STATUS_NOT_FOUND
;
897 if (!split_dfs_path(ctx
, refs
[0].dfspath
, &server
, &share
,
899 return NT_STATUS_NOT_FOUND
;
902 /* Make sure to recreate the original string including any wildcards. */
904 dfs_path
= cli_dfs_make_full_path(ctx
, rootcli
, path
);
906 return NT_STATUS_NO_MEMORY
;
908 pathlen
= strlen(dfs_path
);
909 consumed
= MIN(pathlen
, consumed
);
910 *pp_targetpath
= talloc_strdup(ctx
, &dfs_path
[consumed
]);
911 if (!*pp_targetpath
) {
912 return NT_STATUS_NO_MEMORY
;
914 dfs_path
[consumed
] = '\0';
917 * *pp_targetpath is now the unconsumed part of the path.
918 * dfs_path is now the consumed part of the path
919 * (in \server\share\path format).
922 /* Open the connection to the target server & share */
923 status
= cli_cm_open(ctx
, rootcli
,
928 smb1cli_conn_encryption_on(rootcli
->conn
),
929 smbXcli_conn_protocol(rootcli
->conn
),
933 if (!NT_STATUS_IS_OK(status
)) {
934 d_printf("Unable to follow dfs referral [\\%s\\%s]\n",
939 if (extrapath
&& strlen(extrapath
) > 0) {
940 /* EMC Celerra NAS version 5.6.50 (at least) doesn't appear to */
941 /* put the trailing \ on the path, so to be save we put one in if needed */
942 if (extrapath
[strlen(extrapath
)-1] != '\\' && **pp_targetpath
!= '\\') {
943 *pp_targetpath
= talloc_asprintf(ctx
,
948 *pp_targetpath
= talloc_asprintf(ctx
,
953 if (!*pp_targetpath
) {
954 return NT_STATUS_NO_MEMORY
;
958 /* parse out the consumed mount path */
959 /* trim off the \server\share\ */
963 if (*ppath
!= '\\') {
964 d_printf("cli_resolve_path: "
965 "dfs_path (%s) not in correct format.\n",
967 return NT_STATUS_NOT_FOUND
;
970 ppath
++; /* Now pointing at start of server name. */
972 if ((ppath
= strchr_m( dfs_path
, '\\' )) == NULL
) {
973 return NT_STATUS_NOT_FOUND
;
976 ppath
++; /* Now pointing at start of share name. */
978 if ((ppath
= strchr_m( ppath
+1, '\\' )) == NULL
) {
979 return NT_STATUS_NOT_FOUND
;
982 ppath
++; /* Now pointing at path component. */
984 newmount
= talloc_asprintf(ctx
, "%s\\%s", mountpt
, ppath
);
986 return NT_STATUS_NOT_FOUND
;
989 cli_set_mntpoint(*targetcli
, newmount
);
991 /* Check for another dfs referral, note that we are not
992 checking for loops here. */
994 if (!strequal(*pp_targetpath
, "\\") && !strequal(*pp_targetpath
, "/")) {
995 status
= cli_resolve_path(ctx
,
1002 if (NT_STATUS_IS_OK(status
)) {
1004 * When cli_resolve_path returns true here it's always
1005 * returning the complete path in newpath, so we're done
1008 *targetcli
= newcli
;
1009 *pp_targetpath
= newpath
;
1016 /* If returning true ensure we return a dfs root full path. */
1017 if ((*targetcli
)->dfsroot
) {
1018 dfs_path
= talloc_strdup(ctx
, *pp_targetpath
);
1020 return NT_STATUS_NO_MEMORY
;
1022 *pp_targetpath
= cli_dfs_make_full_path(ctx
, *targetcli
, dfs_path
);
1023 if (*pp_targetpath
== NULL
) {
1024 return NT_STATUS_NO_MEMORY
;
1028 return NT_STATUS_OK
;
1031 /********************************************************************
1032 ********************************************************************/
1034 bool cli_check_msdfs_proxy(TALLOC_CTX
*ctx
,
1035 struct cli_state
*cli
,
1036 const char *sharename
,
1037 char **pp_newserver
,
1040 const char *username
,
1041 const char *password
,
1044 struct client_dfs_referral
*refs
= NULL
;
1045 size_t num_refs
= 0;
1046 size_t consumed
= 0;
1047 char *fullpath
= NULL
;
1050 char *newextrapath
= NULL
;
1052 const char *remote_name
;
1054 if (!cli
|| !sharename
) {
1058 remote_name
= smbXcli_conn_remote_name(cli
->conn
);
1059 cnum
= cli_state_get_tid(cli
);
1061 /* special case. never check for a referral on the IPC$ share */
1063 if (strequal(sharename
, "IPC$")) {
1067 /* send a trans2_query_path_info to check for a referral */
1069 fullpath
= talloc_asprintf(ctx
, "\\%s\\%s", remote_name
, sharename
);
1074 /* check for the referral */
1076 if (!NT_STATUS_IS_OK(cli_tree_connect(cli
, "IPC$", "IPC", NULL
, 0))) {
1080 if (force_encrypt
) {
1081 status
= cli_cm_force_encryption(cli
,
1086 if (!NT_STATUS_IS_OK(status
)) {
1091 status
= cli_dfs_get_referral(ctx
, cli
, fullpath
, &refs
,
1092 &num_refs
, &consumed
);
1093 res
= NT_STATUS_IS_OK(status
);
1095 status
= cli_tdis(cli
);
1096 if (!NT_STATUS_IS_OK(status
)) {
1100 cli_state_set_tid(cli
, cnum
);
1102 if (!res
|| !num_refs
) {
1106 if (!refs
[0].dfspath
) {
1110 if (!split_dfs_path(ctx
, refs
[0].dfspath
, pp_newserver
,
1111 pp_newshare
, &newextrapath
)) {
1115 /* check that this is not a self-referral */
1117 if (strequal(remote_name
, *pp_newserver
) &&
1118 strequal(sharename
, *pp_newshare
)) {