|
18 | 18 | #include <linux/sunrpc/svcauth.h>
|
19 | 19 | #include <linux/err.h>
|
20 | 20 | #include <linux/hash.h>
|
| 21 | +#include <linux/user_namespace.h> |
21 | 22 |
|
22 | 23 | #include <trace/events/sunrpc.h>
|
23 | 24 |
|
@@ -175,6 +176,33 @@ rpc_authflavor_t svc_auth_flavor(struct svc_rqst *rqstp)
|
175 | 176 | }
|
176 | 177 | EXPORT_SYMBOL_GPL(svc_auth_flavor);
|
177 | 178 |
|
| 179 | +/** |
| 180 | + * svcauth_map_clnt_to_svc_cred_local - maps a generic cred |
| 181 | + * to a svc_cred suitable for use in nfsd. |
| 182 | + * @clnt: rpc_clnt associated with nfs client |
| 183 | + * @cred: generic cred associated with nfs client |
| 184 | + * @svc: returned svc_cred that is suitable for use in nfsd |
| 185 | + */ |
| 186 | +void svcauth_map_clnt_to_svc_cred_local(struct rpc_clnt *clnt, |
| 187 | + const struct cred *cred, |
| 188 | + struct svc_cred *svc) |
| 189 | +{ |
| 190 | + struct user_namespace *userns = clnt->cl_cred ? |
| 191 | + clnt->cl_cred->user_ns : &init_user_ns; |
| 192 | + |
| 193 | + memset(svc, 0, sizeof(struct svc_cred)); |
| 194 | + |
| 195 | + svc->cr_uid = KUIDT_INIT(from_kuid_munged(userns, cred->fsuid)); |
| 196 | + svc->cr_gid = KGIDT_INIT(from_kgid_munged(userns, cred->fsgid)); |
| 197 | + svc->cr_flavor = clnt->cl_auth->au_flavor; |
| 198 | + if (cred->group_info) |
| 199 | + svc->cr_group_info = get_group_info(cred->group_info); |
| 200 | + /* These aren't relevant for local (network is bypassed) */ |
| 201 | + svc->cr_principal = NULL; |
| 202 | + svc->cr_gss_mech = NULL; |
| 203 | +} |
| 204 | +EXPORT_SYMBOL_GPL(svcauth_map_clnt_to_svc_cred_local); |
| 205 | + |
178 | 206 | /**************************************************
|
179 | 207 | * 'auth_domains' are stored in a hash table indexed by name.
|
180 | 208 | * When the last reference to an 'auth_domain' is dropped,
|
|
0 commit comments