Commit 5c691044ecbca04dd558fca4c754121689fe1b34

Authored by Trond Myklebust
1 parent 9a559efd41

SUNRPC: Add an rpc_credop callback for binding a credential to an rpc_task

We need the ability to treat 'generic' creds specially, since they want to
bind instances of the auth cred instead of binding themselves.

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>

Showing 6 changed files with 24 additions and 2 deletions Side-by-side Diff

include/linux/sunrpc/auth.h
... ... @@ -112,6 +112,7 @@
112 112 void (*crdestroy)(struct rpc_cred *);
113 113  
114 114 int (*crmatch)(struct auth_cred *, struct rpc_cred *, int);
  115 + void (*crbind)(struct rpc_task *, struct rpc_cred *);
115 116 __be32 * (*crmarshal)(struct rpc_task *, __be32 *);
116 117 int (*crrefresh)(struct rpc_task *);
117 118 __be32 * (*crvalidate)(struct rpc_task *, __be32 *);
... ... @@ -139,6 +140,7 @@
139 140 void rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *);
140 141 struct rpc_cred * rpcauth_lookupcred(struct rpc_auth *, int);
141 142 void rpcauth_bindcred(struct rpc_task *, struct rpc_cred *, int);
  143 +void rpcauth_generic_bind_cred(struct rpc_task *, struct rpc_cred *);
142 144 void put_rpccred(struct rpc_cred *);
143 145 void rpcauth_unbindcred(struct rpc_task *);
144 146 __be32 * rpcauth_marshcred(struct rpc_task *, __be32 *);
... ... @@ -375,13 +375,14 @@
375 375 }
376 376 EXPORT_SYMBOL_GPL(rpcauth_init_cred);
377 377  
378   -static void
  378 +void
379 379 rpcauth_generic_bind_cred(struct rpc_task *task, struct rpc_cred *cred)
380 380 {
381 381 task->tk_msg.rpc_cred = get_rpccred(cred);
382 382 dprintk("RPC: %5u holding %s cred %p\n", task->tk_pid,
383 383 cred->cr_auth->au_ops->au_name, cred);
384 384 }
  385 +EXPORT_SYMBOL_GPL(rpcauth_generic_bind_cred);
385 386  
386 387 static void
387 388 rpcauth_bind_root_cred(struct rpc_task *task)
... ... @@ -421,7 +422,7 @@
421 422 rpcauth_bindcred(struct rpc_task *task, struct rpc_cred *cred, int flags)
422 423 {
423 424 if (cred != NULL)
424   - rpcauth_generic_bind_cred(task, cred);
  425 + cred->cr_ops->crbind(task, cred);
425 426 else if (flags & RPC_TASK_ROOTCREDS)
426 427 rpcauth_bind_root_cred(task);
427 428 else
net/sunrpc/auth_generic.c
... ... @@ -35,6 +35,20 @@
35 35 }
36 36 EXPORT_SYMBOL_GPL(rpc_lookup_cred);
37 37  
  38 +static void
  39 +generic_bind_cred(struct rpc_task *task, struct rpc_cred *cred)
  40 +{
  41 + struct rpc_auth *auth = task->tk_client->cl_auth;
  42 + struct auth_cred *acred = &container_of(cred, struct generic_cred, gc_base)->acred;
  43 + struct rpc_cred *ret;
  44 +
  45 + ret = auth->au_ops->lookup_cred(auth, acred, 0);
  46 + if (!IS_ERR(ret))
  47 + task->tk_msg.rpc_cred = ret;
  48 + else
  49 + task->tk_status = PTR_ERR(ret);
  50 +}
  51 +
38 52 /*
39 53 * Lookup generic creds for current process
40 54 */
... ... @@ -138,6 +152,7 @@
138 152 static const struct rpc_credops generic_credops = {
139 153 .cr_name = "Generic cred",
140 154 .crdestroy = generic_destroy_cred,
  155 + .crbind = generic_bind_cred,
141 156 .crmatch = generic_match,
142 157 };
net/sunrpc/auth_gss/auth_gss.c
... ... @@ -1300,6 +1300,7 @@
1300 1300 .cr_name = "AUTH_GSS",
1301 1301 .crdestroy = gss_destroy_cred,
1302 1302 .cr_init = gss_cred_init,
  1303 + .crbind = rpcauth_generic_bind_cred,
1303 1304 .crmatch = gss_match,
1304 1305 .crmarshal = gss_marshal,
1305 1306 .crrefresh = gss_refresh,
... ... @@ -1311,6 +1312,7 @@
1311 1312 static const struct rpc_credops gss_nullops = {
1312 1313 .cr_name = "AUTH_GSS",
1313 1314 .crdestroy = gss_destroy_cred,
  1315 + .crbind = rpcauth_generic_bind_cred,
1314 1316 .crmatch = gss_match,
1315 1317 .crmarshal = gss_marshal,
1316 1318 .crrefresh = gss_refresh_null,
net/sunrpc/auth_null.c
... ... @@ -125,6 +125,7 @@
125 125 const struct rpc_credops null_credops = {
126 126 .cr_name = "AUTH_NULL",
127 127 .crdestroy = nul_destroy_cred,
  128 + .crbind = rpcauth_generic_bind_cred,
128 129 .crmatch = nul_match,
129 130 .crmarshal = nul_marshal,
130 131 .crrefresh = nul_refresh,
net/sunrpc/auth_unix.c
... ... @@ -237,6 +237,7 @@
237 237 const struct rpc_credops unix_credops = {
238 238 .cr_name = "AUTH_UNIX",
239 239 .crdestroy = unx_destroy_cred,
  240 + .crbind = rpcauth_generic_bind_cred,
240 241 .crmatch = unx_match,
241 242 .crmarshal = unx_marshal,
242 243 .crrefresh = unx_refresh,