From patchwork Thu Jun 1 04:50:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shirish Pargaonkar X-Patchwork-Id: 9758667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 28BFC60375 for ; Thu, 1 Jun 2017 04:50:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 140B7284EA for ; Thu, 1 Jun 2017 04:50:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07426284F4; Thu, 1 Jun 2017 04:50:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FD9A284EA for ; Thu, 1 Jun 2017 04:50:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750790AbdFAEuf (ORCPT ); Thu, 1 Jun 2017 00:50:35 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:34558 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750726AbdFAEue (ORCPT ); Thu, 1 Jun 2017 00:50:34 -0400 Received: by mail-oi0-f68.google.com with SMTP id w10so5076663oif.1 for ; Wed, 31 May 2017 21:50:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=VKnNRnpMznPSqX0OHu/eZvUfOv9U3I4zDG7rZ3PFZQ4=; b=KBbbjg4JOb6DYVl/b1bjPpq3aIByD4B3YffcvRqBpkarrYZvZQFrHuVvHtZpRpU0ni BLvmCsheLT2Kl2RFg/Ryz7TV2366Vnk8Q8eGhcCkGocO4Gdxk1f+uRTqnH2RCgBTFiFj pdAZHUWMiuPfUveN3hA4V/UHnq46cjpm6LkoiYtYu9ElolD9oluGG0coKIvceBPPc47A q9E0F7/8rjPEukgOXC600kGzTuvLSaKx9LGaLiQQ2RanacCLmYFduFYRDrr3K2q2tCAD kWMQ2ulW+LzeYwiUkNhpWPDrzm31B1ZVSbXPf9M7jRHMOMySE8HFoWrLpv9H2ft8Ut1Y USmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VKnNRnpMznPSqX0OHu/eZvUfOv9U3I4zDG7rZ3PFZQ4=; b=OhVnWwdZWZF9RBpuETWXPOwv8w3HnC0sxWgJIpbSr2+5kp/uB0zALadvQu+t6gnOCf y97hZvp631rsv9QHFEwvT/5EvzpXsWjyLC/e/8jMfifhPuHyaDgAGc8d5O/bTEG21aSn 2A5m4KLEdYtW5zmuT5jFPq1I76Lb1Y/EEfICmWbYmkHDyFhCFkxOJqp2inUCcJ4seiqa U6sDIFjO6IFexPDS7/+xliGksP2XaxJ4wd2rQJRI5jSctqUXj2EAmeg1tizWksCcx3kU Ny+uhhuX4I9Nd+hrmovSw6yLHFlQWUA1R5633t1xPB2MmILWePrdkMMuQOkmclQ4ngF8 8Tjg== X-Gm-Message-State: AODbwcDZfmXzOImrUnbFCBICKXVJq7DE92JL66wPdR2IfDUdvA0WXAta Qk8nA/dq8XY6Fg== X-Received: by 10.157.41.166 with SMTP id n35mr7552221otb.148.1496292633636; Wed, 31 May 2017 21:50:33 -0700 (PDT) Received: from shirish-ThinkPad-T400.attlocal.net (75-13-85-90.lightspeed.austtx.sbcglobal.net. [75.13.85.90]) by smtp.gmail.com with ESMTPSA id 90sm1694862otb.53.2017.05.31.21.50.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 May 2017 21:50:32 -0700 (PDT) From: shirishpargaonkar@gmail.com To: smfrench@gmail.com Cc: linux-cifs@vger.kernel.org, Shirish Pargaonkar Subject: [PATCH 2/2] cifs: Use smb 2 - 3 and cifsacl mount options getacl functions Date: Wed, 31 May 2017 23:50:24 -0500 Message-Id: <1496292624-8818-1-git-send-email-shirishpargaonkar@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Shirish Pargaonkar Fill in smb2/3 query acl functions in ops structures and use them. Signed-off-by: Shirish Pargaonkar Reviewed-by: Pavel Shilovsky --- fs/cifs/smb2ops.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index c586918..7157f52 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1288,6 +1288,107 @@ static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon, return rc; } +static struct cifs_ntsd * +get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb, + const struct cifs_fid *cifsfid, u32 *pacllen) +{ + struct cifs_ntsd *pntsd = NULL; + unsigned int xid; + int rc = -EOPNOTSUPP; + struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); + + if (IS_ERR(tlink)) + return ERR_CAST(tlink); + + xid = get_xid(); + cifs_dbg(VFS, "trying to get acl\n"); + + rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid, + cifsfid->volatile_fid, (void **)&pntsd, pacllen); + free_xid(xid); + + cifs_put_tlink(tlink); + + cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen); + if (rc) + return ERR_PTR(rc); + return pntsd; + +} + +static struct cifs_ntsd * +get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb, + const char *path, u32 *pacllen) +{ + struct cifs_ntsd *pntsd = NULL; + u8 oplock = SMB2_OPLOCK_LEVEL_NONE; + unsigned int xid; + int rc; + struct cifs_tcon *tcon; + struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); + struct cifs_fid fid; + struct cifs_open_parms oparms; + __le16 *utf16_path; + + cifs_dbg(FYI, "get smb3 acl for path %s\n", path); + if (IS_ERR(tlink)) + return ERR_CAST(tlink); + + tcon = tlink_tcon(tlink); + xid = get_xid(); + + if (backup_cred(cifs_sb)) + oparms.create_options |= CREATE_OPEN_BACKUP_INTENT; + else + oparms.create_options = 0; + + utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); + if (!utf16_path) + return ERR_PTR(-ENOMEM); + + oparms.tcon = tcon; + oparms.desired_access = READ_CONTROL; + oparms.disposition = FILE_OPEN; + oparms.fid = &fid; + oparms.reconnect = false; + + rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); + kfree(utf16_path); + if (!rc) { + rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid, + fid.volatile_fid, (void **)&pntsd, pacllen); + SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); + } + + cifs_put_tlink(tlink); + free_xid(xid); + + cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen); + if (rc) + return ERR_PTR(rc); + return pntsd; +} + +/* Retrieve an ACL from the server */ +static struct cifs_ntsd * +get_smb2_acl(struct cifs_sb_info *cifs_sb, + struct inode *inode, const char *path, + u32 *pacllen) +{ + struct cifs_ntsd *pntsd = NULL; + struct cifsFileInfo *open_file = NULL; + + if (inode) + open_file = find_readable_file(CIFS_I(inode), true); + if (!open_file) + return get_smb2_acl_by_path(cifs_sb, path, pacllen); + + pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen); + cifsFileInfo_put(open_file); + return pntsd; +} + + static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, loff_t offset, loff_t len, bool keep_size) { @@ -2391,6 +2492,11 @@ struct smb_version_operations smb20_operations = { .dir_needs_close = smb2_dir_needs_close, .get_dfs_refer = smb2_get_dfs_refer, .select_sectype = smb2_select_sectype, +#ifdef CONFIG_CIFS_ACL + .get_acl = get_smb2_acl, + .get_acl_by_fid = get_smb2_acl_by_fid, +/* .set_acl = set_smb3_acl, */ +#endif /* CIFS_ACL */ }; struct smb_version_operations smb21_operations = { @@ -2475,6 +2581,11 @@ struct smb_version_operations smb21_operations = { .enum_snapshots = smb3_enum_snapshots, .get_dfs_refer = smb2_get_dfs_refer, .select_sectype = smb2_select_sectype, +#ifdef CONFIG_CIFS_ACL + .get_acl = get_smb2_acl, + .get_acl_by_fid = get_smb2_acl_by_fid, +/* .set_acl = set_smb3_acl, */ +#endif /* CIFS_ACL */ }; struct smb_version_operations smb30_operations = { @@ -2569,6 +2680,11 @@ struct smb_version_operations smb30_operations = { .receive_transform = smb3_receive_transform, .get_dfs_refer = smb2_get_dfs_refer, .select_sectype = smb2_select_sectype, +#ifdef CONFIG_CIFS_ACL + .get_acl = get_smb2_acl, + .get_acl_by_fid = get_smb2_acl_by_fid, +/* .set_acl = set_smb3_acl, */ +#endif /* CIFS_ACL */ }; #ifdef CONFIG_CIFS_SMB311 @@ -2664,6 +2780,11 @@ struct smb_version_operations smb311_operations = { .receive_transform = smb3_receive_transform, .get_dfs_refer = smb2_get_dfs_refer, .select_sectype = smb2_select_sectype, +#ifdef CONFIG_CIFS_ACL + .get_acl = get_smb2_acl, + .get_acl_by_fid = get_smb2_acl_by_fid, +/* .set_acl = set_smb3_acl, */ +#endif /* CIFS_ACL */ }; #endif /* CIFS_SMB311 */