]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/xfs/xfs_attr.c
[XFS] Kill attr_capable checks as already done in xattr_permission.
[linux-2.6-omap-h63xx.git] / fs / xfs / xfs_attr.c
index 7ce44a7b88a246de3effe15bd9ab8f0aa680b095..86d8619f279c857b889f4e7e4f1b43f4731e2c99 100644 (file)
@@ -49,6 +49,7 @@
 #include "xfs_trans_space.h"
 #include "xfs_acl.h"
 #include "xfs_rw.h"
+#include "xfs_vnodeops.h"
 
 /*
  * xfs_attr.c
@@ -100,14 +101,28 @@ STATIC int xfs_attr_rmtval_remove(xfs_da_args_t *args);
 ktrace_t *xfs_attr_trace_buf;
 #endif
 
+STATIC int
+xfs_attr_name_to_xname(
+       struct xfs_name *xname,
+       const char      *aname)
+{
+       if (!aname)
+               return EINVAL;
+       xname->name = aname;
+       xname->len = strlen(aname);
+       if (xname->len >= MAXNAMELEN)
+               return EFAULT;          /* match IRIX behaviour */
+
+       return 0;
+}
 
 /*========================================================================
  * Overall external interface routines.
  *========================================================================*/
 
 int
-xfs_attr_fetch(xfs_inode_t *ip, const char *name, int namelen,
-              char *value, int *valuelenp, int flags, struct cred *cred)
+xfs_attr_fetch(xfs_inode_t *ip, struct xfs_name *name,
+               char *value, int *valuelenp, int flags)
 {
        xfs_da_args_t   args;
        int             error;
@@ -121,8 +136,8 @@ xfs_attr_fetch(xfs_inode_t *ip, const char *name, int namelen,
         * Fill in the arg structure for this request.
         */
        memset((char *)&args, 0, sizeof(args));
-       args.name = name;
-       args.namelen = namelen;
+       args.name = name->name;
+       args.namelen = name->len;
        args.value = value;
        args.valuelen = *valuelenp;
        args.flags = flags;
@@ -156,32 +171,34 @@ xfs_attr_fetch(xfs_inode_t *ip, const char *name, int namelen,
 }
 
 int
-xfs_attr_get(bhv_desc_t *bdp, const char *name, char *value, int *valuelenp,
-            int flags, struct cred *cred)
+xfs_attr_get(
+       xfs_inode_t     *ip,
+       const char      *name,
+       char            *value,
+       int             *valuelenp,
+       int             flags)
 {
-       xfs_inode_t     *ip = XFS_BHVTOI(bdp);
-       int             error, namelen;
+       int             error;
+       struct xfs_name xname;
 
        XFS_STATS_INC(xs_attr_get);
 
-       if (!name)
-               return(EINVAL);
-       namelen = strlen(name);
-       if (namelen >= MAXNAMELEN)
-               return(EFAULT);         /* match IRIX behaviour */
-
        if (XFS_FORCED_SHUTDOWN(ip->i_mount))
                return(EIO);
 
+       error = xfs_attr_name_to_xname(&xname, name);
+       if (error)
+               return error;
+
        xfs_ilock(ip, XFS_ILOCK_SHARED);
-       error = xfs_attr_fetch(ip, name, namelen, value, valuelenp, flags, cred);
+       error = xfs_attr_fetch(ip, &xname, value, valuelenp, flags);
        xfs_iunlock(ip, XFS_ILOCK_SHARED);
        return(error);
 }
 
-int
-xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
-                char *value, int valuelen, int flags)
+STATIC int
+xfs_attr_set_int(xfs_inode_t *dp, struct xfs_name *name,
+               char *value, int valuelen, int flags)
 {
        xfs_da_args_t   args;
        xfs_fsblock_t   firstblock;
@@ -204,7 +221,7 @@ xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
         */
        if (XFS_IFORK_Q(dp) == 0) {
                int sf_size = sizeof(xfs_attr_sf_hdr_t) +
-                             XFS_ATTR_SF_ENTSIZE_BYNAME(namelen, valuelen);
+                             XFS_ATTR_SF_ENTSIZE_BYNAME(name->len, valuelen);
 
                if ((error = xfs_bmap_add_attrfork(dp, sf_size, rsvd)))
                        return(error);
@@ -214,8 +231,8 @@ xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
         * Fill in the arg structure for this request.
         */
        memset((char *)&args, 0, sizeof(args));
-       args.name = name;
-       args.namelen = namelen;
+       args.name = name->name;
+       args.namelen = name->len;
        args.value = value;
        args.valuelen = valuelen;
        args.flags = flags;
@@ -231,7 +248,7 @@ xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
         * Determine space new attribute will use, and if it would be
         * "local" or "remote" (note: local != inline).
         */
-       size = xfs_attr_leaf_newentsize(namelen, valuelen,
+       size = xfs_attr_leaf_newentsize(name->len, valuelen,
                                        mp->m_sb.sb_blocksize, &local);
 
        nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
@@ -417,31 +434,34 @@ out:
 }
 
 int
-xfs_attr_set(bhv_desc_t *bdp, const char *name, char *value, int valuelen, int flags,
-            struct cred *cred)
+xfs_attr_set(
+       xfs_inode_t     *dp,
+       const char      *name,
+       char            *value,
+       int             valuelen,
+       int             flags)
 {
-       xfs_inode_t     *dp;
-       int             namelen;
-
-       namelen = strlen(name);
-       if (namelen >= MAXNAMELEN)
-               return EFAULT;          /* match IRIX behaviour */
+       int             error;
+       struct xfs_name xname;
 
        XFS_STATS_INC(xs_attr_set);
 
-       dp = XFS_BHVTOI(bdp);
        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return (EIO);
 
-       return xfs_attr_set_int(dp, name, namelen, value, valuelen, flags);
+       error = xfs_attr_name_to_xname(&xname, name);
+       if (error)
+               return error;
+
+       return xfs_attr_set_int(dp, &xname, value, valuelen, flags);
 }
 
 /*
  * Generic handler routine to remove a name from an attribute list.
  * Transitions attribute list from Btree to shortform as necessary.
  */
-int
-xfs_attr_remove_int(xfs_inode_t *dp, const char *name, int namelen, int flags)
+STATIC int
+xfs_attr_remove_int(xfs_inode_t *dp, struct xfs_name *name, int flags)
 {
        xfs_da_args_t   args;
        xfs_fsblock_t   firstblock;
@@ -453,8 +473,8 @@ xfs_attr_remove_int(xfs_inode_t *dp, const char *name, int namelen, int flags)
         * Fill in the arg structure for this request.
         */
        memset((char *)&args, 0, sizeof(args));
-       args.name = name;
-       args.namelen = namelen;
+       args.name = name->name;
+       args.namelen = name->len;
        args.flags = flags;
        args.hashval = xfs_da_hashname(args.name, args.namelen);
        args.dp = dp;
@@ -563,21 +583,23 @@ out:
 }
 
 int
-xfs_attr_remove(bhv_desc_t *bdp, const char *name, int flags, struct cred *cred)
+xfs_attr_remove(
+       xfs_inode_t     *dp,
+       const char      *name,
+       int             flags)
 {
-       xfs_inode_t         *dp;
-       int                 namelen;
-
-       namelen = strlen(name);
-       if (namelen >= MAXNAMELEN)
-               return EFAULT;          /* match IRIX behaviour */
+       int             error;
+       struct xfs_name xname;
 
        XFS_STATS_INC(xs_attr_remove);
 
-       dp = XFS_BHVTOI(bdp);
        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return (EIO);
 
+       error = xfs_attr_name_to_xname(&xname, name);
+       if (error)
+               return error;
+
        xfs_ilock(dp, XFS_ILOCK_SHARED);
        if (XFS_IFORK_Q(dp) == 0 ||
                   (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
@@ -587,10 +609,10 @@ xfs_attr_remove(bhv_desc_t *bdp, const char *name, int flags, struct cred *cred)
        }
        xfs_iunlock(dp, XFS_ILOCK_SHARED);
 
-       return xfs_attr_remove_int(dp, name, namelen, flags);
+       return xfs_attr_remove_int(dp, &xname, flags);
 }
 
-int                                                            /* error */
+STATIC int
 xfs_attr_list_int(xfs_attr_list_context_t *context)
 {
        int error;
@@ -702,11 +724,14 @@ xfs_attr_kern_list_sizes(xfs_attr_list_context_t *context, attrnames_t *namesp,
  * success.
  */
 int
-xfs_attr_list(bhv_desc_t *bdp, char *buffer, int bufsize, int flags,
-                     attrlist_cursor_kern_t *cursor, struct cred *cred)
+xfs_attr_list(
+       xfs_inode_t     *dp,
+       char            *buffer,
+       int             bufsize,
+       int             flags,
+       attrlist_cursor_kern_t *cursor)
 {
        xfs_attr_list_context_t context;
-       xfs_inode_t *dp;
        int error;
 
        XFS_STATS_INC(xs_attr_list);
@@ -731,7 +756,7 @@ xfs_attr_list(bhv_desc_t *bdp, char *buffer, int bufsize, int flags,
        /*
         * Initialize the output buffer.
         */
-       context.dp = dp = XFS_BHVTOI(bdp);
+       context.dp = dp;
        context.cursor = cursor;
        context.count = 0;
        context.dupcnt = 0;
@@ -918,7 +943,7 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
  * This leaf block cannot have a "remote" value, we only call this routine
  * if bmap_one_block() says there is only one block (ie: no remote blks).
  */
-int
+STATIC int
 xfs_attr_leaf_addname(xfs_da_args_t *args)
 {
        xfs_inode_t *dp;
@@ -2502,7 +2527,7 @@ STATIC int
 attr_generic_set(
        bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
 {
-       return -bhv_vop_attr_set(vp, name, data, size, xflags, NULL);
+       return -xfs_attr_set(xfs_vtoi(vp), name, data, size, xflags);
 }
 
 STATIC int
@@ -2511,7 +2536,7 @@ attr_generic_get(
 {
        int     error, asize = size;
 
-       error = bhv_vop_attr_get(vp, name, data, &asize, xflags, NULL);
+       error = xfs_attr_get(xfs_vtoi(vp), name, data, &asize, xflags);
        if (!error)
                return asize;
        return -error;
@@ -2521,7 +2546,7 @@ STATIC int
 attr_generic_remove(
        bhv_vnode_t *vp, char *name, int xflags)
 {
-       return -bhv_vop_attr_remove(vp, name, xflags, NULL);
+       return -xfs_attr_remove(xfs_vtoi(vp), name, xflags);
 }
 
 STATIC int
@@ -2576,7 +2601,7 @@ attr_generic_list(
        attrlist_cursor_kern_t  cursor = { 0 };
        int                     error;
 
-       error = bhv_vop_attr_list(vp, data, size, xflags, &cursor, NULL);
+       error = xfs_attr_list(xfs_vtoi(vp), data, size, xflags, &cursor);
        if (error > 0)
                return -error;
        *result = -error;
@@ -2597,51 +2622,6 @@ attr_lookup_namespace(
        return NULL;
 }
 
-/*
- * Some checks to prevent people abusing EAs to get over quota:
- * - Don't allow modifying user EAs on devices/symlinks;
- * - Don't allow modifying user EAs if sticky bit set;
- */
-STATIC int
-attr_user_capable(
-       bhv_vnode_t     *vp,
-       cred_t          *cred)
-{
-       struct inode    *inode = vn_to_inode(vp);
-
-       if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
-               return -EPERM;
-       if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode) &&
-           !capable(CAP_SYS_ADMIN))
-               return -EPERM;
-       if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
-           (current_fsuid(cred) != inode->i_uid) && !capable(CAP_FOWNER))
-               return -EPERM;
-       return 0;
-}
-
-STATIC int
-attr_trusted_capable(
-       bhv_vnode_t     *vp,
-       cred_t          *cred)
-{
-       struct inode    *inode = vn_to_inode(vp);
-
-       if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
-               return -EPERM;
-       if (!capable(CAP_SYS_ADMIN))
-               return -EPERM;
-       return 0;
-}
-
-STATIC int
-attr_secure_capable(
-       bhv_vnode_t     *vp,
-       cred_t          *cred)
-{
-       return -ENOSECURITY;
-}
-
 STATIC int
 attr_system_set(
        bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
@@ -2692,7 +2672,6 @@ struct attrnames attr_system = {
        .attr_get       = attr_system_get,
        .attr_set       = attr_system_set,
        .attr_remove    = attr_system_remove,
-       .attr_capable   = (attrcapable_t)fs_noerr,
 };
 
 struct attrnames attr_trusted = {
@@ -2702,7 +2681,6 @@ struct attrnames attr_trusted = {
        .attr_get       = attr_generic_get,
        .attr_set       = attr_generic_set,
        .attr_remove    = attr_generic_remove,
-       .attr_capable   = attr_trusted_capable,
 };
 
 struct attrnames attr_secure = {
@@ -2712,7 +2690,6 @@ struct attrnames attr_secure = {
        .attr_get       = attr_generic_get,
        .attr_set       = attr_generic_set,
        .attr_remove    = attr_generic_remove,
-       .attr_capable   = attr_secure_capable,
 };
 
 struct attrnames attr_user = {
@@ -2721,7 +2698,6 @@ struct attrnames attr_user = {
        .attr_get       = attr_generic_get,
        .attr_set       = attr_generic_set,
        .attr_remove    = attr_generic_remove,
-       .attr_capable   = attr_user_capable,
 };
 
 struct attrnames *attr_namespaces[] =