Add support for DFS in smb2+
Subsystems (2)
cover Add support for DFS in smb2+
This series of patch tries to implement the get_dfs_refer operation for smb2.
In smb2+, DFS resolving is now done through an FSCTL. The relevant Microsoft specifications for this are:
MS-SMB2: 3.2.4.20 Application Requests an IO Control Code Operation
MS-SMB2: 3.2.4.20.3 Application Requests DFS Referral Information
MS-SMB2: 3.2.5.14 Receiving an SMB2 IOCTL Response
MS-SMB2: 3.2.5.14.4 Handling a DFS Referral Information Response
MS-DFSC: 2.2 Message Syntax (but really the whole document is useful)
I've managed to make it work while keeping the same prototype for the operation but I believe it should be changed to be more correct and closer to the rest of the smb2 code.
I've sucessfuly tested this against a Windows Server 2016 DFS setup.
There are some things that I'm not sure how to do properly:
* find the right tcon from the session object
* find the IPC tcon from the share tcon
I suspect these can be solved by changing the operation prototype so it provides the right objects (tcon, cifs_sb, ...).
There are some things I've worked around:
* SMB2_ioctl() explicitely checks for DFS requests and uses the IPC tid
* since the tcon in build_path_from_dentry() does *not* have the IN_DFS_SHARE flag (I don't know why that is, because it is set in smbv1) I've added a new version of the function that uses an boolean argument to control whether or not to prefix the tree name. this version is only called once in the smb-generic code that deals with DFS.
You will find more information in the commit messages. Any help solving these issues is welcome.
Aurelien Aptel (6):
fs/cifs: add smb2 fsctl payloads for DFS resolving fs/cifs: implement get_dfs_refer for smb2 fs/cifs: always use ipc for DFS resolving ioctls fs/cifs: add build_path_from_dentry_optional_prefix() fs/cifs: always use tree name prefix for DFS resolving fs/cifs: enable get_dfs_refer operation for smb2+
fs/cifs/cifs_dfs_ref.c | 2 +- fs/cifs/cifsproto.h | 1 + fs/cifs/dir.c | 12 ++- fs/cifs/smb2ops.c | 210 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/smb2pdu.c | 4 + fs/cifs/smb2pdu.h | 15 ++++ 6 files changed, 241 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/6 fs/cifs: add smb2 fsctl payloads for DFS resolving
In reply to a message not in the archive--- fs/cifs/smb2pdu.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
fs/cifs/smb2pdu.h +15 -0
@@ -681,6 +681,21 @@ struct fsctl_get_integrity_information_rsp {/* Integrity flags for above */ #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001 +/* See MS-DFSC 2.2.2 */ +struct fsctl_get_dfs_referral_req { +__le16 MaxReferralLevel; +__u8 RequestFileName[]; +} __packed; + +struct fsctl_get_dfs_referral_rsp { +__le16 PathConsumed; +__le16 NumberOfReferrals; +__le32 ReferralHeaderFlags; +__u8 buffer[]; +} __packed; + +/* reusing struct dfs_referral_level_3 */ +/* See MS-SMB2 2.2.31.3 */ struct network_resiliency_req {__le32 Timeout;
Signature · 1 line
2.1.4
PATCH 2/6 fs/cifs: implement get_dfs_refer for smb2
In reply to a message not in the archiveFew issues with the current situation
* the get_dfs_refer op is meant to be used from cifs thus the prototype of the operation is not adapted for smb2:
- it passes a session as opposed to a tcon like other smb2 operations, which means we have to find the corresponding tcon ourselves. see new function find_session_tcon() which currently assumes the first one is the right one.
- it doesn't pass a cifs_sb so we cannot use the usual utf16 conversion function used in the rest of smb2 code
* the DFS request has to be made on the IPC tcon and i'm not really sure how to get to it since it doesnt seem to be part of the session tcon list.
* the function that extracts the data from the responce is almost entirely copied and adapted from the smb1 code. ideally they should be merged.
--- fs/cifs/smb2ops.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+)
fs/cifs/smb2ops.c +206 -0
@@ -1093,6 +1093,212 @@ smb2_new_lease_key(struct cifs_fid *fid)generate_random_uuid (fid->lease_key); } +/* +* XXX: Return the tcon currently used in the session +*/ +static struct cifs_tcon * +find_session_tcon (struct cifs_ses *ses) +{ +struct cifs_tcon *tcon =NULL , *it; +struct list_head *tmp; +int i =0 ; + +spin_lock (&cifs_tcp_ses_lock); +list_for_each (tmp, &ses->tcon_list) { + it = list_entry(tmp, struct cifs_tcon, tcon_list); +cifs_dbg (FYI ,"XXX: [%d] tcon %p\n" , i, it); + +/* XXX: Assumes the first one is always the right one. */ +if (i ==0 ) { + tcon = it; + } + i++; + } +spin_unlock (&cifs_tcp_ses_lock); + +if (!tcon) +cifs_dbg (FYI ,"XXX: cannot find our tcon\n" ); +return tcon; +} + +/* +* XXX: Copied and adapted from parse_DFS_referrals in cifssmb.c +* TODO: extract logic in a SMB agnostic way +*/ +static int +smb2_parse_dfs_referrers_rsp (struct fsctl_get_dfs_referral_rsp *rsp,u32 rsp_size, +unsigned int *num_of_nodes, +struct dfs_info3_param **target_nodes, +const struct nls_table *nls_codepage,int remap, +const char *searchName) +{ +int i, rc =0 ; +char *data_end; +bool is_unicode = true; +struct dfs_referral_level_3 *ref; + + *num_of_nodes =le16_to_cpu (rsp->NumberOfReferrals); + +if (*num_of_nodes <1 ) { +cifs_dbg (VFS ,"num_referrals: must be at least > 0, but we get num_referrals = %d\n" , + *num_of_nodes); + rc = -EINVAL ; + goto parse_DFS_referrals_exit; + } + + ref = (struct dfs_referral_level_3 *) &rsp->buffer[0 ]; +if (ref->VersionNumber !=cpu_to_le16 (3 )) { +cifs_dbg (VFS ,"Referrals of V%d version are not supported, should be V3\n" , +le16_to_cpu (ref->VersionNumber)); + rc = -EINVAL ; + goto parse_DFS_referrals_exit; + } + +/* get the upper boundary of the resp buffer */ + data_end = (char *)(&(rsp->PathConsumed)) + rsp_size; + +cifs_dbg (FYI ,"num_referrals: %d dfs flags: 0x%x ...\n" , + *num_of_nodes,le32_to_cpu (rsp->ReferralHeaderFlags)); + + *target_nodes =kcalloc (*num_of_nodes,sizeof (struct dfs_info3_param ), +GFP_KERNEL ); +if (*target_nodes ==NULL ) { + rc = -ENOMEM ; + goto parse_DFS_referrals_exit; + } + +/* collect necessary data from referrals */ +for (i =0 ; i < *num_of_nodes; i++) { +char *temp; +int max_len; +__le16 *tmp; +struct dfs_info3_param *node = (*target_nodes)+i; + + node->flags =le32_to_cpu (rsp->ReferralHeaderFlags); + tmp =kmalloc (strlen (searchName)*2 +2 , +GFP_KERNEL ); +if (tmp ==NULL ) { + rc = -ENOMEM ; + goto parse_DFS_referrals_exit; + } +cifsConvertToUTF16 ((__le16 *) tmp, searchName, +PATH_MAX , nls_codepage, remap); + node->path_consumed =cifs_utf16_bytes (tmp, +le16_to_cpu (rsp->PathConsumed), + nls_codepage); +kfree (tmp); + + node->server_type =le16_to_cpu (ref->ServerType); + node->ref_flag =le16_to_cpu (ref->ReferralEntryFlags); + +/* copy DfsPath */ + temp = (char *)ref +le16_to_cpu (ref->DfsPathOffset); + max_len = data_end - temp; + node->path_name =cifs_strndup_from_utf16 (temp, max_len, + true/* is_unicode */ , nls_codepage); +if (!node->path_name) { + rc = -ENOMEM ; + goto parse_DFS_referrals_exit; + } + +/* copy link target UNC */ + temp = (char *)ref +le16_to_cpu (ref->NetworkAddressOffset); + max_len = data_end - temp; + node->node_name =cifs_strndup_from_utf16 (temp, max_len, + is_unicode, nls_codepage); +if (!node->node_name) { + rc = -ENOMEM ; + goto parse_DFS_referrals_exit; + } + + ref++; + } + +parse_DFS_referrals_exit: +if (rc) { +free_dfs_info_array (*target_nodes, *num_of_nodes); + *target_nodes =NULL ; + *num_of_nodes =0 ; + } +return rc; +} + + +static int +smb2_get_dfs_refer (const unsigned int xid,struct cifs_ses *ses, +const char *search_name,struct dfs_info3_param **target_nodes, +unsigned int *num_of_nodes, +const struct nls_table *nls_codepage,int remap) +{ +int rc = -ENOSYS ; +__le16 *utf16_path =NULL ; +int utf16_path_len =0 ; +struct cifs_tcon *tcon; +struct fsctl_get_dfs_referral_req *dfs_req =NULL ; +struct fsctl_get_dfs_referral_rsp *dfs_rsp =NULL ; +u32 dfs_req_size =0 , dfs_rsp_size =0 ; + +cifs_dbg (FYI ,"XXX: In smb2_get_dfs_refer the path <%s> %d\n" , search_name, (int )strlen (search_name)); + +/* +* XXX: Find this session tcon. We shouldnt have to do this +* proper solution would be to update get_dfs_refer op +* prototype to pass it somehow. +*/ + tcon =find_session_tcon (ses); +if (!tcon) + goto out; + +/* +* XXX: Should we use use cifs_convert_path_to_utf16(full_path, cifs_sb) instead? +* it needs cifs_sb superblock pointer which we don't have... +*/ + + utf16_path_len =strlen (search_name) *2 ; + utf16_path =kzalloc (utf16_path_len +2 ,GFP_KERNEL ); +if (!utf16_path) { + rc = -ENOMEM ; + goto out; + } + +cifsConvertToUTF16 (utf16_path, + search_name,PATH_MAX , nls_codepage, + remap); + + dfs_req_size =sizeof (*dfs_req) + utf16_path_len +2 ; + dfs_req =kzalloc (dfs_req_size,GFP_KERNEL ); +if (!dfs_req) { + rc = -ENOMEM ; + goto out; + } + +/* Highest DFS referral version understood (actually the only supported one) */ + dfs_req->MaxReferralLevel =cpu_to_le16 (DFS_VERSION ); +/* Path to resolve in an UTF-16 null-terminated string */ +memcpy (dfs_req->RequestFileName, utf16_path, utf16_path_len); + +do { + rc =SMB2_ioctl (xid, tcon,NO_FILE_ID ,NO_FILE_ID , +FSCTL_DFS_GET_REFERRALS , true/* is_fsctl */ , + (char *)dfs_req, dfs_req_size, + (char **)&dfs_rsp, &dfs_rsp_size); +if (rc) { +cifs_dbg (FYI ,"SMB2_ioctl error in smb2_get_dfs_refer rc=%d\n" , rc); + goto out; + } + + rc =smb2_parse_dfs_referrers_rsp (dfs_rsp, dfs_rsp_size, + num_of_nodes, target_nodes, + nls_codepage, remap, search_name); +kfree (dfs_rsp); + }while (rc == -EAGAIN ); + + out: +kfree (utf16_path); +kfree (dfs_req); +return rc; +} +#define SMB2_SYMLINK_STRUCT_SIZE \ (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
Signature · 1 line
2.1.4
PATCH 3/6 fs/cifs: always use ipc for DFS resolving ioctls
In reply to a message not in the archivesince we cannot access the ipc tcon object, force the use of the ipc tid when crafting DFS resolving ioctl.
--- fs/cifs/smb2pdu.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/cifs/smb2pdu.c +4 -0
@@ -1645,6 +1645,10 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,if (rc)return rc; +/* XXX: how can we access the tcon of the IPC of the host? */ +if (opcode ==FSCTL_DFS_GET_REFERRALS ) { + req->hdr.TreeId = ses->ipc_tid; + } req->CtlCode =cpu_to_le32 (opcode); req->PersistentFileId = persistent_fid; req->VolatileFileId = volatile_fid;
Signature · 1 line
2.1.4
PATCH 4/6 fs/cifs: add build_path_from_dentry_optional_prefix()
In reply to a message not in the archivethis function does the same thing as add build_path_from_dentry() but takes a boolean parameter to decide whether or not to prefix the path with the tree name.
--- fs/cifs/cifsproto.h | 1 + fs/cifs/dir.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
fs/cifs/cifsproto.h +1 -0
@@ -61,6 +61,7 @@ extern void exit_cifs_idmap(void);extern int init_cifs_spnego (void );extern void exit_cifs_spnego (void );extern char *build_path_from_dentry (struct dentry *); +extern char *build_path_from_dentry_optional_prefix (struct dentry *direntry,int prefix);extern char *cifs_build_path_to_root (struct smb_vol *vol,struct cifs_sb_info *cifs_sb,struct cifs_tcon *tcon);
fs/cifs/dir.c +10 -2
@@ -79,7 +79,15 @@ cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,/* Note: caller must free return buffer */ char * -build_path_from_dentry (struct dentry *direntry) +build_path_from_dentry (struct dentry *direntry) { +struct cifs_sb_info *cifs_sb =CIFS_SB (direntry->d_sb); +struct cifs_tcon *tcon =cifs_sb_master_tcon (cifs_sb); +return build_path_from_dentry_optional_prefix (direntry, + tcon->Flags &SMB_SHARE_IS_IN_DFS ); +} + +char * +build_path_from_dentry_optional_prefix (struct dentry *direntry,int prefix) {struct dentry *temp;int namelen;
@@ -92,7 +100,7 @@ build_path_from_dentry(struct dentry *direntry)unsigned seq; dirsep =CIFS_DIR_SEP (cifs_sb); -if (tcon->Flags &SMB_SHARE_IS_IN_DFS ) +if (prefix) dfsplen =strnlen (tcon->treeName,MAX_TREE_SIZE +1 );else dfsplen =0 ;
Signature · 1 line
2.1.4
PATCH 5/6 fs/cifs: always use tree name prefix for DFS resolving
In reply to a message not in the archivefor some reason the tcon used in build_path_from_dentry for that mount point doesn't have the the "IN DFS" flag set so the prefix was not always added even though it is required in this case.
--- fs/cifs/cifs_dfs_ref.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/cifs_dfs_ref.c +1 -1
@@ -302,7 +302,7 @@ static struct vfsmount *cifs_dfs_do_automount(struct dentry *mntpt)* gives us the latter, so we must adjust the result. */ mnt =ERR_PTR (-ENOMEM ); - full_path =build_path_from_dentry (mntpt); + full_path =build_path_from_dentry_optional_prefix (mntpt,1 /* always use tree name prefix */ );if (full_path ==NULL ) goto cdda_exit;
Signature · 1 line
2.1.4
PATCH 6/6 fs/cifs: enable get_dfs_refer operation for smb2+
In reply to a message not in the archive--- fs/cifs/smb2ops.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/cifs/smb2ops.c +4 -0
@@ -1829,6 +1829,7 @@ struct smb_version_operations smb20_operations = { .clone_range = smb2_clone_range, .wp_retry_size = smb2_wp_retry_size, .dir_needs_close = smb2_dir_needs_close, + .get_dfs_refer = smb2_get_dfs_refer, };struct smb_version_operations smb21_operations = {
@@ -1910,6 +1911,7 @@ struct smb_version_operations smb21_operations = { .wp_retry_size = smb2_wp_retry_size, .dir_needs_close = smb2_dir_needs_close, .enum_snapshots = smb3_enum_snapshots, + .get_dfs_refer = smb2_get_dfs_refer, };struct smb_version_operations smb30_operations = {
@@ -1997,6 +1999,7 @@ struct smb_version_operations smb30_operations = { .dir_needs_close = smb2_dir_needs_close, .fallocate = smb3_fallocate, .enum_snapshots = smb3_enum_snapshots, + .get_dfs_refer = smb2_get_dfs_refer, };#ifdef CONFIG_CIFS_SMB311
@@ -2085,6 +2088,7 @@ struct smb_version_operations smb311_operations = { .dir_needs_close = smb2_dir_needs_close, .fallocate = smb3_fallocate, .enum_snapshots = smb3_enum_snapshots, + .get_dfs_refer = smb2_get_dfs_refer, };#endif /* CIFS_SMB311 */
Signature · 1 line
2.1.4
Re: [PATCH v1 2/6] fs/cifs: implement get_dfs_refer for smb2
In reply to a message not in the archive2016-11-08 8:33 GMT-08:00 Aurelien Aptel <aaptel-IBi9RG/[email protected]>:
Quoted 9 lines
Few issues with the current situation
* the
get_dfs_referop is meant to be used from cifs thus the prototype of the operation is not adapted for smb2:- it passes a session as opposed to a tcon like other smb2 operations, which means we have to find the corresponding tcon ourselves. see new function
find_session_tcon()which currently assumes the first one is the right one.
I think it is ok since it matches the spec which suggests to find any ses and tcon.
Quoted 3 lines
- it doesn't pass a
cifs_sbso we cannot use the usual utf16 conversion function used in the rest of smb2 code
I suggest to pass cifs_sb to get_dfs_path() (instead of cifs_remap(cifs_sb)) and then modify a get_dfs_refer() callback to take cifs_sb as well. This let us use cifs_convert_path_to_utf16().
Quoted 4 lines
* the DFS request has to be made on the IPC tcon and i'm not really sure how to get to it since it doesnt seem to be part of the session tcon list.
Should we probably add an extra param to SMB2_ioctl called ipc_tid? In case when tcon passed to this function is NULL ipc_tid will be used in a similar manner how it is done now for CIFS. Otherwise (if tcon is not NULL) tcon is used as it is now.
Quoted 234 lines
* the function that extracts the data from the responce is almost entirely copied and adapted from the smb1 code. ideally they should be merged.
Signed-off-by Aurelien Aptel <aaptel-IBi9RG/[email protected]>--- fs/cifs/smb2ops.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+)fs/cifs/smb2ops.c +206
-1@@ -1093,6 +1093,212 @@ smb2_new_lease_key(struct cifs_fid *fid)generate_random_uuid (fid->lease_key); } +/* +* XXX: Return the tcon currently used in the session +*/ +static struct cifs_tcon * +find_session_tcon (struct cifs_ses *ses) +{ +struct cifs_tcon *tcon =NULL , *it; +struct list_head *tmp; +int i =0 ; + +spin_lock (&cifs_tcp_ses_lock); +list_for_each (tmp, &ses->tcon_list) { + it = list_entry(tmp, struct cifs_tcon, tcon_list); +cifs_dbg (FYI ,"XXX: [%d] tcon %p\n" , i, it); + +/* XXX: Assumes the first one is always the right one. */ +if (i ==0 ) { + tcon = it; + } + i++; + } +spin_unlock (&cifs_tcp_ses_lock); + +if (!tcon) +cifs_dbg (FYI ,"XXX: cannot find our tcon\n" ); +return tcon; +} + +/* +* XXX: Copied and adapted from parse_DFS_referrals in cifssmb.c +* TODO: extract logic in a SMB agnostic way +*/ +static int +smb2_parse_dfs_referrers_rsp (struct fsctl_get_dfs_referral_rsp *rsp,u32 rsp_size, +unsigned int *num_of_nodes, +struct dfs_info3_param **target_nodes, +const struct nls_table *nls_codepage,int remap, +const char *searchName) +{ +int i, rc =0 ; +char *data_end; +bool is_unicode = true; +struct dfs_referral_level_3 *ref; + + *num_of_nodes =le16_to_cpu (rsp->NumberOfReferrals); + +if (*num_of_nodes <1 ) { +cifs_dbg (VFS ,"num_referrals: must be at least > 0, but we get num_referrals = %d\n" , + *num_of_nodes); + rc = -EINVAL ; + goto parse_DFS_referrals_exit; + } + + ref = (struct dfs_referral_level_3 *) &rsp->buffer[0 ]; +if (ref->VersionNumber !=cpu_to_le16 (3 )) { +cifs_dbg (VFS ,"Referrals of V%d version are not supported, should be V3\n" , +le16_to_cpu (ref->VersionNumber)); + rc = -EINVAL ; + goto parse_DFS_referrals_exit; + } + +/* get the upper boundary of the resp buffer */ + data_end = (char *)(&(rsp->PathConsumed)) + rsp_size; + +cifs_dbg (FYI ,"num_referrals: %d dfs flags: 0x%x ...\n" , + *num_of_nodes,le32_to_cpu (rsp->ReferralHeaderFlags)); + + *target_nodes =kcalloc (*num_of_nodes,sizeof (struct dfs_info3_param ), +GFP_KERNEL ); +if (*target_nodes ==NULL ) { + rc = -ENOMEM ; + goto parse_DFS_referrals_exit; + } + +/* collect necessary data from referrals */ +for (i =0 ; i < *num_of_nodes; i++) { +char *temp; +int max_len; +__le16 *tmp; +struct dfs_info3_param *node = (*target_nodes)+i; + + node->flags =le32_to_cpu (rsp->ReferralHeaderFlags); + tmp =kmalloc (strlen (searchName)*2 +2 , +GFP_KERNEL ); +if (tmp ==NULL ) { + rc = -ENOMEM ; + goto parse_DFS_referrals_exit; + } +cifsConvertToUTF16 ((__le16 *) tmp, searchName, +PATH_MAX , nls_codepage, remap); + node->path_consumed =cifs_utf16_bytes (tmp, +le16_to_cpu (rsp->PathConsumed), + nls_codepage); +kfree (tmp); + + node->server_type =le16_to_cpu (ref->ServerType); + node->ref_flag =le16_to_cpu (ref->ReferralEntryFlags); + +/* copy DfsPath */ + temp = (char *)ref +le16_to_cpu (ref->DfsPathOffset); + max_len = data_end - temp; + node->path_name =cifs_strndup_from_utf16 (temp, max_len, + true/* is_unicode */ , nls_codepage); +if (!node->path_name) { + rc = -ENOMEM ; + goto parse_DFS_referrals_exit; + } + +/* copy link target UNC */ + temp = (char *)ref +le16_to_cpu (ref->NetworkAddressOffset); + max_len = data_end - temp; + node->node_name =cifs_strndup_from_utf16 (temp, max_len, + is_unicode, nls_codepage); +if (!node->node_name) { + rc = -ENOMEM ; + goto parse_DFS_referrals_exit; + } + + ref++; + } + +parse_DFS_referrals_exit: +if (rc) { +free_dfs_info_array (*target_nodes, *num_of_nodes); + *target_nodes =NULL ; + *num_of_nodes =0 ; + } +return rc; +} + + +static int +smb2_get_dfs_refer (const unsigned int xid,struct cifs_ses *ses, +const char *search_name,struct dfs_info3_param **target_nodes, +unsigned int *num_of_nodes, +const struct nls_table *nls_codepage,int remap) +{ +int rc = -ENOSYS ; +__le16 *utf16_path =NULL ; +int utf16_path_len =0 ; +struct cifs_tcon *tcon; +struct fsctl_get_dfs_referral_req *dfs_req =NULL ; +struct fsctl_get_dfs_referral_rsp *dfs_rsp =NULL ; +u32 dfs_req_size =0 , dfs_rsp_size =0 ; + +cifs_dbg (FYI ,"XXX: In smb2_get_dfs_refer the path <%s> %d\n" , search_name, (int )strlen (search_name)); + +/* +* XXX: Find this session tcon. We shouldnt have to do this +* proper solution would be to update get_dfs_refer op +* prototype to pass it somehow. +*/ + tcon =find_session_tcon (ses); +if (!tcon) + goto out; + +/* +* XXX: Should we use use cifs_convert_path_to_utf16(full_path, cifs_sb) instead? +* it needs cifs_sb superblock pointer which we don't have... +*/ + + utf16_path_len =strlen (search_name) *2 ; + utf16_path =kzalloc (utf16_path_len +2 ,GFP_KERNEL ); +if (!utf16_path) { + rc = -ENOMEM ; + goto out; + } + +cifsConvertToUTF16 (utf16_path, + search_name,PATH_MAX , nls_codepage, + remap); + + dfs_req_size =sizeof (*dfs_req) + utf16_path_len +2 ; + dfs_req =kzalloc (dfs_req_size,GFP_KERNEL ); +if (!dfs_req) { + rc = -ENOMEM ; + goto out; + } + +/* Highest DFS referral version understood (actually the only supported one) */ + dfs_req->MaxReferralLevel =cpu_to_le16 (DFS_VERSION ); +/* Path to resolve in an UTF-16 null-terminated string */ +memcpy (dfs_req->RequestFileName, utf16_path, utf16_path_len); + +do { + rc =SMB2_ioctl (xid, tcon,NO_FILE_ID ,NO_FILE_ID , +FSCTL_DFS_GET_REFERRALS , true/* is_fsctl */ , + (char *)dfs_req, dfs_req_size, + (char **)&dfs_rsp, &dfs_rsp_size); +if (rc) { +cifs_dbg (FYI ,"SMB2_ioctl error in smb2_get_dfs_refer rc=%d\n" , rc); + goto out; + } + + rc =smb2_parse_dfs_referrers_rsp (dfs_rsp, dfs_rsp_size, + num_of_nodes, target_nodes, + nls_codepage, remap, search_name); +kfree (dfs_rsp); + }while (rc == -EAGAIN ); + + out: +kfree (utf16_path); +kfree (dfs_req); +return rc; +} +#define SMB2_SYMLINK_STRUCT_SIZE \ (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp)) --2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best regards, Pavel Shilovsky
Re: [PATCH v1 3/6] fs/cifs: always use ipc for DFS resolving ioctls
In reply to a message not in the archive2016-11-08 8:33 GMT-08:00 Aurelien Aptel <aaptel-IBi9RG/[email protected]>:
Quoted 13 lines
since we cannot access the ipc tcon object, force the use of the ipc tid when crafting DFS resolving ioctl.
Signed-off-by Aurelien Aptel <aaptel-IBi9RG/[email protected]>--- fs/cifs/smb2pdu.c | 4 ++++ 1 file changed, 4 insertions(+)fs/cifs/smb2pdu.c +0
-0
fs/cifs/smb2pdu.c SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, · line 1651
Quoted 7 lines
fs/cifs/smb2pdu.c +4
-0@@ -1645,6 +1645,10 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,if (rc)return rc; +/* XXX: how can we access the tcon of the IPC of the host? */ +if (opcode ==FSCTL_DFS_GET_REFERRALS ) { + req->hdr.TreeId = ses->ipc_tid; + }
It seems like spec (3.2.4.20.3) says that we can use any existing ses and tcon for the current user. See my comment to the previous patch.
Quoted 10 lines
fs/cifs/smb2pdu.c +0
-1req->CtlCode =cpu_to_le32 (opcode); req->PersistentFileId = persistent_fid; req->VolatileFileId = volatile_fid; --2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best regards, Pavel Shilovsky