-static int capa_is_sane(const struct lu_env *env,
- struct osd_device *dev,
- struct lustre_capa *capa,
- struct lustre_capa_key *keys)
-{
- struct osd_thread_info *oti = osd_oti_get(env);
- struct lustre_capa *tcapa = &oti->oti_capa;
- struct obd_capa *oc;
- int i, rc = 0;
- ENTRY;
-
- oc = capa_lookup(dev->od_capa_hash, capa, 0);
- if (oc) {
- if (capa_is_expired(oc)) {
- DEBUG_CAPA(D_ERROR, capa, "expired");
- rc = -ESTALE;
- }
- capa_put(oc);
- RETURN(rc);
- }
-
- if (capa_is_expired_sec(capa)) {
- DEBUG_CAPA(D_ERROR, capa, "expired");
- RETURN(-ESTALE);
- }
-
- spin_lock(&capa_lock);
- for (i = 0; i < 2; i++) {
- if (keys[i].lk_keyid == capa->lc_keyid) {
- oti->oti_capa_key = keys[i];
- break;
- }
- }
- spin_unlock(&capa_lock);
-
- if (i == 2) {
- DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
- RETURN(-ESTALE);
- }
-
- rc = capa_hmac(tcapa->lc_hmac, capa, oti->oti_capa_key.lk_key);
- if (rc)
- RETURN(rc);
-
- if (memcmp(tcapa->lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac))) {
- DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
- RETURN(-EACCES);
- }
-
- oc = capa_add(dev->od_capa_hash, capa);
- capa_put(oc);
-
- RETURN(0);
-}
-
-int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
- struct lustre_capa *capa, __u64 opc)
-{
- const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
- struct osd_device *osd = osd_dev(dt->do_lu.lo_dev);
- struct lu_capainfo *lci;
- int rc;
-
- if (!osd->od_fl_capa)
- return 0;
-
- if (capa == BYPASS_CAPA)
- return 0;
-
- lci = lu_capainfo_get(env);
- if (unlikely(lci == NULL))
- return 0;
-
- if (lci->lci_auth == LC_ID_NONE)
- return 0;
-
- if (capa == NULL) {
- CERROR("%s: no capability provided for FID "DFID": rc = %d\n",
- osd_name(osd), PFID(fid), -EACCES);
- return -EACCES;
- }
-
- if (!lu_fid_eq(fid, &capa->lc_fid)) {
- DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
- PFID(fid));
- return -EACCES;
- }
-
- if (!capa_opc_supported(capa, opc)) {
- DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
- return -EACCES;
- }
-
- rc = capa_is_sane(env, osd, capa, osd->od_capa_keys);
- if (rc != 0) {
- DEBUG_CAPA(D_ERROR, capa, "insane: rc = %d", rc);
- return -EACCES;
- }
-
- return 0;
-}
-