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 username
= get_cmdline_auth_info_username(auth_info
);
164 password
= get_cmdline_auth_info_password(auth_info
);
166 status
= cli_session_setup(c
, username
,
167 password
, strlen(password
),
168 password
, strlen(password
),
170 if (!NT_STATUS_IS_OK(status
)) {
171 /* If a password was not supplied then
172 * try again with a null username. */
173 if (password
[0] || !username
[0] ||
174 get_cmdline_auth_info_use_kerberos(auth_info
) ||
175 !NT_STATUS_IS_OK(status
= cli_session_setup(c
, "",
179 d_printf("session setup failed: %s\n",
181 if (NT_STATUS_EQUAL(status
,
182 NT_STATUS_MORE_PROCESSING_REQUIRED
))
183 d_printf("did you forget to run kinit?\n");
187 d_printf("Anonymous login successful\n");
188 status
= cli_init_creds(c
, "", lp_workgroup(), "");
190 status
= cli_init_creds(c
, username
, lp_workgroup(), password
);
193 if (!NT_STATUS_IS_OK(status
)) {
194 DEBUG(10,("cli_init_creds() failed: %s\n", nt_errstr(status
)));
199 if ( show_sessetup
) {
200 if (*c
->server_domain
) {
201 DEBUG(0,("Domain=[%s] OS=[%s] Server=[%s]\n",
202 c
->server_domain
,c
->server_os
,c
->server_type
));
203 } else if (*c
->server_os
|| *c
->server_type
) {
204 DEBUG(0,("OS=[%s] Server=[%s]\n",
205 c
->server_os
,c
->server_type
));
208 DEBUG(4,(" session setup ok\n"));
210 /* here's the fun part....to support 'msdfs proxy' shares
211 (on Samba or windows) we have to issues a TRANS_GET_DFS_REFERRAL
212 here before trying to connect to the original share.
213 cli_check_msdfs_proxy() will fail if it is a normal share. */
215 if ((smb1cli_conn_capabilities(c
->conn
) & CAP_DFS
) &&
216 cli_check_msdfs_proxy(ctx
, c
, sharename
,
217 &newserver
, &newshare
,
223 return do_connect(ctx
, newserver
,
224 newshare
, auth_info
, false,
225 force_encrypt
, max_protocol
,
226 port
, name_type
, pcli
);
229 /* must be a normal share */
231 status
= cli_tree_connect(c
, sharename
, "?????",
232 password
, strlen(password
)+1);
233 if (!NT_STATUS_IS_OK(status
)) {
234 d_printf("tree connect failed: %s\n", nt_errstr(status
));
240 status
= cli_cm_force_encryption(c
,
245 if (!NT_STATUS_IS_OK(status
)) {
251 DEBUG(4,(" tconx ok\n"));
256 /****************************************************************************
257 ****************************************************************************/
259 static void cli_set_mntpoint(struct cli_state
*cli
, const char *mnt
)
261 char *name
= clean_name(NULL
, mnt
);
265 TALLOC_FREE(cli
->dfs_mountpoint
);
266 cli
->dfs_mountpoint
= talloc_strdup(cli
, name
);
270 /********************************************************************
271 Add a new connection to the list.
272 referring_cli == NULL means a new initial connection.
273 ********************************************************************/
275 static NTSTATUS
cli_cm_connect(TALLOC_CTX
*ctx
,
276 struct cli_state
*referring_cli
,
279 const struct user_auth_info
*auth_info
,
285 struct cli_state
**pcli
)
287 struct cli_state
*cli
;
290 status
= do_connect(ctx
, server
, share
,
292 show_hdr
, force_encrypt
, max_protocol
,
293 port
, name_type
, &cli
);
295 if (!NT_STATUS_IS_OK(status
)) {
299 /* Enter into the list. */
301 DLIST_ADD_END(referring_cli
, cli
, struct cli_state
*);
304 if (referring_cli
&& referring_cli
->requested_posix_capabilities
) {
306 uint32 caplow
, caphigh
;
307 status
= cli_unix_extensions_version(cli
, &major
, &minor
,
309 if (NT_STATUS_IS_OK(status
)) {
310 cli_set_unix_extensions_capabilities(cli
,
320 /********************************************************************
321 Return a connection to a server on a particular share.
322 ********************************************************************/
324 static struct cli_state
*cli_cm_find(struct cli_state
*cli
,
334 /* Search to the start of the list. */
335 for (p
= cli
; p
; p
= DLIST_PREV(p
)) {
336 const char *remote_name
=
337 smbXcli_conn_remote_name(p
->conn
);
339 if (strequal(server
, remote_name
) &&
340 strequal(share
,p
->share
)) {
345 /* Search to the end of the list. */
346 for (p
= cli
->next
; p
; p
= p
->next
) {
347 const char *remote_name
=
348 smbXcli_conn_remote_name(p
->conn
);
350 if (strequal(server
, remote_name
) &&
351 strequal(share
,p
->share
)) {
359 /****************************************************************************
360 Open a client connection to a \\server\share.
361 ****************************************************************************/
363 NTSTATUS
cli_cm_open(TALLOC_CTX
*ctx
,
364 struct cli_state
*referring_cli
,
367 const struct user_auth_info
*auth_info
,
373 struct cli_state
**pcli
)
375 /* Try to reuse an existing connection in this list. */
376 struct cli_state
*c
= cli_cm_find(referring_cli
, server
, share
);
384 if (auth_info
== NULL
) {
385 /* Can't do a new connection
386 * without auth info. */
387 d_printf("cli_cm_open() Unable to open connection [\\%s\\%s] "
388 "without auth info\n",
390 return NT_STATUS_INVALID_PARAMETER
;
393 status
= cli_cm_connect(ctx
,
404 if (!NT_STATUS_IS_OK(status
)) {
411 /****************************************************************************
412 ****************************************************************************/
414 void cli_cm_display(struct cli_state
*cli
)
418 for (i
=0; cli
; cli
= cli
->next
,i
++ ) {
419 d_printf("%d:\tserver=%s, share=%s\n",
420 i
, smbXcli_conn_remote_name(cli
->conn
), cli
->share
);
424 /****************************************************************************
425 ****************************************************************************/
427 /****************************************************************************
428 ****************************************************************************/
431 void cli_cm_set_credentials(struct user_auth_info
*auth_info
)
433 SAFE_FREE(cm_creds
.username
);
434 cm_creds
.username
= SMB_STRDUP(get_cmdline_auth_info_username(
437 if (get_cmdline_auth_info_got_pass(auth_info
)) {
438 cm_set_password(get_cmdline_auth_info_password(auth_info
));
441 cm_creds
.use_kerberos
= get_cmdline_auth_info_use_kerberos(auth_info
);
442 cm_creds
.fallback_after_kerberos
= false;
443 cm_creds
.signing_state
= get_cmdline_auth_info_signing_state(auth_info
);
447 /**********************************************************************
448 split a dfs path into the server, share name, and extrapath components
449 **********************************************************************/
451 static bool split_dfs_path(TALLOC_CTX
*ctx
,
452 const char *nodepath
,
462 *pp_extrapath
= NULL
;
464 path
= talloc_strdup(ctx
, nodepath
);
469 if ( path
[0] != '\\' ) {
473 p
= strchr_m( path
+ 1, '\\' );
481 /* Look for any extra/deep path */
482 q
= strchr_m(p
, '\\');
486 *pp_extrapath
= talloc_strdup(ctx
, q
);
488 *pp_extrapath
= talloc_strdup(ctx
, "");
490 if (*pp_extrapath
== NULL
) {
494 *pp_share
= talloc_strdup(ctx
, p
);
495 if (*pp_share
== NULL
) {
499 *pp_server
= talloc_strdup(ctx
, &path
[1]);
500 if (*pp_server
== NULL
) {
508 TALLOC_FREE(*pp_share
);
509 TALLOC_FREE(*pp_extrapath
);
514 /****************************************************************************
515 Return the original path truncated at the directory component before
516 the first wildcard character. Trust the caller to provide a NULL
518 ****************************************************************************/
520 static char *clean_path(TALLOC_CTX
*ctx
, const char *path
)
526 /* No absolute paths. */
527 while (IS_DIRECTORY_SEP(*path
)) {
531 path_out
= talloc_strdup(ctx
, path
);
536 p1
= strchr_m(path_out
, '*');
537 p2
= strchr_m(path_out
, '?');
549 /* Now go back to the start of this component. */
550 p1
= strrchr_m(path_out
, '/');
551 p2
= strrchr_m(path_out
, '\\');
558 /* Strip any trailing separator */
560 len
= strlen(path_out
);
561 if ( (len
> 0) && IS_DIRECTORY_SEP(path_out
[len
-1])) {
562 path_out
[len
-1] = '\0';
568 /****************************************************************************
569 ****************************************************************************/
571 static char *cli_dfs_make_full_path(TALLOC_CTX
*ctx
,
572 struct cli_state
*cli
,
575 char path_sep
= '\\';
577 /* Ensure the extrapath doesn't start with a separator. */
578 while (IS_DIRECTORY_SEP(*dir
)) {
582 if (cli
->requested_posix_capabilities
& CIFS_UNIX_POSIX_PATHNAMES_CAP
) {
585 return talloc_asprintf(ctx
, "%c%s%c%s%c%s",
587 smbXcli_conn_remote_name(cli
->conn
),
594 /********************************************************************
595 check for dfs referral
596 ********************************************************************/
598 static bool cli_dfs_check_error(struct cli_state
*cli
, NTSTATUS expected
,
601 /* only deal with DS when we negotiated NT_STATUS codes and UNICODE */
603 if (!(smb1cli_conn_capabilities(cli
->conn
) & CAP_UNICODE
)) {
606 if (!(smb1cli_conn_capabilities(cli
->conn
) & CAP_STATUS32
)) {
609 if (NT_STATUS_EQUAL(status
, expected
)) {
615 /********************************************************************
616 Get the dfs referral link.
617 ********************************************************************/
619 NTSTATUS
cli_dfs_get_referral(TALLOC_CTX
*ctx
,
620 struct cli_state
*cli
,
622 struct client_dfs_referral
**refs
,
626 unsigned int data_len
= 0;
627 unsigned int param_len
= 0;
629 uint16_t recv_flags2
;
630 uint8_t *param
= NULL
;
631 uint8_t *rdata
= NULL
;
634 smb_ucs2_t
*path_ucs
;
635 char *consumed_path
= NULL
;
636 uint16_t consumed_ucs
;
637 uint16 num_referrals
;
638 struct client_dfs_referral
*referrals
= NULL
;
640 TALLOC_CTX
*frame
= talloc_stackframe();
645 SSVAL(setup
, 0, TRANSACT2_GET_DFS_REFERRAL
);
647 param
= talloc_array(talloc_tos(), uint8_t, 2);
649 status
= NT_STATUS_NO_MEMORY
;
652 SSVAL(param
, 0, 0x03); /* max referral level */
654 param
= trans2_bytes_push_str(param
, smbXcli_conn_use_unicode(cli
->conn
),
655 path
, strlen(path
)+1,
658 status
= NT_STATUS_NO_MEMORY
;
661 param_len
= talloc_get_size(param
);
662 path_ucs
= (smb_ucs2_t
*)¶m
[2];
664 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
668 NULL
, 0, CLI_BUFFER_SIZE
,
670 NULL
, 0, NULL
, /* rsetup */
672 &rdata
, 4, &data_len
);
673 if (!NT_STATUS_IS_OK(status
)) {
677 endp
= (char *)rdata
+ data_len
;
679 consumed_ucs
= SVAL(rdata
, 0);
680 num_referrals
= SVAL(rdata
, 2);
682 /* consumed_ucs is the number of bytes
683 * of the UCS2 path consumed not counting any
684 * terminating null. We need to convert
685 * back to unix charset and count again
686 * to get the number of bytes consumed from
687 * the incoming path. */
690 if (pull_string_talloc(talloc_tos(),
698 status
= map_nt_error_from_unix(errno
);
700 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
704 if (consumed_path
== NULL
) {
705 status
= map_nt_error_from_unix(errno
);
708 *consumed
= strlen(consumed_path
);
710 if (num_referrals
!= 0) {
716 referrals
= talloc_array(ctx
, struct client_dfs_referral
,
720 status
= NT_STATUS_NO_MEMORY
;
723 /* start at the referrals array */
726 for (i
=0; i
<num_referrals
&& p
< endp
; i
++) {
730 ref_version
= SVAL(p
, 0);
731 ref_size
= SVAL(p
, 2);
732 node_offset
= SVAL(p
, 16);
734 if (ref_version
!= 3) {
739 referrals
[i
].proximity
= SVAL(p
, 8);
740 referrals
[i
].ttl
= SVAL(p
, 10);
742 if (p
+ node_offset
> endp
) {
743 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
746 clistr_pull_talloc(referrals
,
749 &referrals
[i
].dfspath
,
751 PTR_DIFF(endp
, p
+node_offset
),
752 STR_TERMINATE
|STR_UNICODE
);
754 if (!referrals
[i
].dfspath
) {
755 status
= map_nt_error_from_unix(errno
);
760 if (i
< num_referrals
) {
761 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
766 *num_refs
= num_referrals
;
775 /********************************************************************
776 ********************************************************************/
778 NTSTATUS
cli_resolve_path(TALLOC_CTX
*ctx
,
780 const struct user_auth_info
*dfs_auth_info
,
781 struct cli_state
*rootcli
,
783 struct cli_state
**targetcli
,
784 char **pp_targetpath
)
786 struct client_dfs_referral
*refs
= NULL
;
789 struct cli_state
*cli_ipc
= NULL
;
790 char *dfs_path
= NULL
;
791 char *cleanpath
= NULL
;
792 char *extrapath
= NULL
;
796 struct cli_state
*newcli
= NULL
;
797 char *newpath
= NULL
;
798 char *newmount
= NULL
;
800 SMB_STRUCT_STAT sbuf
;
804 if ( !rootcli
|| !path
|| !targetcli
) {
805 return NT_STATUS_INVALID_PARAMETER
;
808 /* Don't do anything if this is not a DFS root. */
810 if ( !rootcli
->dfsroot
) {
811 *targetcli
= rootcli
;
812 *pp_targetpath
= talloc_strdup(ctx
, path
);
813 if (!*pp_targetpath
) {
814 return NT_STATUS_NO_MEMORY
;
821 /* Send a trans2_query_path_info to check for a referral. */
823 cleanpath
= clean_path(ctx
, path
);
825 return NT_STATUS_NO_MEMORY
;
828 dfs_path
= cli_dfs_make_full_path(ctx
, rootcli
, cleanpath
);
830 return NT_STATUS_NO_MEMORY
;
833 status
= cli_qpathinfo_basic( rootcli
, dfs_path
, &sbuf
, &attributes
);
834 if (NT_STATUS_IS_OK(status
)) {
835 /* This is an ordinary path, just return it. */
836 *targetcli
= rootcli
;
837 *pp_targetpath
= talloc_strdup(ctx
, path
);
838 if (!*pp_targetpath
) {
839 return NT_STATUS_NO_MEMORY
;
844 /* Special case where client asked for a path that does not exist */
846 if (cli_dfs_check_error(rootcli
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
848 *targetcli
= rootcli
;
849 *pp_targetpath
= talloc_strdup(ctx
, path
);
850 if (!*pp_targetpath
) {
851 return NT_STATUS_NO_MEMORY
;
856 /* We got an error, check for DFS referral. */
858 if (!cli_dfs_check_error(rootcli
, NT_STATUS_PATH_NOT_COVERED
,
863 /* Check for the referral. */
865 status
= cli_cm_open(ctx
,
867 smbXcli_conn_remote_name(rootcli
->conn
),
871 smb1cli_conn_encryption_on(rootcli
->conn
),
872 smbXcli_conn_protocol(rootcli
->conn
),
876 if (!NT_STATUS_IS_OK(status
)) {
880 status
= cli_dfs_get_referral(ctx
, cli_ipc
, dfs_path
, &refs
,
881 &num_refs
, &consumed
);
882 if (!NT_STATUS_IS_OK(status
) || !num_refs
) {
886 /* Just store the first referral for now. */
888 if (!refs
[0].dfspath
) {
889 return NT_STATUS_NOT_FOUND
;
891 if (!split_dfs_path(ctx
, refs
[0].dfspath
, &server
, &share
,
893 return NT_STATUS_NOT_FOUND
;
896 /* Make sure to recreate the original string including any wildcards. */
898 dfs_path
= cli_dfs_make_full_path(ctx
, rootcli
, path
);
900 return NT_STATUS_NO_MEMORY
;
902 pathlen
= strlen(dfs_path
);
903 consumed
= MIN(pathlen
, consumed
);
904 *pp_targetpath
= talloc_strdup(ctx
, &dfs_path
[consumed
]);
905 if (!*pp_targetpath
) {
906 return NT_STATUS_NO_MEMORY
;
908 dfs_path
[consumed
] = '\0';
911 * *pp_targetpath is now the unconsumed part of the path.
912 * dfs_path is now the consumed part of the path
913 * (in \server\share\path format).
916 /* Open the connection to the target server & share */
917 status
= cli_cm_open(ctx
, rootcli
,
922 smb1cli_conn_encryption_on(rootcli
->conn
),
923 smbXcli_conn_protocol(rootcli
->conn
),
927 if (!NT_STATUS_IS_OK(status
)) {
928 d_printf("Unable to follow dfs referral [\\%s\\%s]\n",
933 if (extrapath
&& strlen(extrapath
) > 0) {
934 /* EMC Celerra NAS version 5.6.50 (at least) doesn't appear to */
935 /* put the trailing \ on the path, so to be save we put one in if needed */
936 if (extrapath
[strlen(extrapath
)-1] != '\\' && **pp_targetpath
!= '\\') {
937 *pp_targetpath
= talloc_asprintf(ctx
,
942 *pp_targetpath
= talloc_asprintf(ctx
,
947 if (!*pp_targetpath
) {
948 return NT_STATUS_NO_MEMORY
;
952 /* parse out the consumed mount path */
953 /* trim off the \server\share\ */
957 if (*ppath
!= '\\') {
958 d_printf("cli_resolve_path: "
959 "dfs_path (%s) not in correct format.\n",
961 return NT_STATUS_NOT_FOUND
;
964 ppath
++; /* Now pointing at start of server name. */
966 if ((ppath
= strchr_m( dfs_path
, '\\' )) == NULL
) {
967 return NT_STATUS_NOT_FOUND
;
970 ppath
++; /* Now pointing at start of share name. */
972 if ((ppath
= strchr_m( ppath
+1, '\\' )) == NULL
) {
973 return NT_STATUS_NOT_FOUND
;
976 ppath
++; /* Now pointing at path component. */
978 newmount
= talloc_asprintf(ctx
, "%s\\%s", mountpt
, ppath
);
980 return NT_STATUS_NOT_FOUND
;
983 cli_set_mntpoint(*targetcli
, newmount
);
985 /* Check for another dfs referral, note that we are not
986 checking for loops here. */
988 if (!strequal(*pp_targetpath
, "\\") && !strequal(*pp_targetpath
, "/")) {
989 status
= cli_resolve_path(ctx
,
996 if (NT_STATUS_IS_OK(status
)) {
998 * When cli_resolve_path returns true here it's always
999 * returning the complete path in newpath, so we're done
1002 *targetcli
= newcli
;
1003 *pp_targetpath
= newpath
;
1010 /* If returning true ensure we return a dfs root full path. */
1011 if ((*targetcli
)->dfsroot
) {
1012 dfs_path
= talloc_strdup(ctx
, *pp_targetpath
);
1014 return NT_STATUS_NO_MEMORY
;
1016 *pp_targetpath
= cli_dfs_make_full_path(ctx
, *targetcli
, dfs_path
);
1017 if (*pp_targetpath
== NULL
) {
1018 return NT_STATUS_NO_MEMORY
;
1022 return NT_STATUS_OK
;
1025 /********************************************************************
1026 ********************************************************************/
1028 bool cli_check_msdfs_proxy(TALLOC_CTX
*ctx
,
1029 struct cli_state
*cli
,
1030 const char *sharename
,
1031 char **pp_newserver
,
1034 const char *username
,
1035 const char *password
,
1038 struct client_dfs_referral
*refs
= NULL
;
1039 size_t num_refs
= 0;
1040 size_t consumed
= 0;
1041 char *fullpath
= NULL
;
1044 char *newextrapath
= NULL
;
1046 const char *remote_name
;
1048 if (!cli
|| !sharename
) {
1052 remote_name
= smbXcli_conn_remote_name(cli
->conn
);
1053 cnum
= cli_state_get_tid(cli
);
1055 /* special case. never check for a referral on the IPC$ share */
1057 if (strequal(sharename
, "IPC$")) {
1061 /* send a trans2_query_path_info to check for a referral */
1063 fullpath
= talloc_asprintf(ctx
, "\\%s\\%s", remote_name
, sharename
);
1068 /* check for the referral */
1070 if (!NT_STATUS_IS_OK(cli_tree_connect(cli
, "IPC$", "IPC", NULL
, 0))) {
1074 if (force_encrypt
) {
1075 status
= cli_cm_force_encryption(cli
,
1080 if (!NT_STATUS_IS_OK(status
)) {
1085 status
= cli_dfs_get_referral(ctx
, cli
, fullpath
, &refs
,
1086 &num_refs
, &consumed
);
1087 res
= NT_STATUS_IS_OK(status
);
1089 status
= cli_tdis(cli
);
1090 if (!NT_STATUS_IS_OK(status
)) {
1094 cli_state_set_tid(cli
, cnum
);
1096 if (!res
|| !num_refs
) {
1100 if (!refs
[0].dfspath
) {
1104 if (!split_dfs_path(ctx
, refs
[0].dfspath
, pp_newserver
,
1105 pp_newshare
, &newextrapath
)) {
1109 /* check that this is not a self-referral */
1111 if (strequal(remote_name
, *pp_newserver
) &&
1112 strequal(sharename
, *pp_newshare
)) {