From patchwork Tue Aug 3 15:05:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Metzmacher X-Patchwork-Id: 116787 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o73F6ThY013664 for ; Tue, 3 Aug 2010 15:06:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756928Ab0HCPGZ (ORCPT ); Tue, 3 Aug 2010 11:06:25 -0400 Received: from mo-p05-ob.rzone.de ([81.169.146.181]:12184 "EHLO mo-p05-ob.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751351Ab0HCPGY (ORCPT ); Tue, 3 Aug 2010 11:06:24 -0400 X-RZG-AUTH: :IXQkeEW8Yfo/5haL0ckzWIsAYh739YBunhBBa3aCCCbZv/tD854XGrpZ X-RZG-CLASS-ID: mo05 Received: from localhost.localdomain (xdsl-87-79-184-42.netcologne.de [87.79.184.42]) by post.strato.de (jimi mo39) (RZmta 23.4) with (DHE-RSA-AES256-SHA encrypted) ESMTP id q0292dm73DmAJJ ; Tue, 3 Aug 2010 17:06:22 +0200 (MEST) From: Stefan Metzmacher To: smfrench@gmail.com Cc: linux-cifs@vger.kernel.org, Stefan Metzmacher Subject: [PATCH 4/8] cifs: implement CIFSParseMFSymlink() Date: Tue, 3 Aug 2010 17:05:56 +0200 Message-Id: <1280847960-16371-5-git-send-email-metze@samba.org> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1280847960-16371-1-git-send-email-metze@samba.org> References: <1280847960-16371-1-git-send-email-metze@samba.org> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 03 Aug 2010 15:06:30 +0000 (UTC) diff --git a/fs/cifs/link.c b/fs/cifs/link.c index 985373c..33307b1 100644 --- a/fs/cifs/link.c +++ b/fs/cifs/link.c @@ -28,6 +28,67 @@ #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; +} static int CIFSCreateMFSymLink(const int xid, struct cifsTconInfo *tcon,