diff options
Diffstat (limited to 'net/sunrpc/auth_unix.c')
| -rw-r--r-- | net/sunrpc/auth_unix.c | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c index 4e7733aee36e..5ed91e5bcee4 100644 --- a/net/sunrpc/auth_unix.c +++ b/net/sunrpc/auth_unix.c | |||
| @@ -20,11 +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 | |||
| 27 | #define UNX_CRED_EXPIRE (60 * HZ) | ||
| 28 | 23 | ||
| 29 | #define UNX_WRITESLACK (21 + (UNX_MAXNODENAME >> 2)) | 24 | #define UNX_WRITESLACK (21 + (UNX_MAXNODENAME >> 2)) |
| 30 | 25 | ||
| @@ -34,15 +29,14 @@ struct unx_cred { | |||
| 34 | 29 | ||
| 35 | static struct rpc_auth unix_auth; | 30 | static struct rpc_auth unix_auth; |
| 36 | static struct rpc_cred_cache unix_cred_cache; | 31 | static struct rpc_cred_cache unix_cred_cache; |
| 37 | static struct rpc_credops unix_credops; | 32 | static const struct rpc_credops unix_credops; |
| 38 | 33 | ||
| 39 | static struct rpc_auth * | 34 | static struct rpc_auth * |
| 40 | unx_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor) | 35 | unx_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor) |
| 41 | { | 36 | { |
| 42 | dprintk("RPC: creating UNIX authenticator for client %p\n", | 37 | dprintk("RPC: creating UNIX authenticator for client %p\n", |
| 43 | clnt); | 38 | clnt); |
| 44 | if (atomic_inc_return(&unix_auth.au_count) == 0) | 39 | atomic_inc(&unix_auth.au_count); |
| 45 | unix_cred_cache.nextgc = jiffies + (unix_cred_cache.expire >> 1); | ||
| 46 | return &unix_auth; | 40 | return &unix_auth; |
| 47 | } | 41 | } |
| 48 | 42 | ||
| @@ -50,7 +44,7 @@ static void | |||
| 50 | unx_destroy(struct rpc_auth *auth) | 44 | unx_destroy(struct rpc_auth *auth) |
| 51 | { | 45 | { |
| 52 | dprintk("RPC: destroying UNIX authenticator %p\n", auth); | 46 | dprintk("RPC: destroying UNIX authenticator %p\n", auth); |
| 53 | rpcauth_free_credcache(auth); | 47 | rpcauth_clear_credcache(auth->au_credcache); |
| 54 | } | 48 | } |
| 55 | 49 | ||
| 56 | /* | 50 | /* |
| @@ -74,8 +68,8 @@ unx_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags) | |||
| 74 | if (!(cred = kmalloc(sizeof(*cred), GFP_KERNEL))) | 68 | if (!(cred = kmalloc(sizeof(*cred), GFP_KERNEL))) |
| 75 | return ERR_PTR(-ENOMEM); | 69 | return ERR_PTR(-ENOMEM); |
| 76 | 70 | ||
| 77 | atomic_set(&cred->uc_count, 1); | 71 | rpcauth_init_cred(&cred->uc_base, acred, auth, &unix_credops); |
| 78 | cred->uc_flags = RPCAUTH_CRED_UPTODATE; | 72 | cred->uc_base.cr_flags = 1UL << RPCAUTH_CRED_UPTODATE; |
| 79 | if (flags & RPCAUTH_LOOKUP_ROOTCREDS) { | 73 | if (flags & RPCAUTH_LOOKUP_ROOTCREDS) { |
| 80 | cred->uc_uid = 0; | 74 | cred->uc_uid = 0; |
| 81 | cred->uc_gid = 0; | 75 | cred->uc_gid = 0; |
| @@ -85,22 +79,34 @@ unx_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags) | |||
| 85 | if (groups > NFS_NGROUPS) | 79 | if (groups > NFS_NGROUPS) |
| 86 | groups = NFS_NGROUPS; | 80 | groups = NFS_NGROUPS; |
| 87 | 81 | ||
| 88 | cred->uc_uid = acred->uid; | ||
| 89 | cred->uc_gid = acred->gid; | 82 | cred->uc_gid = acred->gid; |
| 90 | for (i = 0; i < groups; i++) | 83 | for (i = 0; i < groups; i++) |
| 91 | cred->uc_gids[i] = GROUP_AT(acred->group_info, i); | 84 | cred->uc_gids[i] = GROUP_AT(acred->group_info, i); |
| 92 | if (i < NFS_NGROUPS) | 85 | if (i < NFS_NGROUPS) |
| 93 | cred->uc_gids[i] = NOGROUP; | 86 | cred->uc_gids[i] = NOGROUP; |
| 94 | } | 87 | } |
| 95 | cred->uc_base.cr_ops = &unix_credops; | ||
| 96 | 88 | ||
| 97 | return (struct rpc_cred *) cred; | 89 | return &cred->uc_base; |
| 90 | } | ||
| 91 | |||
| 92 | static void | ||
| 93 | unx_free_cred(struct unx_cred *unx_cred) | ||
| 94 | { | ||
| 95 | dprintk("RPC: unx_free_cred %p\n", unx_cred); | ||
| 96 | kfree(unx_cred); | ||
| 97 | } | ||
| 98 | |||
| 99 | static void | ||
| 100 | unx_free_cred_callback(struct rcu_head *head) | ||
| 101 | { | ||
| 102 | struct unx_cred *unx_cred = container_of(head, struct unx_cred, uc_base.cr_rcu); | ||
| 103 | unx_free_cred(unx_cred); | ||
| 98 | } | 104 | } |
| 99 | 105 | ||
| 100 | static void | 106 | static void |
| 101 | unx_destroy_cred(struct rpc_cred *cred) | 107 | unx_destroy_cred(struct rpc_cred *cred) |
| 102 | { | 108 | { |
| 103 | kfree(cred); | 109 | call_rcu(&cred->cr_rcu, unx_free_cred_callback); |
| 104 | } | 110 | } |
| 105 | 111 | ||
| 106 | /* | 112 | /* |
| @@ -111,7 +117,7 @@ unx_destroy_cred(struct rpc_cred *cred) | |||
| 111 | static int | 117 | static int |
| 112 | unx_match(struct auth_cred *acred, struct rpc_cred *rcred, int flags) | 118 | unx_match(struct auth_cred *acred, struct rpc_cred *rcred, int flags) |
| 113 | { | 119 | { |
| 114 | struct unx_cred *cred = (struct unx_cred *) rcred; | 120 | struct unx_cred *cred = container_of(rcred, struct unx_cred, uc_base); |
| 115 | int i; | 121 | int i; |
| 116 | 122 | ||
| 117 | if (!(flags & RPCAUTH_LOOKUP_ROOTCREDS)) { | 123 | if (!(flags & RPCAUTH_LOOKUP_ROOTCREDS)) { |
| @@ -142,7 +148,7 @@ static __be32 * | |||
| 142 | unx_marshal(struct rpc_task *task, __be32 *p) | 148 | unx_marshal(struct rpc_task *task, __be32 *p) |
| 143 | { | 149 | { |
| 144 | struct rpc_clnt *clnt = task->tk_client; | 150 | struct rpc_clnt *clnt = task->tk_client; |
| 145 | struct unx_cred *cred = (struct unx_cred *) task->tk_msg.rpc_cred; | 151 | struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base); |
| 146 | __be32 *base, *hold; | 152 | __be32 *base, *hold; |
| 147 | int i; | 153 | int i; |
| 148 | 154 | ||
| @@ -175,7 +181,7 @@ unx_marshal(struct rpc_task *task, __be32 *p) | |||
| 175 | static int | 181 | static int |
| 176 | unx_refresh(struct rpc_task *task) | 182 | unx_refresh(struct rpc_task *task) |
| 177 | { | 183 | { |
| 178 | task->tk_msg.rpc_cred->cr_flags |= RPCAUTH_CRED_UPTODATE; | 184 | set_bit(RPCAUTH_CRED_UPTODATE, &task->tk_msg.rpc_cred->cr_flags); |
| 179 | return 0; | 185 | return 0; |
| 180 | } | 186 | } |
| 181 | 187 | ||
| @@ -198,13 +204,18 @@ unx_validate(struct rpc_task *task, __be32 *p) | |||
| 198 | printk("RPC: giant verf size: %u\n", size); | 204 | printk("RPC: giant verf size: %u\n", size); |
| 199 | return NULL; | 205 | return NULL; |
| 200 | } | 206 | } |
| 201 | task->tk_auth->au_rslack = (size >> 2) + 2; | 207 | task->tk_msg.rpc_cred->cr_auth->au_rslack = (size >> 2) + 2; |
| 202 | p += (size >> 2); | 208 | p += (size >> 2); |
| 203 | 209 | ||
| 204 | return p; | 210 | return p; |
| 205 | } | 211 | } |
| 206 | 212 | ||
| 207 | struct rpc_authops authunix_ops = { | 213 | void __init rpc_init_authunix(void) |
| 214 | { | ||
| 215 | spin_lock_init(&unix_cred_cache.lock); | ||
| 216 | } | ||
| 217 | |||
| 218 | const struct rpc_authops authunix_ops = { | ||
| 208 | .owner = THIS_MODULE, | 219 | .owner = THIS_MODULE, |
| 209 | .au_flavor = RPC_AUTH_UNIX, | 220 | .au_flavor = RPC_AUTH_UNIX, |
| 210 | #ifdef RPC_DEBUG | 221 | #ifdef RPC_DEBUG |
| @@ -218,7 +229,6 @@ struct rpc_authops authunix_ops = { | |||
| 218 | 229 | ||
| 219 | static | 230 | static |
| 220 | struct rpc_cred_cache unix_cred_cache = { | 231 | struct rpc_cred_cache unix_cred_cache = { |
| 221 | .expire = UNX_CRED_EXPIRE, | ||
| 222 | }; | 232 | }; |
| 223 | 233 | ||
| 224 | static | 234 | static |
| @@ -232,7 +242,7 @@ struct rpc_auth unix_auth = { | |||
| 232 | }; | 242 | }; |
| 233 | 243 | ||
| 234 | static | 244 | static |
| 235 | struct rpc_credops unix_credops = { | 245 | const struct rpc_credops unix_credops = { |
| 236 | .cr_name = "AUTH_UNIX", | 246 | .cr_name = "AUTH_UNIX", |
| 237 | .crdestroy = unx_destroy_cred, | 247 | .crdestroy = unx_destroy_cred, |
| 238 | .crmatch = unx_match, | 248 | .crmatch = unx_match, |
