]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - fs/cifs/smb2ops.c
Merge tag 'kvm-4.13-2' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[karo-tx-linux.git] / fs / cifs / smb2ops.c
index 7e48561abd299012616428d28f256906a7c5381f..cfacf2c97e9418c991b7264f7b75ee271039b260 100644 (file)
@@ -1036,6 +1036,18 @@ smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
        return true;
 }
 
+static bool
+smb2_is_session_expired(char *buf)
+{
+       struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
+
+       if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED)
+               return false;
+
+       cifs_dbg(FYI, "Session expired\n");
+       return true;
+}
+
 static int
 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
                     struct cifsInodeInfo *cinode)
@@ -1288,6 +1300,165 @@ smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
        return rc;
 }
 
+#ifdef CONFIG_CIFS_ACL
+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(FYI, "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;
+}
+
+#ifdef CONFIG_CIFS_ACL
+static int
+set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
+               struct inode *inode, const char *path, int aclflag)
+{
+       u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
+       unsigned int xid;
+       int rc, access_flags = 0;
+       struct cifs_tcon *tcon;
+       struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
+       struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
+       struct cifs_fid fid;
+       struct cifs_open_parms oparms;
+       __le16 *utf16_path;
+
+       cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
+       if (IS_ERR(tlink))
+               return PTR_ERR(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;
+
+       if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
+               access_flags = WRITE_OWNER;
+       else
+               access_flags = WRITE_DAC;
+
+       utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
+       if (!utf16_path)
+               return -ENOMEM;
+
+       oparms.tcon = tcon;
+       oparms.desired_access = access_flags;
+       oparms.disposition = FILE_OPEN;
+       oparms.path = path;
+       oparms.fid = &fid;
+       oparms.reconnect = false;
+
+       rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
+       kfree(utf16_path);
+       if (!rc) {
+               rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
+                           fid.volatile_fid, pnntsd, acllen, aclflag);
+               SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
+       }
+
+       cifs_put_tlink(tlink);
+       free_xid(xid);
+       return rc;
+}
+#endif /* CIFS_ACL */
+
+/* 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;
+}
+#endif
+
 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
                            loff_t offset, loff_t len, bool keep_size)
 {
@@ -2058,6 +2229,13 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
                return -ENOTSUPP;
        }
 
+       if (server->ops->is_session_expired &&
+           server->ops->is_session_expired(buf)) {
+               cifs_reconnect(server);
+               wake_up(&server->response_q);
+               return -1;
+       }
+
        if (server->ops->is_status_pending &&
                        server->ops->is_status_pending(buf, server, 0))
                return -1;
@@ -2375,6 +2553,7 @@ struct smb_version_operations smb20_operations = {
        .close_dir = smb2_close_dir,
        .calc_smb_size = smb2_calc_size,
        .is_status_pending = smb2_is_status_pending,
+       .is_session_expired = smb2_is_session_expired,
        .oplock_response = smb2_oplock_response,
        .queryfs = smb2_queryfs,
        .mand_lock = smb2_mand_lock,
@@ -2393,6 +2572,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_smb2_acl,
+#endif /* CIFS_ACL */
 };
 
 struct smb_version_operations smb21_operations = {
@@ -2458,6 +2642,7 @@ struct smb_version_operations smb21_operations = {
        .close_dir = smb2_close_dir,
        .calc_smb_size = smb2_calc_size,
        .is_status_pending = smb2_is_status_pending,
+       .is_session_expired = smb2_is_session_expired,
        .oplock_response = smb2_oplock_response,
        .queryfs = smb2_queryfs,
        .mand_lock = smb2_mand_lock,
@@ -2477,6 +2662,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_smb2_acl,
+#endif /* CIFS_ACL */
 };
 
 struct smb_version_operations smb30_operations = {
@@ -2543,6 +2733,7 @@ struct smb_version_operations smb30_operations = {
        .close_dir = smb2_close_dir,
        .calc_smb_size = smb2_calc_size,
        .is_status_pending = smb2_is_status_pending,
+       .is_session_expired = smb2_is_session_expired,
        .oplock_response = smb2_oplock_response,
        .queryfs = smb2_queryfs,
        .mand_lock = smb2_mand_lock,
@@ -2571,6 +2762,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_smb2_acl,
+#endif /* CIFS_ACL */
 };
 
 #ifdef CONFIG_CIFS_SMB311
@@ -2638,6 +2834,7 @@ struct smb_version_operations smb311_operations = {
        .close_dir = smb2_close_dir,
        .calc_smb_size = smb2_calc_size,
        .is_status_pending = smb2_is_status_pending,
+       .is_session_expired = smb2_is_session_expired,
        .oplock_response = smb2_oplock_response,
        .queryfs = smb2_queryfs,
        .mand_lock = smb2_mand_lock,
@@ -2753,7 +2950,7 @@ struct smb_version_values smb302_values = {
 struct smb_version_values smb311_values = {
        .version_string = SMB311_VERSION_STRING,
        .protocol_id = SMB311_PROT_ID,
-       .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES,
+       .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
        .large_lock_type = 0,
        .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
        .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,