- if (!(mask & MAY_EXEC) ||
- (la->la_mode & S_IXUGO) || S_ISDIR(la->la_mode))
- if (mdd_capable(uc, CFS_CAP_DAC_OVERRIDE))
- RETURN(0);
-
- if ((mask == MAY_READ) ||
- (S_ISDIR(la->la_mode) && !(mask & MAY_WRITE)))
- if (mdd_capable(uc, CFS_CAP_DAC_READ_SEARCH))
- RETURN(0);
-
- RETURN(-EACCES);
-}
-
-int mdd_permission(const struct lu_env *env,
- struct md_object *pobj, struct md_object *cobj,
- struct md_attr *ma, int mask)
-{
- struct mdd_object *mdd_pobj, *mdd_cobj;
- struct md_ucred *uc = NULL;
- struct lu_attr *la = NULL;
- int check_create, check_link;
- int check_unlink;
- int check_rename_src, check_rename_tar;
- int check_vtx_part, check_vtx_full;
- int check_rgetfacl;
- int rc = 0;
- ENTRY;
-
- LASSERT(cobj);
- mdd_cobj = md2mdd_obj(cobj);
-
- /* For cross_open case, the "mask" is open flags,
- * so convert it to permission mask first.
- * XXX: MDS_OPEN_CROSS must be NOT equal to permission mask MAY_*. */
- if (unlikely(mask & MDS_OPEN_CROSS)) {
- la = &mdd_env_info(env)->mti_la;
- rc = mdd_la_get(env, mdd_cobj, la, BYPASS_CAPA);
- if (rc)
- RETURN(rc);
-
- mask = accmode(env, la, mask & ~MDS_OPEN_CROSS);
- }
-
- check_create = mask & MAY_CREATE;
- check_link = mask & MAY_LINK;
- check_unlink = mask & MAY_UNLINK;
- check_rename_src = mask & MAY_RENAME_SRC;
- check_rename_tar = mask & MAY_RENAME_TAR;
- check_vtx_part = mask & MAY_VTX_PART;
- check_vtx_full = mask & MAY_VTX_FULL;
- check_rgetfacl = mask & MAY_RGETFACL;
-
- mask &= ~(MAY_CREATE | MAY_LINK |
- MAY_UNLINK |
- MAY_RENAME_SRC | MAY_RENAME_TAR |
- MAY_VTX_PART | MAY_VTX_FULL |
- MAY_RGETFACL);
-
- rc = mdd_permission_internal_locked(env, mdd_cobj, NULL, mask,
- MOR_TGT_CHILD);
-
- if (!rc && (check_create || check_link))
- rc = mdd_may_create(env, mdd_cobj, NULL, 1, check_link);
-
- if (!rc && check_unlink) {
- LASSERT(ma);
- rc = mdd_may_unlink(env, mdd_cobj, ma);
- }
-
- if (!rc && (check_rename_src || check_rename_tar)) {
- LASSERT(pobj);
- LASSERT(ma);
- mdd_pobj = md2mdd_obj(pobj);
- rc = mdd_may_delete(env, mdd_pobj, mdd_cobj, ma, 1,
- check_rename_tar);
- }
-
- if (!rc && (check_vtx_part || check_vtx_full)) {
- uc = md_ucred(env);
- LASSERT(ma);
- if (likely(!la)) {
- la = &mdd_env_info(env)->mti_la;
- rc = mdd_la_get(env, mdd_cobj, la, BYPASS_CAPA);
- if (rc)
- RETURN(rc);
- }