#include <linux/lustre_ucache.h>
#include <linux/lustre_gs.h>
#include <linux/lustre_fsfilt.h>
+
#include "mds_internal.h"
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4)
int mds_pack_gskey(struct obd_device *obd, struct lustre_msg *repmsg,
int *offset, struct mds_body *body, struct inode *inode)
{
- struct mds_obd *mds = &obd->u.mds;
struct crypto_key_md *md_key;
struct crypto_key *ckey;
__u32 buflen, *sizep;
int size, rc = 0;
ENTRY;
- if ((mds->mds_crypto_type != MKS_TYPE &&
- mds->mds_crypto_type != GKS_TYPE))
- RETURN(rc);
-
sizep = lustre_msg_buf(repmsg, (*offset)++, 4);
if (!sizep) {
CERROR("can't locate returned ckey size buf\n");
*sizep = cpu_to_le32(sizeof(*ckey));
OBD_ALLOC(md_key, sizeof(*md_key));
+ if (!md_key)
+ RETURN(-ENOMEM);
buflen = repmsg->buflens[*offset];
buf = lustre_msg_buf(repmsg, (*offset)++, buflen);
size = fsfilt_get_md(obd, inode, md_key, sizeof(*md_key),
- EA_KEY);
- if (size < 0) {
- CERROR("Can not get gskey from MDS ino %lu rc %d\n",
- inode->i_ino, size);
+ EA_KEY);
+ if (size <= 0) {
+ if (size < 0)
+ CERROR("Can not get gskey from MDS ino %lu rc %d\n",
+ inode->i_ino, size);
GOTO(out, rc = size);
}
if (le32_to_cpu(md_key->md_magic) != MD_KEY_MAGIC) {
RETURN(rc);
}
-static int mds_get_gskey(struct inode *inode, struct crypto_key_md *mkey)
+static int mds_get_gskey(struct inode *inode, struct crypto_key *ckey)
{
- LASSERT(mkey);
+ LASSERT(ckey);
/*tmp create gs key here*/
- get_random_bytes(mkey->md_ck.ck_key, KEY_SIZE);
- mkey->md_ck.ck_type = MKS_TYPE;
+ LASSERT(ckey->ck_type == MKS_TYPE);
+ get_random_bytes(ckey->ck_key, KEY_SIZE);
RETURN(0);
}
{
struct crypto_key_md *md_key = NULL;
struct crypto_key *ckey = (struct crypto_key *)key;
- struct mds_obd *mds = &obd->u.mds;
int rc = 0;
ENTRY;
- if ((mds->mds_crypto_type != MKS_TYPE &&
- mds->mds_crypto_type != GKS_TYPE)) {
- CDEBUG(D_INFO, "mds_crypto_type %d \n", mds->mds_crypto_type);
- RETURN(rc);
- }
+ if (!ckey)
+ RETURN(0);
+
+ LASSERT(ckey->ck_type == MKS_TYPE || ckey->ck_type == GKS_TYPE);
+
OBD_ALLOC(md_key, sizeof(*md_key));
- if (mds->mds_crypto_type == MKS_TYPE) {
- mds_get_gskey(inode, md_key);
- } else {
- LASSERT(ckey != NULL);
- }
+ if (ckey->ck_type == MKS_TYPE)
+ mds_get_gskey(inode, ckey);
+
rc = fsfilt_get_md(obd, inode, md_key, sizeof(*md_key),
EA_KEY);
if (rc < 0)
GOTO(free, rc);
LASSERT(le32_to_cpu(md_key->md_magic) == MD_KEY_MAGIC ||
md_key->md_magic == 0);
+
if (le32_to_cpu(md_key->md_magic) == MD_KEY_MAGIC) {
CDEBUG(D_INFO, "reset key %s mac %s", md_key->md_ck.ck_mac,
md_key->md_ck.ck_key);
}
md_key->md_magic = cpu_to_le32(MD_KEY_MAGIC);
- if (mds->mds_crypto_type == GKS_TYPE) {
/*get key and mac from request buffer*/
- if (valid & ATTR_MAC) {
- memcpy(md_key->md_ck.ck_mac, ckey->ck_mac, MAC_SIZE);
+ if (valid & ATTR_MAC) {
+ memcpy(md_key->md_ck.ck_mac, ckey->ck_mac, MAC_SIZE);
CDEBUG(D_INFO, "set mac %s for ino %lu \n",
md_key->md_ck.ck_mac, inode->i_ino);
- }
- if (valid & ATTR_KEY) {
- memcpy(md_key->md_ck.ck_key, ckey->ck_key, KEY_SIZE);
- CDEBUG(D_INFO, "set key %s for ino %lu \n",
+ }
+ if (valid & ATTR_KEY) {
+ memcpy(md_key->md_ck.ck_key, ckey->ck_key, KEY_SIZE);
+ CDEBUG(D_INFO, "set key %s for ino %lu \n",
md_key->md_ck.ck_key, inode->i_ino);
- }
}
- rc = fsfilt_set_md(obd, inode, handle, md_key,
- sizeof(*md_key), EA_KEY);
+ rc = fsfilt_set_md(obd, inode, handle, md_key, sizeof(*md_key), EA_KEY);
free:
if (md_key)
OBD_FREE(md_key, sizeof(*md_key));
{
struct mds_obd *mds = &obd->u.mds;
ENTRY;
-
if (vallen >= strlen("mks") &&
memcmp(val, "mks", vallen) == 0) {
mds->mds_crypto_type = MKS_TYPE;
r->ur_rdev = rec->cr_rdev;
r->ur_time = rec->cr_time;
r->ur_flags = rec->cr_flags;
+ r->ur_ioepoch = rec->cr_ioepoch;
LASSERT_REQSWAB(req, offset + 1);
r->ur_name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0);
EXIT;
}
+/*
+ * return error if can't find mapping, it's a error so should not
+ * fall into nllu/nllg.
+ */
+int mds_remote_perm_do_reverse_map(struct mds_export_data *med,
+ struct mds_remote_perm *perm)
+{
+ uid_t uid;
+ gid_t gid;
+
+ LASSERT(med->med_remote);
+
+ uid = mds_idmap_lookup_uid(med->med_idmap, 1, perm->mrp_auth_uid);
+ if (uid == MDS_IDMAP_NOTFOUND) {
+ CERROR("no map for uid %u\n", perm->mrp_auth_uid);
+ return -EPERM;
+ }
+ gid = mds_idmap_lookup_gid(med->med_idmap, 1, perm->mrp_auth_gid);
+ if (gid == MDS_IDMAP_NOTFOUND) {
+ CERROR("no map for uid %u\n", perm->mrp_auth_uid);
+ return -EPERM;
+ }
+
+ perm->mrp_auth_uid = uid;
+ perm->mrp_auth_gid = gid;
+ return 0;
+}
+
/**********************
* MDS ucred handling *
**********************/
drop_ucred_lsd(ucred);
EXIT;
}
+