From: Arran Cudbard-Bell Date: Mon, 28 May 2018 12:14:08 +0000 (+0600) Subject: Move auth_name() into proto_radius_auth X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d0c8233bb3db620ee13e8367a2dd8f2bdeee7f1;p=thirdparty%2Ffreeradius-server.git Move auth_name() into proto_radius_auth --- diff --git a/src/include/radiusd.h b/src/include/radiusd.h index 957695b3eba..180ef2c33a1 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -437,7 +437,6 @@ int pairlist_read(TALLOC_CTX *ctx, char const *file, PAIR_LIST **list, int comp void pairlist_free(PAIR_LIST **); /* auth.c */ -char *auth_name(char *buf, size_t buflen, REQUEST *request, bool do_cli); rlm_rcode_t rad_authenticate (REQUEST *); rlm_rcode_t rad_postauth(REQUEST *); rlm_rcode_t rad_virtual_server(REQUEST *); diff --git a/src/main/auth.c b/src/main/auth.c index fb8ee3d8f5b..26b30026f6f 100644 --- a/src/main/auth.c +++ b/src/main/auth.c @@ -33,37 +33,6 @@ RCSID("$Id$") #include -/* - * Return a short string showing the terminal server, port - * and calling station ID. - */ -char *auth_name(char *buf, size_t buflen, REQUEST *request, bool do_cli) -{ - VALUE_PAIR *cli; - VALUE_PAIR *pair; - uint32_t port = 0; /* RFC 2865 NAS-Port is 4 bytes */ - char const *tls = ""; - - if ((cli = fr_pair_find_by_num(request->packet->vps, 0, FR_CALLING_STATION_ID, TAG_ANY)) == NULL) { - do_cli = false; - } - - if ((pair = fr_pair_find_by_num(request->packet->vps, 0, FR_NAS_PORT, TAG_ANY)) != NULL) { - port = pair->vp_uint32; - } - - if (request->packet->dst_port == 0) { - tls = " via proxy to virtual server"; - } - - snprintf(buf, buflen, "from client %.128s port %u%s%.128s%s", - request->client->shortname, port, - (do_cli ? " cli " : ""), (do_cli ? cli->vp_strvalue : ""), - tls); - - return buf; -} - /* * Check password. * @@ -523,9 +492,9 @@ skip: rcode = rad_authenticate(request); if (request->reply->code == FR_CODE_ACCESS_REJECT) { - fr_pair_delete_by_num(&request->control, 0, FR_POST_AUTH_TYPE, TAG_ANY); + fr_pair_delete_by_child_num(&request->control, fr_dict_root(fr_dict_internal), FR_POST_AUTH_TYPE, TAG_ANY); - MEM(vp = fr_pair_afrom_num(request, 0, FR_POST_AUTH_TYPE)); + MEM(vp = fr_pair_afrom_child_num(request, fr_dict_root(fr_dict_internal), FR_POST_AUTH_TYPE)); fr_pair_value_from_str(vp, "Reject", -1); fr_pair_add(&request->control, vp); diff --git a/src/main/stats.c b/src/main/stats.c index 428954606d7..6dae1076195 100644 --- a/src/main/stats.c +++ b/src/main/stats.c @@ -447,6 +447,8 @@ do { \ fr_pair_add(&request->reply->vps, vp); \ } while (0) +static fr_dict_attr_t const *freeradius_vendor_root; + static void request_stats_addvp(REQUEST *request, fr_stats2vp *table, fr_stats_t *stats) { diff --git a/src/modules/proto_radius/proto_radius.c b/src/modules/proto_radius/proto_radius.c index 1055e676566..bfdccb416ef 100644 --- a/src/modules/proto_radius/proto_radius.c +++ b/src/modules/proto_radius/proto_radius.c @@ -668,20 +668,10 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) proto_radius_t *inst = talloc_get_type_abort(instance, proto_radius_t); size_t i; - fr_dict_attr_t const *da; CONF_PAIR *cp = NULL; CONF_ITEM *ci = NULL; CONF_SECTION *server = cf_item_to_section(cf_parent(conf)); - /* - * Needed to populate the code array - */ - da = fr_dict_attr_by_name(NULL, "Packet-Type"); - if (!da) { - ERROR("Missing definition for Packet-Type"); - return -1; - } - /* * Compile each "send/recv + RADIUS packet type" section. * This is so that the submodules don't need to do this. @@ -720,7 +710,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) * Check that the packet type is known. */ packet_type = cf_section_name2(subcs); - dv = fr_dict_enum_by_alias(da, packet_type, -1); + dv = fr_dict_enum_by_alias(attr_packet_type, packet_type, -1); if (!dv || (dv->value->vb_uint32 > FR_CODE_DO_NOT_RESPOND) || !code2component[dv->value->vb_uint32]) { cf_log_err(subcs, "Invalid RADIUS packet type in '%s %s {...}'", name, packet_type); diff --git a/src/modules/proto_radius/proto_radius_auth.c b/src/modules/proto_radius/proto_radius_auth.c index f9c4816b675..930561a230d 100644 --- a/src/modules/proto_radius/proto_radius_auth.c +++ b/src/modules/proto_radius/proto_radius_auth.c @@ -88,6 +88,7 @@ fr_dict_autoload_t proto_radius_auth_dict[] = { { NULL } }; +static fr_dict_attr_t const *attr_calling_station_id; static fr_dict_attr_t const *attr_auth_type; static fr_dict_attr_t const *attr_module_failure_message; static fr_dict_attr_t const *attr_module_success_message; @@ -97,6 +98,7 @@ static fr_dict_attr_t const *attr_service_type; static fr_dict_attr_t const *attr_state; static fr_dict_attr_t const *attr_user_name; static fr_dict_attr_t const *attr_user_password; +static fr_dict_attr_t const *attr_nas_port; extern fr_dict_attr_autoload_t proto_radius_auth_dict_attr[]; fr_dict_attr_autoload_t proto_radius_auth_dict_attr[] = { @@ -104,14 +106,45 @@ fr_dict_attr_autoload_t proto_radius_auth_dict_attr[] = { { .out = &attr_module_failure_message, .name = "Module-Failure-Message", .type = FR_TYPE_STRING, .dict = &dict_freeradius }, { .out = &attr_module_success_message, .name = "Module-Success-Message", .type = FR_TYPE_STRING, .dict = &dict_freeradius }, { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_freeradius }, + + { .out = &attr_calling_station_id, .name = "Calling-Station-Id", .type = FR_TYPE_STRING, .dict = &dict_radius }, { .out = &attr_chap_password, .name = "CHAP-Password", .type = FR_TYPE_OCTETS, .dict = &dict_radius }, { .out = &attr_service_type, .name = "Service-Type", .type = FR_TYPE_UINT32, .dict = &dict_radius }, { .out = &attr_state, .name = "State", .type = FR_TYPE_OCTETS, .dict = &dict_radius }, { .out = &attr_user_name, .name = "User-Name", .type = FR_TYPE_STRING, .dict = &dict_radius }, { .out = &attr_user_password, .name = "User-Password", .type = FR_TYPE_STRING, .dict = &dict_radius }, + { .out = &attr_nas_port, .name = "NAS-Port", .type = FR_TYPE_UINT32, .dict = &dict_radius }, + { NULL } }; +/* + * Return a short string showing the terminal server, port + * and calling station ID. + */ +static char *auth_name(char *buf, size_t buflen, REQUEST *request, bool do_cli) +{ + VALUE_PAIR *cli; + VALUE_PAIR *pair; + uint32_t port = 0; /* RFC 2865 NAS-Port is 4 bytes */ + char const *tls = ""; + + cli = fr_pair_find_by_da(request->packet->vps, attr_calling_station_id, TAG_ANY); + if (!cli) do_cli = false; + + pair = fr_pair_find_by_da(request->packet->vps, attr_nas_port, TAG_ANY); + if (pair != NULL) port = pair->vp_uint32; + + if (request->packet->dst_port == 0) tls = " via proxy to virtual server"; + + snprintf(buf, buflen, "from client %.128s port %u%s%.128s%s", + request->client->shortname, port, + (do_cli ? " cli " : ""), (do_cli ? cli->vp_strvalue : ""), + tls); + + return buf; +} + /* * Make sure user/pass are clean and then create an attribute * which contains the log message.