Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 213393
b: refs/heads/master
c: c69c1b6
h: refs/heads/master
i:
  213391: ff82f64
v: v3
  • Loading branch information
Stefan Metzmacher authored and Steve French committed Sep 29, 2010
1 parent 53a7b85 commit cb5ac35
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 3eb9a8893a76cf1cda3b41c3212eb2cfe83eae0e
refs/heads/master: c69c1b6eaea1b3e1eecf7ad2fba0208ac4a11131
62 changes: 62 additions & 0 deletions trunk/fs/cifs/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,68 @@
#include "cifsproto.h"
#include "cifs_debug.h"
#include "cifs_fs_sb.h"
#include "md5.h"

#define CIFS_MF_SYMLINK_LEN_OFFSET (4+1)
#define CIFS_MF_SYMLINK_MD5_OFFSET (CIFS_MF_SYMLINK_LEN_OFFSET+(4+1))
#define CIFS_MF_SYMLINK_LINK_OFFSET (CIFS_MF_SYMLINK_MD5_OFFSET+(32+1))
#define CIFS_MF_SYMLINK_LINK_MAXLEN (1024)
#define CIFS_MF_SYMLINK_FILE_SIZE \
(CIFS_MF_SYMLINK_LINK_OFFSET + CIFS_MF_SYMLINK_LINK_MAXLEN)

#define CIFS_MF_SYMLINK_LEN_FORMAT "XSym\n%04u\n"
#define CIFS_MF_SYMLINK_MD5_FORMAT \
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n"
#define CIFS_MF_SYMLINK_MD5_ARGS(md5_hash) \
md5_hash[0], md5_hash[1], md5_hash[2], md5_hash[3], \
md5_hash[4], md5_hash[5], md5_hash[6], md5_hash[7], \
md5_hash[8], md5_hash[9], md5_hash[10], md5_hash[11],\
md5_hash[12], md5_hash[13], md5_hash[14], md5_hash[15]

static int
CIFSParseMFSymlink(const u8 *buf,
unsigned int buf_len,
unsigned int *_link_len,
char **_link_str)
{
int rc;
unsigned int link_len;
const char *md5_str1;
const char *link_str;
struct MD5Context md5_ctx;
u8 md5_hash[16];
char md5_str2[34];

if (buf_len != CIFS_MF_SYMLINK_FILE_SIZE)
return -EINVAL;

md5_str1 = (const char *)&buf[CIFS_MF_SYMLINK_MD5_OFFSET];
link_str = (const char *)&buf[CIFS_MF_SYMLINK_LINK_OFFSET];

rc = sscanf(buf, CIFS_MF_SYMLINK_LEN_FORMAT, &link_len);
if (rc != 1)
return -EINVAL;

cifs_MD5_init(&md5_ctx);
cifs_MD5_update(&md5_ctx, (const u8 *)link_str, link_len);
cifs_MD5_final(md5_hash, &md5_ctx);

snprintf(md5_str2, sizeof(md5_str2),
CIFS_MF_SYMLINK_MD5_FORMAT,
CIFS_MF_SYMLINK_MD5_ARGS(md5_hash));

if (strncmp(md5_str1, md5_str2, 17) != 0)
return -EINVAL;

if (_link_str) {
*_link_str = kstrndup(link_str, link_len, GFP_KERNEL);
if (!*_link_str)
return -ENOMEM;
}

*_link_len = link_len;
return 0;
}

int
cifs_hardlink(struct dentry *old_file, struct inode *inode,
Expand Down

0 comments on commit cb5ac35

Please sign in to comment.