X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=net%2Fsunrpc%2Fsvcauth.c;h=0148c3310157d8b769a7eebe7a1f991cb157b3e2;hb=6a77f38946aaee1cd85eeec6cf4229b204c15071;hp=db78e727d1ebf429a810435fd23941c6527f1c8e;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/net/sunrpc/svcauth.c b/net/sunrpc/svcauth.c index db78e727d..0148c3310 100644 --- a/net/sunrpc/svcauth.c +++ b/net/sunrpc/svcauth.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -27,6 +28,7 @@ extern struct auth_ops svcauth_null; extern struct auth_ops svcauth_unix; +static DEFINE_SPINLOCK(authtab_lock); static struct auth_ops *authtab[RPC_AUTH_MAXFLAVOR] = { [0] = &svcauth_null, [1] = &svcauth_unix, @@ -43,10 +45,15 @@ svc_authenticate(struct svc_rqst *rqstp, u32 *authp) flavor = ntohl(svc_getu32(&rqstp->rq_arg.head[0])); dprintk("svc: svc_authenticate (%d)\n", flavor); - if (flavor >= RPC_AUTH_MAXFLAVOR || !(aops = authtab[flavor])) { + + spin_lock(&authtab_lock); + if (flavor >= RPC_AUTH_MAXFLAVOR || !(aops = authtab[flavor]) + || !try_module_get(aops->owner)) { + spin_unlock(&authtab_lock); *authp = rpc_autherr_badcred; return SVC_DENIED; } + spin_unlock(&authtab_lock); rqstp->rq_authop = aops; return aops->accept(rqstp, authp); @@ -63,28 +70,35 @@ int svc_authorise(struct svc_rqst *rqstp) rqstp->rq_authop = NULL; - if (aops) + if (aops) { rv = aops->release(rqstp); - - /* FIXME should I count and release authops */ + module_put(aops->owner); + } return rv; } int svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops) { - if (flavor >= RPC_AUTH_MAXFLAVOR || authtab[flavor]) - return -EINVAL; - authtab[flavor] = aops; - return 0; + int rv = -EINVAL; + spin_lock(&authtab_lock); + if (flavor < RPC_AUTH_MAXFLAVOR && authtab[flavor] == NULL) { + authtab[flavor] = aops; + rv = 0; + } + spin_unlock(&authtab_lock); + return rv; } void svc_auth_unregister(rpc_authflavor_t flavor) { + spin_lock(&authtab_lock); if (flavor < RPC_AUTH_MAXFLAVOR) authtab[flavor] = NULL; + spin_unlock(&authtab_lock); } +EXPORT_SYMBOL(svc_auth_unregister); /************************************************** * cache for domain name to auth_domain @@ -114,7 +128,8 @@ svc_auth_unregister(rpc_authflavor_t flavor) #define DN_HASHMASK (DN_HASHMAX-1) static struct cache_head *auth_domain_table[DN_HASHMAX]; -void auth_domain_drop(struct cache_head *item, struct cache_detail *cd) + +static void auth_domain_drop(struct cache_head *item, struct cache_detail *cd) { struct auth_domain *dom = container_of(item, struct auth_domain, h); if (cache_put(item,cd)) @@ -142,25 +157,49 @@ static inline int auth_domain_match(struct auth_domain *tmp, struct auth_domain { return strcmp(tmp->name, item->name) == 0; } -DefineCacheLookup(struct auth_domain, - h, - auth_domain_lookup, - (struct auth_domain *item, int set), - /* no setup */, - &auth_domain_cache, - auth_domain_hash(item), - auth_domain_match(tmp, item), - kfree(new); if(!set) { - if (new) - write_unlock(&auth_domain_cache.hash_lock); - else - read_unlock(&auth_domain_cache.hash_lock); - return NULL; - } - new=item; atomic_inc(&new->h.refcnt), - /* no update */, - 0 /* no inplace updates */ - ) + +struct auth_domain * +auth_domain_lookup(struct auth_domain *item, int set) +{ + struct auth_domain *tmp = NULL; + struct cache_head **hp, **head; + head = &auth_domain_cache.hash_table[auth_domain_hash(item)]; + + if (set) + write_lock(&auth_domain_cache.hash_lock); + else + read_lock(&auth_domain_cache.hash_lock); + for (hp=head; *hp != NULL; hp = &tmp->h.next) { + tmp = container_of(*hp, struct auth_domain, h); + if (!auth_domain_match(tmp, item)) + continue; + cache_get(&tmp->h); + if (!set) + goto out_noset; + *hp = tmp->h.next; + tmp->h.next = NULL; + clear_bit(CACHE_HASHED, &tmp->h.flags); + auth_domain_drop(&tmp->h, &auth_domain_cache); + goto out_set; + } + /* Didn't find anything */ + if (!set) + goto out_nada; + auth_domain_cache.entries++; +out_set: + set_bit(CACHE_HASHED, &item->h.flags); + item->h.next = *head; + *head = &item->h; + write_unlock(&auth_domain_cache.hash_lock); + cache_fresh(&auth_domain_cache, &item->h, item->h.expiry_time); + cache_get(&item->h); + return item; +out_nada: + tmp = NULL; +out_noset: + read_unlock(&auth_domain_cache.hash_lock); + return tmp; +} struct auth_domain *auth_domain_find(char *name) {