From: Arran Cudbard-Bell Date: Wed, 11 Apr 2018 08:34:25 +0000 (+0600) Subject: Autoload rlm_example attributes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05855ceb1091a67384d31eafe60aa1ca988c8707;p=thirdparty%2Ffreeradius-server.git Autoload rlm_example attributes --- diff --git a/src/modules/rlm_example/rlm_example.c b/src/modules/rlm_example/rlm_example.c index d022d56b472..30a5c92055e 100644 --- a/src/modules/rlm_example/rlm_example.c +++ b/src/modules/rlm_example/rlm_example.c @@ -53,6 +53,27 @@ static const CONF_PARSER module_config[] = { CONF_PARSER_TERMINATOR }; +static fr_dict_t const *dict_radius; + +static fr_dict_attr_t const *attr_user_name; +static fr_dict_attr_t const *attr_reply_message; +static fr_dict_attr_t const *attr_state; + +extern fr_dict_attr_autoload_t rlm_example_dict_attr[]; +fr_dict_attr_autoload_t rlm_example_dict_attr[] = { + { .out = &attr_user_name, .name = "User-Name", .type = FR_TYPE_STRING, .dict = &dict_radius }, + { .out = &attr_reply_message, .name = "Reply-Message", .type = FR_TYPE_STRING, .dict = &dict_radius }, + { .out = &attr_state, .name = "State", .type = FR_TYPE_OCTETS, .dict = &dict_radius }, + + { NULL } +}; + +extern fr_dict_autoload_t rlm_example_dict[]; +fr_dict_autoload_t rlm_example_dict[] = { + { .out = &dict_radius, .proto = "radius" }, + { NULL } +}; + static int rlm_example_cmp(UNUSED void *instance, REQUEST *request, UNUSED VALUE_PAIR *thing, VALUE_PAIR *check, UNUSED VALUE_PAIR *check_pairs, UNUSED VALUE_PAIR **reply_pairs) { @@ -82,8 +103,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) return -1; } - if (paircompare_register_byname("Example-Paircmp", fr_dict_attr_by_num(NULL, 0, FR_USER_NAME), false, - rlm_example_cmp, inst) < 0) { + if (paircompare_register_byname("Example-Paircmp", attr_user_name, false, rlm_example_cmp, inst) < 0) { return -1; } @@ -98,22 +118,22 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) */ static rlm_rcode_t CC_HINT(nonnull) mod_authorize(UNUSED void *instance, UNUSED void *thread, REQUEST *request) { - VALUE_PAIR *state; + VALUE_PAIR *vp; /* * Look for the 'state' attribute. */ - state = fr_pair_find_by_num(request->packet->vps, 0, FR_STATE, TAG_ANY); - if (state != NULL) { + vp = fr_pair_find_by_da(request->packet->vps, attr_state, TAG_ANY); + if (vp != NULL) { RDEBUG("Found reply to access challenge"); return RLM_MODULE_OK; } - /* - * Create the challenge, and add it to the reply. - */ - pair_make_reply("Reply-Message", "This is a challenge", T_OP_EQ); - pair_make_reply("State", "0", T_OP_EQ); + MEM(vp = pair_update_reply(attr_reply_message, TAG_ANY)); + if (vp->vp_length == 0) fr_pair_value_strcpy(vp, "This is a challenge"); + + MEM(vp = pair_add_reply(attr_state, TAG_ANY)); + fr_pair_value_memcpy(vp, (uint8_t *){ 0x00 }, 1); /* * Mark the packet as an Access-Challenge packet.