CIFS: Implement follow_link for SMB2
Subsystems (2)
PATCH 1/2 CIFS: Implement follow_link for SMB2
that allows to access files through symlink created on a server.
--- fs/cifs/cifsglob.h | 3 +++ fs/cifs/inode.c | 4 ++++ fs/cifs/link.c | 24 +++++---------------- fs/cifs/readdir.c | 3 +++ fs/cifs/smb2file.c | 2 +- fs/cifs/smb2inode.c | 9 ++++---- fs/cifs/smb2misc.c | 4 ++++ fs/cifs/smb2ops.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++--- fs/cifs/smb2pdu.c | 9 +++++++- fs/cifs/smb2pdu.h | 14 ++++++++++++ fs/cifs/smb2proto.h | 3 ++- 11 files changed, 106 insertions(+), 29 deletions(-)
fs/cifs/cifsglob.h +3 -0
@@ -305,6 +305,9 @@ struct smb_version_operations {int (*create_hardlink)(const unsigned int ,struct cifs_tcon *,const char *,const char *,struct cifs_sb_info *); +/* query symlink target */ +int (*query_symlink)(const unsigned int ,struct cifs_tcon *, +const char *,char **,struct cifs_sb_info *);/* open a file for non-posix mounts */ int (*open)(const unsigned int ,struct cifs_open_parms *,__u32 *,FILE_ALL_INFO *);
fs/cifs/inode.c +4 -0
@@ -549,6 +549,10 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,* when Unix extensions are disabled - fake it. */ fattr->cf_nlink =2 ; + }else if (fattr->cf_cifsattrs &ATTR_REPARSE ) { + fattr->cf_mode =S_IFLNK ; + fattr->cf_dtype =DT_LNK ; + fattr->cf_nlink =le32_to_cpu (info->NumberOfLinks); }else { fattr->cf_mode =S_IFREG | cifs_sb->mnt_file_mode; fattr->cf_dtype =DT_REG ;
fs/cifs/link.c +5 -19
@@ -487,6 +487,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb);struct tcon_link *tlink =NULL ;struct cifs_tcon *tcon; +struct TCP_Server_Info *server; xid =get_xid ();
@@ -497,25 +498,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd) goto out; } tcon =tlink_tcon (tlink); - -/* -* For now, we just handle symlinks with unix extensions enabled. -* Eventually we should handle NTFS reparse points, and MacOS -* symlink support. For instance... -* -* rc = CIFSSMBQueryReparseLinkInfo(...) -* -* For now, just return -EACCES when the server doesn't support posix -* extensions. Note that we still allow querying symlinks when posix -* extensions are manually disabled. We could disable these as well -* but there doesn't seem to be any harm in allowing the client to -* read them. -*/ -if (!(cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MF_SYMLINKS ) && - !cap_unix (tcon->ses)) { - rc = -EACCES ; - goto out; - } + server = tcon->ses->server; full_path =build_path_from_dentry (direntry);if (!full_path)
@@ -537,6 +520,9 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)if ((rc !=0 ) &&cap_unix (tcon->ses)) rc =CIFSSMBUnixQuerySymLink (xid, tcon, full_path, &target_path, cifs_sb->local_nls); +else if (rc !=0 && server->ops->query_symlink) + rc = server->ops->query_symlink (xid, tcon, full_path, + &target_path, cifs_sb);kfree (full_path); out:
fs/cifs/readdir.c +3 -0
@@ -164,6 +164,9 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)if (cifs_dfs_is_possible (cifs_sb) && (fattr->cf_cifsattrs &ATTR_REPARSE )) fattr->cf_flags |=CIFS_FATTR_NEED_REVAL ; + }else if (fattr->cf_cifsattrs &ATTR_REPARSE ) { + fattr->cf_mode =S_IFLNK ; + fattr->cf_dtype =DT_LNK ; }else { fattr->cf_mode =S_IFREG | cifs_sb->mnt_file_mode; fattr->cf_dtype =DT_REG ;
fs/cifs/smb2file.c +1 -1
@@ -86,7 +86,7 @@ smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,if (oparms->tcon->ses->server->capabilities &SMB2_GLOBAL_CAP_LEASING )memcpy (smb2_oplock +1 , fid->lease_key,SMB2_LEASE_KEY_SIZE ); - rc =SMB2_open (xid, oparms, smb2_path, smb2_oplock, smb2_data); + rc =SMB2_open (xid, oparms, smb2_path, smb2_oplock, smb2_data,NULL );if (rc) goto out;
fs/cifs/smb2inode.c +5 -4
@@ -60,7 +60,7 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ); + rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ,NULL );if (rc) {kfree (utf16_path);return rc;
@@ -136,7 +136,8 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ; rc =smb2_open_op_close (xid, tcon, cifs_sb, full_path, -FILE_READ_ATTRIBUTES ,FILE_OPEN ,0 , smb2_data, +FILE_READ_ATTRIBUTES ,FILE_OPEN , +OPEN_REPARSE_POINT , smb2_data,SMB2_OP_QUERY_INFO );if (rc) goto out;
@@ -191,8 +192,8 @@ smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, struct cifs_sb_info *cifs_sb) {return smb2_open_op_close (xid, tcon, cifs_sb, name,DELETE ,FILE_OPEN , -CREATE_DELETE_ON_CLOSE ,NULL , -SMB2_OP_DELETE ); +CREATE_DELETE_ON_CLOSE |OPEN_REPARSE_POINT , +NULL ,SMB2_OP_DELETE ); } static int
fs/cifs/smb2misc.c +4 -0
@@ -171,6 +171,10 @@ smb2_check_message(char *buf, unsigned int length)if (4 + len != clc_len) {cifs_dbg (FYI ,"Calculated size %u length %u mismatch mid %llu\n" , clc_len,4 + len, mid); +/* create failed on symlink */ +if (command ==SMB2_CREATE_HE && + hdr->Status ==STATUS_STOPPED_ON_SYMLINK ) +return 0 ;/* Windows 7 server returns 24 bytes more */ if (clc_len +20 == len && command ==SMB2_OPLOCK_BREAK_HE )return 0 ;
fs/cifs/smb2ops.c +57 -3
102 lines not on this page · raw message
fs/cifs/smb2pdu.c +8 -1
@@ -977,7 +977,8 @@ add_durable_context(struct kvec *iov, unsigned int *num_iovec,int SMB2_open (const unsigned int xid,struct cifs_open_parms *oparms,__le16 *path, -__u8 *oplock,struct smb2_file_all_info *buf) +__u8 *oplock,struct smb2_file_all_info *buf, +struct smb2_err_rsp **err_buf) {struct smb2_create_req *req;struct smb2_create_rsp *rsp;
@@ -1081,6 +1082,12 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,if (rc !=0 ) {cifs_stats_fail_inc (tcon,SMB2_CREATE_HE ); +if (err_buf) { +unsigned int buf_size =get_rfc1002_length (rsp) +4 ; + *err_buf =kmalloc (buf_size,GFP_KERNEL ); +if (*err_buf) +memcpy (*err_buf, rsp, buf_size); + } goto creat_exit; }
fs/cifs/smb2pdu.h +14 -0
@@ -150,6 +150,20 @@ struct smb2_err_rsp {__u8 ErrorData[1 ];/* variable length */ } __packed; +struct smb2_symlink_err_rsp { +__le32 SymLinkLength; +__le32 SymLinkErrorTag; +__le32 ReparseTag; +__le16 ReparseDataLength; +__le16 UnparsedPathLength; +__le16 SubstituteNameOffset; +__le16 SubstituteNameLength; +__le16 PrintNameOffset; +__le16 PrintNameLength; +__le32 Flags; +__u8 PathBuffer[0 ]; +} __packed; +#define SMB2_CLIENT_GUID_SIZE 16extern __u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE ];
fs/cifs/smb2proto.h +2 -1
@@ -106,7 +106,8 @@ extern int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses,extern int SMB2_tdis (const unsigned int xid,struct cifs_tcon *tcon);extern int SMB2_open (const unsigned int xid,struct cifs_open_parms *oparms,__le16 *path,__u8 *oplock, -struct smb2_file_all_info *buf); +struct smb2_file_all_info *buf, +struct smb2_err_rsp **err_buf); extern int SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid, u32 opcode, bool is_fsctl, char *in_data, u32 indatalen,
Signature · 1 line
1.7.10.4
A message that is not in the archive (sent off-list or not yet received): 1376053042-8608-1-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org
PATCH 2/2 CIFS: Implement follow_link for nounix CIFS mounts
by using a query reparse ioctl request.
--- fs/cifs/cifspdu.h | 11 +++--- fs/cifs/cifsproto.h | 10 ++--- fs/cifs/cifssmb.c | 110 ++++++++++++++++++++++++--------------------------- fs/cifs/smb1ops.c | 32 +++++++++++++++ 4 files changed, 92 insertions(+), 71 deletions(-)
fs/cifs/cifspdu.h +6 -5
@@ -1490,11 +1490,12 @@ struct reparse_data {__u32 ReparseTag;__u16 ReparseDataLength;__u16 Reserved; -__u16 AltNameOffset; -__u16 AltNameLen; -__u16 TargetNameOffset; -__u16 TargetNameLen; -char LinkNamesBuf[1 ]; +__u16 SubstituteNameOffset; +__u16 SubstituteNameLength; +__u16 PrintNameOffset; +__u16 PrintNameLength; +__u32 Flags; +char PathBuffer[0 ]; } __attribute__((packed));struct cifs_quota_data {
fs/cifs/cifsproto.h +3 -7
@@ -357,13 +357,9 @@ extern int CIFSSMBUnixQuerySymLink(const unsigned int xid,struct cifs_tcon *tcon, const unsigned char *searchName, char **syminfo, const struct nls_table *nls_codepage); -#ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL -extern int CIFSSMBQueryReparseLinkInfo (const unsigned int xid, -struct cifs_tcon *tcon, -const unsigned char *searchName, -char *symlinkinfo,const int buflen,__u16 fid, -const struct nls_table *nls_codepage); -#endif /* temporarily unused until cifs_symlink fixed */ +extern int CIFSSMBQuerySymLink (const unsigned int xid,struct cifs_tcon *tcon, +__u16 fid,char **symlinkinfo, +const struct nls_table *nls_codepage); extern int CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon, const char *fileName, const int disposition, const int access_flags, const int omode,
fs/cifs/cifssmb.c +51 -59
142 lines not on this page · raw message
fs/cifs/smb1ops.c +32 -0
@@ -881,6 +881,37 @@ cifs_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, (__u8)type, wait, 0); } +static int +cifs_query_symlink (const unsigned int xid,struct cifs_tcon *tcon, +const char *full_path,char **target_path, +struct cifs_sb_info *cifs_sb) +{ +int rc; +int oplock =0 ; +__u16 netfid; + +cifs_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); + + rc =CIFSSMBOpen (xid, tcon, full_path,FILE_OPEN , +FILE_READ_ATTRIBUTES ,OPEN_REPARSE_POINT , &netfid, + &oplock,NULL , cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +if (rc) +return rc; + + rc =CIFSSMBQuerySymLink (xid, tcon, netfid, target_path, + cifs_sb->local_nls); +if (rc) { +CIFSSMBClose (xid, tcon, netfid); +return rc; + } + +convert_delimiter (*target_path,'/' ); +CIFSSMBClose (xid, tcon, netfid); +cifs_dbg (FYI ,"%s: target path: %s\n" , __func__, *target_path); +return rc; +} +struct smb_version_operations smb1_operations = { .send_cancel = send_nt_cancel, .compare_fids = cifs_compare_fids,
@@ -927,6 +958,7 @@ struct smb_version_operations smb1_operations = { .rename_pending_delete = cifs_rename_pending_delete, .rename = CIFSSMBRename, .create_hardlink = CIFSCreateHardLink, + .query_symlink = cifs_query_symlink, .open = cifs_open_file, .set_fid = cifs_set_fid, .close = cifs_close_file,
Signature · 1 line
1.7.10.4
A message that is not in the archive (sent off-list or not yet received): 1376053042-8608-2-git-send-email-pshilovsky-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org
Jeff Layton
Acked-byRe: [PATCH 2/2] CIFS: Implement follow_link for nounix CIFS mounts
Quoted 188 lines · On Fri, 9 Aug 2013 16:57:22 +0400 Pavel Shilovsky…
by using a query reparse ioctl request.
Signed-off-by Pavel Shilovsky <[email protected]>--- fs/cifs/cifspdu.h | 11 +++--- fs/cifs/cifsproto.h | 10 ++--- fs/cifs/cifssmb.c | 110 ++++++++++++++++++++++++--------------------------- fs/cifs/smb1ops.c | 32 +++++++++++++++ 4 files changed, 92 insertions(+), 71 deletions(-)fs/cifs/cifspdu.h +6
-5@@ -1490,11 +1490,12 @@ struct reparse_data {__u32 ReparseTag;__u16 ReparseDataLength;__u16 Reserved; -__u16 AltNameOffset; -__u16 AltNameLen; -__u16 TargetNameOffset; -__u16 TargetNameLen; -char LinkNamesBuf[1 ]; +__u16 SubstituteNameOffset; +__u16 SubstituteNameLength; +__u16 PrintNameOffset; +__u16 PrintNameLength; +__u32 Flags; +char PathBuffer[0 ]; } __attribute__((packed));struct cifs_quota_data {fs/cifs/cifsproto.h +3
-7@@ -357,13 +357,9 @@ extern int CIFSSMBUnixQuerySymLink(const unsigned int xid,struct cifs_tcon *tcon, const unsigned char *searchName, char **syminfo, const struct nls_table *nls_codepage); -#ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL -extern int CIFSSMBQueryReparseLinkInfo (const unsigned int xid, -struct cifs_tcon *tcon, -const unsigned char *searchName, -char *symlinkinfo,const int buflen,__u16 fid, -const struct nls_table *nls_codepage); -#endif /* temporarily unused until cifs_symlink fixed */ +extern int CIFSSMBQuerySymLink (const unsigned int xid,struct cifs_tcon *tcon, +__u16 fid,char **symlinkinfo, +const struct nls_table *nls_codepage); extern int CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon, const char *fileName, const int disposition, const int access_flags, const int omode,fs/cifs/cifssmb.c +47
-55@@ -3067,7 +3067,6 @@ querySymLinkRetry:return rc; } -#ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL /* * Recent Windows versions now create symlinks more frequently * and they use the "reparse point" mechanism below. We can of course @@ -3079,18 +3078,22 @@ querySymLinkRetry:* it is not compiled in by default until callers fixed up and more tested. */ int -CIFSSMBQueryReparseLinkInfo (const unsigned int xid,struct cifs_tcon *tcon, -const unsigned char *searchName, -char *symlinkinfo,const int buflen,__u16 fid, -const struct nls_table *nls_codepage) +CIFSSMBQuerySymLink (const unsigned int xid,struct cifs_tcon *tcon, +__u16 fid,char **symlinkinfo, +const struct nls_table *nls_codepage) {int rc =0 ;int bytes_returned;struct smb_com_transaction_ioctl_req *pSMB;struct smb_com_transaction_ioctl_rsp *pSMBr; +bool is_unicode; +unsigned int sub_len; +char *sub_start; +struct reparse_data *reparse_buf; +__u32 data_offset, data_count; +char *end_of_smb; -cifs_dbg (FYI ,"In Windows reparse style QueryLink for path %s\n" , - searchName); +cifs_dbg (FYI ,"In Windows reparse style QueryLink for fid %u\n" , fid); rc =smb_init (SMB_COM_NT_TRANSACT ,23 , tcon, (void **) &pSMB, (void **) &pSMBr);if (rc)@@ -3119,66 +3122,55 @@ CIFSSMBQueryReparseLinkInfo(const unsigned int xid, struct cifs_tcon *tcon, (struct smb_hdr *) pSMBr, &bytes_returned, 0);if (rc) {cifs_dbg (FYI ,"Send error in QueryReparseLinkInfo = %d\n" , rc); - }else {/* decode response */ -__u32 data_offset =le32_to_cpu (pSMBr->DataOffset); -__u32 data_count =le32_to_cpu (pSMBr->DataCount); -if (get_bcc (&pSMBr->hdr) <2 || data_offset >512 ) { -/* BB also check enough total bytes returned */ - rc = -EIO ;/* bad smb */ - goto qreparse_out; - } -if (data_count && (data_count <2048 )) { -char *end_of_smb =2 /* sizeof byte count */ + -get_bcc (&pSMBr->hdr) + (char *)&pSMBr->ByteCount; - -struct reparse_data *reparse_buf = - (struct reparse_data *) - ((char *)&pSMBr->hdr.Protocol - + data_offset); -if ((char *)reparse_buf >= end_of_smb) { - rc = -EIO ; - goto qreparse_out; - } -if ((reparse_buf->LinkNamesBuf + - reparse_buf->TargetNameOffset + - reparse_buf->TargetNameLen) > end_of_smb) { -cifs_dbg (FYI ,"reparse buf beyond SMB\n" ); - rc = -EIO ; - goto qreparse_out; - } + goto qreparse_out; + } -if (pSMBr->hdr.Flags2 &SMBFLG2_UNICODE ) { -cifs_from_ucs2 (symlinkinfo, (__le16 *) - (reparse_buf->LinkNamesBuf + - reparse_buf->TargetNameOffset), - buflen, - reparse_buf->TargetNameLen, - nls_codepage,0 ); - }else {/* ASCII names */ -strncpy (symlinkinfo, - reparse_buf->LinkNamesBuf + - reparse_buf->TargetNameOffset, - min_t(const int, buflen, - reparse_buf->TargetNameLen)); - } - }else { - rc = -EIO ; -cifs_dbg (FYI ,"Invalid return data count on get reparse info ioctl\n" ); - } - symlinkinfo[buflen] =0 ;/* just in case so the caller -does not go off the end of the buffer */ -cifs_dbg (FYI ,"readlink result - %s\n" , symlinkinfo); + data_offset =le32_to_cpu (pSMBr->DataOffset); + data_count =le32_to_cpu (pSMBr->DataCount); +if (get_bcc (&pSMBr->hdr) <2 || data_offset >512 ) { +/* BB also check enough total bytes returned */ + rc = -EIO ;/* bad smb */ + goto qreparse_out; + } +if (!data_count || (data_count >2048 )) { + rc = -EIO ; +cifs_dbg (FYI ,"Invalid return data count on get reparse info ioctl\n" ); + goto qreparse_out; + } + end_of_smb =2 +get_bcc (&pSMBr->hdr) + (char *)&pSMBr->ByteCount; + reparse_buf = (struct reparse_data *) + ((char *)&pSMBr->hdr.Protocol + data_offset); +if ((char *)reparse_buf >= end_of_smb) { + rc = -EIO ; + goto qreparse_out; } +if ((reparse_buf->PathBuffer + reparse_buf->PrintNameOffset + + reparse_buf->PrintNameLength) > end_of_smb) { +cifs_dbg (FYI ,"reparse buf beyond SMB\n" ); + rc = -EIO ; + goto qreparse_out; + } + sub_start = reparse_buf->SubstituteNameOffset + reparse_buf->PathBuffer; + sub_len = reparse_buf->SubstituteNameLength; +if (pSMBr->hdr.Flags2 &SMBFLG2_UNICODE ) + is_unicode = true; +else + is_unicode = false; +/* BB FIXME investigate remapping reserved chars here */ + *symlinkinfo =cifs_strndup_from_utf16 (sub_start, sub_len, is_unicode, + nls_codepage); +if (!*symlinkinfo) + rc = -ENOMEM ; qreparse_out:cifs_buf_release (pSMB);
fs/cifs/cifssmb.c CIFSSMBQueryReparseLinkInfo(const unsigned int xid, struct cifs_tcon *tcon, · line 3173
Quoted 10 lines
fs/cifs/cifssmb.c +4
-3-/* Note: On -EAGAIN error only caller can retry on handle based calls -since file handle passed in no longer valid */ - +/* +* Note: On -EAGAIN error only caller can retry on handle based calls +* since file handle passed in no longer valid. +*/ return rc; }
Took me a few minutes to understand that you were just refactoring the code in the above function, without really changing much. Might be nice to do that in a separate patch instead.
Quoted 47 lines
fs/cifs/cifssmb.c +0
-1-#endif /* CIFS_SYMLINK_EXPERIMENTAL */ /* BB temporarily unused */ #ifdef CONFIG_CIFS_POSIX fs/cifs/smb1ops.c +31
-0@@ -881,6 +881,37 @@ cifs_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, (__u8)type, wait, 0); } +static int +cifs_query_symlink (const unsigned int xid,struct cifs_tcon *tcon, +const char *full_path,char **target_path, +struct cifs_sb_info *cifs_sb) +{ +int rc; +int oplock =0 ; +__u16 netfid; + +cifs_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); + + rc =CIFSSMBOpen (xid, tcon, full_path,FILE_OPEN , +FILE_READ_ATTRIBUTES ,OPEN_REPARSE_POINT , &netfid, + &oplock,NULL , cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +if (rc) +return rc; + + rc =CIFSSMBQuerySymLink (xid, tcon, netfid, target_path, + cifs_sb->local_nls); +if (rc) { +CIFSSMBClose (xid, tcon, netfid); +return rc; + } + +convert_delimiter (*target_path,'/' ); +CIFSSMBClose (xid, tcon, netfid); +cifs_dbg (FYI ,"%s: target path: %s\n" , __func__, *target_path); +return rc; +} +struct smb_version_operations smb1_operations = { .send_cancel = send_nt_cancel, .compare_fids = cifs_compare_fids,
fs/cifs/smb1ops.c struct smb_version_operations smb1_operations = { · line 964
Quoted 7 lines
fs/cifs/smb1ops.c +1
-0@@ -927,6 +958,7 @@ struct smb_version_operations smb1_operations = { .rename_pending_delete = cifs_rename_pending_delete, .rename = CIFSSMBRename, .create_hardlink = CIFSCreateHardLink, + .query_symlink = cifs_query_symlink, .open = cifs_open_file, .set_fid = cifs_set_fid, .close = cifs_close_file,
Other than the nit above...
A message that is not in the archive (sent off-list or not yet received): 20130812095902.326489e9-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org
Re: [PATCH 2/2] CIFS: Implement follow_link for nounix CIFS mounts
2013/8/12 Jeff Layton <[email protected]>:
Quoted 263 lines
Quoted 188 lines · On Fri, 9 Aug 2013 16:57:22 +0400 Pavel Shilovsky…
by using a query reparse ioctl request.
Signed-off-by Pavel Shilovsky <[email protected]>--- fs/cifs/cifspdu.h | 11 +++--- fs/cifs/cifsproto.h | 10 ++--- fs/cifs/cifssmb.c | 110 ++++++++++++++++++++++++--------------------------- fs/cifs/smb1ops.c | 32 +++++++++++++++ 4 files changed, 92 insertions(+), 71 deletions(-)fs/cifs/cifspdu.h +6
-5@@ -1490,11 +1490,12 @@ struct reparse_data {__u32 ReparseTag;__u16 ReparseDataLength;__u16 Reserved; -__u16 AltNameOffset; -__u16 AltNameLen; -__u16 TargetNameOffset; -__u16 TargetNameLen; -char LinkNamesBuf[1 ]; +__u16 SubstituteNameOffset; +__u16 SubstituteNameLength; +__u16 PrintNameOffset; +__u16 PrintNameLength; +__u32 Flags; +char PathBuffer[0 ]; } __attribute__((packed));struct cifs_quota_data {fs/cifs/cifsproto.h +3
-7@@ -357,13 +357,9 @@ extern int CIFSSMBUnixQuerySymLink(const unsigned int xid,struct cifs_tcon *tcon, const unsigned char *searchName, char **syminfo, const struct nls_table *nls_codepage); -#ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL -extern int CIFSSMBQueryReparseLinkInfo (const unsigned int xid, -struct cifs_tcon *tcon, -const unsigned char *searchName, -char *symlinkinfo,const int buflen,__u16 fid, -const struct nls_table *nls_codepage); -#endif /* temporarily unused until cifs_symlink fixed */ +extern int CIFSSMBQuerySymLink (const unsigned int xid,struct cifs_tcon *tcon, +__u16 fid,char **symlinkinfo, +const struct nls_table *nls_codepage); extern int CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon, const char *fileName, const int disposition, const int access_flags, const int omode,fs/cifs/cifssmb.c +47
-55@@ -3067,7 +3067,6 @@ querySymLinkRetry:return rc; } -#ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL /* * Recent Windows versions now create symlinks more frequently * and they use the "reparse point" mechanism below. We can of course @@ -3079,18 +3078,22 @@ querySymLinkRetry:* it is not compiled in by default until callers fixed up and more tested. */ int -CIFSSMBQueryReparseLinkInfo (const unsigned int xid,struct cifs_tcon *tcon, -const unsigned char *searchName, -char *symlinkinfo,const int buflen,__u16 fid, -const struct nls_table *nls_codepage) +CIFSSMBQuerySymLink (const unsigned int xid,struct cifs_tcon *tcon, +__u16 fid,char **symlinkinfo, +const struct nls_table *nls_codepage) {int rc =0 ;int bytes_returned;struct smb_com_transaction_ioctl_req *pSMB;struct smb_com_transaction_ioctl_rsp *pSMBr; +bool is_unicode; +unsigned int sub_len; +char *sub_start; +struct reparse_data *reparse_buf; +__u32 data_offset, data_count; +char *end_of_smb; -cifs_dbg (FYI ,"In Windows reparse style QueryLink for path %s\n" , - searchName); +cifs_dbg (FYI ,"In Windows reparse style QueryLink for fid %u\n" , fid); rc =smb_init (SMB_COM_NT_TRANSACT ,23 , tcon, (void **) &pSMB, (void **) &pSMBr);if (rc)@@ -3119,66 +3122,55 @@ CIFSSMBQueryReparseLinkInfo(const unsigned int xid, struct cifs_tcon *tcon, (struct smb_hdr *) pSMBr, &bytes_returned, 0);if (rc) {cifs_dbg (FYI ,"Send error in QueryReparseLinkInfo = %d\n" , rc); - }else {/* decode response */ -__u32 data_offset =le32_to_cpu (pSMBr->DataOffset); -__u32 data_count =le32_to_cpu (pSMBr->DataCount); -if (get_bcc (&pSMBr->hdr) <2 || data_offset >512 ) { -/* BB also check enough total bytes returned */ - rc = -EIO ;/* bad smb */ - goto qreparse_out; - } -if (data_count && (data_count <2048 )) { -char *end_of_smb =2 /* sizeof byte count */ + -get_bcc (&pSMBr->hdr) + (char *)&pSMBr->ByteCount; - -struct reparse_data *reparse_buf = - (struct reparse_data *) - ((char *)&pSMBr->hdr.Protocol - + data_offset); -if ((char *)reparse_buf >= end_of_smb) { - rc = -EIO ; - goto qreparse_out; - } -if ((reparse_buf->LinkNamesBuf + - reparse_buf->TargetNameOffset + - reparse_buf->TargetNameLen) > end_of_smb) { -cifs_dbg (FYI ,"reparse buf beyond SMB\n" ); - rc = -EIO ; - goto qreparse_out; - } + goto qreparse_out; + } -if (pSMBr->hdr.Flags2 &SMBFLG2_UNICODE ) { -cifs_from_ucs2 (symlinkinfo, (__le16 *) - (reparse_buf->LinkNamesBuf + - reparse_buf->TargetNameOffset), - buflen, - reparse_buf->TargetNameLen, - nls_codepage,0 ); - }else {/* ASCII names */ -strncpy (symlinkinfo, - reparse_buf->LinkNamesBuf + - reparse_buf->TargetNameOffset, - min_t(const int, buflen, - reparse_buf->TargetNameLen)); - } - }else { - rc = -EIO ; -cifs_dbg (FYI ,"Invalid return data count on get reparse info ioctl\n" ); - } - symlinkinfo[buflen] =0 ;/* just in case so the caller -does not go off the end of the buffer */ -cifs_dbg (FYI ,"readlink result - %s\n" , symlinkinfo); + data_offset =le32_to_cpu (pSMBr->DataOffset); + data_count =le32_to_cpu (pSMBr->DataCount); +if (get_bcc (&pSMBr->hdr) <2 || data_offset >512 ) { +/* BB also check enough total bytes returned */ + rc = -EIO ;/* bad smb */ + goto qreparse_out; + } +if (!data_count || (data_count >2048 )) { + rc = -EIO ; +cifs_dbg (FYI ,"Invalid return data count on get reparse info ioctl\n" ); + goto qreparse_out; + } + end_of_smb =2 +get_bcc (&pSMBr->hdr) + (char *)&pSMBr->ByteCount; + reparse_buf = (struct reparse_data *) + ((char *)&pSMBr->hdr.Protocol + data_offset); +if ((char *)reparse_buf >= end_of_smb) { + rc = -EIO ; + goto qreparse_out; } +if ((reparse_buf->PathBuffer + reparse_buf->PrintNameOffset + + reparse_buf->PrintNameLength) > end_of_smb) { +cifs_dbg (FYI ,"reparse buf beyond SMB\n" ); + rc = -EIO ; + goto qreparse_out; + } + sub_start = reparse_buf->SubstituteNameOffset + reparse_buf->PathBuffer; + sub_len = reparse_buf->SubstituteNameLength; +if (pSMBr->hdr.Flags2 &SMBFLG2_UNICODE ) + is_unicode = true; +else + is_unicode = false; +/* BB FIXME investigate remapping reserved chars here */ + *symlinkinfo =cifs_strndup_from_utf16 (sub_start, sub_len, is_unicode, + nls_codepage); +if (!*symlinkinfo) + rc = -ENOMEM ; qreparse_out:cifs_buf_release (pSMB);fs/cifs/cifssmb.c CIFSSMBQueryReparseLinkInfo(const unsigned int xid, struct cifs_tcon *tcon, · line 3173
Quoted 10 lines
fs/cifs/cifssmb.c +4
-3-/* Note: On -EAGAIN error only caller can retry on handle based calls -since file handle passed in no longer valid */ - +/* +* Note: On -EAGAIN error only caller can retry on handle based calls +* since file handle passed in no longer valid. +*/ return rc; }Took me a few minutes to understand that you were just refactoring the code in the above function, without really changing much. Might be nice to do that in a separate patch instead.
Quoted 47 lines
fs/cifs/cifssmb.c +0
-1-#endif /* CIFS_SYMLINK_EXPERIMENTAL */ /* BB temporarily unused */ #ifdef CONFIG_CIFS_POSIX fs/cifs/smb1ops.c +31
-0@@ -881,6 +881,37 @@ cifs_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, (__u8)type, wait, 0); } +static int +cifs_query_symlink (const unsigned int xid,struct cifs_tcon *tcon, +const char *full_path,char **target_path, +struct cifs_sb_info *cifs_sb) +{ +int rc; +int oplock =0 ; +__u16 netfid; + +cifs_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); + + rc =CIFSSMBOpen (xid, tcon, full_path,FILE_OPEN , +FILE_READ_ATTRIBUTES ,OPEN_REPARSE_POINT , &netfid, + &oplock,NULL , cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR ); +if (rc) +return rc; + + rc =CIFSSMBQuerySymLink (xid, tcon, netfid, target_path, + cifs_sb->local_nls); +if (rc) { +CIFSSMBClose (xid, tcon, netfid); +return rc; + } + +convert_delimiter (*target_path,'/' ); +CIFSSMBClose (xid, tcon, netfid); +cifs_dbg (FYI ,"%s: target path: %s\n" , __func__, *target_path); +return rc; +} +struct smb_version_operations smb1_operations = { .send_cancel = send_nt_cancel, .compare_fids = cifs_compare_fids,fs/cifs/smb1ops.c struct smb_version_operations smb1_operations = { · line 964
Quoted 7 lines
fs/cifs/smb1ops.c +1
-0@@ -927,6 +958,7 @@ struct smb_version_operations smb1_operations = { .rename_pending_delete = cifs_rename_pending_delete, .rename = CIFSSMBRename, .create_hardlink = CIFSCreateHardLink, + .query_symlink = cifs_query_symlink, .open = cifs_open_file, .set_fid = cifs_set_fid, .close = cifs_close_file,Other than the nit above...
Quoted 1 line
Acked-by Jeff Layton <[email protected]>
Thank you for reviewing the series. As for this patch - I decided not to create an extra patch for refactoring CIFSSMBQuerySymLink function since nobody used it till now.
Signature · 2 lines
Best regards, Pavel Shilovsky.
Jeff Layton
Acked-byQuoted 114 lines · On Fri, 9 Aug 2013 16:57:21 +0400 Pavel Shilovsky…
that allows to access files through symlink created on a server.
Signed-off-by Pavel Shilovsky <[email protected]>--- fs/cifs/cifsglob.h | 3 +++ fs/cifs/inode.c | 4 ++++ fs/cifs/link.c | 24 +++++---------------- fs/cifs/readdir.c | 3 +++ fs/cifs/smb2file.c | 2 +- fs/cifs/smb2inode.c | 9 ++++---- fs/cifs/smb2misc.c | 4 ++++ fs/cifs/smb2ops.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++--- fs/cifs/smb2pdu.c | 9 +++++++- fs/cifs/smb2pdu.h | 14 ++++++++++++ fs/cifs/smb2proto.h | 3 ++- 11 files changed, 106 insertions(+), 29 deletions(-)fs/cifs/cifsglob.h +3
-0@@ -305,6 +305,9 @@ struct smb_version_operations {int (*create_hardlink)(const unsigned int ,struct cifs_tcon *,const char *,const char *,struct cifs_sb_info *); +/* query symlink target */ +int (*query_symlink)(const unsigned int ,struct cifs_tcon *, +const char *,char **,struct cifs_sb_info *);/* open a file for non-posix mounts */ int (*open)(const unsigned int ,struct cifs_open_parms *,__u32 *,FILE_ALL_INFO *);fs/cifs/inode.c +4
-0@@ -549,6 +549,10 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,* when Unix extensions are disabled - fake it. */ fattr->cf_nlink =2 ; + }else if (fattr->cf_cifsattrs &ATTR_REPARSE ) { + fattr->cf_mode =S_IFLNK ; + fattr->cf_dtype =DT_LNK ; + fattr->cf_nlink =le32_to_cpu (info->NumberOfLinks); }else { fattr->cf_mode =S_IFREG | cifs_sb->mnt_file_mode; fattr->cf_dtype =DT_REG ;fs/cifs/link.c +5
-19@@ -487,6 +487,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb);struct tcon_link *tlink =NULL ;struct cifs_tcon *tcon; +struct TCP_Server_Info *server; xid =get_xid ();@@ -497,25 +498,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd) goto out; } tcon =tlink_tcon (tlink); - -/* -* For now, we just handle symlinks with unix extensions enabled. -* Eventually we should handle NTFS reparse points, and MacOS -* symlink support. For instance... -* -* rc = CIFSSMBQueryReparseLinkInfo(...) -* -* For now, just return -EACCES when the server doesn't support posix -* extensions. Note that we still allow querying symlinks when posix -* extensions are manually disabled. We could disable these as well -* but there doesn't seem to be any harm in allowing the client to -* read them. -*/ -if (!(cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MF_SYMLINKS ) && - !cap_unix (tcon->ses)) { - rc = -EACCES ; - goto out; - } + server = tcon->ses->server; full_path =build_path_from_dentry (direntry);if (!full_path)@@ -537,6 +520,9 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)if ((rc !=0 ) &&cap_unix (tcon->ses)) rc =CIFSSMBUnixQuerySymLink (xid, tcon, full_path, &target_path, cifs_sb->local_nls); +else if (rc !=0 && server->ops->query_symlink) + rc = server->ops->query_symlink (xid, tcon, full_path, + &target_path, cifs_sb);kfree (full_path); out:fs/cifs/readdir.c +3
-0@@ -164,6 +164,9 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)if (cifs_dfs_is_possible (cifs_sb) && (fattr->cf_cifsattrs &ATTR_REPARSE )) fattr->cf_flags |=CIFS_FATTR_NEED_REVAL ; + }else if (fattr->cf_cifsattrs &ATTR_REPARSE ) { + fattr->cf_mode =S_IFLNK ; + fattr->cf_dtype =DT_LNK ; }else { fattr->cf_mode =S_IFREG | cifs_sb->mnt_file_mode; fattr->cf_dtype =DT_REG ;fs/cifs/smb2file.c +0
-0
fs/cifs/smb2file.c smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, · line 89
Quoted 5 lines
fs/cifs/smb2file.c +1
-1@@ -86,7 +86,7 @@ smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,if (oparms->tcon->ses->server->capabilities &SMB2_GLOBAL_CAP_LEASING )memcpy (smb2_oplock +1 , fid->lease_key,SMB2_LEASE_KEY_SIZE ); - rc =SMB2_open (xid, oparms, smb2_path, smb2_oplock, smb2_data); + rc =SMB2_open (xid, oparms, smb2_path, smb2_oplock, smb2_data,NULL );
So what happens if I run across one of these symlinks as the terminal dentry of an atomic_open call? Does that just fail currently?
Quoted 180 lines
fs/cifs/smb2file.c +0
-0if (rc) goto out;fs/cifs/smb2inode.c +5
-4@@ -60,7 +60,7 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ); + rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ,NULL );if (rc) {kfree (utf16_path);return rc;@@ -136,7 +136,8 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ; rc =smb2_open_op_close (xid, tcon, cifs_sb, full_path, -FILE_READ_ATTRIBUTES ,FILE_OPEN ,0 , smb2_data, +FILE_READ_ATTRIBUTES ,FILE_OPEN , +OPEN_REPARSE_POINT , smb2_data,SMB2_OP_QUERY_INFO );if (rc) goto out;@@ -191,8 +192,8 @@ smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, struct cifs_sb_info *cifs_sb) {return smb2_open_op_close (xid, tcon, cifs_sb, name,DELETE ,FILE_OPEN , -CREATE_DELETE_ON_CLOSE ,NULL , -SMB2_OP_DELETE ); +CREATE_DELETE_ON_CLOSE |OPEN_REPARSE_POINT , +NULL ,SMB2_OP_DELETE ); } static intfs/cifs/smb2misc.c +4
-0@@ -171,6 +171,10 @@ smb2_check_message(char *buf, unsigned int length)if (4 + len != clc_len) {cifs_dbg (FYI ,"Calculated size %u length %u mismatch mid %llu\n" , clc_len,4 + len, mid); +/* create failed on symlink */ +if (command ==SMB2_CREATE_HE && + hdr->Status ==STATUS_STOPPED_ON_SYMLINK ) +return 0 ;/* Windows 7 server returns 24 bytes more */ if (clc_len +20 == len && command ==SMB2_OPLOCK_BREAK_HE )return 0 ;fs/cifs/smb2ops.c +57
-3@@ -24,6 +24,7 @@#include "smb2proto.h" #include "cifsproto.h" #include "cifs_debug.h" +#include "cifs_unicode.h" #include "smb2status.h" #include "smb2glob.h" @@ -229,7 +230,7 @@ smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ); + rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ,NULL );if (rc) {kfree (utf16_path);return rc;@@ -463,7 +464,7 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = fid; oparms.reconnect = false; - rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ); + rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ,NULL );kfree (utf16_path);if (rc) {cifs_dbg (VFS ,"open dir failed\n" );@@ -550,7 +551,7 @@ smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc =SMB2_open (xid, &oparms, &srch_path, &oplock,NULL ); + rc =SMB2_open (xid, &oparms, &srch_path, &oplock,NULL ,NULL );if (rc)return rc; buf->f_type =SMB2_MAGIC_NUMBER ;@@ -596,6 +597,57 @@ smb2_new_lease_key(struct cifs_fid *fid)get_random_bytes (fid->lease_key,SMB2_LEASE_KEY_SIZE ); } +int +smb2_query_symlink (const unsigned int xid,struct cifs_tcon *tcon, +const char *full_path,char **target_path, +struct cifs_sb_info *cifs_sb) +{ +int rc; +__le16 *utf16_path; +__u8 oplock =SMB2_OPLOCK_LEVEL_NONE ; +struct cifs_open_parms oparms; +struct cifs_fid fid; +struct smb2_err_rsp *err_buf =NULL ; +struct smb2_symlink_err_rsp *symlink; +unsigned int sub_len, sub_offset; + +cifs_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); + + utf16_path =cifs_convert_path_to_utf16 (full_path, cifs_sb); +if (!utf16_path) +return -ENOMEM ; + + oparms.tcon = tcon; + oparms.desired_access =FILE_READ_ATTRIBUTES ; + oparms.disposition =FILE_OPEN ; + oparms.create_options =0 ; + oparms.fid = &fid; + oparms.reconnect = false; + + rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL , &err_buf); + +if (!rc || !err_buf) { +kfree (utf16_path); +return -ENOENT ; + } +/* open must fail on symlink - reset rc */ + rc =0 ; + symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; + sub_len =le16_to_cpu (symlink->SubstituteNameLength); + sub_offset =le16_to_cpu (symlink->SubstituteNameOffset); + *target_path =cifs_strndup_from_utf16 ( + (char *)symlink->PathBuffer + sub_offset, + sub_len, true, cifs_sb->local_nls); +if (!(*target_path)) { +kfree (utf16_path); +return -ENOMEM ; + } +convert_delimiter (*target_path,'/' ); +cifs_dbg (FYI ,"%s: target path: %s\n" , __func__, *target_path); +kfree (utf16_path); +return rc; +} +struct smb_version_operations smb21_operations = { .compare_fids = smb2_compare_fids, .setup_request = smb2_setup_request,@@ -638,6 +690,7 @@ struct smb_version_operations smb21_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, + .query_symlink = smb2_query_symlink, .open = smb2_open_file, .set_fid = smb2_set_fid, .close = smb2_close_file,@@ -706,6 +759,7 @@ struct smb_version_operations smb30_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, + .query_symlink = smb2_query_symlink, .open = smb2_open_file, .set_fid = smb2_set_fid, .close = smb2_close_file,fs/cifs/smb2pdu.c +2
-1@@ -977,7 +977,8 @@ add_durable_context(struct kvec *iov, unsigned int *num_iovec,int SMB2_open (const unsigned int xid,struct cifs_open_parms *oparms,__le16 *path, -__u8 *oplock,struct smb2_file_all_info *buf) +__u8 *oplock,struct smb2_file_all_info *buf, +struct smb2_err_rsp **err_buf) {struct smb2_create_req *req;struct smb2_create_rsp *rsp;
fs/cifs/smb2pdu.c SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, · line 1090
Quoted 9 lines
fs/cifs/smb2pdu.c +6
-0@@ -1081,6 +1082,12 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,if (rc !=0 ) {cifs_stats_fail_inc (tcon,SMB2_CREATE_HE ); +if (err_buf) { +unsigned int buf_size =get_rfc1002_length (rsp) +4 ; + *err_buf =kmalloc (buf_size,GFP_KERNEL ); +if (*err_buf) +memcpy (*err_buf, rsp, buf_size); + }
This should be replaced with kmemdup().
Quoted 33 lines
fs/cifs/smb2pdu.c +0
-0goto creat_exit; }fs/cifs/smb2pdu.h +14
-0@@ -150,6 +150,20 @@ struct smb2_err_rsp {__u8 ErrorData[1 ];/* variable length */ } __packed; +struct smb2_symlink_err_rsp { +__le32 SymLinkLength; +__le32 SymLinkErrorTag; +__le32 ReparseTag; +__le16 ReparseDataLength; +__le16 UnparsedPathLength; +__le16 SubstituteNameOffset; +__le16 SubstituteNameLength; +__le16 PrintNameOffset; +__le16 PrintNameLength; +__le32 Flags; +__u8 PathBuffer[0 ]; +} __packed; +#define SMB2_CLIENT_GUID_SIZE 16extern __u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE ];fs/cifs/smb2proto.h +0
-0
fs/cifs/smb2proto.h extern int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, · line 113
Quoted 9 lines
fs/cifs/smb2proto.h +2
-1@@ -106,7 +106,8 @@ extern int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses,extern int SMB2_tdis (const unsigned int xid,struct cifs_tcon *tcon);extern int SMB2_open (const unsigned int xid,struct cifs_open_parms *oparms,__le16 *path,__u8 *oplock, -struct smb2_file_all_info *buf); +struct smb2_file_all_info *buf, +struct smb2_err_rsp **err_buf); extern int SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid, u32 opcode, bool is_fsctl, char *in_data, u32 indatalen,
Looks fairly reasonable otherwise...
A message that is not in the archive (sent off-list or not yet received): 20130812095611.7a4c91f8-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org
2013/8/12 Jeff Layton <[email protected]>:
Quoted 120 lines
Quoted 117 lines · On Fri, 9 Aug 2013 16:57:21 +0400 Pavel Shilovsky…
that allows to access files through symlink created on a server.
Signed-off-by Pavel Shilovsky <[email protected]>--- fs/cifs/cifsglob.h | 3 +++ fs/cifs/inode.c | 4 ++++ fs/cifs/link.c | 24 +++++---------------- fs/cifs/readdir.c | 3 +++ fs/cifs/smb2file.c | 2 +- fs/cifs/smb2inode.c | 9 ++++---- fs/cifs/smb2misc.c | 4 ++++ fs/cifs/smb2ops.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++--- fs/cifs/smb2pdu.c | 9 +++++++- fs/cifs/smb2pdu.h | 14 ++++++++++++ fs/cifs/smb2proto.h | 3 ++- 11 files changed, 106 insertions(+), 29 deletions(-)fs/cifs/cifsglob.h +3
-0@@ -305,6 +305,9 @@ struct smb_version_operations {int (*create_hardlink)(const unsigned int ,struct cifs_tcon *,const char *,const char *,struct cifs_sb_info *); +/* query symlink target */ +int (*query_symlink)(const unsigned int ,struct cifs_tcon *, +const char *,char **,struct cifs_sb_info *);/* open a file for non-posix mounts */ int (*open)(const unsigned int ,struct cifs_open_parms *,__u32 *,FILE_ALL_INFO *);fs/cifs/inode.c +4
-0@@ -549,6 +549,10 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,* when Unix extensions are disabled - fake it. */ fattr->cf_nlink =2 ; + }else if (fattr->cf_cifsattrs &ATTR_REPARSE ) { + fattr->cf_mode =S_IFLNK ; + fattr->cf_dtype =DT_LNK ; + fattr->cf_nlink =le32_to_cpu (info->NumberOfLinks); }else { fattr->cf_mode =S_IFREG | cifs_sb->mnt_file_mode; fattr->cf_dtype =DT_REG ;fs/cifs/link.c +5
-19@@ -487,6 +487,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb);struct tcon_link *tlink =NULL ;struct cifs_tcon *tcon; +struct TCP_Server_Info *server; xid =get_xid ();@@ -497,25 +498,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd) goto out; } tcon =tlink_tcon (tlink); - -/* -* For now, we just handle symlinks with unix extensions enabled. -* Eventually we should handle NTFS reparse points, and MacOS -* symlink support. For instance... -* -* rc = CIFSSMBQueryReparseLinkInfo(...) -* -* For now, just return -EACCES when the server doesn't support posix -* extensions. Note that we still allow querying symlinks when posix -* extensions are manually disabled. We could disable these as well -* but there doesn't seem to be any harm in allowing the client to -* read them. -*/ -if (!(cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MF_SYMLINKS ) && - !cap_unix (tcon->ses)) { - rc = -EACCES ; - goto out; - } + server = tcon->ses->server; full_path =build_path_from_dentry (direntry);if (!full_path)@@ -537,6 +520,9 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)if ((rc !=0 ) &&cap_unix (tcon->ses)) rc =CIFSSMBUnixQuerySymLink (xid, tcon, full_path, &target_path, cifs_sb->local_nls); +else if (rc !=0 && server->ops->query_symlink) + rc = server->ops->query_symlink (xid, tcon, full_path, + &target_path, cifs_sb);kfree (full_path); out:fs/cifs/readdir.c +3
-0@@ -164,6 +164,9 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)if (cifs_dfs_is_possible (cifs_sb) && (fattr->cf_cifsattrs &ATTR_REPARSE )) fattr->cf_flags |=CIFS_FATTR_NEED_REVAL ; + }else if (fattr->cf_cifsattrs &ATTR_REPARSE ) { + fattr->cf_mode =S_IFLNK ; + fattr->cf_dtype =DT_LNK ; }else { fattr->cf_mode =S_IFREG | cifs_sb->mnt_file_mode; fattr->cf_dtype =DT_REG ;fs/cifs/smb2file.c +0
-0@@ -86,7 +86,7 @@ smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,if (oparms->tcon->ses->server->capabilities &SMB2_GLOBAL_CAP_LEASING )memcpy (smb2_oplock +1 , fid->lease_key,SMB2_LEASE_KEY_SIZE );
Quoted 5 lines
fs/cifs/smb2file.c smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, · line 89
Quoted 2 lines
fs/cifs/smb2file.c +1
-1- rc =SMB2_open (xid, oparms, smb2_path, smb2_oplock, smb2_data); + rc =SMB2_open (xid, oparms, smb2_path, smb2_oplock, smb2_data,NULL );So what happens if I run across one of these symlinks as the terminal dentry of an
atomic_opencall? Does that just fail currently?
Yes, it fails now. We can try to handle this error by resolving an actual path and resend the atomic open request but it is work for other patches, I think.
Quoted 239 lines
Quoted 181 lines
fs/cifs/smb2file.c +0
-0if (rc) goto out;fs/cifs/smb2inode.c +5
-4@@ -60,7 +60,7 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ); + rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ,NULL );if (rc) {kfree (utf16_path);return rc;@@ -136,7 +136,8 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,return -ENOMEM ; rc =smb2_open_op_close (xid, tcon, cifs_sb, full_path, -FILE_READ_ATTRIBUTES ,FILE_OPEN ,0 , smb2_data, +FILE_READ_ATTRIBUTES ,FILE_OPEN , +OPEN_REPARSE_POINT , smb2_data,SMB2_OP_QUERY_INFO );if (rc) goto out;@@ -191,8 +192,8 @@ smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, struct cifs_sb_info *cifs_sb) {return smb2_open_op_close (xid, tcon, cifs_sb, name,DELETE ,FILE_OPEN , -CREATE_DELETE_ON_CLOSE ,NULL , -SMB2_OP_DELETE ); +CREATE_DELETE_ON_CLOSE |OPEN_REPARSE_POINT , +NULL ,SMB2_OP_DELETE ); } static intfs/cifs/smb2misc.c +4
-0@@ -171,6 +171,10 @@ smb2_check_message(char *buf, unsigned int length)if (4 + len != clc_len) {cifs_dbg (FYI ,"Calculated size %u length %u mismatch mid %llu\n" , clc_len,4 + len, mid); +/* create failed on symlink */ +if (command ==SMB2_CREATE_HE && + hdr->Status ==STATUS_STOPPED_ON_SYMLINK ) +return 0 ;/* Windows 7 server returns 24 bytes more */ if (clc_len +20 == len && command ==SMB2_OPLOCK_BREAK_HE )return 0 ;fs/cifs/smb2ops.c +57
-3@@ -24,6 +24,7 @@#include "smb2proto.h" #include "cifsproto.h" #include "cifs_debug.h" +#include "cifs_unicode.h" #include "smb2status.h" #include "smb2glob.h" @@ -229,7 +230,7 @@ smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ); + rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ,NULL );if (rc) {kfree (utf16_path);return rc;@@ -463,7 +464,7 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = fid; oparms.reconnect = false; - rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ); + rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ,NULL );kfree (utf16_path);if (rc) {cifs_dbg (VFS ,"open dir failed\n" );@@ -550,7 +551,7 @@ smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, oparms.fid = &fid; oparms.reconnect = false; - rc =SMB2_open (xid, &oparms, &srch_path, &oplock,NULL ); + rc =SMB2_open (xid, &oparms, &srch_path, &oplock,NULL ,NULL );if (rc)return rc; buf->f_type =SMB2_MAGIC_NUMBER ;@@ -596,6 +597,57 @@ smb2_new_lease_key(struct cifs_fid *fid)get_random_bytes (fid->lease_key,SMB2_LEASE_KEY_SIZE ); } +int +smb2_query_symlink (const unsigned int xid,struct cifs_tcon *tcon, +const char *full_path,char **target_path, +struct cifs_sb_info *cifs_sb) +{ +int rc; +__le16 *utf16_path; +__u8 oplock =SMB2_OPLOCK_LEVEL_NONE ; +struct cifs_open_parms oparms; +struct cifs_fid fid; +struct smb2_err_rsp *err_buf =NULL ; +struct smb2_symlink_err_rsp *symlink; +unsigned int sub_len, sub_offset; + +cifs_dbg (FYI ,"%s: path: %s\n" , __func__, full_path); + + utf16_path =cifs_convert_path_to_utf16 (full_path, cifs_sb); +if (!utf16_path) +return -ENOMEM ; + + oparms.tcon = tcon; + oparms.desired_access =FILE_READ_ATTRIBUTES ; + oparms.disposition =FILE_OPEN ; + oparms.create_options =0 ; + oparms.fid = &fid; + oparms.reconnect = false; + + rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL , &err_buf); + +if (!rc || !err_buf) { +kfree (utf16_path); +return -ENOENT ; + } +/* open must fail on symlink - reset rc */ + rc =0 ; + symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; + sub_len =le16_to_cpu (symlink->SubstituteNameLength); + sub_offset =le16_to_cpu (symlink->SubstituteNameOffset); + *target_path =cifs_strndup_from_utf16 ( + (char *)symlink->PathBuffer + sub_offset, + sub_len, true, cifs_sb->local_nls); +if (!(*target_path)) { +kfree (utf16_path); +return -ENOMEM ; + } +convert_delimiter (*target_path,'/' ); +cifs_dbg (FYI ,"%s: target path: %s\n" , __func__, *target_path); +kfree (utf16_path); +return rc; +} +struct smb_version_operations smb21_operations = { .compare_fids = smb2_compare_fids, .setup_request = smb2_setup_request,@@ -638,6 +690,7 @@ struct smb_version_operations smb21_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, + .query_symlink = smb2_query_symlink, .open = smb2_open_file, .set_fid = smb2_set_fid, .close = smb2_close_file,@@ -706,6 +759,7 @@ struct smb_version_operations smb30_operations = { .unlink = smb2_unlink, .rename = smb2_rename_path, .create_hardlink = smb2_create_hardlink, + .query_symlink = smb2_query_symlink, .open = smb2_open_file, .set_fid = smb2_set_fid, .close = smb2_close_file,fs/cifs/smb2pdu.c +2
-1@@ -977,7 +977,8 @@ add_durable_context(struct kvec *iov, unsigned int *num_iovec,int SMB2_open (const unsigned int xid,struct cifs_open_parms *oparms,__le16 *path, -__u8 *oplock,struct smb2_file_all_info *buf) +__u8 *oplock,struct smb2_file_all_info *buf, +struct smb2_err_rsp **err_buf) {struct smb2_create_req *req;struct smb2_create_rsp *rsp;fs/cifs/smb2pdu.c SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, · line 1090
Quoted 9 lines
fs/cifs/smb2pdu.c +6
-0@@ -1081,6 +1082,12 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,if (rc !=0 ) {cifs_stats_fail_inc (tcon,SMB2_CREATE_HE ); +if (err_buf) { +unsigned int buf_size =get_rfc1002_length (rsp) +4 ; + *err_buf =kmalloc (buf_size,GFP_KERNEL ); +if (*err_buf) +memcpy (*err_buf, rsp, buf_size); + }This should be replaced with
kmemdup().Quoted 33 lines
fs/cifs/smb2pdu.c +0
-0goto creat_exit; }fs/cifs/smb2pdu.h +14
-0@@ -150,6 +150,20 @@ struct smb2_err_rsp {__u8 ErrorData[1 ];/* variable length */ } __packed; +struct smb2_symlink_err_rsp { +__le32 SymLinkLength; +__le32 SymLinkErrorTag; +__le32 ReparseTag; +__le16 ReparseDataLength; +__le16 UnparsedPathLength; +__le16 SubstituteNameOffset; +__le16 SubstituteNameLength; +__le16 PrintNameOffset; +__le16 PrintNameLength; +__le32 Flags; +__u8 PathBuffer[0 ]; +} __packed; +#define SMB2_CLIENT_GUID_SIZE 16extern __u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE ];fs/cifs/smb2proto.h +0
-0fs/cifs/smb2proto.h extern int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, · line 113
Quoted 9 lines
fs/cifs/smb2proto.h +2
-1@@ -106,7 +106,8 @@ extern int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses,extern int SMB2_tdis (const unsigned int xid,struct cifs_tcon *tcon);extern int SMB2_open (const unsigned int xid,struct cifs_open_parms *oparms,__le16 *path,__u8 *oplock, -struct smb2_file_all_info *buf); +struct smb2_file_all_info *buf, +struct smb2_err_rsp **err_buf); extern int SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid, u32 opcode, bool is_fsctl, char *in_data, u32 indatalen,Looks fairly reasonable otherwise...
Acked-by Jeff Layton <[email protected]>
Signature · 2 lines
Best regards, Pavel Shilovsky.