Commit b62d37e6 authored by Trond Myklebust's avatar Trond Myklebust

RPC: make rpcauth_lookupcred() return error codes.

 So we can distinguish between ENOMEM and EACCES errors.
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 5a9e20ef
......@@ -1532,8 +1532,11 @@ int nfs_permission(struct inode *inode, int mask, struct nameidata *nd)
goto out_notsup;
cred = rpcauth_lookupcred(NFS_CLIENT(inode)->cl_auth, 0);
res = nfs_do_access(inode, cred, mask);
put_rpccred(cred);
if (!IS_ERR(cred)) {
res = nfs_do_access(inode, cred, mask);
put_rpccred(cred);
} else
res = PTR_ERR(cred);
unlock_kernel();
out:
return res;
......
......@@ -918,8 +918,9 @@ int nfs_open(struct inode *inode, struct file *filp)
struct nfs_open_context *ctx;
struct rpc_cred *cred;
if ((cred = rpcauth_lookupcred(NFS_CLIENT(inode)->cl_auth, 0)) == NULL)
return -ENOMEM;
cred = rpcauth_lookupcred(NFS_CLIENT(inode)->cl_auth, 0);
if (IS_ERR(cred))
return PTR_ERR(cred);
ctx = alloc_nfs_open_context(filp->f_dentry, cred);
put_rpccred(cred);
if (ctx == NULL)
......@@ -1613,6 +1614,12 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
clnt->cl_chatty = 1;
clp->cl_rpcclient = clnt;
clp->cl_cred = rpcauth_lookupcred(clnt->cl_auth, 0);
if (IS_ERR(clp->cl_cred)) {
up_write(&clp->cl_sem);
err = PTR_ERR(clp->cl_cred);
clp->cl_cred = NULL;
goto out_fail;
}
memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr));
nfs_idmap_new(clp);
}
......
......@@ -774,6 +774,8 @@ nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
}
cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
if (IS_ERR(cred))
return (struct inode *)cred;
state = nfs4_do_open(dir, dentry, nd->intent.open.flags, &attr, cred);
put_rpccred(cred);
if (IS_ERR(state))
......@@ -789,6 +791,8 @@ nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags)
struct inode *inode;
cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
if (IS_ERR(cred))
return PTR_ERR(cred);
state = nfs4_open_delegated(dentry->d_inode, openflags, cred);
if (IS_ERR(state))
state = nfs4_do_open(dir, dentry, openflags, NULL, cred);
......@@ -1009,6 +1013,8 @@ nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
if (size_change) {
struct rpc_cred *cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0);
if (IS_ERR(cred))
return PTR_ERR(cred);
state = nfs4_find_state(inode, cred, FMODE_WRITE);
if (state == NULL) {
state = nfs4_open_delegated(dentry->d_inode,
......@@ -1324,6 +1330,8 @@ nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
struct rpc_cred *cred;
cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
if (IS_ERR(cred))
return (struct inode *)cred;
state = nfs4_do_open(dir, dentry, flags, sattr, cred);
put_rpccred(cred);
if (IS_ERR(state)) {
......@@ -2004,8 +2012,8 @@ nfs4_proc_file_open(struct inode *inode, struct file *filp)
/* Find our open stateid */
cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0);
if (unlikely(cred == NULL))
return -ENOMEM;
if (IS_ERR(cred))
return PTR_ERR(cred);
ctx = alloc_nfs_open_context(dentry, cred);
put_rpccred(cred);
if (unlikely(ctx == NULL))
......
......@@ -167,6 +167,11 @@ nfs_async_unlink(struct dentry *dentry)
goto out;
memset(data, 0, sizeof(*data));
data->cred = rpcauth_lookupcred(clnt->cl_auth, 0);
if (IS_ERR(data->cred)) {
status = PTR_ERR(data->cred);
goto out_free;
}
data->dir = dget(dir);
data->dentry = dentry;
......@@ -183,12 +188,14 @@ nfs_async_unlink(struct dentry *dentry)
spin_lock(&dentry->d_lock);
dentry->d_flags |= DCACHE_NFSFS_RENAMED;
spin_unlock(&dentry->d_lock);
data->cred = rpcauth_lookupcred(clnt->cl_auth, 0);
rpc_sleep_on(&nfs_delete_queue, task, NULL, NULL);
status = 0;
out:
return status;
out_free:
kfree(data);
return status;
}
/**
......
......@@ -446,7 +446,7 @@ nfsd4_probe_callback(struct nfs4_client *clp)
atomic_inc(&clp->cl_count);
msg.rpc_cred = nfsd4_lookupcred(clp,0);
if (msg.rpc_cred == NULL)
if (IS_ERR(msg.rpc_cred))
goto out_rpciod;
status = rpc_call_async(clnt, &msg, RPC_TASK_ASYNC, nfs4_cb_null, NULL);
put_rpccred(msg.rpc_cred);
......@@ -512,7 +512,7 @@ nfsd4_cb_recall(struct nfs4_delegation *dp)
return;
msg.rpc_cred = nfsd4_lookupcred(clp, 0);
if (msg.rpc_cred == NULL)
if (IS_ERR(msg.rpc_cred))
goto out;
cbr->cbr_trunc = 0; /* XXX need to implement truncate optimization */
......
......@@ -226,12 +226,13 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
if (!cred) {
new = auth->au_ops->crcreate(auth, acred, taskflags);
if (new) {
if (!IS_ERR(new)) {
#ifdef RPC_DEBUG
new->cr_magic = RPCAUTH_CRED_MAGIC;
#endif
goto retry;
}
} else
cred = new;
}
return (struct rpc_cred *) cred;
......@@ -269,10 +270,11 @@ rpcauth_bindcred(struct rpc_task *task)
dprintk("RPC: %4d looking up %s cred\n",
task->tk_pid, task->tk_auth->au_ops->au_name);
task->tk_msg.rpc_cred = auth->au_ops->lookup_cred(auth, &acred, task->tk_flags);
if (task->tk_msg.rpc_cred == 0)
task->tk_status = -ENOMEM;
ret = task->tk_msg.rpc_cred;
ret = auth->au_ops->lookup_cred(auth, &acred, task->tk_flags);
if (!IS_ERR(ret))
task->tk_msg.rpc_cred = ret;
else
task->tk_status = PTR_ERR(ret);
put_group_info(current->group_info);
return ret;
}
......
......@@ -581,10 +581,11 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
} else {
struct auth_cred acred = { .uid = uid };
spin_unlock(&gss_auth->lock);
err = -ENOENT;
cred = rpcauth_lookup_credcache(clnt->cl_auth, &acred, 0);
if (!cred)
if (IS_ERR(cred)) {
err = PTR_ERR(cred);
goto err_put_ctx;
}
gss_cred_set_ctx(cred, gss_get_ctx(ctx));
}
gss_put_ctx(ctx);
......@@ -791,7 +792,7 @@ gss_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int taskflags)
out_err:
dprintk("RPC: gss_create_cred failed with error %d\n", err);
if (cred) gss_destroy_cred(&cred->gc_base);
return NULL;
return ERR_PTR(err);
}
static int
......
......@@ -75,7 +75,7 @@ unx_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
acred->uid, acred->gid);
if (!(cred = (struct unx_cred *) kmalloc(sizeof(*cred), GFP_KERNEL)))
return NULL;
return ERR_PTR(-ENOMEM);
atomic_set(&cred->uc_count, 1);
cred->uc_flags = RPCAUTH_CRED_UPTODATE;
......
......@@ -425,9 +425,9 @@ rpc_call_setup(struct rpc_task *task, struct rpc_message *msg, int flags)
task->tk_msg = *msg;
task->tk_flags |= flags;
/* Bind the user cred */
if (task->tk_msg.rpc_cred != NULL) {
if (task->tk_msg.rpc_cred != NULL)
rpcauth_holdcred(task);
} else
else
rpcauth_bindcred(task);
if (task->tk_status == 0)
......
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