From: Arran Cudbard-Bell Date: Wed, 30 May 2018 05:46:43 +0000 (+0600) Subject: Add dictionary pointer to request, and use it to qualify name based dictionary lookups X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e2149264add245eb225e03645afa5ef82e03dea8;p=thirdparty%2Ffreeradius-server.git Add dictionary pointer to request, and use it to qualify name based dictionary lookups --- diff --git a/src/include/radiusd.h b/src/include/radiusd.h index 180ef2c33a1..2956260af21 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -212,6 +212,8 @@ struct rad_request { uint64_t child_number; //!< Monotonically increasing number for children of this request char const *name; //!< for debug printing, as (%d) is no longer sufficient + fr_dict_t const *dict; //!< Dictionary of the protocol that this request belongs to. + fr_event_list_t *el; //!< thread-specific event list. fr_heap_t *backlog; //!< thread-specific backlog fr_request_state_t request_state; //!< state for the various protocol handlers. diff --git a/src/main/request.c b/src/main/request.c index e40eca736a1..e20e807ad50 100644 --- a/src/main/request.c +++ b/src/main/request.c @@ -123,6 +123,7 @@ static REQUEST *request_init_fake(REQUEST *request, REQUEST *fake) fake->seq_start = 0; /* children always start with their own sequence */ fake->parent = request; + fake->dict = request->dict; fake->root = request->root; fake->client = request->client; diff --git a/src/main/tmpl.c b/src/main/tmpl.c index 8164540340c..e172c02306f 100644 --- a/src/main/tmpl.c +++ b/src/main/tmpl.c @@ -2506,7 +2506,7 @@ void tmpl_verify(char const *file, int line, vp_tmpl_t const *vpt) /* * Attribute may be present with multiple names */ - da = fr_dict_attr_by_name(NULL, vpt->tmpl_da->name); + da = fr_dict_attr_by_name(fr_dict_by_da(vpt->tmpl_da), vpt->tmpl_da->name); if (!da) { FR_FAULT_LOG("CONSISTENCY CHECK FAILED %s[%u]: TMPL_TYPE_ATTR " "attribute \"%s\" (%s) not found in global dictionary", diff --git a/src/main/trigger.c b/src/main/trigger.c index d417be0e004..68ea00a1b7c 100644 --- a/src/main/trigger.c +++ b/src/main/trigger.c @@ -67,7 +67,7 @@ static ssize_t xlat_trigger(UNUSED TALLOC_CTX *ctx, char **out, UNUSED size_t ou */ if (!head) return -1; - da = fr_dict_attr_by_name(NULL, fmt); + da = fr_dict_attr_by_name(request->dict, fmt); if (!da) { ERROR("Unknown attribute \"%s\"", fmt); return -1; diff --git a/src/modules/proto_dhcpv4/proto_dhcpv4.c b/src/modules/proto_dhcpv4/proto_dhcpv4.c index bac0c15c0ec..e06bcbd93bb 100644 --- a/src/modules/proto_dhcpv4/proto_dhcpv4.c +++ b/src/modules/proto_dhcpv4/proto_dhcpv4.c @@ -264,6 +264,13 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat rad_assert(data[0] < FR_MAX_PACKET_CODE); + /* + * Set the request dictionary so that we can do + * generic->protocol attribute conversions as + * the request runs through the server. + */ + request->dict = dict_dhcpv4; + #if 0 /* * @todo - print hex packets here! diff --git a/src/modules/proto_radius/proto_radius.c b/src/modules/proto_radius/proto_radius.c index ddbf6a13ef8..1d393fbfcb6 100644 --- a/src/modules/proto_radius/proto_radius.c +++ b/src/modules/proto_radius/proto_radius.c @@ -299,6 +299,13 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat fr_radius_print_hex(fr_log_fp, data, data_len); } + /* + * Set the request dictionary so that we can do + * generic->protocol attribute conversions as + * the request runs through the server. + */ + request->dict = dict_radius; + client = address->radclient; /* diff --git a/src/modules/proto_vmps/proto_vmps.c b/src/modules/proto_vmps/proto_vmps.c index 5fe29413f56..907d5ef19f2 100644 --- a/src/modules/proto_vmps/proto_vmps.c +++ b/src/modules/proto_vmps/proto_vmps.c @@ -229,6 +229,13 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat fr_vmps_print_hex(fr_log_fp, data, data_len); } + /* + * Set the request dictionary so that we can do + * generic->protocol attribute conversions as + * the request runs through the server. + */ + request->dict = dict_vqp; + client = address->radclient; /* diff --git a/src/modules/rlm_client/rlm_client.c b/src/modules/rlm_client/rlm_client.c index bbc61f4b27a..b83c427084b 100644 --- a/src/modules/rlm_client/rlm_client.c +++ b/src/modules/rlm_client/rlm_client.c @@ -65,7 +65,7 @@ static int _map_proc_client_get_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *r return -1; } - da = fr_dict_attr_by_name(NULL, attr); + da = fr_dict_attr_by_name(request->dict, attr); if (!da) { RWDEBUG("No such attribute '%s'", attr); return -1; diff --git a/src/modules/rlm_couchbase/mod.c b/src/modules/rlm_couchbase/mod.c index fcc43673f84..fd7943aa3d1 100644 --- a/src/modules/rlm_couchbase/mod.c +++ b/src/modules/rlm_couchbase/mod.c @@ -369,7 +369,7 @@ int mod_json_object_to_map(TALLOC_CTX *ctx, fr_cursor_t *out, REQUEST *request, * Lookup the string attr_name in the * request dictionary. */ - da = fr_dict_attr_by_name(NULL, attr_name); + da = fr_dict_attr_by_name(request->dict, attr_name); if (!da) { RPERROR("Invalid attribute \"%s\"", attr_name); goto error; diff --git a/src/modules/rlm_csv/rlm_csv.c b/src/modules/rlm_csv/rlm_csv.c index 32ef571a51d..42f96d4f3b0 100644 --- a/src/modules/rlm_csv/rlm_csv.c +++ b/src/modules/rlm_csv/rlm_csv.c @@ -428,7 +428,8 @@ static int csv_map_getvalue(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, return -1; } - da = fr_dict_attr_by_name(NULL, attr); + + da = fr_dict_attr_by_name(request->dict, attr); if (!da) { RWDEBUG("No such attribute '%s'", attr); return -1; diff --git a/src/modules/rlm_lua/lua.c b/src/modules/rlm_lua/lua.c index e81606c0755..a8575e1a6e4 100644 --- a/src/modules/rlm_lua/lua.c +++ b/src/modules/rlm_lua/lua.c @@ -544,7 +544,7 @@ static int _lua_pair_accessor_init(lua_State *L) return -1; } - da = fr_dict_attr_by_name(NULL, attr); + da = fr_dict_attr_by_name(request->dict, attr); if (!da) { REDEBUG("Unknown or invalid attribute name \"%s\"", attr); return -1; diff --git a/src/modules/rlm_rest/rest.c b/src/modules/rlm_rest/rest.c index 70b225306eb..2475be45463 100644 --- a/src/modules/rlm_rest/rest.c +++ b/src/modules/rlm_rest/rest.c @@ -791,7 +791,7 @@ static int rest_decode_post(UNUSED rlm_rest_t const *instance, UNUSED rlm_rest_s continue; } - da = fr_dict_attr_by_name(NULL, attribute); + da = fr_dict_attr_by_name(request->dict, attribute); if (!da) { RWDEBUG("Attribute \"%s\" unknown, skipping", attribute); diff --git a/src/modules/rlm_stats/rlm_stats.c b/src/modules/rlm_stats/rlm_stats.c index 9246ec38764..cecec0ca92b 100644 --- a/src/modules/rlm_stats/rlm_stats.c +++ b/src/modules/rlm_stats/rlm_stats.c @@ -344,7 +344,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_stats(void *instance, void *thread, REQU if (!local_stats[i]) continue; strlcpy(buffer + 18, fr_packet_codes[i], sizeof(buffer) - 18); - da = fr_dict_attr_by_name(NULL, buffer); + da = fr_dict_attr_by_name(dict_radius, buffer); if (!da) continue; vp = fr_pair_afrom_da(request->reply, da);