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)
53 if (smbXcli_conn_protocol(c->conn) >= PROTOCOL_SMB2_02) {
54 status = smb2cli_session_encryption_on(c->smb2.session);
55 if (NT_STATUS_EQUAL(status,NT_STATUS_NOT_SUPPORTED)) {
56 d_printf("Encryption required and "
57 "server doesn't support "
58 "SMB3 encryption - failing connect\n");
59 } else if (!NT_STATUS_IS_OK(status)) {
60 d_printf("Encryption required and "
61 "setup failed with error %s.\n",
67 status = cli_force_encryption(c,
72 if (NT_STATUS_EQUAL(status,NT_STATUS_NOT_SUPPORTED)) {
73 d_printf("Encryption required and "
74 "server that doesn't support "
75 "UNIX extensions - failing connect\n");
76 } else if (NT_STATUS_EQUAL(status,NT_STATUS_UNKNOWN_REVISION)) {
77 d_printf("Encryption required and "
78 "can't get UNIX CIFS extensions "
79 "version from server.\n");
80 } else if (NT_STATUS_EQUAL(status,NT_STATUS_UNSUPPORTED_COMPRESSION)) {
81 d_printf("Encryption required and "
82 "share %s doesn't support "
83 "encryption.\n", sharename);
84 } else if (!NT_STATUS_IS_OK(status)) {
85 d_printf("Encryption required and "
86 "setup failed with error %s.\n",
93 /********************************************************************
94 Return a connection to a server.
95 ********************************************************************/
97 static NTSTATUS do_connect(TALLOC_CTX *ctx,
100 const struct user_auth_info *auth_info,
106 struct cli_state **pcli)
108 struct cli_state *c = NULL;
111 char *newserver, *newshare;
112 const char *username;
113 const char *password;
117 /* make a copy so we don't modify the global string 'service' */
118 servicename = talloc_strdup(ctx,share);
120 return NT_STATUS_NO_MEMORY;
122 sharename = servicename;
123 if (*sharename == '\\') {
125 if (server == NULL) {
128 sharename = strchr_m(sharename,'\\');
130 return NT_STATUS_NO_MEMORY;
135 if (server == NULL) {
136 return NT_STATUS_INVALID_PARAMETER;
139 if (get_cmdline_auth_info_use_kerberos(auth_info)) {
140 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
142 if (get_cmdline_auth_info_fallback_after_kerberos(auth_info)) {
143 flags |= CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS;
145 if (get_cmdline_auth_info_use_ccache(auth_info)) {
146 flags |= CLI_FULL_CONNECTION_USE_CCACHE;
148 if (get_cmdline_auth_info_use_pw_nt_hash(auth_info)) {
149 flags |= CLI_FULL_CONNECTION_USE_NT_HASH;
152 status = cli_connect_nb(
153 server, NULL, port, name_type, NULL,
154 get_cmdline_auth_info_signing_state(auth_info),
157 if (!NT_STATUS_IS_OK(status)) {
158 d_printf("Connection to %s failed (Error %s)\n",
164 if (max_protocol == 0) {
165 max_protocol = PROTOCOL_NT1;
167 DEBUG(4,(" session request ok\n"));
169 status = smbXcli_negprot(c->conn, c->timeout,
170 lp_cli_minprotocol(),
173 if (!NT_STATUS_IS_OK(status)) {
174 d_printf("protocol negotiation failed: %s\n",
180 if (smbXcli_conn_protocol(c->conn) >= PROTOCOL_SMB2_02) {
181 /* Ensure we ask for some initial credits. */
182 smb2cli_conn_set_max_credits(c->conn, DEFAULT_SMB2_MAX_CREDITS);
185 username = get_cmdline_auth_info_username(auth_info);
186 password = get_cmdline_auth_info_password(auth_info);
188 status = cli_session_setup(c, username,
189 password, strlen(password),
190 password, strlen(password),
192 if (!NT_STATUS_IS_OK(status)) {
193 /* If a password was not supplied then
194 * try again with a null username. */
195 if (password[0] || !username[0] ||
196 get_cmdline_auth_info_use_kerberos(auth_info) ||
197 !NT_STATUS_IS_OK(status = cli_session_setup(c, "",
201 d_printf("session setup failed: %s\n",
203 if (NT_STATUS_EQUAL(status,
204 NT_STATUS_MORE_PROCESSING_REQUIRED))
205 d_printf("did you forget to run kinit?\n");
209 d_printf("Anonymous login successful\n");
210 status = cli_init_creds(c, "", lp_workgroup(), "");
212 status = cli_init_creds(c, username, lp_workgroup(), password);
215 if (!NT_STATUS_IS_OK(status)) {
216 DEBUG(10,("cli_init_creds() failed: %s\n", nt_errstr(status)));
221 if ( show_sessetup ) {
222 if (*c->server_domain) {
223 DEBUG(0,("Domain=[%s] OS=[%s] Server=[%s]\n",
224 c->server_domain,c->server_os,c->server_type));
225 } else if (*c->server_os || *c->server_type) {
226 DEBUG(0,("OS=[%s] Server=[%s]\n",
227 c->server_os,c->server_type));
230 DEBUG(4,(" session setup ok\n"));
232 /* here's the fun part....to support 'msdfs proxy' shares
233 (on Samba or windows) we have to issues a TRANS_GET_DFS_REFERRAL
234 here before trying to connect to the original share.
235 cli_check_msdfs_proxy() will fail if it is a normal share. */
237 if (smbXcli_conn_dfs_supported(c->conn) &&
238 cli_check_msdfs_proxy(ctx, c, sharename,
239 &newserver, &newshare,
245 return do_connect(ctx, newserver,
246 newshare, auth_info, false,
247 force_encrypt, max_protocol,
248 port, name_type, pcli);
251 /* must be a normal share */
253 status = cli_tree_connect(c, sharename, "?????",
254 password, strlen(password)+1);
255 if (!NT_STATUS_IS_OK(status)) {
256 d_printf("tree connect failed: %s\n", nt_errstr(status));
262 status = cli_cm_force_encryption(c,
267 if (!NT_STATUS_IS_OK(status)) {
273 DEBUG(4,(" tconx ok\n"));
278 /****************************************************************************
279 ****************************************************************************/
281 static void cli_set_mntpoint(struct cli_state *cli, const char *mnt)
283 char *name = clean_name(NULL, mnt);
287 TALLOC_FREE(cli->dfs_mountpoint);
288 cli->dfs_mountpoint = talloc_strdup(cli, name);
292 /********************************************************************
293 Add a new connection to the list.
294 referring_cli == NULL means a new initial connection.
295 ********************************************************************/
297 static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
298 struct cli_state *referring_cli,
301 const struct user_auth_info *auth_info,
307 struct cli_state **pcli)
309 struct cli_state *cli;
312 status = do_connect(ctx, server, share,
314 show_hdr, force_encrypt, max_protocol,
315 port, name_type, &cli);
317 if (!NT_STATUS_IS_OK(status)) {
321 /* Enter into the list. */
323 DLIST_ADD_END(referring_cli, cli, struct cli_state *);
326 if (referring_cli && referring_cli->requested_posix_capabilities) {
328 uint32 caplow, caphigh;
329 status = cli_unix_extensions_version(cli, &major, &minor,
331 if (NT_STATUS_IS_OK(status)) {
332 cli_set_unix_extensions_capabilities(cli,
342 /********************************************************************
343 Return a connection to a server on a particular share.
344 ********************************************************************/
346 static struct cli_state *cli_cm_find(struct cli_state *cli,
356 /* Search to the start of the list. */
357 for (p = cli; p; p = DLIST_PREV(p)) {
358 const char *remote_name =
359 smbXcli_conn_remote_name(p->conn);
361 if (strequal(server, remote_name) &&
362 strequal(share,p->share)) {
367 /* Search to the end of the list. */
368 for (p = cli->next; p; p = p->next) {
369 const char *remote_name =
370 smbXcli_conn_remote_name(p->conn);
372 if (strequal(server, remote_name) &&
373 strequal(share,p->share)) {
381 /****************************************************************************
382 Open a client connection to a \\server\share.
383 ****************************************************************************/
385 NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
386 struct cli_state *referring_cli,
389 const struct user_auth_info *auth_info,
395 struct cli_state **pcli)
397 /* Try to reuse an existing connection in this list. */
398 struct cli_state *c = cli_cm_find(referring_cli, server, share);
406 if (auth_info == NULL) {
407 /* Can't do a new connection
408 * without auth info. */
409 d_printf("cli_cm_open() Unable to open connection [\\%s\\%s] "
410 "without auth info\n",
412 return NT_STATUS_INVALID_PARAMETER;
415 status = cli_cm_connect(ctx,
426 if (!NT_STATUS_IS_OK(status)) {
433 /****************************************************************************
434 ****************************************************************************/
436 void cli_cm_display(struct cli_state *cli)
440 for (i=0; cli; cli = cli->next,i++ ) {
441 d_printf("%d:\tserver=%s, share=%s\n",
442 i, smbXcli_conn_remote_name(cli->conn), cli->share);
446 /****************************************************************************
447 ****************************************************************************/
449 /****************************************************************************
450 ****************************************************************************/
453 void cli_cm_set_credentials(struct user_auth_info *auth_info)
455 SAFE_FREE(cm_creds.username);
456 cm_creds.username = SMB_STRDUP(get_cmdline_auth_info_username(
459 if (get_cmdline_auth_info_got_pass(auth_info)) {
460 cm_set_password(get_cmdline_auth_info_password(auth_info));
463 cm_creds.use_kerberos = get_cmdline_auth_info_use_kerberos(auth_info);
464 cm_creds.fallback_after_kerberos = false;
465 cm_creds.signing_state = get_cmdline_auth_info_signing_state(auth_info);
469 /**********************************************************************
470 split a dfs path into the server, share name, and extrapath components
471 **********************************************************************/
473 static bool split_dfs_path(TALLOC_CTX *ctx,
474 const char *nodepath,
484 *pp_extrapath = NULL;
486 path = talloc_strdup(ctx, nodepath);
491 if ( path[0] != '\\' ) {
495 p = strchr_m( path + 1, '\\' );
503 /* Look for any extra/deep path */
504 q = strchr_m(p, '\\');
508 *pp_extrapath = talloc_strdup(ctx, q);
510 *pp_extrapath = talloc_strdup(ctx, "");
512 if (*pp_extrapath == NULL) {
516 *pp_share = talloc_strdup(ctx, p);
517 if (*pp_share == NULL) {
521 *pp_server = talloc_strdup(ctx, &path[1]);
522 if (*pp_server == NULL) {
530 TALLOC_FREE(*pp_share);
531 TALLOC_FREE(*pp_extrapath);
536 /****************************************************************************
537 Return the original path truncated at the directory component before
538 the first wildcard character. Trust the caller to provide a NULL
540 ****************************************************************************/
542 static char *clean_path(TALLOC_CTX *ctx, const char *path)
548 /* No absolute paths. */
549 while (IS_DIRECTORY_SEP(*path)) {
553 path_out = talloc_strdup(ctx, path);
558 p1 = strchr_m(path_out, '*');
559 p2 = strchr_m(path_out, '?');
571 /* Now go back to the start of this component. */
572 p1 = strrchr_m(path_out, '/');
573 p2 = strrchr_m(path_out, '\\');
580 /* Strip any trailing separator */
582 len = strlen(path_out);
583 if ( (len > 0) && IS_DIRECTORY_SEP(path_out[len-1])) {
584 path_out[len-1] = '\0';
590 /****************************************************************************
591 ****************************************************************************/
593 static char *cli_dfs_make_full_path(TALLOC_CTX *ctx,
594 struct cli_state *cli,
597 char path_sep = '\\';
599 /* Ensure the extrapath doesn't start with a separator. */
600 while (IS_DIRECTORY_SEP(*dir)) {
604 if (cli->requested_posix_capabilities & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
607 return talloc_asprintf(ctx, "%c%s%c%s%c%s",
609 smbXcli_conn_remote_name(cli->conn),
616 /********************************************************************
617 check for dfs referral
618 ********************************************************************/
620 static bool cli_dfs_check_error(struct cli_state *cli, NTSTATUS expected,
623 /* only deal with DS when we negotiated NT_STATUS codes and UNICODE */
625 if (!(smbXcli_conn_use_unicode(cli->conn))) {
628 if (!(smb1cli_conn_capabilities(cli->conn) & CAP_STATUS32)) {
631 if (NT_STATUS_EQUAL(status, expected)) {
637 /********************************************************************
638 Get the dfs referral link.
639 ********************************************************************/
641 NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx,
642 struct cli_state *cli,
644 struct client_dfs_referral **refs,
648 unsigned int param_len = 0;
649 uint16_t recv_flags2;
650 uint8_t *param = NULL;
651 uint8_t *rdata = NULL;
654 smb_ucs2_t *path_ucs;
655 char *consumed_path = NULL;
656 uint16_t consumed_ucs;
657 uint16 num_referrals;
658 struct client_dfs_referral *referrals = NULL;
660 TALLOC_CTX *frame = talloc_stackframe();
665 param = talloc_array(talloc_tos(), uint8_t, 2);
667 status = NT_STATUS_NO_MEMORY;
670 SSVAL(param, 0, 0x03); /* max referral level */
672 param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn),
673 path, strlen(path)+1,
676 status = NT_STATUS_NO_MEMORY;
679 param_len = talloc_get_size(param);
680 path_ucs = (smb_ucs2_t *)¶m[2];
682 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
683 DATA_BLOB in_input_buffer;
684 DATA_BLOB in_output_buffer = data_blob_null;
685 DATA_BLOB out_input_buffer = data_blob_null;
686 DATA_BLOB out_output_buffer = data_blob_null;
688 in_input_buffer.data = param;
689 in_input_buffer.length = param_len;
691 status = smb2cli_ioctl(cli->conn,
695 UINT64_MAX, /* in_fid_persistent */
696 UINT64_MAX, /* in_fid_volatile */
697 FSCTL_DFS_GET_REFERRALS,
698 0, /* in_max_input_length */
700 CLI_BUFFER_SIZE, /* in_max_output_length */
702 SMB2_IOCTL_FLAG_IS_FSCTL,
706 if (!NT_STATUS_IS_OK(status)) {
710 if (out_output_buffer.length < 4) {
711 status = NT_STATUS_INVALID_NETWORK_RESPONSE;
715 recv_flags2 = FLAGS2_UNICODE_STRINGS;
716 rdata = out_output_buffer.data;
717 endp = (char *)rdata + out_output_buffer.length;
719 unsigned int data_len = 0;
722 SSVAL(setup, 0, TRANSACT2_GET_DFS_REFERRAL);
724 status = cli_trans(talloc_tos(), cli, SMBtrans2,
728 NULL, 0, CLI_BUFFER_SIZE,
730 NULL, 0, NULL, /* rsetup */
732 &rdata, 4, &data_len);
733 if (!NT_STATUS_IS_OK(status)) {
737 endp = (char *)rdata + data_len;
740 consumed_ucs = SVAL(rdata, 0);
741 num_referrals = SVAL(rdata, 2);
743 /* consumed_ucs is the number of bytes
744 * of the UCS2 path consumed not counting any
745 * terminating null. We need to convert
746 * back to unix charset and count again
747 * to get the number of bytes consumed from
748 * the incoming path. */
751 if (pull_string_talloc(talloc_tos(),
759 status = map_nt_error_from_unix(errno);
761 status = NT_STATUS_INVALID_NETWORK_RESPONSE;
765 if (consumed_path == NULL) {
766 status = map_nt_error_from_unix(errno);
769 *consumed = strlen(consumed_path);
771 if (num_referrals != 0) {
777 referrals = talloc_array(ctx, struct client_dfs_referral,
781 status = NT_STATUS_NO_MEMORY;
784 /* start at the referrals array */
787 for (i=0; i<num_referrals && p < endp; i++) {
791 ref_version = SVAL(p, 0);
792 ref_size = SVAL(p, 2);
793 node_offset = SVAL(p, 16);
795 if (ref_version != 3) {
800 referrals[i].proximity = SVAL(p, 8);
801 referrals[i].ttl = SVAL(p, 10);
803 if (p + node_offset > endp) {
804 status = NT_STATUS_INVALID_NETWORK_RESPONSE;
807 clistr_pull_talloc(referrals,
810 &referrals[i].dfspath,
812 PTR_DIFF(endp, p+node_offset),
813 STR_TERMINATE|STR_UNICODE);
815 if (!referrals[i].dfspath) {
816 status = map_nt_error_from_unix(errno);
821 if (i < num_referrals) {
822 status = NT_STATUS_INVALID_NETWORK_RESPONSE;
827 *num_refs = num_referrals;
836 /********************************************************************
837 ********************************************************************/
839 NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
841 const struct user_auth_info *dfs_auth_info,
842 struct cli_state *rootcli,
844 struct cli_state **targetcli,
845 char **pp_targetpath)
847 struct client_dfs_referral *refs = NULL;
850 struct cli_state *cli_ipc = NULL;
851 char *dfs_path = NULL;
852 char *cleanpath = NULL;
853 char *extrapath = NULL;
857 struct cli_state *newcli = NULL;
858 char *newpath = NULL;
859 char *newmount = NULL;
861 SMB_STRUCT_STAT sbuf;
864 struct smbXcli_tcon *root_tcon = NULL;
865 struct smbXcli_tcon *target_tcon = NULL;
867 if ( !rootcli || !path || !targetcli ) {
868 return NT_STATUS_INVALID_PARAMETER;
871 /* Don't do anything if this is not a DFS root. */
873 if (smbXcli_conn_protocol(rootcli->conn) >= PROTOCOL_SMB2_02) {
874 root_tcon = rootcli->smb2.tcon;
876 root_tcon = rootcli->smb1.tcon;
879 if (!smbXcli_tcon_is_dfs_share(root_tcon)) {
880 *targetcli = rootcli;
881 *pp_targetpath = talloc_strdup(ctx, path);
882 if (!*pp_targetpath) {
883 return NT_STATUS_NO_MEMORY;
890 /* Send a trans2_query_path_info to check for a referral. */
892 cleanpath = clean_path(ctx, path);
894 return NT_STATUS_NO_MEMORY;
897 dfs_path = cli_dfs_make_full_path(ctx, rootcli, cleanpath);
899 return NT_STATUS_NO_MEMORY;
902 status = cli_qpathinfo_basic( rootcli, dfs_path, &sbuf, &attributes);
903 if (NT_STATUS_IS_OK(status)) {
904 /* This is an ordinary path, just return it. */
905 *targetcli = rootcli;
906 *pp_targetpath = talloc_strdup(ctx, path);
907 if (!*pp_targetpath) {
908 return NT_STATUS_NO_MEMORY;
913 /* Special case where client asked for a path that does not exist */
915 if (cli_dfs_check_error(rootcli, NT_STATUS_OBJECT_NAME_NOT_FOUND,
917 *targetcli = rootcli;
918 *pp_targetpath = talloc_strdup(ctx, path);
919 if (!*pp_targetpath) {
920 return NT_STATUS_NO_MEMORY;
925 /* We got an error, check for DFS referral. */
927 if (!cli_dfs_check_error(rootcli, NT_STATUS_PATH_NOT_COVERED,
932 /* Check for the referral. */
934 status = cli_cm_open(ctx,
936 smbXcli_conn_remote_name(rootcli->conn),
940 smb1cli_conn_encryption_on(rootcli->conn),
941 smbXcli_conn_protocol(rootcli->conn),
945 if (!NT_STATUS_IS_OK(status)) {
949 status = cli_dfs_get_referral(ctx, cli_ipc, dfs_path, &refs,
950 &num_refs, &consumed);
951 if (!NT_STATUS_IS_OK(status) || !num_refs) {
955 /* Just store the first referral for now. */
957 if (!refs[0].dfspath) {
958 return NT_STATUS_NOT_FOUND;
960 if (!split_dfs_path(ctx, refs[0].dfspath, &server, &share,
962 return NT_STATUS_NOT_FOUND;
965 /* Make sure to recreate the original string including any wildcards. */
967 dfs_path = cli_dfs_make_full_path(ctx, rootcli, path);
969 return NT_STATUS_NO_MEMORY;
971 pathlen = strlen(dfs_path);
972 consumed = MIN(pathlen, consumed);
973 *pp_targetpath = talloc_strdup(ctx, &dfs_path[consumed]);
974 if (!*pp_targetpath) {
975 return NT_STATUS_NO_MEMORY;
977 dfs_path[consumed] = '\0';
980 * *pp_targetpath is now the unconsumed part of the path.
981 * dfs_path is now the consumed part of the path
982 * (in \server\share\path format).
985 /* Open the connection to the target server & share */
986 status = cli_cm_open(ctx, rootcli,
991 smb1cli_conn_encryption_on(rootcli->conn),
992 smbXcli_conn_protocol(rootcli->conn),
996 if (!NT_STATUS_IS_OK(status)) {
997 d_printf("Unable to follow dfs referral [\\%s\\%s]\n",
1002 if (extrapath && strlen(extrapath) > 0) {
1003 /* EMC Celerra NAS version 5.6.50 (at least) doesn't appear to */
1004 /* put the trailing \ on the path, so to be save we put one in if needed */
1005 if (extrapath[strlen(extrapath)-1] != '\\' && **pp_targetpath != '\\') {
1006 *pp_targetpath = talloc_asprintf(ctx,
1011 *pp_targetpath = talloc_asprintf(ctx,
1016 if (!*pp_targetpath) {
1017 return NT_STATUS_NO_MEMORY;
1021 /* parse out the consumed mount path */
1022 /* trim off the \server\share\ */
1026 if (*ppath != '\\') {
1027 d_printf("cli_resolve_path: "
1028 "dfs_path (%s) not in correct format.\n",
1030 return NT_STATUS_NOT_FOUND;
1033 ppath++; /* Now pointing at start of server name. */
1035 if ((ppath = strchr_m( dfs_path, '\\' )) == NULL) {
1036 return NT_STATUS_NOT_FOUND;
1039 ppath++; /* Now pointing at start of share name. */
1041 if ((ppath = strchr_m( ppath+1, '\\' )) == NULL) {
1042 return NT_STATUS_NOT_FOUND;
1045 ppath++; /* Now pointing at path component. */
1047 newmount = talloc_asprintf(ctx, "%s\\%s", mountpt, ppath );
1049 return NT_STATUS_NOT_FOUND;
1052 cli_set_mntpoint(*targetcli, newmount);
1054 /* Check for another dfs referral, note that we are not
1055 checking for loops here. */
1057 if (!strequal(*pp_targetpath, "\\") && !strequal(*pp_targetpath, "/")) {
1058 status = cli_resolve_path(ctx,
1065 if (NT_STATUS_IS_OK(status)) {
1067 * When cli_resolve_path returns true here it's always
1068 * returning the complete path in newpath, so we're done
1071 *targetcli = newcli;
1072 *pp_targetpath = newpath;
1079 if (smbXcli_conn_protocol((*targetcli)->conn) >= PROTOCOL_SMB2_02) {
1080 target_tcon = (*targetcli)->smb2.tcon;
1082 target_tcon = (*targetcli)->smb1.tcon;
1085 /* If returning true ensure we return a dfs root full path. */
1086 if (smbXcli_tcon_is_dfs_share(target_tcon)) {
1087 dfs_path = talloc_strdup(ctx, *pp_targetpath);
1089 return NT_STATUS_NO_MEMORY;
1091 *pp_targetpath = cli_dfs_make_full_path(ctx, *targetcli, dfs_path);
1092 if (*pp_targetpath == NULL) {
1093 return NT_STATUS_NO_MEMORY;
1097 return NT_STATUS_OK;
1100 /********************************************************************
1101 ********************************************************************/
1103 bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
1104 struct cli_state *cli,
1105 const char *sharename,
1106 char **pp_newserver,
1109 const char *username,
1110 const char *password,
1113 struct client_dfs_referral *refs = NULL;
1114 size_t num_refs = 0;
1115 size_t consumed = 0;
1116 char *fullpath = NULL;
1119 char *newextrapath = NULL;
1121 const char *remote_name;
1123 if (!cli || !sharename) {
1127 remote_name = smbXcli_conn_remote_name(cli->conn);
1128 cnum = cli_state_get_tid(cli);
1130 /* special case. never check for a referral on the IPC$ share */
1132 if (strequal(sharename, "IPC$")) {
1136 /* send a trans2_query_path_info to check for a referral */
1138 fullpath = talloc_asprintf(ctx, "\\%s\\%s", remote_name, sharename);
1143 /* check for the referral */
1145 if (!NT_STATUS_IS_OK(cli_tree_connect(cli, "IPC$", "IPC", NULL, 0))) {
1149 if (force_encrypt) {
1150 status = cli_cm_force_encryption(cli,
1155 if (!NT_STATUS_IS_OK(status)) {
1160 status = cli_dfs_get_referral(ctx, cli, fullpath, &refs,
1161 &num_refs, &consumed);
1162 res = NT_STATUS_IS_OK(status);
1164 status = cli_tdis(cli);
1165 if (!NT_STATUS_IS_OK(status)) {
1169 cli_state_set_tid(cli, cnum);
1171 if (!res || !num_refs) {
1175 if (!refs[0].dfspath) {
1179 if (!split_dfs_path(ctx, refs[0].dfspath, pp_newserver,
1180 pp_newshare, &newextrapath)) {
1184 /* check that this is not a self-referral */
1186 if (strequal(remote_name, *pp_newserver) &&
1187 strequal(sharename, *pp_newshare)) {