2007-07-30 20:22:37 +00:00
/*
* We don't use unput, so don't generate code for it.
*/
2005-07-15 21:12:27 +00:00
%option nounput
2007-07-30 20:22:37 +00:00
/*
* We don't read from the terminal.
*/
2005-07-15 21:12:27 +00:00
%option never-interactive
2007-07-30 20:22:37 +00:00
/*
* The language we're scanning is case-insensitive.
*/
2005-07-15 21:12:27 +00:00
%option caseless
2007-07-30 20:22:37 +00:00
/*
* Prefix scanner routines with "Radius" rather than "yy", so this scanner
* can coexist with other scanners.
*/
%option prefix="Radius"
2005-07-15 21:12:27 +00:00
%option outfile="radius_dict.c"
%{
2006-03-23 00:57:56 +00:00
/* radius_dict.l
2005-07-15 21:41:47 +00:00
*
* RADIUS dictionary parser
*
* $Id$
*
2006-05-21 05:12:17 +00:00
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
2005-07-15 21:41:47 +00:00
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2007-07-30 20:22:37 +00:00
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2005-07-15 21:41:47 +00:00
*/
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <epan/packet.h>
#include <epan/dissectors/packet-radius.h>
2007-08-04 02:13:52 +00:00
#include "radius_dict_lex.h"
2008-05-22 15:46:27 +00:00
#include <wsutil/file_util.h>
2007-10-16 15:43:18 +00:00
2008-04-25 18:26:54 +00:00
#ifdef _WIN32
/* disable Windows VC compiler warning "signed/unsigned mismatch" associated */
/* with YY_INPUT code generated by flex versions such as 2.5.35. */
#pragma warning (disable:4018)
#endif
2005-07-15 21:12:27 +00:00
#define ECHO
#define MAX_INCLUDE_DEPTH 10
2009-04-02 19:05:52 +00:00
void add_vendor(const gchar* name, guint32 vendor_id, guint vendor_type_octets, guint vendor_length_octets, gboolean vendor_has_flags);
2005-09-24 15:07:38 +00:00
void add_value(const gchar* attrib_name,const gchar* value_repr, long value);
2009-04-02 19:05:52 +00:00
void add_tlv(const gchar* name, const gchar* code, radius_attr_dissector_t type, const gchar* current_attr);
void add_attribute(const gchar*,const gchar*, radius_attr_dissector_t,const gchar*, gboolean, gboolean, const gchar*);
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
static YY_BUFFER_STATE include_stack[10];
static int include_stack_ptr = 0;
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
static radius_dictionary_t* dict = NULL;
static GHashTable* value_strings = NULL; /* GArray(value_string) by attribute name */
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
static gchar* attr_name = NULL;
static gchar* attr_id = NULL;
static radius_attr_dissector_t* attr_type = NULL;
static gchar* attr_vendor = NULL;
static gchar* vendor_name = NULL;
2009-04-02 19:05:52 +00:00
static guint32 vendor_id = 0;
static guint vendor_type_octets = 1;
static guint vendor_length_octets = 1;
static gboolean vendor_has_flags = FALSE;
2005-07-15 21:12:27 +00:00
static gchar* value_repr = NULL;
2005-07-27 17:52:51 +00:00
static gboolean encrypted = FALSE;
2005-07-15 21:12:27 +00:00
static gboolean has_tag = FALSE;
static gchar* current_vendor = NULL;
2009-04-02 19:05:52 +00:00
static gchar* current_attr = NULL;
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
static GString* error = NULL;
static gchar* directory = NULL;
static int linenums[] = {1,1,1,1,1,1,1,1,1,1};
static gchar* fullpaths[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
%}
2011-05-26 02:59:25 +00:00
/* Note: FreeRadius allows VENDOR, ATTRIBUTE and VALUE names to contain any non-blank character.
* Using [^[:blank:]] below for those names fails for some reason so for now the patterns for each
* include those characters found in the the corresponding names in the FreeRadius dictionaries.
*/
2009-04-02 19:05:52 +00:00
%START WS_OUT VENDOR VENDOR_W_NAME ATTR ATTR_W_NAME ATTR_W_ID ATTR_W_TYPE ATTR_W_VENDOR VALUE VALUE_W_ATTR VALUE_W_NAME INCLUDE JUNK BEGIN_VENDOR END_VENDOR VENDOR_W_ID VENDOR_W_FORMAT VENDOR_W_TYPE_OCTETS VENDOR_W_LENGTH_OCTETS VENDOR_W_CONTINUATION BEGIN_TLV END_TLV
2005-07-15 21:12:27 +00:00
%%
[:blank:] ;
#[^\n]* ;
<JUNK>.*\qn ;
2007-03-22 23:32:31 +00:00
<WS_OUT>VENDOR { BEGIN VENDOR; }
<WS_OUT>ATTRIBUTE { BEGIN ATTR; }
<WS_OUT>VALUE { BEGIN VALUE; }
<WS_OUT>\$INCLUDE { BEGIN INCLUDE; }
<WS_OUT>BEGIN-VENDOR { BEGIN BEGIN_VENDOR; }
<WS_OUT>END-VENDOR { BEGIN END_VENDOR; }
2009-04-02 19:05:52 +00:00
<WS_OUT>BEGIN-TLV { BEGIN BEGIN_TLV; }
<WS_OUT>END-TLV { BEGIN END_TLV; }
2005-07-15 21:12:27 +00:00
2005-09-24 15:07:38 +00:00
<BEGIN_VENDOR>[0-9a-z_-]+ {
if (current_vendor) {
g_free(current_vendor);
}
current_vendor = g_strdup(yytext);
2007-03-22 23:32:31 +00:00
BEGIN WS_OUT;
2005-09-24 15:07:38 +00:00
}
<END_VENDOR>[^\n]* {
if (current_vendor) {
g_free(current_vendor);
current_vendor = NULL;
}
2007-03-22 23:32:31 +00:00
BEGIN WS_OUT;
2005-09-24 15:07:38 +00:00
}
2005-07-15 21:12:27 +00:00
2009-04-02 19:05:52 +00:00
<BEGIN_TLV>[0-9a-z_-]+ {
if (current_attr) {
g_free(current_attr);
}
current_attr = g_strdup(yytext);
BEGIN WS_OUT;
}
<END_TLV>[^\n]* {
if (current_attr) {
g_free(current_attr);
current_attr = NULL;
}
2007-03-22 23:32:31 +00:00
BEGIN WS_OUT;
2005-09-24 15:07:38 +00:00
}
2009-04-02 19:05:52 +00:00
<VENDOR>[0-9a-z_-]+ {
vendor_name = g_strdup(yytext);
vendor_type_octets = 1;
vendor_length_octets = 1;
vendor_has_flags = FALSE;
BEGIN VENDOR_W_NAME;
}
<VENDOR_W_NAME>[0-9]+ {
vendor_id = strtol(yytext,NULL,10);
BEGIN VENDOR_W_ID;
}
2005-09-24 15:07:38 +00:00
<VENDOR_W_NAME>0x[0-9a-f]+ {
2009-04-02 19:05:52 +00:00
vendor_id = strtol(yytext,NULL,16);
BEGIN VENDOR_W_ID;
}
<VENDOR_W_ID>format= {
BEGIN VENDOR_W_FORMAT;
}
<VENDOR_W_FORMAT>[124] {
vendor_type_octets = strtol(yytext,NULL,10);
BEGIN VENDOR_W_TYPE_OCTETS;
}
<VENDOR_W_TYPE_OCTETS>,[012] {
vendor_length_octets = strtol(yytext+1,NULL,10);
BEGIN VENDOR_W_LENGTH_OCTETS;
}
<VENDOR_W_LENGTH_OCTETS>,c {
vendor_has_flags = TRUE;
BEGIN VENDOR_W_CONTINUATION;
}
<VENDOR_W_FORMAT>\n |
<VENDOR_W_TYPE_OCTETS>\n |
<VENDOR_W_LENGTH_OCTETS>\n |
<VENDOR_W_CONTINUATION>\n |
<VENDOR_W_ID>\n {
add_vendor(vendor_name, vendor_id, vendor_type_octets, vendor_length_octets, vendor_has_flags);
2005-09-24 15:07:38 +00:00
g_free(vendor_name);
2007-03-22 23:32:31 +00:00
BEGIN WS_OUT;
2005-09-24 15:07:38 +00:00
}
2005-07-15 21:12:27 +00:00
2011-05-26 14:15:51 +00:00
<ATTR>[0-9a-z_/\.-]+ { attr_name = g_strdup(yytext); encrypted = FALSE; has_tag = FALSE; BEGIN ATTR_W_NAME; }
2005-09-26 08:48:19 +00:00
<ATTR_W_NAME>[0-9]+ { attr_id = g_strdup(yytext); BEGIN ATTR_W_ID;}
<ATTR_W_NAME>0x[0-9a-f]+ { attr_id = g_strdup_printf("%u",(int)strtoul(yytext,NULL,16)); BEGIN ATTR_W_ID;}
<ATTR_W_ID>integer { attr_type = radius_integer; BEGIN ATTR_W_TYPE; }
<ATTR_W_ID>string { attr_type = radius_string; BEGIN ATTR_W_TYPE; }
<ATTR_W_ID>octets { attr_type = radius_octets; BEGIN ATTR_W_TYPE; }
<ATTR_W_ID>ipaddr { attr_type = radius_ipaddr; BEGIN ATTR_W_TYPE; }
<ATTR_W_ID>ipv6addr { attr_type = radius_ipv6addr; BEGIN ATTR_W_TYPE; }
2009-03-18 07:31:35 +00:00
<ATTR_W_ID>ipv6prefix { attr_type = radius_ipv6prefix; BEGIN ATTR_W_TYPE; }
2005-09-26 08:48:19 +00:00
<ATTR_W_ID>ipxnet { attr_type = radius_ipxnet; BEGIN ATTR_W_TYPE; }
<ATTR_W_ID>date { attr_type = radius_date; BEGIN ATTR_W_TYPE; }
2009-07-06 14:05:37 +00:00
<ATTR_W_ID>abinary { attr_type = radius_abinary; BEGIN ATTR_W_TYPE; }
<ATTR_W_ID>ether { attr_type = radius_ether; BEGIN ATTR_W_TYPE; }
2005-09-26 08:48:19 +00:00
<ATTR_W_ID>ifid { attr_type = radius_ifid; BEGIN ATTR_W_TYPE; }
2009-04-02 19:05:52 +00:00
<ATTR_W_ID>byte { attr_type = radius_integer; BEGIN ATTR_W_TYPE; }
<ATTR_W_ID>short { attr_type = radius_integer; BEGIN ATTR_W_TYPE; }
<ATTR_W_ID>signed { attr_type = radius_signed; BEGIN ATTR_W_TYPE; }
<ATTR_W_ID>combo-ip { attr_type = radius_combo_ip; BEGIN ATTR_W_TYPE; }
<ATTR_W_ID>tlv { attr_type = radius_tlv; BEGIN ATTR_W_TYPE; }
2005-09-26 08:48:19 +00:00
<ATTR_W_ID>[0-9a-z_-]+ { attr_type = radius_octets; BEGIN ATTR_W_TYPE; }
2006-03-23 00:57:56 +00:00
<ATTR_W_TYPE>has_tag[,]? { has_tag = TRUE; }
<ATTR_W_TYPE>encrypt=1[,]? { encrypted=TRUE; }
<ATTR_W_TYPE>[0-9a-z_-]+=([^\n]*) ;
2005-09-26 08:48:19 +00:00
<ATTR_W_TYPE>[0-9a-z_-]+ {
2005-09-24 15:07:38 +00:00
attr_vendor = g_strdup(yytext);
2009-04-02 19:05:52 +00:00
add_attribute(attr_name,attr_id,attr_type,attr_vendor,encrypted,has_tag,current_attr);
2005-09-24 15:07:38 +00:00
g_free(attr_id);
g_free(attr_vendor);
g_free(attr_name);
attr_id = NULL;
attr_vendor = NULL;
attr_name = NULL;
2007-03-22 23:32:31 +00:00
BEGIN WS_OUT;
2005-09-24 15:07:38 +00:00
}
<ATTR_W_TYPE>\n {
2009-04-02 19:05:52 +00:00
add_attribute(attr_name,attr_id,attr_type,current_vendor,encrypted,has_tag,current_attr);
2005-09-24 15:07:38 +00:00
g_free(attr_id);
g_free(attr_name);
linenums[include_stack_ptr]++;
2006-03-23 00:57:56 +00:00
has_tag = FALSE;
encrypted=FALSE;
2007-03-22 23:32:31 +00:00
BEGIN WS_OUT;
2005-09-24 15:07:38 +00:00
}
<ATTR_W_VENDOR>\n {
2009-04-02 19:05:52 +00:00
add_attribute(attr_name,attr_id,attr_type,attr_vendor,encrypted,has_tag,current_attr);
2005-09-24 15:07:38 +00:00
g_free(attr_id);
g_free(attr_vendor);
g_free(attr_name);
2007-10-16 15:43:18 +00:00
linenums[include_stack_ptr]++;
2007-03-22 23:32:31 +00:00
BEGIN WS_OUT;
2005-09-24 15:07:38 +00:00
};
<VALUE>[0-9a-z_/-]+ { attr_name = g_strdup(yytext); BEGIN VALUE_W_ATTR; }
2005-07-15 21:12:27 +00:00
<VALUE_W_ATTR>[^[:blank:]]+ { value_repr = g_strdup(yytext); BEGIN VALUE_W_NAME; }
2007-03-22 23:32:31 +00:00
<VALUE_W_NAME>[0-9]+ { add_value(attr_name,value_repr,strtol(yytext,NULL,10)); g_free(attr_name); g_free(value_repr); BEGIN WS_OUT;}
<VALUE_W_NAME>0x[0-9a-f]+ { add_value(attr_name,value_repr,strtol(yytext,NULL,16)); g_free(attr_name); g_free(value_repr); BEGIN WS_OUT;}
2005-07-15 21:12:27 +00:00
<INCLUDE>[^[:blank:]\n]+ {
if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
2008-05-11 18:33:49 +00:00
g_string_append_printf(error, "$INCLUDE files nested to deeply\n");
2005-07-15 21:12:27 +00:00
yyterminate();
}
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
2007-10-16 15:43:18 +00:00
2007-01-02 06:39:22 +00:00
fullpaths[include_stack_ptr] = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
directory,yytext);
2005-07-15 21:12:27 +00:00
2008-05-22 15:46:27 +00:00
yyin = ws_fopen( fullpaths[include_stack_ptr], "r" );
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
if (!yyin) {
if (errno) {
2008-05-11 18:33:49 +00:00
g_string_append_printf(error, "Could not open file: '%s', error: %s\n", fullpaths[include_stack_ptr], strerror(errno) );
2005-07-15 21:12:27 +00:00
yyterminate();
}
} else {
linenums[include_stack_ptr] = 1;
yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE ) );
}
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
2007-03-22 23:32:31 +00:00
BEGIN WS_OUT;
2005-07-15 21:12:27 +00:00
}
<<EOF>> {
2007-10-16 15:43:18 +00:00
2005-12-20 02:50:04 +00:00
fclose(yyin);
yyin = NULL;
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
if ( --include_stack_ptr < 0 ) {
yyterminate();
} else {
g_free(fullpaths[include_stack_ptr+1]);
fullpaths[include_stack_ptr+1] = NULL;
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
yy_delete_buffer( YY_CURRENT_BUFFER );
yy_switch_to_buffer(include_stack[include_stack_ptr]);
}
2007-03-22 23:32:31 +00:00
BEGIN WS_OUT;
2005-07-15 21:12:27 +00:00
}
2007-03-22 23:32:31 +00:00
\n { linenums[include_stack_ptr]++; BEGIN WS_OUT; }
2005-07-15 21:12:27 +00:00
%%
2009-04-02 19:05:52 +00:00
void add_vendor(const gchar* name, guint32 vendor_id, guint vendor_type_octets, guint vendor_length_octets, gboolean vendor_has_flags) {
2008-12-29 15:16:41 +00:00
radius_vendor_info_t* v;
2007-10-16 15:43:18 +00:00
2009-04-02 19:05:52 +00:00
v = g_hash_table_lookup(dict->vendors_by_id, GUINT_TO_POINTER(vendor_id));
2008-12-29 15:16:41 +00:00
if (!v) {
v = g_malloc(sizeof(radius_vendor_info_t));
v->attrs_by_id = g_hash_table_new(g_direct_hash,g_direct_equal);
v->code = vendor_id;
v->ett = -1;
v->name = NULL;
}
2011-05-26 14:15:51 +00:00
/* Assume that the dictionary knows the 'ground truth' about the
2009-07-03 16:03:02 +00:00
* type/length/has_flags information and thus allow the dictionary to
* overwrite these values even for vendors that have already been loaded.
*/
v->type_octets = vendor_type_octets;
v->length_octets = vendor_length_octets;
2011-05-26 14:15:51 +00:00
v->has_flags = vendor_has_flags;
2008-12-29 15:16:41 +00:00
if (v->name)
g_free((gpointer) v->name);
2005-09-24 15:07:38 +00:00
v->name = g_strdup(name);
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
g_hash_table_insert(dict->vendors_by_id,GUINT_TO_POINTER(v->code),v);
2007-03-22 00:49:06 +00:00
g_hash_table_insert(dict->vendors_by_name, (gpointer) v->name, v);
2005-07-15 21:12:27 +00:00
}
2009-04-02 19:05:52 +00:00
void add_attribute(const gchar* name, const gchar* codestr, radius_attr_dissector_t type, const gchar* vendor_name, gboolean crypt, gboolean tagged, const gchar* current_attr) {
2008-12-29 15:16:41 +00:00
radius_attr_info_t* a;
2005-07-15 21:12:27 +00:00
GHashTable* by_id;
2008-12-29 15:16:41 +00:00
guint32 code;
2007-10-16 15:43:18 +00:00
2009-04-02 19:05:52 +00:00
if (current_attr){
add_tlv(name, codestr, type, current_attr);
return;
}
2005-07-15 21:12:27 +00:00
if (vendor_name) {
radius_vendor_info_t* v;
v = g_hash_table_lookup(dict->vendors_by_name,vendor_name);
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
if (! v) {
2008-05-11 18:33:49 +00:00
g_string_append_printf(error, "Vendor: '%s', does not exist in %s:%i \n", vendor_name, fullpaths[include_stack_ptr], linenums[include_stack_ptr] );
2005-07-15 21:12:27 +00:00
BEGIN JUNK;
return;
} else {
by_id = v->attrs_by_id;
}
} else {
by_id = dict->attrs_by_id;
}
2007-10-16 15:43:18 +00:00
2008-12-29 15:16:41 +00:00
code=strtol(codestr, NULL, 10);
a=g_hash_table_lookup(by_id, GUINT_TO_POINTER(code));
if (!a) {
a = g_malloc(sizeof(radius_attr_info_t));
a->name = NULL;
a->dissector = NULL;
}
a->code = code;
2005-07-15 21:12:27 +00:00
a->encrypt = crypt;
a->tagged = tagged;
a->type = type;
a->vs = NULL;
a->hf = -1;
a->hf64 = -1;
a->hf_tag = -1;
a->hf_len = -1;
a->ett = -1;
2009-04-02 19:05:52 +00:00
a->tlvs_by_id = NULL;
2007-10-16 15:43:18 +00:00
2008-12-29 15:16:41 +00:00
if (a->name)
g_free((gpointer) a->name);
a->name = g_strdup(name);
g_hash_table_insert(by_id, GUINT_TO_POINTER(code),a);
2005-08-20 22:08:35 +00:00
g_hash_table_insert(dict->attrs_by_name,(gpointer) (a->name),a);
2005-07-15 21:12:27 +00:00
}
2009-04-02 19:05:52 +00:00
void add_tlv(const gchar* name, const gchar* codestr, radius_attr_dissector_t type, const gchar* current_attr) {
radius_attr_info_t* a;
2011-02-17 18:53:35 +00:00
radius_attr_info_t* s;
2009-04-02 19:05:52 +00:00
guint32 code;
a = g_hash_table_lookup(dict->attrs_by_name, current_attr);
if (! a) {
g_string_sprintfa(error, "Attr: '%s', does not exist in %s:%i \n", current_attr, fullpaths[include_stack_ptr], linenums[include_stack_ptr]);
BEGIN JUNK;
return;
}
if (type == radius_tlv) {
g_string_sprintfa(error, "sub-TLV: '%s', sub-TLV's type is specified as tlv in %s:%i \n", name, fullpaths[include_stack_ptr], linenums[include_stack_ptr]);
BEGIN JUNK;
return;
}
if (! a->tlvs_by_id) {
a->tlvs_by_id = g_hash_table_new(g_direct_hash,g_direct_equal);
}
code=strtol(codestr, NULL, 10);
2011-05-26 14:15:51 +00:00
2009-04-02 19:05:52 +00:00
s = g_hash_table_lookup(a->tlvs_by_id, GUINT_TO_POINTER(code));
if (!s) {
s = g_malloc(sizeof(radius_attr_info_t));
s->name = NULL;
s->dissector = NULL;
}
s->code = code;
s->type = type;
s->encrypt = FALSE;
s->tagged = FALSE;
s->dissector = NULL;
s->vs = NULL;
s->hf = -1;
s->hf64 = -1;
s->hf_tag = -1;
s->hf_len = -1;
s->ett = -1;
s->tlvs_by_id = NULL;
if (s->name)
g_free((gpointer) s->name);
s->name = g_strdup(name);
g_hash_table_insert(a->tlvs_by_id,GUINT_TO_POINTER(s->code),s);
g_hash_table_insert(dict->tlvs_by_name,(gpointer) (s->name),s);
}
2005-09-24 15:07:38 +00:00
void add_value(const gchar* attrib_name, const gchar* value_repr, long value) {
2005-07-15 21:12:27 +00:00
value_string v;
GArray* a = g_hash_table_lookup(value_strings,attrib_name);
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
if (! a) {
a = g_array_new(TRUE,TRUE,sizeof(value_string));
2005-09-24 15:07:38 +00:00
g_hash_table_insert(value_strings,g_strdup(attrib_name),a);
2005-07-15 21:12:27 +00:00
}
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
v.value = value;
2005-09-24 15:07:38 +00:00
v.strptr = g_strdup(value_repr);
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
g_array_append_val(a,v);
}
2009-04-02 19:05:52 +00:00
static void setup_tlvs(gpointer k _U_, gpointer v, gpointer p _U_) {
radius_attr_info_t* s = v;
gpointer key;
union {
GArray* a;
gpointer p;
} vs;
if (g_hash_table_lookup_extended(value_strings, s->name, &key, &vs.p)) {
2011-04-25 21:19:22 +00:00
s->vs = (value_string*)(void *)vs.a->data;
2009-04-02 19:05:52 +00:00
g_array_free(vs.a, FALSE);
g_hash_table_remove(value_strings, key);
g_free(key);
}
}
2005-07-15 21:12:27 +00:00
2005-08-02 04:34:35 +00:00
static void setup_attrs(gpointer k _U_, gpointer v, gpointer p _U_) {
2005-07-15 21:12:27 +00:00
radius_attr_info_t* a = v;
gpointer key;
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
union {
GArray* a;
gpointer p;
} vs;
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
if (g_hash_table_lookup_extended(value_strings,a->name,&key,&vs.p) ) {
2011-04-25 21:19:22 +00:00
a->vs = (value_string*)(void *)vs.a->data;
2005-07-15 21:12:27 +00:00
g_array_free(vs.a,FALSE);
g_hash_table_remove(value_strings,key);
g_free(key);
}
2009-04-02 19:05:52 +00:00
if (a->tlvs_by_id) {
g_hash_table_foreach(a->tlvs_by_id, setup_tlvs, p);
}
2005-07-15 21:12:27 +00:00
}
2005-08-02 04:34:35 +00:00
static void setup_vendors(gpointer k _U_, gpointer v, gpointer p) {
2005-07-15 21:12:27 +00:00
radius_vendor_info_t* vnd = v;
2007-10-16 15:43:18 +00:00
g_hash_table_foreach(vnd->attrs_by_id,setup_attrs,p);
2005-07-15 21:12:27 +00:00
}
2005-09-24 15:07:38 +00:00
static gboolean destroy_value_strings(gpointer k, gpointer v, gpointer p _U_) {
2011-04-25 21:19:22 +00:00
value_string* vs = (value_string*)(void *)(((GArray*)v)->data);
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
g_free(k);
2007-10-16 15:43:18 +00:00
2011-04-25 21:19:22 +00:00
for (;vs->strptr;vs++) {
g_free((void*)vs->strptr);
}
2007-10-16 15:43:18 +00:00
2005-09-24 15:07:38 +00:00
g_array_free(v,TRUE);
2005-07-15 21:12:27 +00:00
return TRUE;
}
2009-04-02 19:05:52 +00:00
static gboolean destroy_tlvs(gpointer k _U_, gpointer v, gpointer p _U_) {
radius_attr_info_t* s = v;
int i;
g_free((gpointer) (s->name));
if (s->vs) {
for(i=0; s->vs[i].strptr; i++) {
g_free((void *)s->vs[i].strptr);
}
g_free((void *)s->vs);
}
g_free(s);
return TRUE;
}
2005-08-02 04:34:35 +00:00
static gboolean destroy_attrs(gpointer k _U_, gpointer v, gpointer p _U_) {
2005-07-15 21:12:27 +00:00
radius_attr_info_t* a = v;
int i;
2007-10-16 15:43:18 +00:00
2005-08-20 22:08:35 +00:00
g_free((gpointer) (a->name));
2009-04-02 19:05:52 +00:00
if (a->tlvs_by_id) {
g_hash_table_foreach_remove(a->tlvs_by_id, destroy_tlvs, p);
g_hash_table_destroy(a->tlvs_by_id);
}
2005-07-15 21:12:27 +00:00
if (a->vs) {
for(i=0; a->vs[i].strptr; i++) {
2005-07-16 01:33:22 +00:00
g_free((void *)a->vs[i].strptr);
2005-07-15 21:12:27 +00:00
}
2005-07-16 01:33:22 +00:00
g_free((void *)a->vs);
2005-07-15 21:12:27 +00:00
}
g_free(a);
return TRUE;
}
2005-08-02 04:34:35 +00:00
static gboolean destroy_vendors(gpointer k _U_, gpointer v, gpointer p) {
2005-07-15 21:12:27 +00:00
radius_vendor_info_t* vnd = v;
2007-03-22 00:49:06 +00:00
g_free( (gpointer) vnd->name);
2005-07-15 21:12:27 +00:00
g_hash_table_foreach_remove(vnd->attrs_by_id,destroy_attrs,p);
g_hash_table_destroy(vnd->attrs_by_id);
g_free(vnd);
return TRUE;
}
2005-08-02 04:34:35 +00:00
static void destroy_dict(radius_dictionary_t* d) {
2005-07-15 21:12:27 +00:00
g_hash_table_foreach_remove(d->attrs_by_id,destroy_attrs,NULL);
2007-10-16 15:43:18 +00:00
g_hash_table_foreach_remove(d->vendors_by_id,destroy_vendors,NULL);
2005-07-15 21:12:27 +00:00
g_hash_table_destroy(d->vendors_by_id);
g_hash_table_destroy(d->attrs_by_id);
g_hash_table_destroy(d->vendors_by_name);
g_hash_table_destroy(d->attrs_by_name);
g_free(d);
}
2008-04-03 22:13:52 +00:00
gboolean radius_load_dictionary (radius_dictionary_t* d, gchar* dir, const gchar* filename, gchar** err_str) {
2005-07-15 21:12:27 +00:00
int i;
2007-10-16 15:43:18 +00:00
2008-04-03 22:13:52 +00:00
dict = d;
2005-07-15 21:12:27 +00:00
directory = dir;
2007-10-16 15:43:18 +00:00
2007-01-02 06:39:22 +00:00
fullpaths[include_stack_ptr] = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
directory,filename);
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
error = g_string_new("");
2008-05-22 15:46:27 +00:00
yyin = ws_fopen(fullpaths[include_stack_ptr],"r");
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
if (!yyin) {
2008-05-11 18:33:49 +00:00
g_string_append_printf(error, "Could not open file: '%s', error: %s\n", fullpaths[include_stack_ptr], strerror(errno) );
2005-07-15 21:12:27 +00:00
g_free(fullpaths[include_stack_ptr]);
*err_str = error->str;
g_string_free(error,FALSE);
2008-04-03 22:13:52 +00:00
return FALSE;
2005-07-15 21:12:27 +00:00
}
value_strings = g_hash_table_new(g_str_hash,g_str_equal);
2007-10-16 15:43:18 +00:00
2007-03-22 23:32:31 +00:00
BEGIN WS_OUT;
2005-07-15 21:12:27 +00:00
yylex();
2005-12-20 02:50:04 +00:00
if (yyin != NULL) fclose(yyin);
yyin = NULL;
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
for (i=0; i < 10; i++) {
if (fullpaths[i]) g_free(fullpaths[i]);
}
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
g_hash_table_foreach(dict->attrs_by_id,setup_attrs,NULL);
2007-10-16 15:43:18 +00:00
g_hash_table_foreach(dict->vendors_by_id,setup_vendors,NULL);
2005-09-24 15:07:38 +00:00
g_hash_table_foreach_remove(value_strings,destroy_value_strings,NULL);
2007-10-16 15:43:18 +00:00
2005-07-15 21:12:27 +00:00
if (error->len > 0) {
*err_str = error->str;
g_string_free(error,FALSE);
destroy_dict(dict);
2008-04-03 22:13:52 +00:00
return FALSE;
2005-07-15 21:12:27 +00:00
} else {
*err_str = NULL;
g_string_free(error,TRUE);
2008-04-03 22:13:52 +00:00
return TRUE;
2005-07-15 21:12:27 +00:00
}
}
2008-04-25 17:40:29 +00:00
/*
* We want to stop processing when we get to the end of the input.
2008-05-22 15:46:27 +00:00
* (%option noyywrap is not used because if used then
2008-04-25 17:40:29 +00:00
* some flex versions (eg: 2.5.35) generate code which causes
* warnings by the Windows VC compiler).
*/
int yywrap(void) {
return 1;
}