diff options
Diffstat (limited to 'net/sunrpc/svcauth_unix.c')
| -rw-r--r-- | net/sunrpc/svcauth_unix.c | 229 |
1 files changed, 135 insertions, 94 deletions
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index 3e6c694bbad1..7e5707e2d6b6 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c | |||
| @@ -27,41 +27,35 @@ struct unix_domain { | |||
| 27 | /* other stuff later */ | 27 | /* other stuff later */ |
| 28 | }; | 28 | }; |
| 29 | 29 | ||
| 30 | extern struct auth_ops svcauth_unix; | ||
| 31 | |||
| 30 | struct auth_domain *unix_domain_find(char *name) | 32 | struct auth_domain *unix_domain_find(char *name) |
| 31 | { | 33 | { |
| 32 | struct auth_domain *rv, ud; | 34 | struct auth_domain *rv; |
| 33 | struct unix_domain *new; | 35 | struct unix_domain *new = NULL; |
| 34 | 36 | ||
| 35 | ud.name = name; | 37 | rv = auth_domain_lookup(name, NULL); |
| 36 | 38 | while(1) { | |
| 37 | rv = auth_domain_lookup(&ud, 0); | 39 | if (rv) { |
| 38 | 40 | if (new && rv != &new->h) | |
| 39 | foundit: | 41 | auth_domain_put(&new->h); |
| 40 | if (rv && rv->flavour != RPC_AUTH_UNIX) { | 42 | |
| 41 | auth_domain_put(rv); | 43 | if (rv->flavour != &svcauth_unix) { |
| 42 | return NULL; | 44 | auth_domain_put(rv); |
| 43 | } | 45 | return NULL; |
| 44 | if (rv) | 46 | } |
| 45 | return rv; | 47 | return rv; |
| 46 | 48 | } | |
| 47 | new = kmalloc(sizeof(*new), GFP_KERNEL); | 49 | |
| 48 | if (new == NULL) | 50 | new = kmalloc(sizeof(*new), GFP_KERNEL); |
| 49 | return NULL; | 51 | if (new == NULL) |
| 50 | cache_init(&new->h.h); | 52 | return NULL; |
| 51 | new->h.name = kstrdup(name, GFP_KERNEL); | 53 | kref_init(&new->h.ref); |
| 52 | new->h.flavour = RPC_AUTH_UNIX; | 54 | new->h.name = kstrdup(name, GFP_KERNEL); |
| 53 | new->addr_changes = 0; | 55 | new->h.flavour = &svcauth_unix; |
| 54 | new->h.h.expiry_time = NEVER; | 56 | new->addr_changes = 0; |
| 55 | 57 | rv = auth_domain_lookup(name, &new->h); | |
| 56 | rv = auth_domain_lookup(&new->h, 2); | ||
| 57 | if (rv == &new->h) { | ||
| 58 | if (atomic_dec_and_test(&new->h.h.refcnt)) BUG(); | ||
| 59 | } else { | ||
| 60 | auth_domain_put(&new->h); | ||
| 61 | goto foundit; | ||
| 62 | } | 58 | } |
| 63 | |||
| 64 | return rv; | ||
| 65 | } | 59 | } |
| 66 | 60 | ||
| 67 | static void svcauth_unix_domain_release(struct auth_domain *dom) | 61 | static void svcauth_unix_domain_release(struct auth_domain *dom) |
| @@ -90,15 +84,15 @@ struct ip_map { | |||
| 90 | }; | 84 | }; |
| 91 | static struct cache_head *ip_table[IP_HASHMAX]; | 85 | static struct cache_head *ip_table[IP_HASHMAX]; |
| 92 | 86 | ||
| 93 | static void ip_map_put(struct cache_head *item, struct cache_detail *cd) | 87 | static void ip_map_put(struct kref *kref) |
| 94 | { | 88 | { |
| 89 | struct cache_head *item = container_of(kref, struct cache_head, ref); | ||
| 95 | struct ip_map *im = container_of(item, struct ip_map,h); | 90 | struct ip_map *im = container_of(item, struct ip_map,h); |
| 96 | if (cache_put(item, cd)) { | 91 | |
| 97 | if (test_bit(CACHE_VALID, &item->flags) && | 92 | if (test_bit(CACHE_VALID, &item->flags) && |
| 98 | !test_bit(CACHE_NEGATIVE, &item->flags)) | 93 | !test_bit(CACHE_NEGATIVE, &item->flags)) |
| 99 | auth_domain_put(&im->m_client->h); | 94 | auth_domain_put(&im->m_client->h); |
| 100 | kfree(im); | 95 | kfree(im); |
| 101 | } | ||
| 102 | } | 96 | } |
| 103 | 97 | ||
| 104 | #if IP_HASHBITS == 8 | 98 | #if IP_HASHBITS == 8 |
| @@ -112,28 +106,38 @@ static inline int hash_ip(unsigned long ip) | |||
| 112 | return (hash ^ (hash>>8)) & 0xff; | 106 | return (hash ^ (hash>>8)) & 0xff; |
| 113 | } | 107 | } |
| 114 | #endif | 108 | #endif |
| 115 | 109 | static int ip_map_match(struct cache_head *corig, struct cache_head *cnew) | |
| 116 | static inline int ip_map_hash(struct ip_map *item) | ||
| 117 | { | ||
| 118 | return hash_str(item->m_class, IP_HASHBITS) ^ | ||
| 119 | hash_ip((unsigned long)item->m_addr.s_addr); | ||
| 120 | } | ||
| 121 | static inline int ip_map_match(struct ip_map *item, struct ip_map *tmp) | ||
| 122 | { | 110 | { |
| 123 | return strcmp(tmp->m_class, item->m_class) == 0 | 111 | struct ip_map *orig = container_of(corig, struct ip_map, h); |
| 124 | && tmp->m_addr.s_addr == item->m_addr.s_addr; | 112 | struct ip_map *new = container_of(cnew, struct ip_map, h); |
| 113 | return strcmp(orig->m_class, new->m_class) == 0 | ||
| 114 | && orig->m_addr.s_addr == new->m_addr.s_addr; | ||
| 125 | } | 115 | } |
| 126 | static inline void ip_map_init(struct ip_map *new, struct ip_map *item) | 116 | static void ip_map_init(struct cache_head *cnew, struct cache_head *citem) |
| 127 | { | 117 | { |
| 118 | struct ip_map *new = container_of(cnew, struct ip_map, h); | ||
| 119 | struct ip_map *item = container_of(citem, struct ip_map, h); | ||
| 120 | |||
| 128 | strcpy(new->m_class, item->m_class); | 121 | strcpy(new->m_class, item->m_class); |
| 129 | new->m_addr.s_addr = item->m_addr.s_addr; | 122 | new->m_addr.s_addr = item->m_addr.s_addr; |
| 130 | } | 123 | } |
| 131 | static inline void ip_map_update(struct ip_map *new, struct ip_map *item) | 124 | static void update(struct cache_head *cnew, struct cache_head *citem) |
| 132 | { | 125 | { |
| 133 | cache_get(&item->m_client->h.h); | 126 | struct ip_map *new = container_of(cnew, struct ip_map, h); |
| 127 | struct ip_map *item = container_of(citem, struct ip_map, h); | ||
| 128 | |||
| 129 | kref_get(&item->m_client->h.ref); | ||
| 134 | new->m_client = item->m_client; | 130 | new->m_client = item->m_client; |
| 135 | new->m_add_change = item->m_add_change; | 131 | new->m_add_change = item->m_add_change; |
| 136 | } | 132 | } |
| 133 | static struct cache_head *ip_map_alloc(void) | ||
| 134 | { | ||
| 135 | struct ip_map *i = kmalloc(sizeof(*i), GFP_KERNEL); | ||
| 136 | if (i) | ||
| 137 | return &i->h; | ||
| 138 | else | ||
| 139 | return NULL; | ||
| 140 | } | ||
| 137 | 141 | ||
| 138 | static void ip_map_request(struct cache_detail *cd, | 142 | static void ip_map_request(struct cache_detail *cd, |
| 139 | struct cache_head *h, | 143 | struct cache_head *h, |
| @@ -154,7 +158,8 @@ static void ip_map_request(struct cache_detail *cd, | |||
| 154 | (*bpp)[-1] = '\n'; | 158 | (*bpp)[-1] = '\n'; |
| 155 | } | 159 | } |
| 156 | 160 | ||
| 157 | static struct ip_map *ip_map_lookup(struct ip_map *, int); | 161 | static struct ip_map *ip_map_lookup(char *class, struct in_addr addr); |
| 162 | static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t expiry); | ||
| 158 | 163 | ||
| 159 | static int ip_map_parse(struct cache_detail *cd, | 164 | static int ip_map_parse(struct cache_detail *cd, |
| 160 | char *mesg, int mlen) | 165 | char *mesg, int mlen) |
| @@ -166,7 +171,11 @@ static int ip_map_parse(struct cache_detail *cd, | |||
| 166 | int len; | 171 | int len; |
| 167 | int b1,b2,b3,b4; | 172 | int b1,b2,b3,b4; |
| 168 | char c; | 173 | char c; |
| 169 | struct ip_map ipm, *ipmp; | 174 | char class[8]; |
| 175 | struct in_addr addr; | ||
| 176 | int err; | ||
| 177 | |||
| 178 | struct ip_map *ipmp; | ||
| 170 | struct auth_domain *dom; | 179 | struct auth_domain *dom; |
| 171 | time_t expiry; | 180 | time_t expiry; |
| 172 | 181 | ||
| @@ -175,7 +184,7 @@ static int ip_map_parse(struct cache_detail *cd, | |||
| 175 | mesg[mlen-1] = 0; | 184 | mesg[mlen-1] = 0; |
| 176 | 185 | ||
| 177 | /* class */ | 186 | /* class */ |
| 178 | len = qword_get(&mesg, ipm.m_class, sizeof(ipm.m_class)); | 187 | len = qword_get(&mesg, class, sizeof(class)); |
| 179 | if (len <= 0) return -EINVAL; | 188 | if (len <= 0) return -EINVAL; |
| 180 | 189 | ||
| 181 | /* ip address */ | 190 | /* ip address */ |
| @@ -200,25 +209,22 @@ static int ip_map_parse(struct cache_detail *cd, | |||
| 200 | } else | 209 | } else |
| 201 | dom = NULL; | 210 | dom = NULL; |
| 202 | 211 | ||
| 203 | ipm.m_addr.s_addr = | 212 | addr.s_addr = |
| 204 | htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4); | 213 | htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4); |
| 205 | ipm.h.flags = 0; | 214 | |
| 206 | if (dom) { | 215 | ipmp = ip_map_lookup(class,addr); |
| 207 | ipm.m_client = container_of(dom, struct unix_domain, h); | 216 | if (ipmp) { |
| 208 | ipm.m_add_change = ipm.m_client->addr_changes; | 217 | err = ip_map_update(ipmp, |
| 218 | container_of(dom, struct unix_domain, h), | ||
| 219 | expiry); | ||
| 209 | } else | 220 | } else |
| 210 | set_bit(CACHE_NEGATIVE, &ipm.h.flags); | 221 | err = -ENOMEM; |
| 211 | ipm.h.expiry_time = expiry; | ||
| 212 | 222 | ||
| 213 | ipmp = ip_map_lookup(&ipm, 1); | ||
| 214 | if (ipmp) | ||
| 215 | ip_map_put(&ipmp->h, &ip_map_cache); | ||
| 216 | if (dom) | 223 | if (dom) |
| 217 | auth_domain_put(dom); | 224 | auth_domain_put(dom); |
| 218 | if (!ipmp) | 225 | |
| 219 | return -ENOMEM; | ||
| 220 | cache_flush(); | 226 | cache_flush(); |
| 221 | return 0; | 227 | return err; |
| 222 | } | 228 | } |
| 223 | 229 | ||
| 224 | static int ip_map_show(struct seq_file *m, | 230 | static int ip_map_show(struct seq_file *m, |
| @@ -262,32 +268,70 @@ struct cache_detail ip_map_cache = { | |||
| 262 | .cache_request = ip_map_request, | 268 | .cache_request = ip_map_request, |
| 263 | .cache_parse = ip_map_parse, | 269 | .cache_parse = ip_map_parse, |
| 264 | .cache_show = ip_map_show, | 270 | .cache_show = ip_map_show, |
| 271 | .match = ip_map_match, | ||
| 272 | .init = ip_map_init, | ||
| 273 | .update = update, | ||
| 274 | .alloc = ip_map_alloc, | ||
| 265 | }; | 275 | }; |
| 266 | 276 | ||
| 267 | static DefineSimpleCacheLookup(ip_map, 0) | 277 | static struct ip_map *ip_map_lookup(char *class, struct in_addr addr) |
| 278 | { | ||
| 279 | struct ip_map ip; | ||
| 280 | struct cache_head *ch; | ||
| 281 | |||
| 282 | strcpy(ip.m_class, class); | ||
| 283 | ip.m_addr = addr; | ||
| 284 | ch = sunrpc_cache_lookup(&ip_map_cache, &ip.h, | ||
| 285 | hash_str(class, IP_HASHBITS) ^ | ||
| 286 | hash_ip((unsigned long)addr.s_addr)); | ||
| 287 | |||
| 288 | if (ch) | ||
| 289 | return container_of(ch, struct ip_map, h); | ||
| 290 | else | ||
| 291 | return NULL; | ||
| 292 | } | ||
| 268 | 293 | ||
| 294 | static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t expiry) | ||
| 295 | { | ||
| 296 | struct ip_map ip; | ||
| 297 | struct cache_head *ch; | ||
| 298 | |||
| 299 | ip.m_client = udom; | ||
| 300 | ip.h.flags = 0; | ||
| 301 | if (!udom) | ||
| 302 | set_bit(CACHE_NEGATIVE, &ip.h.flags); | ||
| 303 | else { | ||
| 304 | ip.m_add_change = udom->addr_changes; | ||
| 305 | /* if this is from the legacy set_client system call, | ||
| 306 | * we need m_add_change to be one higher | ||
| 307 | */ | ||
| 308 | if (expiry == NEVER) | ||
| 309 | ip.m_add_change++; | ||
| 310 | } | ||
| 311 | ip.h.expiry_time = expiry; | ||
| 312 | ch = sunrpc_cache_update(&ip_map_cache, | ||
| 313 | &ip.h, &ipm->h, | ||
| 314 | hash_str(ipm->m_class, IP_HASHBITS) ^ | ||
| 315 | hash_ip((unsigned long)ipm->m_addr.s_addr)); | ||
| 316 | if (!ch) | ||
| 317 | return -ENOMEM; | ||
| 318 | cache_put(ch, &ip_map_cache); | ||
| 319 | return 0; | ||
| 320 | } | ||
| 269 | 321 | ||
| 270 | int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom) | 322 | int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom) |
| 271 | { | 323 | { |
| 272 | struct unix_domain *udom; | 324 | struct unix_domain *udom; |
| 273 | struct ip_map ip, *ipmp; | 325 | struct ip_map *ipmp; |
| 274 | 326 | ||
| 275 | if (dom->flavour != RPC_AUTH_UNIX) | 327 | if (dom->flavour != &svcauth_unix) |
| 276 | return -EINVAL; | 328 | return -EINVAL; |
| 277 | udom = container_of(dom, struct unix_domain, h); | 329 | udom = container_of(dom, struct unix_domain, h); |
| 278 | strcpy(ip.m_class, "nfsd"); | 330 | ipmp = ip_map_lookup("nfsd", addr); |
| 279 | ip.m_addr = addr; | ||
| 280 | ip.m_client = udom; | ||
| 281 | ip.m_add_change = udom->addr_changes+1; | ||
| 282 | ip.h.flags = 0; | ||
| 283 | ip.h.expiry_time = NEVER; | ||
| 284 | |||
| 285 | ipmp = ip_map_lookup(&ip, 1); | ||
| 286 | 331 | ||
| 287 | if (ipmp) { | 332 | if (ipmp) |
| 288 | ip_map_put(&ipmp->h, &ip_map_cache); | 333 | return ip_map_update(ipmp, udom, NEVER); |
| 289 | return 0; | 334 | else |
| 290 | } else | ||
| 291 | return -ENOMEM; | 335 | return -ENOMEM; |
| 292 | } | 336 | } |
| 293 | 337 | ||
| @@ -295,7 +339,7 @@ int auth_unix_forget_old(struct auth_domain *dom) | |||
| 295 | { | 339 | { |
| 296 | struct unix_domain *udom; | 340 | struct unix_domain *udom; |
| 297 | 341 | ||
| 298 | if (dom->flavour != RPC_AUTH_UNIX) | 342 | if (dom->flavour != &svcauth_unix) |
| 299 | return -EINVAL; | 343 | return -EINVAL; |
| 300 | udom = container_of(dom, struct unix_domain, h); | 344 | udom = container_of(dom, struct unix_domain, h); |
| 301 | udom->addr_changes++; | 345 | udom->addr_changes++; |
| @@ -310,7 +354,7 @@ struct auth_domain *auth_unix_lookup(struct in_addr addr) | |||
| 310 | strcpy(key.m_class, "nfsd"); | 354 | strcpy(key.m_class, "nfsd"); |
| 311 | key.m_addr = addr; | 355 | key.m_addr = addr; |
| 312 | 356 | ||
| 313 | ipm = ip_map_lookup(&key, 0); | 357 | ipm = ip_map_lookup("nfsd", addr); |
| 314 | 358 | ||
| 315 | if (!ipm) | 359 | if (!ipm) |
| 316 | return NULL; | 360 | return NULL; |
| @@ -323,31 +367,28 @@ struct auth_domain *auth_unix_lookup(struct in_addr addr) | |||
| 323 | rv = NULL; | 367 | rv = NULL; |
| 324 | } else { | 368 | } else { |
| 325 | rv = &ipm->m_client->h; | 369 | rv = &ipm->m_client->h; |
| 326 | cache_get(&rv->h); | 370 | kref_get(&rv->ref); |
| 327 | } | 371 | } |
| 328 | ip_map_put(&ipm->h, &ip_map_cache); | 372 | cache_put(&ipm->h, &ip_map_cache); |
| 329 | return rv; | 373 | return rv; |
| 330 | } | 374 | } |
| 331 | 375 | ||
| 332 | void svcauth_unix_purge(void) | 376 | void svcauth_unix_purge(void) |
| 333 | { | 377 | { |
| 334 | cache_purge(&ip_map_cache); | 378 | cache_purge(&ip_map_cache); |
| 335 | cache_purge(&auth_domain_cache); | ||
| 336 | } | 379 | } |
| 337 | 380 | ||
| 338 | static int | 381 | static int |
| 339 | svcauth_unix_set_client(struct svc_rqst *rqstp) | 382 | svcauth_unix_set_client(struct svc_rqst *rqstp) |
| 340 | { | 383 | { |
| 341 | struct ip_map key, *ipm; | 384 | struct ip_map *ipm; |
| 342 | 385 | ||
| 343 | rqstp->rq_client = NULL; | 386 | rqstp->rq_client = NULL; |
| 344 | if (rqstp->rq_proc == 0) | 387 | if (rqstp->rq_proc == 0) |
| 345 | return SVC_OK; | 388 | return SVC_OK; |
| 346 | 389 | ||
| 347 | strcpy(key.m_class, rqstp->rq_server->sv_program->pg_class); | 390 | ipm = ip_map_lookup(rqstp->rq_server->sv_program->pg_class, |
| 348 | key.m_addr = rqstp->rq_addr.sin_addr; | 391 | rqstp->rq_addr.sin_addr); |
| 349 | |||
| 350 | ipm = ip_map_lookup(&key, 0); | ||
| 351 | 392 | ||
| 352 | if (ipm == NULL) | 393 | if (ipm == NULL) |
| 353 | return SVC_DENIED; | 394 | return SVC_DENIED; |
| @@ -361,8 +402,8 @@ svcauth_unix_set_client(struct svc_rqst *rqstp) | |||
| 361 | return SVC_DENIED; | 402 | return SVC_DENIED; |
| 362 | case 0: | 403 | case 0: |
| 363 | rqstp->rq_client = &ipm->m_client->h; | 404 | rqstp->rq_client = &ipm->m_client->h; |
| 364 | cache_get(&rqstp->rq_client->h); | 405 | kref_get(&rqstp->rq_client->ref); |
| 365 | ip_map_put(&ipm->h, &ip_map_cache); | 406 | cache_put(&ipm->h, &ip_map_cache); |
| 366 | break; | 407 | break; |
| 367 | } | 408 | } |
| 368 | return SVC_OK; | 409 | return SVC_OK; |
