aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2007-06-23 19:55:31 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2007-07-10 23:40:35 -0400
commit5fe4755e2526a2aa82b7ed8daeb3aed74a236925 (patch)
treeaceb993080fc6aac5861f04d8a8494becb4046eb /net
parentf1c0a8615090359d57e096157feb9f900cbb233c (diff)
SUNRPC: Clean up rpc credential initialisation
Add a helper rpc_cred_init() Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'net')
-rw-r--r--net/sunrpc/auth.c24
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c6
-rw-r--r--net/sunrpc/auth_unix.c10
3 files changed, 21 insertions, 19 deletions
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index d3f0f944c0b5..2156327da45b 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -264,13 +264,9 @@ retry:
264 264
265 if (!cred) { 265 if (!cred) {
266 new = auth->au_ops->crcreate(auth, acred, flags); 266 new = auth->au_ops->crcreate(auth, acred, flags);
267 if (!IS_ERR(new)) { 267 if (!IS_ERR(new))
268#ifdef RPC_DEBUG
269 new->cr_magic = RPCAUTH_CRED_MAGIC;
270#endif
271 goto retry; 268 goto retry;
272 } else 269 cred = new;
273 cred = new;
274 } else if ((cred->cr_flags & RPCAUTH_CRED_NEW) 270 } else if ((cred->cr_flags & RPCAUTH_CRED_NEW)
275 && cred->cr_ops->cr_init != NULL 271 && cred->cr_ops->cr_init != NULL
276 && !(flags & RPCAUTH_LOOKUP_NEW)) { 272 && !(flags & RPCAUTH_LOOKUP_NEW)) {
@@ -302,6 +298,22 @@ rpcauth_lookupcred(struct rpc_auth *auth, int flags)
302 return ret; 298 return ret;
303} 299}
304 300
301void
302rpcauth_init_cred(struct rpc_cred *cred, const struct auth_cred *acred,
303 struct rpc_auth *auth, const struct rpc_credops *ops)
304{
305 INIT_HLIST_NODE(&cred->cr_hash);
306 atomic_set(&cred->cr_count, 1);
307 cred->cr_auth = auth;
308 cred->cr_ops = ops;
309 cred->cr_expire = jiffies;
310#ifdef RPC_DEBUG
311 cred->cr_magic = RPCAUTH_CRED_MAGIC;
312#endif
313 cred->cr_uid = acred->uid;
314}
315EXPORT_SYMBOL(rpcauth_init_cred);
316
305struct rpc_cred * 317struct rpc_cred *
306rpcauth_bindcred(struct rpc_task *task) 318rpcauth_bindcred(struct rpc_task *task)
307{ 319{
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 177a9e413c0a..766de0a41b22 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -727,15 +727,11 @@ gss_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
727 if (!(cred = kzalloc(sizeof(*cred), GFP_KERNEL))) 727 if (!(cred = kzalloc(sizeof(*cred), GFP_KERNEL)))
728 goto out_err; 728 goto out_err;
729 729
730 atomic_set(&cred->gc_count, 1); 730 rpcauth_init_cred(&cred->gc_base, acred, auth, &gss_credops);
731 cred->gc_uid = acred->uid;
732 /* 731 /*
733 * Note: in order to force a call to call_refresh(), we deliberately 732 * Note: in order to force a call to call_refresh(), we deliberately
734 * fail to flag the credential as RPCAUTH_CRED_UPTODATE. 733 * fail to flag the credential as RPCAUTH_CRED_UPTODATE.
735 */ 734 */
736 cred->gc_flags = 0;
737 cred->gc_base.cr_auth = auth;
738 cred->gc_base.cr_ops = &gss_credops;
739 cred->gc_base.cr_flags = RPCAUTH_CRED_NEW; 735 cred->gc_base.cr_flags = RPCAUTH_CRED_NEW;
740 cred->gc_service = gss_auth->service; 736 cred->gc_service = gss_auth->service;
741 return &cred->gc_base; 737 return &cred->gc_base;
diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c
index 6600c7ad72a9..2f1bdb5c86b3 100644
--- a/net/sunrpc/auth_unix.c
+++ b/net/sunrpc/auth_unix.c
@@ -20,9 +20,6 @@ struct unx_cred {
20 gid_t uc_gids[NFS_NGROUPS]; 20 gid_t uc_gids[NFS_NGROUPS];
21}; 21};
22#define uc_uid uc_base.cr_uid 22#define uc_uid uc_base.cr_uid
23#define uc_count uc_base.cr_count
24#define uc_flags uc_base.cr_flags
25#define uc_expire uc_base.cr_expire
26 23
27#define UNX_CRED_EXPIRE (60 * HZ) 24#define UNX_CRED_EXPIRE (60 * HZ)
28 25
@@ -74,8 +71,8 @@ unx_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
74 if (!(cred = kmalloc(sizeof(*cred), GFP_KERNEL))) 71 if (!(cred = kmalloc(sizeof(*cred), GFP_KERNEL)))
75 return ERR_PTR(-ENOMEM); 72 return ERR_PTR(-ENOMEM);
76 73
77 atomic_set(&cred->uc_count, 1); 74 rpcauth_init_cred(&cred->uc_base, acred, auth, &unix_credops);
78 cred->uc_flags = RPCAUTH_CRED_UPTODATE; 75 cred->uc_base.cr_flags = RPCAUTH_CRED_UPTODATE;
79 if (flags & RPCAUTH_LOOKUP_ROOTCREDS) { 76 if (flags & RPCAUTH_LOOKUP_ROOTCREDS) {
80 cred->uc_uid = 0; 77 cred->uc_uid = 0;
81 cred->uc_gid = 0; 78 cred->uc_gid = 0;
@@ -85,15 +82,12 @@ unx_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
85 if (groups > NFS_NGROUPS) 82 if (groups > NFS_NGROUPS)
86 groups = NFS_NGROUPS; 83 groups = NFS_NGROUPS;
87 84
88 cred->uc_uid = acred->uid;
89 cred->uc_gid = acred->gid; 85 cred->uc_gid = acred->gid;
90 for (i = 0; i < groups; i++) 86 for (i = 0; i < groups; i++)
91 cred->uc_gids[i] = GROUP_AT(acred->group_info, i); 87 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
92 if (i < NFS_NGROUPS) 88 if (i < NFS_NGROUPS)
93 cred->uc_gids[i] = NOGROUP; 89 cred->uc_gids[i] = NOGROUP;
94 } 90 }
95 cred->uc_base.cr_auth = &unix_auth;
96 cred->uc_base.cr_ops = &unix_credops;
97 91
98 return (struct rpc_cred *) cred; 92 return (struct rpc_cred *) cred;
99} 93}