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,
.name = name,
.f_getattr = &f_getattr,
.d_getattr = &d_getattr,
.server = server,
};
struct nfs_openres o_res = {
.cinfo = &d_cinfo,
.f_getattr = &f_getattr,
.d_getattr = &d_getattr,
.server = server,
};
struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
......@@ -685,9 +687,11 @@ nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr,
.fh = fhandle,
.iap = sattr,
.attr = &getattr,
.server = server,
};
struct nfs_setattrres res = {
.attr = &getattr,
.server = server,
};
struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
......
......@@ -8,7 +8,7 @@
*
* Kendrick Smith <kmsmith@umich.edu>
* Andy Adamson <andros@umich.edu>
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
......@@ -50,6 +50,7 @@
#include <linux/nfs.h>
#include <linux/nfs4.h>
#include <linux/nfs_fs.h>
#include <linux/nfs_idmap.h>
#define NFSDBG_FACILITY NFSDBG_XDR
......@@ -233,30 +234,9 @@ encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
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
encode_gid(char *p, gid_t gid)
{
strcpy(p, "nobody");
return 6;
}
static int
encode_attrs(struct xdr_stream *xdr, struct iattr *iap)
encode_attrs(struct xdr_stream *xdr, struct iattr *iap,
struct nfs_server *server)
{
char owner_name[256];
char owner_group[256];
......@@ -284,20 +264,27 @@ encode_attrs(struct xdr_stream *xdr, struct iattr *iap)
if (iap->ia_valid & ATTR_MODE)
len += 4;
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) {
printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
iap->ia_uid);
goto out;
/* XXX */
strcpy(owner_name, "nobody");
owner_namelen = sizeof("nobody") - 1;
/* goto out; */
}
len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
}
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) {
printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
iap->ia_gid);
goto out;
strcpy(owner_group, "nobody");
owner_grouplen = sizeof("nobody") - 1;
/* goto out; */
}
len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
}
......@@ -417,7 +404,8 @@ encode_commit(struct xdr_stream *xdr, struct nfs_writeargs *args)
}
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;
......@@ -446,7 +434,7 @@ encode_create(struct xdr_stream *xdr, struct nfs4_create *create)
WRITE32(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
......@@ -589,7 +577,7 @@ encode_open(struct xdr_stream *xdr, struct nfs_openargs *arg)
else if (arg->u.attrs) {
RESERVE_SPACE(4);
WRITE32(arg->createmode);
if ((status = encode_attrs(xdr, arg->u.attrs)))
if ((status = encode_attrs(xdr, arg->u.attrs, arg->server)))
return status;
}
else {
......@@ -774,7 +762,8 @@ encode_savefh(struct xdr_stream *xdr)
}
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;
uint32_t *p;
......@@ -783,7 +772,7 @@ encode_setattr(struct xdr_stream *xdr, struct nfs_setattrargs *arg)
WRITE32(OP_SETATTR);
WRITEMEM(arg->stateid, sizeof(nfs4_stateid));
if ((status = encode_attrs(xdr, arg->iap)))
if ((status = encode_attrs(xdr, arg->iap, server)))
return status;
return 0;
......@@ -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);
break;
case OP_CREATE:
status = encode_create(xdr, &cp->ops[i].u.create);
status = encode_create(xdr, &cp->ops[i].u.create, cp->server);
break;
case OP_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)
status = encode_savefh(&xdr);
if (status)
goto out;
status = encode_open(&xdr,args);
status = encode_open(&xdr, args);
if (status)
goto out;
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)
*/
static int
nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
{
struct xdr_stream xdr;
struct compound_hdr hdr = {
......@@ -1075,7 +1065,7 @@ nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *
status = encode_putfh(&xdr, args->fh);
if(status)
goto out;
status = encode_setattr(&xdr, args);
status = encode_setattr(&xdr, args, args->server);
if(status)
goto out;
status = encode_getattr(&xdr, args->attr);
......@@ -1182,28 +1172,6 @@ xdr_error: \
} \
} 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
decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
{
......@@ -1328,7 +1296,8 @@ extern uint32_t nfs4_fsstat_bitmap[2];
extern uint32_t nfs4_pathconf_bitmap[2];
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_fsstat *fsstat = getattr->gt_fsstat;
......@@ -1492,35 +1461,39 @@ decode_getattr(struct xdr_stream *xdr, struct nfs4_getattr *getattr)
}
if (bmval1 & FATTR4_WORD1_OWNER) {
READ_BUF(4);
len += 4;
READ32(dummy32); /* name length */
if (dummy32 > XDR_MAX_NETOBJ) {
len += 4;
READ32(dummy32); /* name length */
if (dummy32 > XDR_MAX_NETOBJ) {
dprintk("read_attrs: name too long!\n");
goto xdr_error;
}
READ_BUF(dummy32);
len += (XDR_QUADLEN(dummy32) << 2);
if ((status = decode_uid((char *)p, dummy32, &nfp->uid))) {
dprintk("read_attrs: gss_get_num failed!\n");
goto out;
}
dprintk("read_attrs: uid=%d\n", (int)nfp->uid);
goto xdr_error;
}
READ_BUF(dummy32);
len += (XDR_QUADLEN(dummy32) << 2);
if ((status = nfs_idmap_id(server, IDMAP_TYPE_USER,
(char *)p, len, &nfp->uid)) == -1) {
dprintk("read_attrs: gss_get_num failed!\n");
/* goto out; */
nfp->uid = -2;
}
dprintk("read_attrs: uid=%d\n", (int)nfp->uid);
}
if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
READ_BUF(4);
len += 4;
READ32(dummy32);
if (dummy32 > XDR_MAX_NETOBJ) {
dprintk("read_attrs: name too long!\n");
goto xdr_error;
}
READ_BUF(dummy32);
len += (XDR_QUADLEN(dummy32) << 2);
if ((status = decode_gid((char *)p, dummy32, &nfp->gid))) {
dprintk("read_attrs: gss_get_num failed!\n");
goto out;
}
dprintk("read_attrs: gid=%d\n", (int)nfp->gid);
len += 4;
READ32(dummy32);
if (dummy32 > XDR_MAX_NETOBJ) {
dprintk("read_attrs: name too long!\n");
goto xdr_error;
}
READ_BUF(dummy32);
len += (XDR_QUADLEN(dummy32) << 2);
if ((status = nfs_idmap_id(server, IDMAP_TYPE_GROUP,
(char *)p, len, &nfp->gid)) == -1) {
dprintk("read_attrs: gss_get_num failed!\n");
nfp->gid = -2;
/* goto out; */
}
dprintk("read_attrs: gid=%d\n", (int)nfp->gid);
}
if (bmval1 & FATTR4_WORD1_RAWDEV) {
uint32_t major, minor;
......@@ -2128,7 +2101,7 @@ decode_compound(struct xdr_stream *xdr, struct nfs4_compound *cp, struct rpc_rqs
status = decode_create(xdr, &op->u.create);
break;
case OP_GETATTR:
status = decode_getattr(xdr, &op->u.getattr);
status = decode_getattr(xdr, &op->u.getattr, cp->server);
break;
case OP_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)
status = decode_open(&xdr, res);
if (status)
goto out;
status = decode_getattr(&xdr, res->f_getattr);
status = decode_getattr(&xdr, res->f_getattr, res->server);
if (status)
goto out;
status = decode_getfh(&xdr, &gfh);
......@@ -2264,7 +2237,7 @@ nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
status = decode_restorefh(&xdr);
if (status)
goto out;
status = decode_getattr(&xdr, res->d_getattr);
status = decode_getattr(&xdr, res->d_getattr, res->server);
if (status)
goto out;
out:
......@@ -2313,7 +2286,7 @@ nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres
status = decode_setattr(&xdr, res);
if (status)
goto out;
status = decode_getattr(&xdr, res->attr);
status = decode_getattr(&xdr, res->attr, res->server);
out:
return status;
}
......@@ -2448,7 +2421,7 @@ nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
#endif
#define PROC(proc, argtype, restype) \
[NFSPROC4_CLNT_##proc] = { \
[NFSPROC4_CLNT_##proc] = { \
.p_proc = NFSPROC4_COMPOUND, \
.p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
.p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
......
......@@ -105,6 +105,7 @@ struct nfs_openargs {
struct qstr * name;
struct nfs4_getattr * f_getattr;
struct nfs4_getattr * d_getattr;
struct nfs_server * server; /* Needed for ID mapping */
};
struct nfs_openres {
......@@ -115,6 +116,7 @@ struct nfs_openres {
__u32 rflags;
struct nfs4_getattr * f_getattr;
struct nfs4_getattr * d_getattr;
struct nfs_server * server;
};
/*
......@@ -248,10 +250,12 @@ struct nfs_setattrargs {
nfs4_stateid stateid;
struct iattr * iap;
struct nfs4_getattr * attr;
struct nfs_server * server; /* Needed for name mapping */
};
struct nfs_setattrres {
struct nfs4_getattr * attr;
struct nfs_server * server;
};
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