diff options
| author | NeilBrown <neilb@suse.com> | 2018-12-02 19:30:30 -0500 |
|---|---|---|
| committer | Anna Schumaker <Anna.Schumaker@Netapp.com> | 2018-12-19 13:52:45 -0500 |
| commit | 1a80810fbf238e6dbaaaa5262a76d328ace21376 (patch) | |
| tree | 1c1c3331bb9345c2418d044d19f3ee0c7e7a3992 | |
| parent | 8276c902bbe95d628f48a7fdc13c71e265992085 (diff) | |
SUNRPC: remove machine_cred field from struct auth_cred
The cred is a machine_cred iff ->principal is set, so there is no
need for the extra flag.
There is one case which deserves some
explanation. nfs4_root_machine_cred() calls rpc_lookup_machine_cred()
with a NULL principal name which results in not getting a machine
credential, but getting a root credential instead.
This appears to be what is expected of the caller, and is
clearly the result provided by both auth_unix and auth_gss
which already ignore the flag.
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
| -rw-r--r-- | include/linux/sunrpc/auth.h | 3 | ||||
| -rw-r--r-- | net/sunrpc/auth_generic.c | 12 | ||||
| -rw-r--r-- | net/sunrpc/auth_gss/auth_gss.c | 5 |
3 files changed, 8 insertions, 12 deletions
diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h index 831ea65bd9f4..1c0468f39479 100644 --- a/include/linux/sunrpc/auth.h +++ b/include/linux/sunrpc/auth.h | |||
| @@ -46,9 +46,8 @@ enum { | |||
| 46 | 46 | ||
| 47 | struct auth_cred { | 47 | struct auth_cred { |
| 48 | const struct cred *cred; | 48 | const struct cred *cred; |
| 49 | const char *principal; | 49 | const char *principal; /* If present, this is a machine credential */ |
| 50 | unsigned long ac_flags; | 50 | unsigned long ac_flags; |
| 51 | unsigned char machine_cred : 1; | ||
| 52 | }; | 51 | }; |
| 53 | 52 | ||
| 54 | /* | 53 | /* |
diff --git a/net/sunrpc/auth_generic.c b/net/sunrpc/auth_generic.c index 6c7c65da6063..7d1a8f45726c 100644 --- a/net/sunrpc/auth_generic.c +++ b/net/sunrpc/auth_generic.c | |||
| @@ -50,12 +50,13 @@ EXPORT_SYMBOL_GPL(rpc_lookup_cred_nonblock); | |||
| 50 | 50 | ||
| 51 | /* | 51 | /* |
| 52 | * Public call interface for looking up machine creds. | 52 | * Public call interface for looking up machine creds. |
| 53 | * Note that if service_name is NULL, we actually look up | ||
| 54 | * "root" credential. | ||
| 53 | */ | 55 | */ |
| 54 | struct rpc_cred *rpc_lookup_machine_cred(const char *service_name) | 56 | struct rpc_cred *rpc_lookup_machine_cred(const char *service_name) |
| 55 | { | 57 | { |
| 56 | struct auth_cred acred = { | 58 | struct auth_cred acred = { |
| 57 | .principal = service_name, | 59 | .principal = service_name, |
| 58 | .machine_cred = 1, | ||
| 59 | .cred = get_task_cred(&init_task), | 60 | .cred = get_task_cred(&init_task), |
| 60 | }; | 61 | }; |
| 61 | struct rpc_cred *ret; | 62 | struct rpc_cred *ret; |
| @@ -108,11 +109,10 @@ generic_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags, g | |||
| 108 | 109 | ||
| 109 | gcred->acred.cred = gcred->gc_base.cr_cred; | 110 | gcred->acred.cred = gcred->gc_base.cr_cred; |
| 110 | gcred->acred.ac_flags = 0; | 111 | gcred->acred.ac_flags = 0; |
| 111 | gcred->acred.machine_cred = acred->machine_cred; | ||
| 112 | gcred->acred.principal = acred->principal; | 112 | gcred->acred.principal = acred->principal; |
| 113 | 113 | ||
| 114 | dprintk("RPC: allocated %s cred %p for uid %d gid %d\n", | 114 | dprintk("RPC: allocated %s cred %p for uid %d gid %d\n", |
| 115 | gcred->acred.machine_cred ? "machine" : "generic", | 115 | gcred->acred.principal ? "machine" : "generic", |
| 116 | gcred, | 116 | gcred, |
| 117 | from_kuid(&init_user_ns, acred->cred->fsuid), | 117 | from_kuid(&init_user_ns, acred->cred->fsuid), |
| 118 | from_kgid(&init_user_ns, acred->cred->fsgid)); | 118 | from_kgid(&init_user_ns, acred->cred->fsgid)); |
| @@ -145,7 +145,7 @@ generic_destroy_cred(struct rpc_cred *cred) | |||
| 145 | static int | 145 | static int |
| 146 | machine_cred_match(struct auth_cred *acred, struct generic_cred *gcred, int flags) | 146 | machine_cred_match(struct auth_cred *acred, struct generic_cred *gcred, int flags) |
| 147 | { | 147 | { |
| 148 | if (!gcred->acred.machine_cred || | 148 | if (!gcred->acred.principal || |
| 149 | gcred->acred.principal != acred->principal || | 149 | gcred->acred.principal != acred->principal || |
| 150 | !uid_eq(gcred->acred.cred->fsuid, acred->cred->fsuid) || | 150 | !uid_eq(gcred->acred.cred->fsuid, acred->cred->fsuid) || |
| 151 | !gid_eq(gcred->acred.cred->fsgid, acred->cred->fsgid)) | 151 | !gid_eq(gcred->acred.cred->fsgid, acred->cred->fsgid)) |
| @@ -163,12 +163,12 @@ generic_match(struct auth_cred *acred, struct rpc_cred *cred, int flags) | |||
| 163 | int i; | 163 | int i; |
| 164 | struct group_info *a, *g; | 164 | struct group_info *a, *g; |
| 165 | 165 | ||
| 166 | if (acred->machine_cred) | 166 | if (acred->principal) |
| 167 | return machine_cred_match(acred, gcred, flags); | 167 | return machine_cred_match(acred, gcred, flags); |
| 168 | 168 | ||
| 169 | if (!uid_eq(gcred->acred.cred->fsuid, acred->cred->fsuid) || | 169 | if (!uid_eq(gcred->acred.cred->fsuid, acred->cred->fsuid) || |
| 170 | !gid_eq(gcred->acred.cred->fsgid, acred->cred->fsgid) || | 170 | !gid_eq(gcred->acred.cred->fsgid, acred->cred->fsgid) || |
| 171 | gcred->acred.machine_cred != 0) | 171 | gcred->acred.principal != NULL) |
| 172 | goto out_nomatch; | 172 | goto out_nomatch; |
| 173 | 173 | ||
| 174 | a = acred->cred->group_info; | 174 | a = acred->cred->group_info; |
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c index 762b071cba71..b218e15b61cb 100644 --- a/net/sunrpc/auth_gss/auth_gss.c +++ b/net/sunrpc/auth_gss/auth_gss.c | |||
| @@ -1395,9 +1395,7 @@ gss_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags, gfp_t | |||
| 1395 | */ | 1395 | */ |
| 1396 | cred->gc_base.cr_flags = 1UL << RPCAUTH_CRED_NEW; | 1396 | cred->gc_base.cr_flags = 1UL << RPCAUTH_CRED_NEW; |
| 1397 | cred->gc_service = gss_auth->service; | 1397 | cred->gc_service = gss_auth->service; |
| 1398 | cred->gc_principal = NULL; | 1398 | cred->gc_principal = acred->principal; |
| 1399 | if (acred->machine_cred) | ||
| 1400 | cred->gc_principal = acred->principal; | ||
| 1401 | kref_get(&gss_auth->kref); | 1399 | kref_get(&gss_auth->kref); |
| 1402 | return &cred->gc_base; | 1400 | return &cred->gc_base; |
| 1403 | 1401 | ||
| @@ -1610,7 +1608,6 @@ static int gss_renew_cred(struct rpc_task *task) | |||
| 1610 | struct auth_cred acred = { | 1608 | struct auth_cred acred = { |
| 1611 | .cred = oldcred->cr_cred, | 1609 | .cred = oldcred->cr_cred, |
| 1612 | .principal = gss_cred->gc_principal, | 1610 | .principal = gss_cred->gc_principal, |
| 1613 | .machine_cred = (gss_cred->gc_principal != NULL ? 1 : 0), | ||
| 1614 | }; | 1611 | }; |
| 1615 | struct rpc_cred *new; | 1612 | struct rpc_cred *new; |
| 1616 | 1613 | ||
