Commit 67ff3b39 authored by Neil Brown's avatar Neil Brown Committed by Linus Torvalds

[PATCH] knfsd: svcrpc: share code duplicated between auth_unix and auth_null

Call a helper function from svcauth_unix_accept() and svcauth_null_accept()
instead of duplicating code.
Signed-off-by: default avatarJ. Bruce Fields <bfields@citi.umich.edu>
Signed-off-by: default avatarNeil Brown <neilb@cse.unsw.edu.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 3c36df6c
......@@ -329,6 +329,38 @@ void svcauth_unix_purge(void)
cache_purge(&auth_domain_cache);
}
static int
svcauth_unix_set_client(struct svc_rqst *rqstp)
{
struct ip_map key, *ipm;
rqstp->rq_client = NULL;
if (rqstp->rq_proc == 0)
return SVC_OK;
strcpy(key.m_class, rqstp->rq_server->sv_program->pg_class);
key.m_addr = rqstp->rq_addr.sin_addr;
ipm = ip_map_lookup(&key, 0);
if (ipm == NULL)
return SVC_DENIED;
switch (cache_check(&ip_map_cache, &ipm->h, &rqstp->rq_chandle)) {
default:
BUG();
case -EAGAIN:
return SVC_DROP;
case -ENOENT:
return SVC_DENIED;
case 0:
rqstp->rq_client = &ipm->m_client->h;
cache_get(&rqstp->rq_client->h);
ip_map_put(&ipm->h, &ip_map_cache);
break;
}
return SVC_OK;
}
static int
svcauth_null_accept(struct svc_rqst *rqstp, u32 *authp)
......@@ -337,7 +369,6 @@ svcauth_null_accept(struct svc_rqst *rqstp, u32 *authp)
struct kvec *resv = &rqstp->rq_res.head[0];
struct svc_cred *cred = &rqstp->rq_cred;
int rv=0;
struct ip_map key, *ipm;
cred->cr_group_info = NULL;
rqstp->rq_client = NULL;
......@@ -363,30 +394,8 @@ svcauth_null_accept(struct svc_rqst *rqstp, u32 *authp)
if (cred->cr_group_info == NULL)
return SVC_DROP; /* kmalloc failure - client must retry */
strcpy(key.m_class, rqstp->rq_server->sv_program->pg_class);
key.m_addr = rqstp->rq_addr.sin_addr;
ipm = ip_map_lookup(&key, 0);
if (ipm)
switch (cache_check(&ip_map_cache, &ipm->h, &rqstp->rq_chandle)) {
case -EAGAIN:
rv = SVC_DROP;
break;
case -ENOENT:
rv = SVC_OK; /* rq_client is NULL */
break;
case 0:
rqstp->rq_client = &ipm->m_client->h;
cache_get(&rqstp->rq_client->h);
ip_map_put(&ipm->h, &ip_map_cache);
rv = SVC_OK;
break;
default: BUG();
}
else rv = SVC_DROP;
if (rv == SVC_OK && rqstp->rq_client == NULL && rqstp->rq_proc != 0)
rv = svcauth_unix_set_client(rqstp);
if (rv == SVC_DENIED)
goto badcred;
/* Put NULL verifier */
......@@ -432,7 +441,6 @@ svcauth_unix_accept(struct svc_rqst *rqstp, u32 *authp)
u32 slen, i;
int len = argv->iov_len;
int rv=0;
struct ip_map key, *ipm;
cred->cr_group_info = NULL;
rqstp->rq_client = NULL;
......@@ -464,32 +472,8 @@ svcauth_unix_accept(struct svc_rqst *rqstp, u32 *authp)
return SVC_DENIED;
}
strcpy(key.m_class, rqstp->rq_server->sv_program->pg_class);
key.m_addr = rqstp->rq_addr.sin_addr;
ipm = ip_map_lookup(&key, 0);
if (ipm)
switch (cache_check(&ip_map_cache, &ipm->h, &rqstp->rq_chandle)) {
case -EAGAIN:
rv = SVC_DROP;
break;
case -ENOENT:
rv = SVC_OK; /* rq_client is NULL */
break;
case 0:
rqstp->rq_client = &ipm->m_client->h;
cache_get(&rqstp->rq_client->h);
ip_map_put(&ipm->h, &ip_map_cache);
rv = SVC_OK;
break;
default: BUG();
}
else rv = SVC_DROP;
if (rv == SVC_OK && rqstp->rq_client == NULL && rqstp->rq_proc != 0)
rv = svcauth_unix_set_client(rqstp);
if (rv == SVC_DENIED)
goto badcred;
/* Put NULL verifier */
......
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