@@ -43,8 +43,17 @@ struct smb_snapshot_array {
/* snapshots[]; */
} __packed;
+struct smb_query_info {
+ __u32 buffer_length;
+ __u32 info_type;
+ __u32 file_info_class;
+ __u32 additional_information;
+ /* char buffer[]; */
+} __packed;
+
#define CIFS_IOCTL_MAGIC 0xCF
#define CIFS_IOC_COPYCHUNK_FILE _IOW(CIFS_IOCTL_MAGIC, 3, int)
#define CIFS_IOC_SET_INTEGRITY _IO(CIFS_IOCTL_MAGIC, 4)
#define CIFS_IOC_GET_MNT_INFO _IOR(CIFS_IOCTL_MAGIC, 5, struct smb_mnt_fs_info)
#define CIFS_ENUMERATE_SNAPSHOTS _IOR(CIFS_IOCTL_MAGIC, 6, struct smb_snapshot_array)
+#define CIFS_QUERY_INFO _IOWR(CIFS_IOCTL_MAGIC, 7, struct smb_query_info)
@@ -465,6 +465,10 @@ struct smb_version_operations {
enum securityEnum (*select_sectype)(struct TCP_Server_Info *,
enum securityEnum);
int (*next_header)(char *);
+ /* ioctl passthrough for query_info */
+ int (*ioctl_query_info)(const unsigned int xid,
+ struct cifsFileInfo *file,
+ unsigned long p);
};
struct smb_version_values {
@@ -34,6 +34,24 @@
#include "cifs_ioctl.h"
#include <linux/btrfs.h>
+static long cifs_ioctl_query_info(unsigned int xid, struct file *filep,
+ unsigned long p)
+{
+ struct cifsFileInfo *pSMBFile = filep->private_data;
+ struct cifs_tcon *tcon;
+
+ cifs_dbg(FYI, "cifs_ioctl_query_info %p\n", pSMBFile);
+ if (pSMBFile == NULL)
+ return -EISDIR;
+ tcon = tlink_tcon(pSMBFile->tlink);
+
+ if (tcon->ses->server->ops->ioctl_query_info)
+ return tcon->ses->server->ops->ioctl_query_info(
+ xid, pSMBFile, p);
+ else
+ return -EOPNOTSUPP;
+}
+
static long cifs_ioctl_copychunk(unsigned int xid, struct file *dst_file,
unsigned long srcfd)
{
@@ -196,6 +214,9 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
case CIFS_IOC_COPYCHUNK_FILE:
rc = cifs_ioctl_copychunk(xid, filep, arg);
break;
+ case CIFS_QUERY_INFO:
+ rc = cifs_ioctl_query_info(xid, filep, arg);
+ break;
case CIFS_IOC_SET_INTEGRITY:
if (pSMBFile == NULL)
break;
@@ -1057,6 +1057,69 @@ SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
return rc;
}
+static int
+smb2_ioctl_query_info(const unsigned int xid,
+ struct cifsFileInfo *file,
+ unsigned long p)
+{
+ struct cifs_tcon *tcon = tlink_tcon(file->tlink);
+ struct cifs_ses *ses = tcon->ses;
+ void __user *arg = (void __user *)p;
+ struct smb_query_info qi, *pqi;
+ int rc = 0;
+ int flags = 0;
+ struct smb_rqst rqst;
+ struct kvec iov[1];
+ struct kvec rsp_iov;
+ int resp_buftype;
+ struct smb2_query_info_rsp *rsp = NULL;
+
+ if (copy_from_user(&qi, arg, sizeof(struct smb_query_info)))
+ return -EFAULT;
+
+ if (!ses || !(ses->server))
+ return -EIO;
+
+ if (smb3_encryption_required(tcon))
+ flags |= CIFS_TRANSFORM_REQ;
+
+ memset(&rqst, 0, sizeof(struct smb_rqst));
+ memset(&iov, 0, sizeof(iov));
+ rqst.rq_iov = iov;
+ rqst.rq_nvec = 1;
+
+ rc = SMB2_query_info_init(tcon, &rqst, file->fid.persistent_fid,
+ file->fid.volatile_fid,
+ qi.file_info_class, qi.info_type,
+ qi.additional_information,
+ qi.buffer_length);
+ if (rc)
+ goto iqinf_exit;
+
+ rc = cifs_send_recv(xid, ses, &rqst, &resp_buftype, flags, &rsp_iov);
+ rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
+ if (rc)
+ goto iqinf_exit;
+
+ pqi = arg;
+ if (le32_to_cpu(rsp->OutputBufferLength) < qi.buffer_length)
+ qi.buffer_length = le32_to_cpu(rsp->OutputBufferLength);
+ if (copy_to_user(&pqi->buffer_length, &qi.buffer_length,
+ sizeof(qi.buffer_length))) {
+ rc = -EFAULT;
+ goto iqinf_exit;
+ }
+ if (copy_to_user(pqi + 1, rsp->Buffer, qi.buffer_length)) {
+ rc = -EFAULT;
+ goto iqinf_exit;
+ }
+
+ iqinf_exit:
+ SMB2_query_info_free(&rqst);
+ free_rsp_buf(resp_buftype, rsp);
+ return rc;
+}
+
static ssize_t
smb2_copychunk_range(const unsigned int xid,
struct cifsFileInfo *srcfile,
@@ -3303,6 +3366,7 @@ struct smb_version_operations smb20_operations = {
.set_acl = set_smb2_acl,
#endif /* CIFS_ACL */
.next_header = smb2_next_header,
+ .ioctl_query_info = smb2_ioctl_query_info,
};
struct smb_version_operations smb21_operations = {
@@ -3398,6 +3462,7 @@ struct smb_version_operations smb21_operations = {
.set_acl = set_smb2_acl,
#endif /* CIFS_ACL */
.next_header = smb2_next_header,
+ .ioctl_query_info = smb2_ioctl_query_info,
};
struct smb_version_operations smb30_operations = {
@@ -3502,6 +3567,7 @@ struct smb_version_operations smb30_operations = {
.set_acl = set_smb2_acl,
#endif /* CIFS_ACL */
.next_header = smb2_next_header,
+ .ioctl_query_info = smb2_ioctl_query_info,
};
struct smb_version_operations smb311_operations = {
@@ -3607,6 +3673,7 @@ struct smb_version_operations smb311_operations = {
.set_acl = set_smb2_acl,
#endif /* CIFS_ACL */
.next_header = smb2_next_header,
+ .ioctl_query_info = smb2_ioctl_query_info,
};
struct smb_version_values smb20_values = {
This allows userspace tools to query the raw info levels for cifs files and process the response in userspace. In particular this is useful for many of those data where there is no corresponding native data structure in linux. For example querying the security descriptor for a file and extract the SIDs. Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com> --- fs/cifs/cifs_ioctl.h | 9 +++++++ fs/cifs/cifsglob.h | 4 ++++ fs/cifs/ioctl.c | 21 ++++++++++++++++ fs/cifs/smb2ops.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+)