]> git.apps.os.sepia.ceph.com Git - ceph-client.git/commitdiff
ceph: add ceph_encode_encrypted_dname() helper
authorXiubo Li <xiubli@redhat.com>
Mon, 14 Mar 2022 02:28:35 +0000 (10:28 +0800)
committerJeff Layton <jlayton@kernel.org>
Tue, 31 May 2022 15:49:59 +0000 (11:49 -0400)
Add a new helper that basically calls ceph_encode_encrypted_fname, but
with a qstr pointer instead of a dentry pointer. This will make it
simpler to decrypt names in a readdir reply, before we have a dentry.

Signed-off-by: Xiubo Li <xiubli@redhat.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
fs/ceph/crypto.c
fs/ceph/crypto.h

index 6fb2fd1a8af06449489ee431483822169e693ff9..05498859eef50687dc90bf3f43deefbbcaac633b 100644 (file)
@@ -188,7 +188,7 @@ void ceph_fscrypt_as_ctx_to_req(struct ceph_mds_request *req, struct ceph_acl_se
        swap(req->r_fscrypt_auth, as->fscrypt_auth);
 }
 
-int ceph_encode_encrypted_fname(const struct inode *parent, struct dentry *dentry, char *buf)
+int ceph_encode_encrypted_dname(const struct inode *parent, struct qstr *d_name, char *buf)
 {
        u32 len;
        int elen;
@@ -203,7 +203,7 @@ int ceph_encode_encrypted_fname(const struct inode *parent, struct dentry *dentr
         *
         * See: fscrypt_setup_filename
         */
-       if (!fscrypt_fname_encrypted_size(parent, dentry->d_name.len, NAME_MAX, &len))
+       if (!fscrypt_fname_encrypted_size(parent, d_name->len, NAME_MAX, &len))
                return -ENAMETOOLONG;
 
        /* Allocate a buffer appropriate to hold the result */
@@ -211,7 +211,7 @@ int ceph_encode_encrypted_fname(const struct inode *parent, struct dentry *dentr
        if (!cryptbuf)
                return -ENOMEM;
 
-       ret = fscrypt_fname_encrypt(parent, &dentry->d_name, cryptbuf, len);
+       ret = fscrypt_fname_encrypt(parent, d_name, cryptbuf, len);
        if (ret) {
                kfree(cryptbuf);
                return ret;
@@ -235,6 +235,11 @@ int ceph_encode_encrypted_fname(const struct inode *parent, struct dentry *dentr
        return elen;
 }
 
+int ceph_encode_encrypted_fname(const struct inode *parent, struct dentry *dentry, char *buf)
+{
+       return ceph_encode_encrypted_dname(parent, &dentry->d_name, buf);
+}
+
 /**
  * ceph_fname_to_usr - convert a filename for userland presentation
  * @fname: ceph_fname to be converted
index f231d6e3ba0f6bf82a88ad7a05162e3b1ba2af2b..704e5a0e96f7a47414a98b49e88658caafc5ccdd 100644 (file)
@@ -75,6 +75,7 @@ void ceph_fscrypt_free_dummy_policy(struct ceph_fs_client *fsc);
 int ceph_fscrypt_prepare_context(struct inode *dir, struct inode *inode,
                                 struct ceph_acl_sec_ctx *as);
 void ceph_fscrypt_as_ctx_to_req(struct ceph_mds_request *req, struct ceph_acl_sec_ctx *as);
+int ceph_encode_encrypted_dname(const struct inode *parent, struct qstr *d_name, char *buf);
 int ceph_encode_encrypted_fname(const struct inode *parent, struct dentry *dentry, char *buf);
 
 static inline int ceph_fname_alloc_buffer(struct inode *parent, struct fscrypt_str *fname)
@@ -116,6 +117,13 @@ static inline void ceph_fscrypt_as_ctx_to_req(struct ceph_mds_request *req,
 {
 }
 
+static inline int ceph_encode_encrypted_dname(const struct inode *parent,
+                                             struct qstr *d_name, char *buf)
+{
+       memcpy(buf, d_name->name, d_name->len);
+       return d_name->len;
+}
+
 static inline int ceph_encode_encrypted_fname(const struct inode *parent,
                                                struct dentry *dentry, char *buf)
 {