From: Alan T. DeKok Date: Fri, 13 Apr 2012 14:58:54 +0000 (+0200) Subject: Added "instance" to xlat_unregister X-Git-Tag: release_2_2_0~142 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3504e1766ae965c2983f6ea4c8aa17bb840f4a4;p=thirdparty%2Ffreeradius-server.git Added "instance" to xlat_unregister This is so that on HUP, a module can re-register, and over-ride the old value. When the old module is deleted, it de-registers its xlat. But because the instance is now different, it doesn't delete the *new* xlat --- diff --git a/src/include/radiusd.h b/src/include/radiusd.h index 2809100a78e..38890a5f58b 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -599,7 +599,8 @@ int radius_xlat(char * out, int outlen, const char *fmt, typedef size_t (*RAD_XLAT_FUNC)(void *instance, REQUEST *, char *, char *, size_t, RADIUS_ESCAPE_STRING func); int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance); -void xlat_unregister(const char *module, RAD_XLAT_FUNC func); +void xlat_unregister(const char *module, RAD_XLAT_FUNC func, + void *instance); void xlat_free(void); /* threads.c */ diff --git a/src/main/xlat.c b/src/main/xlat.c index 25ea050e88a..ca5207d3250 100644 --- a/src/main/xlat.c +++ b/src/main/xlat.c @@ -795,9 +795,9 @@ int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance) * We can only have one function to call per name, so the * passing of "func" here is extraneous. */ -void xlat_unregister(const char *module, RAD_XLAT_FUNC func) +void xlat_unregister(const char *module, RAD_XLAT_FUNC func, void *instance) { - rbnode_t *node; + xlat_t *c; xlat_t my_xlat; func = func; /* -Wunused */ @@ -807,10 +807,12 @@ void xlat_unregister(const char *module, RAD_XLAT_FUNC func) strlcpy(my_xlat.module, module, sizeof(my_xlat.module)); my_xlat.length = strlen(my_xlat.module); - node = rbtree_find(xlat_root, &my_xlat); - if (!node) return; + c = rbtree_finddata(xlat_root, &my_xlat); + if (!c) return; + + if (c->instance != instance) return; - rbtree_delete(xlat_root, node); + rbtree_deletebydata(xlat_root, c); } /* diff --git a/src/modules/rlm_exec/rlm_exec.c b/src/modules/rlm_exec/rlm_exec.c index f4c8a46b7f9..41002f81a6f 100644 --- a/src/modules/rlm_exec/rlm_exec.c +++ b/src/modules/rlm_exec/rlm_exec.c @@ -160,7 +160,7 @@ static int exec_detach(void *instance) rlm_exec_t *inst = instance; if (inst->xlat_name) { - xlat_unregister(inst->xlat_name, exec_xlat); + xlat_unregister(inst->xlat_name, exec_xlat, instance); free(inst->xlat_name); } diff --git a/src/modules/rlm_expr/rlm_expr.c b/src/modules/rlm_expr/rlm_expr.c index 80e1f08aa49..bcb9bb98783 100644 --- a/src/modules/rlm_expr/rlm_expr.c +++ b/src/modules/rlm_expr/rlm_expr.c @@ -338,7 +338,7 @@ static int expr_detach(void *instance) { rlm_expr_t *inst = instance; - xlat_unregister(inst->xlat_name, expr_xlat); + xlat_unregister(inst->xlat_name, expr_xlat, instance); pair_builtincompare_detach(); free(inst->xlat_name); diff --git a/src/modules/rlm_ldap/rlm_ldap.c b/src/modules/rlm_ldap/rlm_ldap.c index a2b5200bb7e..edda19d8252 100644 --- a/src/modules/rlm_ldap/rlm_ldap.c +++ b/src/modules/rlm_ldap/rlm_ldap.c @@ -2636,7 +2636,7 @@ ldap_detach(void *instance) free(inst->atts); paircompare_unregister(PW_LDAP_GROUP, ldap_groupcmp); - xlat_unregister(inst->xlat_name,ldap_xlat); + xlat_unregister(inst->xlat_name,ldap_xlat, instance); free(inst->xlat_name); free(inst); diff --git a/src/modules/rlm_mschap/rlm_mschap.c b/src/modules/rlm_mschap/rlm_mschap.c index ea700047113..918befe44db 100644 --- a/src/modules/rlm_mschap/rlm_mschap.c +++ b/src/modules/rlm_mschap/rlm_mschap.c @@ -554,7 +554,7 @@ static const CONF_PARSER module_config[] = { static int mschap_detach(void *instance){ #define inst ((rlm_mschap_t *)instance) if (inst->xlat_name) { - xlat_unregister(inst->xlat_name, mschap_xlat); + xlat_unregister(inst->xlat_name, mschap_xlat, instance); free(inst->xlat_name); } free(instance); diff --git a/src/modules/rlm_perl/rlm_perl.c b/src/modules/rlm_perl/rlm_perl.c index 4682ba507bc..122d52db12d 100644 --- a/src/modules/rlm_perl/rlm_perl.c +++ b/src/modules/rlm_perl/rlm_perl.c @@ -978,7 +978,7 @@ static int perl_detach(void *instance) } } - xlat_unregister(inst->xlat_name, perl_xlat); + xlat_unregister(inst->xlat_name, perl_xlat, instance); free(inst->xlat_name); #ifdef USE_ITHREADS diff --git a/src/modules/rlm_redis/rlm_redis.c b/src/modules/rlm_redis/rlm_redis.c index 515533e1c25..5d6140a9104 100644 --- a/src/modules/rlm_redis/rlm_redis.c +++ b/src/modules/rlm_redis/rlm_redis.c @@ -268,7 +268,7 @@ static int redis_detach(void *instance) redis_poolfree(inst); if (inst->xlat_name) { - xlat_unregister(inst->xlat_name, (RAD_XLAT_FUNC)redis_xlat); + xlat_unregister(inst->xlat_name, (RAD_XLAT_FUNC)redis_xlat, instance); free(inst->xlat_name); } free(inst->xlat_name); diff --git a/src/modules/rlm_soh/rlm_soh.c b/src/modules/rlm_soh/rlm_soh.c index b98a79cb4f4..92dd867176e 100644 --- a/src/modules/rlm_soh/rlm_soh.c +++ b/src/modules/rlm_soh/rlm_soh.c @@ -108,7 +108,7 @@ static int soh_detach(void *instance) { rlm_soh_t *inst = instance; if (inst->xlat_name) { - xlat_unregister(inst->xlat_name, soh_xlat); + xlat_unregister(inst->xlat_name, soh_xlat, instance); free(inst->xlat_name); } free(instance); diff --git a/src/modules/rlm_sql/rlm_sql.c b/src/modules/rlm_sql/rlm_sql.c index c26bded430a..6f75c13adff 100644 --- a/src/modules/rlm_sql/rlm_sql.c +++ b/src/modules/rlm_sql/rlm_sql.c @@ -810,7 +810,7 @@ static int rlm_sql_detach(void *instance) } if (inst->config->xlat_name) { - xlat_unregister(inst->config->xlat_name,(RAD_XLAT_FUNC)sql_xlat); + xlat_unregister(inst->config->xlat_name,(RAD_XLAT_FUNC)sql_xlat, instance); free(inst->config->xlat_name); }