cifs: change CIFSSMBUnixQuerySymLink to use new helpers

Change CIFSSMBUnixQuerySymLink to use the new unicode helper functions.
Also change the calling conventions so that the allocation of the target
name buffer is done in CIFSSMBUnixQuerySymLink rather than by the caller.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Acked-by: Suresh Jayaraman <sjayaraman@suse.de>
Signed-off-by: Steve French <sfrench@us.ibm.com>
This commit is contained in:
Jeff Layton 2009-04-30 07:17:56 -04:00 committed by Steve French
parent 59140797c5
commit 460b96960d
3 changed files with 20 additions and 41 deletions

View file

@ -260,8 +260,7 @@ extern int CIFSUnixCreateSymLink(const int xid,
const struct nls_table *nls_codepage); const struct nls_table *nls_codepage);
extern int CIFSSMBUnixQuerySymLink(const int xid, extern int CIFSSMBUnixQuerySymLink(const int xid,
struct cifsTconInfo *tcon, struct cifsTconInfo *tcon,
const unsigned char *searchName, const unsigned char *searchName, char **syminfo,
char *syminfo, const int buflen,
const struct nls_table *nls_codepage); const struct nls_table *nls_codepage);
extern int CIFSSMBQueryReparseLinkInfo(const int xid, extern int CIFSSMBQueryReparseLinkInfo(const int xid,
struct cifsTconInfo *tcon, struct cifsTconInfo *tcon,

View file

@ -2382,8 +2382,7 @@ CIFSCreateHardLink(const int xid, struct cifsTconInfo *tcon,
int int
CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon, CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon,
const unsigned char *searchName, const unsigned char *searchName, char **symlinkinfo,
char *symlinkinfo, const int buflen,
const struct nls_table *nls_codepage) const struct nls_table *nls_codepage)
{ {
/* SMB_QUERY_FILE_UNIX_LINK */ /* SMB_QUERY_FILE_UNIX_LINK */
@ -2393,6 +2392,7 @@ CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon,
int bytes_returned; int bytes_returned;
int name_len; int name_len;
__u16 params, byte_count; __u16 params, byte_count;
char *data_start;
cFYI(1, ("In QPathSymLinkInfo (Unix) for path %s", searchName)); cFYI(1, ("In QPathSymLinkInfo (Unix) for path %s", searchName));
@ -2447,30 +2447,22 @@ CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon,
/* decode response */ /* decode response */
rc = validate_t2((struct smb_t2_rsp *)pSMBr); rc = validate_t2((struct smb_t2_rsp *)pSMBr);
if (rc || (pSMBr->ByteCount < 2))
/* BB also check enough total bytes returned */ /* BB also check enough total bytes returned */
rc = -EIO; /* bad smb */ if (rc || (pSMBr->ByteCount < 2))
rc = -EIO;
else { else {
__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); u16 count = le16_to_cpu(pSMBr->t2.DataCount);
__u16 count = le16_to_cpu(pSMBr->t2.DataCount);
data_start = ((char *) &pSMBr->hdr.Protocol) +
le16_to_cpu(pSMBr->t2.DataOffset);
if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) {
name_len = UniStrnlen((wchar_t *) ((char *)
&pSMBr->hdr.Protocol + data_offset),
min_t(const int, buflen, count) / 2);
/* BB FIXME investigate remapping reserved chars here */ /* BB FIXME investigate remapping reserved chars here */
cifs_strfromUCS_le(symlinkinfo, *symlinkinfo = cifs_strndup(data_start, count,
(__le16 *) ((char *)&pSMBr->hdr.Protocol pSMBr->hdr.Flags2 &
+ data_offset), SMBFLG2_UNICODE,
name_len, nls_codepage); nls_codepage);
} else { if (!symlinkinfo)
strncpy(symlinkinfo, rc = -ENOMEM;
(char *) &pSMBr->hdr.Protocol +
data_offset,
min_t(const int, buflen, count));
}
symlinkinfo[buflen] = 0;
/* just in case so calling code does not go off the end of buffer */
} }
} }
cifs_buf_release(pSMB); cifs_buf_release(pSMB);

View file

@ -119,16 +119,11 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
full_path = build_path_from_dentry(direntry); full_path = build_path_from_dentry(direntry);
if (!full_path) if (!full_path)
goto out_no_free; goto out;
cFYI(1, ("Full path: %s inode = 0x%p", full_path, inode)); cFYI(1, ("Full path: %s inode = 0x%p", full_path, inode));
cifs_sb = CIFS_SB(inode->i_sb); cifs_sb = CIFS_SB(inode->i_sb);
pTcon = cifs_sb->tcon; pTcon = cifs_sb->tcon;
target_path = kmalloc(PATH_MAX, GFP_KERNEL);
if (!target_path) {
target_path = ERR_PTR(-ENOMEM);
goto out;
}
/* We could change this to: /* We could change this to:
if (pTcon->unix_ext) if (pTcon->unix_ext)
@ -138,8 +133,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
if (pTcon->ses->capabilities & CAP_UNIX) if (pTcon->ses->capabilities & CAP_UNIX)
rc = CIFSSMBUnixQuerySymLink(xid, pTcon, full_path, rc = CIFSSMBUnixQuerySymLink(xid, pTcon, full_path,
target_path, &target_path,
PATH_MAX-1,
cifs_sb->local_nls); cifs_sb->local_nls);
else { else {
/* BB add read reparse point symlink code here */ /* BB add read reparse point symlink code here */
@ -148,22 +142,16 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
/* BB Add MAC style xsymlink check here if enabled */ /* BB Add MAC style xsymlink check here if enabled */
} }
if (rc == 0) { if (rc != 0) {
/* BB Add special case check for Samba DFS symlinks */
target_path[PATH_MAX-1] = 0;
} else {
kfree(target_path); kfree(target_path);
target_path = ERR_PTR(rc); target_path = ERR_PTR(rc);
} }
out:
kfree(full_path); kfree(full_path);
out_no_free: out:
FreeXid(xid); FreeXid(xid);
nd_set_link(nd, target_path); nd_set_link(nd, target_path);
return NULL; /* No cookie */ return NULL;
} }
int int