Whamcloud - gitweb
LU-14651 llite: extend inode methods with user namespace arg
[fs/lustre-release.git] / libcfs / libcfs / crypto / policy.c
index 8d209e2..243b412 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/random.h>
 #include <linux/string.h>
 #include <linux/mount.h>
+#include <lustre_compat.h>
 #include "llcrypt_private.h"
 
 /**
@@ -282,6 +283,25 @@ static int set_encryption_policy(struct inode *inode,
        return lsi->lsi_cop->set_context(inode, &ctx, ctxsize, NULL);
 }
 
+/* Tell if an inode's encryption policy has filename encryption */
+bool llcrypt_policy_has_filename_enc(struct inode *inode)
+{
+       union llcrypt_policy policy;
+       int err;
+
+       err = llcrypt_get_policy(inode, &policy);
+       if (err)
+               return true;
+
+       if ((policy.version == LLCRYPT_POLICY_V1 &&
+            policy.v1.filenames_encryption_mode == LLCRYPT_MODE_NULL) ||
+           (policy.version == LLCRYPT_POLICY_V2 &&
+            policy.v2.filenames_encryption_mode == LLCRYPT_MODE_NULL))
+               return false;
+       return true;
+}
+EXPORT_SYMBOL(llcrypt_policy_has_filename_enc);
+
 int llcrypt_ioctl_set_policy(struct file *filp, const void __user *arg)
 {
        union llcrypt_policy policy;
@@ -314,7 +334,7 @@ int llcrypt_ioctl_set_policy(struct file *filp, const void __user *arg)
                return -EFAULT;
        policy.version = version;
 
-       if (!inode_owner_or_capable(inode))
+       if (!inode_owner_or_capable(&init_user_ns, inode))
                return -EACCES;
 
        ret = mnt_want_write_file(filp);