Linux NFS development
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Trond Myklebust <Trond.Myklebust@netapp.com>
Cc: linux-nfs@vger.kernel.org, Kevin Coffman <kwc@citi.umich.edu>
Subject: Re: [PATCH 4/6] SUNRPC: Add a generic RPC credential
Date: Fri, 28 Mar 2008 11:35:44 -0400	[thread overview]
Message-ID: <20080328153544.GC30169@fieldses.org> (raw)
In-Reply-To: <20080313174809.13840.50790.stgit-KPEdlmqt5P7XOazzY/2fV4TcuzvYVacciM950cveMlzk1uMJSBkQmQ@public.gmane.org>

On Thu, Mar 13, 2008 at 01:48:09PM -0400, Trond Myklebust wrote:
> Add an rpc credential that is not tied to any particular auth mechanism,
> but that can be cached by NFS, and later used to look up a cred for
> whichever auth mechanism that turns out to be valid when the RPC call is
> being made.
> 
> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
> ---
> 
>  include/linux/sunrpc/auth.h |    3 +
>  net/sunrpc/Makefile         |    2 -
>  net/sunrpc/auth.c           |    1 
>  net/sunrpc/auth_generic.c   |  142 +++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 147 insertions(+), 1 deletions(-)
> 
> diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h
> index 348546c..70644ed 100644
> --- a/include/linux/sunrpc/auth.h
> +++ b/include/linux/sunrpc/auth.h
> @@ -125,9 +125,12 @@ extern const struct rpc_authops	authunix_ops;
>  extern const struct rpc_authops	authnull_ops;
>  
>  void __init		rpc_init_authunix(void);
> +void __init		rpc_init_generic_auth(void);
>  void __init		rpcauth_init_module(void);
>  void __exit		rpcauth_remove_module(void);
> +void __exit		rpc_destroy_generic_auth(void);
>  
> +struct rpc_cred *	rpc_lookup_cred(void);
>  int			rpcauth_register(const struct rpc_authops *);
>  int			rpcauth_unregister(const struct rpc_authops *);
>  struct rpc_auth *	rpcauth_create(rpc_authflavor_t, struct rpc_clnt *);
> diff --git a/net/sunrpc/Makefile b/net/sunrpc/Makefile
> index 92e1dbe..5369aa3 100644
> --- a/net/sunrpc/Makefile
> +++ b/net/sunrpc/Makefile
> @@ -8,7 +8,7 @@ obj-$(CONFIG_SUNRPC_GSS) += auth_gss/
>  obj-$(CONFIG_SUNRPC_XPRT_RDMA) += xprtrdma/
>  
>  sunrpc-y := clnt.o xprt.o socklib.o xprtsock.o sched.o \
> -	    auth.o auth_null.o auth_unix.o \
> +	    auth.o auth_null.o auth_unix.o auth_generic.o \
>  	    svc.o svcsock.o svcauth.o svcauth_unix.o \
>  	    rpcb_clnt.o timer.o xdr.o \
>  	    sunrpc_syms.o cache.o rpc_pipe.o \
> diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
> index 1cdb163..012f2a3 100644
> --- a/net/sunrpc/auth.c
> +++ b/net/sunrpc/auth.c
> @@ -566,6 +566,7 @@ static struct shrinker rpc_cred_shrinker = {
>  void __init rpcauth_init_module(void)
>  {
>  	rpc_init_authunix();
> +	rpc_init_generic_auth();
>  	register_shrinker(&rpc_cred_shrinker);
>  }
>  
> diff --git a/net/sunrpc/auth_generic.c b/net/sunrpc/auth_generic.c
> new file mode 100644
> index 0000000..6f129b1
> --- /dev/null
> +++ b/net/sunrpc/auth_generic.c
> @@ -0,0 +1,142 @@
> +/*
> + * Generic RPC credential
> + *
> + * Copyright (C) 2008, Trond Myklebust <Trond.Myklebust@netapp.com>
> + */
> +
> +#include <linux/err.h>
> +#include <linux/types.h>
> +#include <linux/module.h>
> +#include <linux/sched.h>
> +#include <linux/sunrpc/auth.h>
> +#include <linux/sunrpc/clnt.h>
> +#include <linux/sunrpc/debug.h>
> +#include <linux/sunrpc/sched.h>
> +
> +#ifdef RPC_DEBUG
> +# define RPCDBG_FACILITY	RPCDBG_AUTH
> +#endif
> +
> +struct generic_cred {
> +	struct rpc_cred gc_base;
> +	struct auth_cred acred;
> +};

Does generic_cred need both gc_base.cr_uid and acred.uid?  Will those
ever disagree?

--b.

> +
> +static struct rpc_auth generic_auth;
> +static struct rpc_cred_cache generic_cred_cache;
> +static const struct rpc_credops generic_credops;
> +
> +/*
> + * Public call interface
> + */
> +struct rpc_cred *rpc_lookup_cred(void)
> +{
> +	return rpcauth_lookupcred(&generic_auth, 0);
> +}
> +EXPORT_SYMBOL_GPL(rpc_lookup_cred);
> +
> +/*
> + * Lookup generic creds for current process
> + */
> +static struct rpc_cred *
> +generic_lookup_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
> +{
> +	return rpcauth_lookup_credcache(&generic_auth, acred, flags);
> +}
> +
> +static struct rpc_cred *
> +generic_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
> +{
> +	struct generic_cred *gcred;
> +
> +	gcred = kmalloc(sizeof(*gcred), GFP_KERNEL);
> +	if (gcred == NULL)
> +		return ERR_PTR(-ENOMEM);
> +
> +	rpcauth_init_cred(&gcred->gc_base, acred, &generic_auth, &generic_credops);
> +	gcred->gc_base.cr_flags = 1UL << RPCAUTH_CRED_UPTODATE;
> +
> +	gcred->acred.uid = acred->uid;
> +	gcred->acred.gid = acred->gid;
> +	gcred->acred.group_info = acred->group_info;
> +	if (gcred->acred.group_info != NULL)
> +		get_group_info(gcred->acred.group_info);
> +
> +	dprintk("RPC:       allocated generic cred %p for uid %d gid %d\n",
> +			gcred, acred->uid, acred->gid);
> +	return &gcred->gc_base;
> +}
> +
> +static void
> +generic_free_cred(struct rpc_cred *cred)
> +{
> +	struct generic_cred *gcred = container_of(cred, struct generic_cred, gc_base);
> +
> +	dprintk("RPC:       generic_free_cred %p\n", gcred);
> +	if (gcred->acred.group_info != NULL)
> +		put_group_info(gcred->acred.group_info);
> +	kfree(gcred);
> +}
> +
> +static void
> +generic_free_cred_callback(struct rcu_head *head)
> +{
> +	struct rpc_cred *cred = container_of(head, struct rpc_cred, cr_rcu);
> +	generic_free_cred(cred);
> +}
> +
> +static void
> +generic_destroy_cred(struct rpc_cred *cred)
> +{
> +	call_rcu(&cred->cr_rcu, generic_free_cred_callback);
> +}
> +
> +/*
> + * Match credentials against current process creds.
> + */
> +static int
> +generic_match(struct auth_cred *acred, struct rpc_cred *cred, int flags)
> +{
> +	struct generic_cred *gcred = container_of(cred, struct generic_cred, gc_base);
> +
> +	if (gcred->acred.uid != acred->uid ||
> +	    gcred->acred.gid != acred->gid ||
> +	    gcred->acred.group_info != acred->group_info)
> +		return 0;
> +	return 1;
> +}
> +
> +void __init rpc_init_generic_auth(void)
> +{
> +	spin_lock_init(&generic_cred_cache.lock);
> +}
> +
> +void __exit rpc_destroy_generic_auth(void)
> +{
> +	rpcauth_clear_credcache(&generic_cred_cache);
> +}
> +
> +static struct rpc_cred_cache generic_cred_cache = {
> +	{{ NULL, },},
> +};
> +
> +static const struct rpc_authops generic_auth_ops = {
> +	.owner = THIS_MODULE,
> +#ifdef RPC_DEBUG
> +	.au_name = "Generic",
> +#endif
> +	.lookup_cred = generic_lookup_cred,
> +	.crcreate = generic_create_cred,
> +};
> +
> +static struct rpc_auth generic_auth = {
> +	.au_ops = &generic_auth_ops,
> +	.au_count = ATOMIC_INIT(0),
> +	.au_credcache = &generic_cred_cache,
> +};
> +
> +static const struct rpc_credops generic_credops = {
> +	.cr_name = "Generic cred",
> +	.crdestroy = generic_destroy_cred,
> +	.crmatch = generic_match,
> +};
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2008-03-28 15:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080313174806.13840.90325.stgit@c-69-242-210-120.hsd1.mi.comcast.net>
     [not found] ` <20080313174806.13840.90325.stgit-KPEdlmqt5P7XOazzY/2fV4TcuzvYVacciM950cveMlzk1uMJSBkQmQ@public.gmane.org>
2008-03-13 17:48   ` [PATCH 1/6] SUNRPC: Fix a bug in rpcauth_lookup_credcache() Trond Myklebust
     [not found]     ` <20080313174806.13840.26367.stgit-KPEdlmqt5P7XOazzY/2fV4TcuzvYVacciM950cveMlzk1uMJSBkQmQ@public.gmane.org>
2008-03-28 15:12       ` J. Bruce Fields
2008-03-28 19:08         ` Trond Myklebust
2008-03-13 17:48   ` [PATCH 2/6] SUNRPC: Fix RPCAUTH_LOOKUP_ROOTCREDS Trond Myklebust
     [not found]     ` <20080313174807.13840.38440.stgit-KPEdlmqt5P7XOazzY/2fV4TcuzvYVacciM950cveMlzk1uMJSBkQmQ@public.gmane.org>
2008-03-13 19:11       ` Olga Kornievskaia
2008-03-13 19:19         ` Trond Myklebust
     [not found]           ` <1205435968.13453.27.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-03-13 19:25             ` Trond Myklebust
     [not found]               ` <1205436339.13453.35.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-03-13 19:43                 ` J. Bruce Fields
2008-03-13 20:36                   ` Trond Myklebust
     [not found]                     ` <1205440566.15354.21.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-03-13 20:42                       ` Trond Myklebust
2008-03-13 20:45                       ` J. Bruce Fields
2008-03-13 19:30             ` Olga Kornievskaia
2008-03-13 19:39               ` Trond Myklebust
2008-03-28 15:32       ` J. Bruce Fields
2008-03-28 17:05         ` Chuck Lever
2008-03-13 17:48   ` [PATCH 4/6] SUNRPC: Add a generic RPC credential Trond Myklebust
     [not found]     ` <20080313174809.13840.50790.stgit-KPEdlmqt5P7XOazzY/2fV4TcuzvYVacciM950cveMlzk1uMJSBkQmQ@public.gmane.org>
2008-03-28 15:35       ` J. Bruce Fields [this message]
2008-03-28 19:15         ` Trond Myklebust
2008-03-13 17:48   ` [PATCH 3/6] SUNRPC: Clean up rpcauth_bindcred() Trond Myklebust
2008-03-13 17:48   ` [PATCH 5/6] SUNRPC: Add an rpc_credop callback for binding a credential to an rpc_task Trond Myklebust
2008-03-13 17:48   ` [PATCH 6/6] SUNRPC: Add a helper rpcauth_lookup_generic_cred() Trond Myklebust

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080328153544.GC30169@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=Trond.Myklebust@netapp.com \
    --cc=kwc@citi.umich.edu \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox