2024-06-12 03:08:07

by Mike Snitzer

[permalink] [raw]
Subject: [RFC PATCH v2 04/15] sunrpc: add rpcauth_map_to_svc_cred_local

From: Weston Andros Adamson <[email protected]>

Add new funtion rpcauth_map_to_svc_cred_local which maps a generic
rpc_cred to an svc_cred suitable for use in nfsd.

This is needed by the localio code to map nfs client creds to nfs
server credentials.

Signed-off-by: Weston Andros Adamson <[email protected]>
Signed-off-by: Lance Shelton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Mike Snitzer <[email protected]>
---
include/linux/sunrpc/auth.h | 4 ++++
net/sunrpc/auth.c | 17 +++++++++++++++++
2 files changed, 21 insertions(+)

diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h
index 61e58327b1aa..f8b561cf78ab 100644
--- a/include/linux/sunrpc/auth.h
+++ b/include/linux/sunrpc/auth.h
@@ -11,6 +11,7 @@
#define _LINUX_SUNRPC_AUTH_H

#include <linux/sunrpc/sched.h>
+#include <linux/sunrpc/svcauth.h>
#include <linux/sunrpc/msg_prot.h>
#include <linux/sunrpc/xdr.h>

@@ -184,6 +185,9 @@ int rpcauth_uptodatecred(struct rpc_task *);
int rpcauth_init_credcache(struct rpc_auth *);
void rpcauth_destroy_credcache(struct rpc_auth *);
void rpcauth_clear_credcache(struct rpc_cred_cache *);
+bool rpcauth_map_to_svc_cred_local(struct rpc_auth *,
+ const struct cred *,
+ struct svc_cred *);
char * rpcauth_stringify_acceptor(struct rpc_cred *);

static inline
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index 04534ea537c8..f75728922d57 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -308,6 +308,23 @@ rpcauth_init_credcache(struct rpc_auth *auth)
}
EXPORT_SYMBOL_GPL(rpcauth_init_credcache);

+bool
+rpcauth_map_to_svc_cred_local(struct rpc_auth *auth, const struct cred *cred,
+ struct svc_cred *svc)
+{
+ svc->cr_uid = cred->uid;
+ svc->cr_gid = cred->gid;
+ svc->cr_flavor = auth->au_flavor;
+ if (cred->group_info)
+ svc->cr_group_info = get_group_info(cred->group_info);
+ /* These aren't relevant for local (network is bypassed) */
+ svc->cr_principal = NULL;
+ svc->cr_gss_mech = NULL;
+
+ return true;
+}
+EXPORT_SYMBOL_GPL(rpcauth_map_to_svc_cred_local);
+
char *
rpcauth_stringify_acceptor(struct rpc_cred *cred)
{
--
2.44.0



2024-06-12 04:28:31

by NeilBrown

[permalink] [raw]
Subject: Re: [RFC PATCH v2 04/15] sunrpc: add rpcauth_map_to_svc_cred_local

On Wed, 12 Jun 2024, Mike Snitzer wrote:
> From: Weston Andros Adamson <[email protected]>
>
> Add new funtion rpcauth_map_to_svc_cred_local which maps a generic
> rpc_cred to an svc_cred suitable for use in nfsd.

This comment is stale. There is not such thing as an "rpc_cred".

NeilBrown

>
> This is needed by the localio code to map nfs client creds to nfs
> server credentials.
>
> Signed-off-by: Weston Andros Adamson <[email protected]>
> Signed-off-by: Lance Shelton <[email protected]>
> Signed-off-by: Trond Myklebust <[email protected]>
> Signed-off-by: Mike Snitzer <[email protected]>
> ---
> include/linux/sunrpc/auth.h | 4 ++++
> net/sunrpc/auth.c | 17 +++++++++++++++++
> 2 files changed, 21 insertions(+)
>
> diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h
> index 61e58327b1aa..f8b561cf78ab 100644
> --- a/include/linux/sunrpc/auth.h
> +++ b/include/linux/sunrpc/auth.h
> @@ -11,6 +11,7 @@
> #define _LINUX_SUNRPC_AUTH_H
>
> #include <linux/sunrpc/sched.h>
> +#include <linux/sunrpc/svcauth.h>
> #include <linux/sunrpc/msg_prot.h>
> #include <linux/sunrpc/xdr.h>
>
> @@ -184,6 +185,9 @@ int rpcauth_uptodatecred(struct rpc_task *);
> int rpcauth_init_credcache(struct rpc_auth *);
> void rpcauth_destroy_credcache(struct rpc_auth *);
> void rpcauth_clear_credcache(struct rpc_cred_cache *);
> +bool rpcauth_map_to_svc_cred_local(struct rpc_auth *,
> + const struct cred *,
> + struct svc_cred *);
> char * rpcauth_stringify_acceptor(struct rpc_cred *);
>
> static inline
> diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
> index 04534ea537c8..f75728922d57 100644
> --- a/net/sunrpc/auth.c
> +++ b/net/sunrpc/auth.c
> @@ -308,6 +308,23 @@ rpcauth_init_credcache(struct rpc_auth *auth)
> }
> EXPORT_SYMBOL_GPL(rpcauth_init_credcache);
>
> +bool
> +rpcauth_map_to_svc_cred_local(struct rpc_auth *auth, const struct cred *cred,
> + struct svc_cred *svc)
> +{
> + svc->cr_uid = cred->uid;
> + svc->cr_gid = cred->gid;
> + svc->cr_flavor = auth->au_flavor;
> + if (cred->group_info)
> + svc->cr_group_info = get_group_info(cred->group_info);
> + /* These aren't relevant for local (network is bypassed) */
> + svc->cr_principal = NULL;
> + svc->cr_gss_mech = NULL;
> +
> + return true;
> +}
> +EXPORT_SYMBOL_GPL(rpcauth_map_to_svc_cred_local);
> +
> char *
> rpcauth_stringify_acceptor(struct rpc_cred *cred)
> {
> --
> 2.44.0
>
>
>


2024-06-12 18:34:09

by Anna Schumaker

[permalink] [raw]
Subject: Re: [RFC PATCH v2 04/15] sunrpc: add rpcauth_map_to_svc_cred_local

Hi Mike,

On Tue, Jun 11, 2024 at 11:08 PM Mike Snitzer <[email protected]> wrote:
>
> From: Weston Andros Adamson <[email protected]>
>
> Add new funtion rpcauth_map_to_svc_cred_local which maps a generic
> rpc_cred to an svc_cred suitable for use in nfsd.
>
> This is needed by the localio code to map nfs client creds to nfs
> server credentials.
>
> Signed-off-by: Weston Andros Adamson <[email protected]>
> Signed-off-by: Lance Shelton <[email protected]>
> Signed-off-by: Trond Myklebust <[email protected]>
> Signed-off-by: Mike Snitzer <[email protected]>
> ---
> include/linux/sunrpc/auth.h | 4 ++++
> net/sunrpc/auth.c | 17 +++++++++++++++++
> 2 files changed, 21 insertions(+)
>
> diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h
> index 61e58327b1aa..f8b561cf78ab 100644
> --- a/include/linux/sunrpc/auth.h
> +++ b/include/linux/sunrpc/auth.h
> @@ -11,6 +11,7 @@
> #define _LINUX_SUNRPC_AUTH_H
>
> #include <linux/sunrpc/sched.h>
> +#include <linux/sunrpc/svcauth.h>
> #include <linux/sunrpc/msg_prot.h>
> #include <linux/sunrpc/xdr.h>
>
> @@ -184,6 +185,9 @@ int rpcauth_uptodatecred(struct rpc_task *);
> int rpcauth_init_credcache(struct rpc_auth *);
> void rpcauth_destroy_credcache(struct rpc_auth *);
> void rpcauth_clear_credcache(struct rpc_cred_cache *);
> +bool rpcauth_map_to_svc_cred_local(struct rpc_auth *,
> + const struct cred *,
> + struct svc_cred *);
> char * rpcauth_stringify_acceptor(struct rpc_cred *);
>
> static inline
> diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
> index 04534ea537c8..f75728922d57 100644
> --- a/net/sunrpc/auth.c
> +++ b/net/sunrpc/auth.c
> @@ -308,6 +308,23 @@ rpcauth_init_credcache(struct rpc_auth *auth)
> }
> EXPORT_SYMBOL_GPL(rpcauth_init_credcache);
>
> +bool
> +rpcauth_map_to_svc_cred_local(struct rpc_auth *auth, const struct cred *cred,
> + struct svc_cred *svc)
> +{
> + svc->cr_uid = cred->uid;
> + svc->cr_gid = cred->gid;
> + svc->cr_flavor = auth->au_flavor;
> + if (cred->group_info)
> + svc->cr_group_info = get_group_info(cred->group_info);
> + /* These aren't relevant for local (network is bypassed) */
> + svc->cr_principal = NULL;
> + svc->cr_gss_mech = NULL;
> +
> + return true;
> +}

This function doesn't have a way to fail, and only ever returns true.
Could it be a void function instead of bool?

Anna

> +EXPORT_SYMBOL_GPL(rpcauth_map_to_svc_cred_local);
> +
> char *
> rpcauth_stringify_acceptor(struct rpc_cred *cred)
> {
> --
> 2.44.0
>
>