Commit c5230112 authored by Marius Aamodt Eriksen's avatar Marius Aamodt Eriksen Committed by Trond Myklebust

Add hooks into the NFSv4 XDR code to make use of the new uid/gid

mapper upcall mechanism.
parent 8e8c637b
...@@ -596,11 +596,13 @@ nfs4_do_open(struct inode *dir, struct qstr *name, int flags, ...@@ -596,11 +596,13 @@ nfs4_do_open(struct inode *dir, struct qstr *name, int flags,
.name = name, .name = name,
.f_getattr = &f_getattr, .f_getattr = &f_getattr,
.d_getattr = &d_getattr, .d_getattr = &d_getattr,
.server = server,
}; };
struct nfs_openres o_res = { struct nfs_openres o_res = {
.cinfo = &d_cinfo, .cinfo = &d_cinfo,
.f_getattr = &f_getattr, .f_getattr = &f_getattr,
.d_getattr = &d_getattr, .d_getattr = &d_getattr,
.server = server,
}; };
struct rpc_message msg = { struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
...@@ -685,9 +687,11 @@ nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr, ...@@ -685,9 +687,11 @@ nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr,
.fh = fhandle, .fh = fhandle,
.iap = sattr, .iap = sattr,
.attr = &getattr, .attr = &getattr,
.server = server,
}; };
struct nfs_setattrres res = { struct nfs_setattrres res = {
.attr = &getattr, .attr = &getattr,
.server = server,
}; };
struct rpc_message msg = { struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include <linux/nfs.h> #include <linux/nfs.h>
#include <linux/nfs4.h> #include <linux/nfs4.h>
#include <linux/nfs_fs.h> #include <linux/nfs_fs.h>
#include <linux/nfs_idmap.h>
#define NFSDBG_FACILITY NFSDBG_XDR #define NFSDBG_FACILITY NFSDBG_XDR
...@@ -233,30 +234,9 @@ encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) ...@@ -233,30 +234,9 @@ encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
return 0; return 0;
} }
/*
* FIXME: The following dummy entries will be replaced once the userland
* upcall gets in...
*/
static int
encode_uid(char *p, uid_t uid)
{
strcpy(p, "nobody");
return 6;
}
/*
* FIXME: The following dummy entries will be replaced once the userland
* upcall gets in...
*/
static int static int
encode_gid(char *p, gid_t gid) encode_attrs(struct xdr_stream *xdr, struct iattr *iap,
{ struct nfs_server *server)
strcpy(p, "nobody");
return 6;
}
static int
encode_attrs(struct xdr_stream *xdr, struct iattr *iap)
{ {
char owner_name[256]; char owner_name[256];
char owner_group[256]; char owner_group[256];
...@@ -284,20 +264,27 @@ encode_attrs(struct xdr_stream *xdr, struct iattr *iap) ...@@ -284,20 +264,27 @@ encode_attrs(struct xdr_stream *xdr, struct iattr *iap)
if (iap->ia_valid & ATTR_MODE) if (iap->ia_valid & ATTR_MODE)
len += 4; len += 4;
if (iap->ia_valid & ATTR_UID) { if (iap->ia_valid & ATTR_UID) {
status = owner_namelen = encode_uid(owner_name, iap->ia_uid); status = nfs_idmap_name(server, IDMAP_TYPE_USER,
iap->ia_uid, owner_name, &owner_namelen);
if (status < 0) { if (status < 0) {
printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n", printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
iap->ia_uid); iap->ia_uid);
goto out; /* XXX */
strcpy(owner_name, "nobody");
owner_namelen = sizeof("nobody") - 1;
/* goto out; */
} }
len += 4 + (XDR_QUADLEN(owner_namelen) << 2); len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
} }
if (iap->ia_valid & ATTR_GID) { if (iap->ia_valid & ATTR_GID) {
status = owner_grouplen = encode_gid(owner_group, iap->ia_gid); status = nfs_idmap_name(server, IDMAP_TYPE_GROUP,
iap->ia_gid, owner_group, &owner_grouplen);
if (status < 0) { if (status < 0) {
printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n", printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
iap->ia_gid); iap->ia_gid);
goto out; strcpy(owner_group, "nobody");
owner_grouplen = sizeof("nobody") - 1;
/* goto out; */
} }
len += 4 + (XDR_QUADLEN(owner_grouplen) << 2); len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
} }
...@@ -417,7 +404,8 @@ encode_commit(struct xdr_stream *xdr, struct nfs_writeargs *args) ...@@ -417,7 +404,8 @@ encode_commit(struct xdr_stream *xdr, struct nfs_writeargs *args)
} }
static int static int
encode_create(struct xdr_stream *xdr, struct nfs4_create *create) encode_create(struct xdr_stream *xdr, struct nfs4_create *create,
struct nfs_server *server)
{ {
uint32_t *p; uint32_t *p;
...@@ -446,7 +434,7 @@ encode_create(struct xdr_stream *xdr, struct nfs4_create *create) ...@@ -446,7 +434,7 @@ encode_create(struct xdr_stream *xdr, struct nfs4_create *create)
WRITE32(create->cr_namelen); WRITE32(create->cr_namelen);
WRITEMEM(create->cr_name, create->cr_namelen); WRITEMEM(create->cr_name, create->cr_namelen);
return encode_attrs(xdr, create->cr_attrs); return encode_attrs(xdr, create->cr_attrs, server);
} }
static int static int
...@@ -589,7 +577,7 @@ encode_open(struct xdr_stream *xdr, struct nfs_openargs *arg) ...@@ -589,7 +577,7 @@ encode_open(struct xdr_stream *xdr, struct nfs_openargs *arg)
else if (arg->u.attrs) { else if (arg->u.attrs) {
RESERVE_SPACE(4); RESERVE_SPACE(4);
WRITE32(arg->createmode); WRITE32(arg->createmode);
if ((status = encode_attrs(xdr, arg->u.attrs))) if ((status = encode_attrs(xdr, arg->u.attrs, arg->server)))
return status; return status;
} }
else { else {
...@@ -774,7 +762,8 @@ encode_savefh(struct xdr_stream *xdr) ...@@ -774,7 +762,8 @@ encode_savefh(struct xdr_stream *xdr)
} }
static int static int
encode_setattr(struct xdr_stream *xdr, struct nfs_setattrargs *arg) encode_setattr(struct xdr_stream *xdr, struct nfs_setattrargs *arg,
struct nfs_server *server)
{ {
int status; int status;
uint32_t *p; uint32_t *p;
...@@ -783,7 +772,7 @@ encode_setattr(struct xdr_stream *xdr, struct nfs_setattrargs *arg) ...@@ -783,7 +772,7 @@ encode_setattr(struct xdr_stream *xdr, struct nfs_setattrargs *arg)
WRITE32(OP_SETATTR); WRITE32(OP_SETATTR);
WRITEMEM(arg->stateid, sizeof(nfs4_stateid)); WRITEMEM(arg->stateid, sizeof(nfs4_stateid));
if ((status = encode_attrs(xdr, arg->iap))) if ((status = encode_attrs(xdr, arg->iap, server)))
return status; return status;
return 0; return 0;
...@@ -866,7 +855,7 @@ encode_compound(struct xdr_stream *xdr, struct nfs4_compound *cp, struct rpc_rqs ...@@ -866,7 +855,7 @@ encode_compound(struct xdr_stream *xdr, struct nfs4_compound *cp, struct rpc_rqs
status = encode_access(xdr, &cp->ops[i].u.access); status = encode_access(xdr, &cp->ops[i].u.access);
break; break;
case OP_CREATE: case OP_CREATE:
status = encode_create(xdr, &cp->ops[i].u.create); status = encode_create(xdr, &cp->ops[i].u.create, cp->server);
break; break;
case OP_GETATTR: case OP_GETATTR:
status = encode_getattr(xdr, &cp->ops[i].u.getattr); status = encode_getattr(xdr, &cp->ops[i].u.getattr);
...@@ -983,7 +972,7 @@ nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args) ...@@ -983,7 +972,7 @@ nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
status = encode_savefh(&xdr); status = encode_savefh(&xdr);
if (status) if (status)
goto out; goto out;
status = encode_open(&xdr,args); status = encode_open(&xdr, args);
if (status) if (status)
goto out; goto out;
status = encode_getattr(&xdr, args->f_getattr); status = encode_getattr(&xdr, args->f_getattr);
...@@ -1063,6 +1052,7 @@ nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args) ...@@ -1063,6 +1052,7 @@ nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
*/ */
static int static int
nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args) nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
{ {
struct xdr_stream xdr; struct xdr_stream xdr;
struct compound_hdr hdr = { struct compound_hdr hdr = {
...@@ -1075,7 +1065,7 @@ nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs * ...@@ -1075,7 +1065,7 @@ nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *
status = encode_putfh(&xdr, args->fh); status = encode_putfh(&xdr, args->fh);
if(status) if(status)
goto out; goto out;
status = encode_setattr(&xdr, args); status = encode_setattr(&xdr, args, args->server);
if(status) if(status)
goto out; goto out;
status = encode_getattr(&xdr, args->attr); status = encode_getattr(&xdr, args->attr);
...@@ -1182,28 +1172,6 @@ xdr_error: \ ...@@ -1182,28 +1172,6 @@ xdr_error: \
} \ } \
} while (0) } while (0)
/*
* FIXME: The following dummy entry will be replaced once the userland
* upcall gets in...
*/
static int
decode_uid(char *p, uint32_t len, uid_t *uid)
{
*uid = -2;
return 0;
}
/*
* FIXME: The following dummy entry will be replaced once the userland
* upcall gets in...
*/
static int
decode_gid(char *p, uint32_t len, gid_t *gid)
{
*gid = -2;
return 0;
}
static int static int
decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr) decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
{ {
...@@ -1328,7 +1296,8 @@ extern uint32_t nfs4_fsstat_bitmap[2]; ...@@ -1328,7 +1296,8 @@ extern uint32_t nfs4_fsstat_bitmap[2];
extern uint32_t nfs4_pathconf_bitmap[2]; extern uint32_t nfs4_pathconf_bitmap[2];
static int static int
decode_getattr(struct xdr_stream *xdr, struct nfs4_getattr *getattr) decode_getattr(struct xdr_stream *xdr, struct nfs4_getattr *getattr,
struct nfs_server *server)
{ {
struct nfs_fattr *nfp = getattr->gt_attrs; struct nfs_fattr *nfp = getattr->gt_attrs;
struct nfs_fsstat *fsstat = getattr->gt_fsstat; struct nfs_fsstat *fsstat = getattr->gt_fsstat;
...@@ -1500,9 +1469,11 @@ decode_getattr(struct xdr_stream *xdr, struct nfs4_getattr *getattr) ...@@ -1500,9 +1469,11 @@ decode_getattr(struct xdr_stream *xdr, struct nfs4_getattr *getattr)
} }
READ_BUF(dummy32); READ_BUF(dummy32);
len += (XDR_QUADLEN(dummy32) << 2); len += (XDR_QUADLEN(dummy32) << 2);
if ((status = decode_uid((char *)p, dummy32, &nfp->uid))) { if ((status = nfs_idmap_id(server, IDMAP_TYPE_USER,
(char *)p, len, &nfp->uid)) == -1) {
dprintk("read_attrs: gss_get_num failed!\n"); dprintk("read_attrs: gss_get_num failed!\n");
goto out; /* goto out; */
nfp->uid = -2;
} }
dprintk("read_attrs: uid=%d\n", (int)nfp->uid); dprintk("read_attrs: uid=%d\n", (int)nfp->uid);
} }
...@@ -1516,9 +1487,11 @@ decode_getattr(struct xdr_stream *xdr, struct nfs4_getattr *getattr) ...@@ -1516,9 +1487,11 @@ decode_getattr(struct xdr_stream *xdr, struct nfs4_getattr *getattr)
} }
READ_BUF(dummy32); READ_BUF(dummy32);
len += (XDR_QUADLEN(dummy32) << 2); len += (XDR_QUADLEN(dummy32) << 2);
if ((status = decode_gid((char *)p, dummy32, &nfp->gid))) { if ((status = nfs_idmap_id(server, IDMAP_TYPE_GROUP,
(char *)p, len, &nfp->gid)) == -1) {
dprintk("read_attrs: gss_get_num failed!\n"); dprintk("read_attrs: gss_get_num failed!\n");
goto out; nfp->gid = -2;
/* goto out; */
} }
dprintk("read_attrs: gid=%d\n", (int)nfp->gid); dprintk("read_attrs: gid=%d\n", (int)nfp->gid);
} }
...@@ -2128,7 +2101,7 @@ decode_compound(struct xdr_stream *xdr, struct nfs4_compound *cp, struct rpc_rqs ...@@ -2128,7 +2101,7 @@ decode_compound(struct xdr_stream *xdr, struct nfs4_compound *cp, struct rpc_rqs
status = decode_create(xdr, &op->u.create); status = decode_create(xdr, &op->u.create);
break; break;
case OP_GETATTR: case OP_GETATTR:
status = decode_getattr(xdr, &op->u.getattr); status = decode_getattr(xdr, &op->u.getattr, cp->server);
break; break;
case OP_GETFH: case OP_GETFH:
status = decode_getfh(xdr, &op->u.getfh); status = decode_getfh(xdr, &op->u.getfh);
...@@ -2255,7 +2228,7 @@ nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res) ...@@ -2255,7 +2228,7 @@ nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
status = decode_open(&xdr, res); status = decode_open(&xdr, res);
if (status) if (status)
goto out; goto out;
status = decode_getattr(&xdr, res->f_getattr); status = decode_getattr(&xdr, res->f_getattr, res->server);
if (status) if (status)
goto out; goto out;
status = decode_getfh(&xdr, &gfh); status = decode_getfh(&xdr, &gfh);
...@@ -2264,7 +2237,7 @@ nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res) ...@@ -2264,7 +2237,7 @@ nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
status = decode_restorefh(&xdr); status = decode_restorefh(&xdr);
if (status) if (status)
goto out; goto out;
status = decode_getattr(&xdr, res->d_getattr); status = decode_getattr(&xdr, res->d_getattr, res->server);
if (status) if (status)
goto out; goto out;
out: out:
...@@ -2313,7 +2286,7 @@ nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres ...@@ -2313,7 +2286,7 @@ nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres
status = decode_setattr(&xdr, res); status = decode_setattr(&xdr, res);
if (status) if (status)
goto out; goto out;
status = decode_getattr(&xdr, res->attr); status = decode_getattr(&xdr, res->attr, res->server);
out: out:
return status; return status;
} }
......
...@@ -105,6 +105,7 @@ struct nfs_openargs { ...@@ -105,6 +105,7 @@ struct nfs_openargs {
struct qstr * name; struct qstr * name;
struct nfs4_getattr * f_getattr; struct nfs4_getattr * f_getattr;
struct nfs4_getattr * d_getattr; struct nfs4_getattr * d_getattr;
struct nfs_server * server; /* Needed for ID mapping */
}; };
struct nfs_openres { struct nfs_openres {
...@@ -115,6 +116,7 @@ struct nfs_openres { ...@@ -115,6 +116,7 @@ struct nfs_openres {
__u32 rflags; __u32 rflags;
struct nfs4_getattr * f_getattr; struct nfs4_getattr * f_getattr;
struct nfs4_getattr * d_getattr; struct nfs4_getattr * d_getattr;
struct nfs_server * server;
}; };
/* /*
...@@ -248,10 +250,12 @@ struct nfs_setattrargs { ...@@ -248,10 +250,12 @@ struct nfs_setattrargs {
nfs4_stateid stateid; nfs4_stateid stateid;
struct iattr * iap; struct iattr * iap;
struct nfs4_getattr * attr; struct nfs4_getattr * attr;
struct nfs_server * server; /* Needed for name mapping */
}; };
struct nfs_setattrres { struct nfs_setattrres {
struct nfs4_getattr * attr; struct nfs4_getattr * attr;
struct nfs_server * server;
}; };
struct nfs_linkargs { struct nfs_linkargs {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment