diff options
author | Jeff Morriss <jeff.morriss@ulticom.com> | 2007-10-16 15:43:18 +0000 |
---|---|---|
committer | Jeff Morriss <jeff.morriss@ulticom.com> | 2007-10-16 15:43:18 +0000 |
commit | 853e79144494125bdff6dc64db298483810e4045 (patch) | |
tree | e8d57bb5805a73a0c6e9d6a02b866053f510553c /epan | |
parent | 0918c7159b9b8ded2f9f662d57d4bcf30f8b6517 (diff) |
Change more fopen() to eth_fopen() to finish fixing bug 1827:
http://bugs.wireshark.org/bugzilla/show_bug.cgi?id=1827
Update README.developer to tell developers not to use fopen() and friends
directly.
svn path=/trunk/; revision=23206
Diffstat (limited to 'epan')
-rw-r--r-- | epan/diam_dict.l | 159 | ||||
-rw-r--r-- | epan/dissectors/packet-giop.c | 3 | ||||
-rw-r--r-- | epan/dissectors/packet-isakmp.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-ssl-utils.c | 19 | ||||
-rw-r--r-- | epan/dissectors/packet-ssl.c | 3 | ||||
-rw-r--r-- | epan/radius_dict.l | 92 | ||||
-rw-r--r-- | epan/uat.c | 169 | ||||
-rw-r--r-- | epan/uat_load.l | 55 |
8 files changed, 255 insertions, 247 deletions
diff --git a/epan/diam_dict.l b/epan/diam_dict.l index 754bfd6af0..1927845689 100644 --- a/epan/diam_dict.l +++ b/epan/diam_dict.l @@ -55,11 +55,11 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, ** Boston, MA 02110-1301, USA. */ - + #ifdef HAVE_CONFIG_H #include "config.h" #endif - + #include <glib.h> #include <stdio.h> #include <string.h> @@ -69,6 +69,7 @@ #include "emem.h" #include "diam_dict.h" #include "diam_dict_lex.h" +#include <wiretap/file_util.h> typedef struct entity_t { char* name; @@ -175,7 +176,7 @@ application_end<\/application> command_start <command command_end<\/command> -typedefn_start <typedefn +typedefn_start <typedefn avp_start <avp avp_end <\/avp> @@ -206,7 +207,7 @@ description_attr description=\042 %S GET_ATTR GET_UINT_ATTR END_ATTR OUTSIDE IN_DICT IN_APPL IN_AVP APPL_ATTRS IGNORE_ATTR %S TYPE_ATTRS GAVP_ATTRS ENUM_ATTRS AVP_ATTRS VENDOR_ATTRS COMMAND_ATTRS TYPEDEFN_ATTRS %S XMLPI_ATTRS XMLPI_GETKEY XMLPI_GETVAL XMLPI_ENDATTR -%% +%% <LOADING>{doctype} ; <LOADING>{doctype_end} ; @@ -222,10 +223,10 @@ description_attr description=\042 xmlpi->key = NULL; xmlpi->value = NULL; xmlpi->next = NULL; - + if (!dict->xmlpis) last_xmlpi = dict->xmlpis = xmlpi; else last_xmlpi = last_xmlpi->next = xmlpi; - + BEGIN XMLPI_ATTRS; } @@ -273,9 +274,9 @@ description_attr description=\042 <LOADING>{entity} { char* p = ++yytext; entity_t* e; - + while(*p != ';') p++; - + *p = '\0'; D(("looking for entity: %s\n",yytext)); @@ -284,10 +285,10 @@ description_attr description=\042 fprintf(stderr, "included files nested to deeply\n"); yyterminate(); } - + include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER; - + for (e = ents.next; e; e = e->next) { if (strcmp(e->name,yytext) == 0) { yyin = ddict_open(sys_dir,e->file); @@ -304,20 +305,20 @@ description_attr description=\042 break; } } - + if (!e) { fprintf(stderr, "Could not find entity: '%s'", e->name ); yyterminate(); } - + } -<<EOF>> { +<<EOF>> { if (!yyin) yyterminate(); - + fclose(yyin); D(("closing: %p %i\n",yyin,include_stack_ptr)); - + if ( --include_stack_ptr < 0 ) { D(("DONE READING\n")); yyin = NULL; @@ -369,12 +370,12 @@ description_attr description=\042 <IN_DICT>{applictation_start} { D(("applictation_start\n")); - + appl = g_malloc(sizeof(ddict_application_t)); appl->name = NULL; appl->code = 0; appl->next = NULL; - + if (!dict->applications) last_appl = dict->applications = appl; else last_appl = last_appl->next = appl; @@ -389,18 +390,18 @@ description_attr description=\042 <IN_APPL>{command_end} ; -<IN_APPL>{command_start} { +<IN_APPL>{command_start} { D(("command_start\n")); - + cmd = g_malloc(sizeof(ddict_cmd_t)); cmd->name = NULL; cmd->vendor = NULL; cmd->code = 0; cmd->next = NULL; - + if (!dict->cmds) last_cmd = dict->cmds = cmd; else last_cmd = last_cmd->next = cmd; - + BEGIN COMMAND_ATTRS; } @@ -412,15 +413,15 @@ description_attr description=\042 <IN_APPL>{vendor_start} { D(("vendor_start\n")); - + vnd = g_malloc(sizeof(ddict_vendor_t)); vnd->name = NULL; vnd->code = 0; vnd->next = NULL; - + if (!dict->vendors) last_vnd = dict->vendors = vnd; else last_vnd = last_vnd->next = vnd; - + BEGIN VENDOR_ATTRS; } @@ -432,15 +433,15 @@ description_attr description=\042 <IN_APPL>{typedefn_start} { D(("typedefn_start\n")); - + typedefn = g_malloc(sizeof(ddict_typedefn_t)); typedefn->name = NULL; typedefn->parent = NULL; typedefn->next = NULL; - + if (!dict->typedefns) last_typedefn = dict->typedefns = typedefn; else last_typedefn = last_typedefn->next = typedefn; - + BEGIN TYPEDEFN_ATTRS; } @@ -452,7 +453,7 @@ description_attr description=\042 <IN_APPL>{avp_start} { D(("avp_start\n")); - + avp = g_malloc(sizeof(ddict_avp_t)); avp->name = NULL; avp->description = NULL; @@ -462,7 +463,7 @@ description_attr description=\042 avp->enums = NULL; avp->gavps = NULL; avp->next = NULL; - + if (! dict->avps ) last_avp = dict->avps = avp; else last_avp = last_avp->next = avp; @@ -483,14 +484,14 @@ description_attr description=\042 <IN_AVP>{type_start} { BEGIN TYPE_ATTRS; } <TYPE_ATTRS>{typename_attr} { ATTR_STR(avp->type); } -<IN_AVP>{gavp_start} { +<IN_AVP>{gavp_start} { D(("gavp_start\n")); - + gavp = g_malloc(sizeof(ddict_gavp_t)); gavp->name = NULL; gavp->code = 0; gavp->next = NULL; - + if (!avp->gavps) last_gavp = avp->gavps = gavp; else last_gavp = last_gavp->next = gavp; @@ -501,14 +502,14 @@ description_attr description=\042 <GAVP_ATTRS>{name_attr} { ATTR_STR(gavp->name); } -<IN_AVP>{enum_start} { +<IN_AVP>{enum_start} { D(("enum_start\n")); - + enumitem = g_malloc(sizeof(ddict_enum_t)); enumitem->name = NULL; enumitem->code = 0; enumitem->next = NULL; - + if (!avp->enums) last_enumitem = avp->enums = enumitem; else last_enumitem = last_enumitem->next = enumitem; @@ -548,11 +549,11 @@ static int debugging = 0; static void ddict_debug(const char* fmt, ...) { va_list ap; - + va_start(ap, fmt); if (debugging) vfprintf(stderr, fmt, ap); va_end(ap); - + fflush(stderr); } @@ -574,12 +575,12 @@ static void append_to_buffer(char* txt, int len) { if (strbuf == NULL) { read_ptr = write_ptr = strbuf = g_malloc(size_strbuf); } - + if ( (len_strbuf + len) >= size_strbuf ) { read_ptr = strbuf = g_realloc(strbuf,size_strbuf *= 2); } - - write_ptr = strbuf + len_strbuf; + + write_ptr = strbuf + len_strbuf; strncpy(write_ptr,txt,len); len_strbuf += len; @@ -587,13 +588,13 @@ static void append_to_buffer(char* txt, int len) { static size_t file_input(char* buf, size_t max) { size_t read; - + read = fread(buf,1,max,yyin); if ( read == max ) { return max; } else if (read > 0) { - return read; + return read; } else { return YY_NULL; } @@ -609,8 +610,8 @@ static size_t string_input(char* buf, size_t max) { memcpy(buf,read_ptr,max); read_ptr += max; - - return max; + + return max; } static FILE* ddict_open(const char* system_directory, const char* filename) { @@ -623,8 +624,8 @@ static FILE* ddict_open(const char* system_directory, const char* filename) { } else { fname = strdup(filename); } - - fh = fopen(fname,"r"); + + fh = eth_fopen(fname,"r"); D(("fname: %s fh: %p\n",fname,fh)); @@ -635,9 +636,9 @@ static FILE* ddict_open(const char* system_directory, const char* filename) { } ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg) { - + debugging = dbg; - + sys_dir = system_directory; yyin = ddict_open(sys_dir,filename); @@ -646,10 +647,10 @@ ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg) D(("unable to open %s\n", filename)); return NULL; } - + write_ptr = NULL; read_ptr = NULL; - + dict = g_malloc(sizeof(ddict_t)); dict->applications = NULL; dict->cmds = NULL; @@ -657,7 +658,7 @@ ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg) dict->typedefns = NULL; dict->avps = NULL; dict->xmlpis = NULL; - + appl = NULL; avp = NULL; enumitem = NULL; @@ -666,7 +667,7 @@ ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg) cmd = NULL; vnd = NULL; xmlpi = NULL; - + last_appl = NULL; last_avp = NULL; last_enumitem = NULL; @@ -680,9 +681,9 @@ ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg) current_yyinput = file_input; BEGIN LOADING; yylex(); - + D(("\n---------------\n%s\n------- %d -------\n",strbuf,len_strbuf)); - + current_yyinput = string_input; BEGIN OUTSIDE; @@ -691,7 +692,7 @@ ddict_t* ddict_scan(const char* system_directory, const char* filename, int dbg) g_free(strbuf); strbuf = NULL; size_strbuf = 8192; - + return dict; } @@ -703,50 +704,50 @@ void ddict_free(ddict_t* d) { ddict_avp_t *a, *an; #define FREE_NAMEANDOBJ(n) do { if(n->name) g_free(n->name); g_free(n); } while(0) - + for (p = d->applications; p; p = pn ) { pn = p->next; FREE_NAMEANDOBJ(p); } - + for (v = d->vendors; v; v = vn) { - vn = v->next; + vn = v->next; if (!v->desc) g_free(v->desc); FREE_NAMEANDOBJ(v); } - + for (c = d->cmds; c; c = cn ) { cn = c->next; FREE_NAMEANDOBJ(c); } - + for (t = d->typedefns; t; t = tn) { - tn = t->next; + tn = t->next; if (!t->parent) g_free(t->parent); FREE_NAMEANDOBJ(t); } - + for (a = d->avps; a; a = an) { ddict_gavp_t* g, *gn; ddict_enum_t* e, *en; an = a->next; - + for (g = a->gavps; g; g = gn) { gn = g->next; FREE_NAMEANDOBJ(g); } - + for (e = a->enums; e; e = en) { en = e->next; FREE_NAMEANDOBJ(e); } - + if (!a->vendor) g_free(a->vendor); if (!a->type) g_free(a->type); if (!a->description) g_free(a->description); FREE_NAMEANDOBJ(a); } - + g_free(d); } @@ -756,24 +757,24 @@ void ddict_print(FILE* fh, ddict_t* d) { ddict_cmd_t* c; ddict_typedefn_t* t; ddict_avp_t* a; - - + + for (p = d->applications; p; p = p->next) { fprintf(fh,"Application: %s[%u]:\n", p->name ? p->name : "-", p->code); } - + for (v = d->vendors; v; v = v->next) { fprintf(fh,"Vendor: %s[%u]:\n", v->name ? v->name : "-", v->code); } - + for (c = d->cmds; c; c = c->next) { fprintf(fh,"Command: %s[%u] \n", c->name ? c->name : "-", - c->code); + c->code); } for (t = d->typedefns; t; t = t->next) { @@ -781,14 +782,14 @@ void ddict_print(FILE* fh, ddict_t* d) { t->name ? t->name : "-", t->parent ? t->parent : "" ); } - + for (a = d->avps; a; a = a->next) { ddict_gavp_t* g; ddict_enum_t* e; fprintf(fh,"AVP: %s[%u:%s] %s %s\n", a->name ? a->name : "-", - a->code, - a->vendor ? a->vendor : "None", + a->code, + a->vendor ? a->vendor : "None", a->type ? a->type : "-", a->description ? a->description : ""); @@ -796,7 +797,7 @@ void ddict_print(FILE* fh, ddict_t* d) { fprintf(fh,"\tGAVP: %s\n", g->name ? g->name : "-" ); } - + for (e = a->enums; e; e = e->next) { fprintf(fh,"\tEnum: %s[%u]\n", e->name ? e->name : "-", @@ -811,20 +812,20 @@ int main(int argc, char** argv) { char* dname = NULL; char* fname; int i = 1; - + switch (argc) { case 3: dname = argv[i++]; - case 2: + case 2: fname = argv[i]; break; default: fprintf(stderr,"%s: usage [dictionary_dir] dictionary_filename\n",argv[0]); return 1; } - + d = ddict_scan(dname,fname,1); - + ddict_print(stdout, d); return 0; diff --git a/epan/dissectors/packet-giop.c b/epan/dissectors/packet-giop.c index 1a0275124b..c5d3fe28b2 100644 --- a/epan/dissectors/packet-giop.c +++ b/epan/dissectors/packet-giop.c @@ -301,6 +301,7 @@ #include "packet-giop.h" #include "packet-tcp.h" +#include <wiretap/file_util.h> /* * Set to 1 for DEBUG output - TODO make this a runtime option @@ -1289,7 +1290,7 @@ static void read_IOR_strings_from_file(const gchar *name, int max_iorlen) { gboolean stream_is_big_endian; - fp = fopen(name,"r"); /* open read only */ + fp = eth_fopen(name,"r"); /* open read only */ if (fp == NULL) { if (errno == EACCES) diff --git a/epan/dissectors/packet-isakmp.c b/epan/dissectors/packet-isakmp.c index c2ebfe2451..79cfc00637 100644 --- a/epan/dissectors/packet-isakmp.c +++ b/epan/dissectors/packet-isakmp.c @@ -3181,7 +3181,7 @@ isakmp_init_protocol(void) { G_ALLOC_AND_FREE); if (logf) fclose(logf); - logf = fopen(pluto_log_path, "r"); + logf = eth_fopen(pluto_log_path, "r"); scan_pluto_log(); #endif /* HAVE_LIBNETTLE */ diff --git a/epan/dissectors/packet-ssl-utils.c b/epan/dissectors/packet-ssl-utils.c index af1a2e1d71..0626fce489 100644 --- a/epan/dissectors/packet-ssl-utils.c +++ b/epan/dissectors/packet-ssl-utils.c @@ -36,6 +36,7 @@ #include "packet-ssl-utils.h" #include <epan/emem.h> +#include <wiretap/file_util.h> /* * Lookup tables @@ -312,9 +313,9 @@ const value_string ssl_31_ciphersuite[] = { { 0x001d, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" }, #if 0 /* Because it clashes with KRB5, is never used any more, and is safe to remove according to David Hopwood <david.hopwood@zetnet.co.uk> - of the ietf-tls list */ + of the ietf-tls list */ { 0x001e, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" }, -#endif +#endif /* RFC 2712 */ { 0x001E, "TLS_KRB5_WITH_DES_CBC_SHA" }, @@ -336,7 +337,7 @@ const value_string ssl_31_ciphersuite[] = { { 0x002C, "TLS_PSK_WITH_NULL_SHA" }, { 0x002D, "TLS_DHE_PSK_WITH_NULL_SHA" }, { 0x002E, "TLS_RSA_PSK_WITH_NULL_SHA" }, - + /* RFC 3268 */ { 0x002F, "TLS_RSA_WITH_AES_128_CBC_SHA" }, { 0x0030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" }, @@ -350,7 +351,7 @@ const value_string ssl_31_ciphersuite[] = { { 0x0038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" }, { 0x0039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" }, { 0x003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" }, - + /* ??? */ { 0x0060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" }, { 0x0061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" }, @@ -375,7 +376,7 @@ const value_string ssl_31_ciphersuite[] = { { 0x0087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" }, { 0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" }, { 0x0089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" }, - + /* RFC 4279 */ { 0x008A, "TLS_PSK_WITH_RC4_128_SHA" }, { 0x008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" }, @@ -397,7 +398,7 @@ const value_string ssl_31_ciphersuite[] = { { 0x0099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" }, { 0x009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" }, { 0x009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" }, - + /* From RFC 4492 */ { 0xc001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" }, { 0xc002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" }, @@ -435,7 +436,7 @@ const value_string ssl_31_ciphersuite[] = { { 0xC020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" }, { 0xC021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" }, { 0xC022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" }, - + /* these from http://www.mozilla.org/projects/ security/pki/nss/ssl/fips-ssl-ciphersuites.html */ { 0xfefe, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"}, @@ -2396,7 +2397,7 @@ ssl_parse_key_list(const gchar * keys_list, GHashTable *key_hash, GTree* associa ip[0], ip[1], ip[2], ip[3], service->port, filename); /* try to load pen file*/ - fp = fopen(filename, "rb"); + fp = eth_fopen(filename, "rb"); if (!fp) { fprintf(stderr, "can't open file %s \n",filename); continue; @@ -2485,7 +2486,7 @@ ssl_set_debug(char* name) else if (!name || (strcmp(name, "") ==0)) ssl_debug_file = NULL; else - ssl_debug_file = fopen(name, "w"); + ssl_debug_file = eth_fopen(name, "w"); if (!use_stderr && ssl_debug_file) debug_file_must_be_closed = 1; } diff --git a/epan/dissectors/packet-ssl.c b/epan/dissectors/packet-ssl.c index 55efbd03cd..c4b60da5cb 100644 --- a/epan/dissectors/packet-ssl.c +++ b/epan/dissectors/packet-ssl.c @@ -119,6 +119,7 @@ #include "inet_v6defs.h" #include "packet-ssl.h" #include "packet-ssl-utils.h" +#include <wiretap/file_util.h> static gboolean ssl_desegment = TRUE; @@ -331,7 +332,7 @@ ssl_parse(void) if (ssl_keys_list && (ssl_keys_list[0] != 0)) { if (file_exists(ssl_keys_list)) { - if ((ssl_keys_file = fopen(ssl_keys_list, "r"))) { + if ((ssl_keys_file = eth_fopen(ssl_keys_list, "r"))) { read_failed = FALSE; fstat(fileno(ssl_keys_file), &statb); size = statb.st_size; diff --git a/epan/radius_dict.l b/epan/radius_dict.l index dcdd5c18a6..749f33568e 100644 --- a/epan/radius_dict.l +++ b/epan/radius_dict.l @@ -51,11 +51,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - + #ifdef HAVE_CONFIG_H #include "config.h" #endif - + #include <glib.h> #include <stdio.h> #include <stdlib.h> @@ -64,19 +64,21 @@ #include <epan/packet.h> #include <epan/dissectors/packet-radius.h> #include "radius_dict_lex.h" +#include <wiretap/file_util.h> + #define ECHO #define MAX_INCLUDE_DEPTH 10 void add_vendor(const gchar* name, guint32 vendor_id); void add_value(const gchar* attrib_name,const gchar* value_repr, long value); void add_attribute(const gchar*,const gchar*, radius_attr_dissector_t,const gchar*, gboolean, gboolean); - + static YY_BUFFER_STATE include_stack[10]; static int include_stack_ptr = 0; - + static radius_dictionary_t* dict = NULL; static GHashTable* value_strings = NULL; /* GArray(value_string) by attribute name */ - + static gchar* attr_name = NULL; static gchar* attr_id = NULL; static radius_attr_dissector_t* attr_type = NULL; @@ -86,12 +88,12 @@ static gboolean encrypted = FALSE; static gboolean has_tag = FALSE; static gchar* current_vendor = NULL; - + 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}; - + %} %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 @@ -175,7 +177,7 @@ g_free(attr_id); g_free(attr_vendor); g_free(attr_name); - linenums[include_stack_ptr]++; + linenums[include_stack_ptr]++; BEGIN WS_OUT; }; @@ -189,14 +191,14 @@ g_string_sprintfa(error, "$INCLUDE files nested to deeply\n"); yyterminate(); } - + include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER; - + fullpaths[include_stack_ptr] = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", directory,yytext); - yyin = fopen( fullpaths[include_stack_ptr], "r" ); - + yyin = eth_fopen( fullpaths[include_stack_ptr], "r" ); + if (!yyin) { if (errno) { g_string_sprintfa(error, "Could not open file: '%s', error: %s\n", fullpaths[include_stack_ptr], strerror(errno) ); @@ -206,22 +208,22 @@ linenums[include_stack_ptr] = 1; yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE ) ); } - + BEGIN WS_OUT; } <<EOF>> { - + fclose(yyin); yyin = NULL; - + if ( --include_stack_ptr < 0 ) { yyterminate(); } else { g_free(fullpaths[include_stack_ptr+1]); fullpaths[include_stack_ptr+1] = NULL; - + yy_delete_buffer( YY_CURRENT_BUFFER ); yy_switch_to_buffer(include_stack[include_stack_ptr]); } @@ -236,12 +238,12 @@ void add_vendor(const gchar* name, guint32 vendor_id) { radius_vendor_info_t* v = g_malloc(sizeof(radius_vendor_info_t)); - + v->name = g_strdup(name); v->code = vendor_id; v->attrs_by_id = g_hash_table_new(g_direct_hash,g_direct_equal); v->ett = -1; - + g_hash_table_insert(dict->vendors_by_id,GUINT_TO_POINTER(v->code),v); g_hash_table_insert(dict->vendors_by_name, (gpointer) v->name, v); } @@ -249,11 +251,11 @@ void add_vendor(const gchar* name, guint32 vendor_id) { void add_attribute(const gchar* name, const gchar* code, radius_attr_dissector_t type, const gchar* vendor_name, gboolean crypt, gboolean tagged) { radius_attr_info_t* a = g_malloc(sizeof(radius_attr_info_t)); GHashTable* by_id; - + if (vendor_name) { radius_vendor_info_t* v; v = g_hash_table_lookup(dict->vendors_by_name,vendor_name); - + if (! v) { g_string_sprintfa(error, "Vendor: '%s', does not exist in %s:%i \n", vendor_name, fullpaths[include_stack_ptr], linenums[include_stack_ptr] ); BEGIN JUNK; @@ -264,7 +266,7 @@ void add_attribute(const gchar* name, const gchar* code, radius_attr_dissector_ } else { by_id = dict->attrs_by_id; } - + a->name = g_strdup(name); a->code = strtol(code,NULL,10); a->encrypt = crypt; @@ -277,7 +279,7 @@ void add_attribute(const gchar* name, const gchar* code, radius_attr_dissector_ a->hf_tag = -1; a->hf_len = -1; a->ett = -1; - + g_hash_table_insert(by_id,GUINT_TO_POINTER(a->code),a); g_hash_table_insert(dict->attrs_by_name,(gpointer) (a->name),a); } @@ -285,15 +287,15 @@ void add_attribute(const gchar* name, const gchar* code, radius_attr_dissector_ void add_value(const gchar* attrib_name, const gchar* value_repr, long value) { value_string v; GArray* a = g_hash_table_lookup(value_strings,attrib_name); - + if (! a) { a = g_array_new(TRUE,TRUE,sizeof(value_string)); g_hash_table_insert(value_strings,g_strdup(attrib_name),a); } - + v.value = value; v.strptr = g_strdup(value_repr); - + g_array_append_val(a,v); } @@ -301,12 +303,12 @@ void add_value(const gchar* attrib_name, const gchar* value_repr, long value) { static void setup_attrs(gpointer k _U_, gpointer v, gpointer p _U_) { radius_attr_info_t* a = v; gpointer key; - + union { GArray* a; gpointer p; } vs; - + if (g_hash_table_lookup_extended(value_strings,a->name,&key,&vs.p) ) { a->vs = (value_string*) vs.a->data; g_array_free(vs.a,FALSE); @@ -317,19 +319,19 @@ static void setup_attrs(gpointer k _U_, gpointer v, gpointer p _U_) { static void setup_vendors(gpointer k _U_, gpointer v, gpointer p) { radius_vendor_info_t* vnd = v; - - g_hash_table_foreach(vnd->attrs_by_id,setup_attrs,p); + + g_hash_table_foreach(vnd->attrs_by_id,setup_attrs,p); } static gboolean destroy_value_strings(gpointer k, gpointer v, gpointer p _U_) { value_string* vs = (value_string*)(((GArray*)v)->data); - + g_free(k); - + for (;vs->strptr;vs++) { g_free((void*)vs->strptr); } - + g_array_free(v,TRUE); return TRUE; } @@ -337,7 +339,7 @@ static gboolean destroy_value_strings(gpointer k, gpointer v, gpointer p _U_) { static gboolean destroy_attrs(gpointer k _U_, gpointer v, gpointer p _U_) { radius_attr_info_t* a = v; int i; - + g_free((gpointer) (a->name)); if (a->vs) { for(i=0; a->vs[i].strptr; i++) { @@ -360,7 +362,7 @@ static gboolean destroy_vendors(gpointer k _U_, gpointer v, gpointer p) { static void destroy_dict(radius_dictionary_t* d) { g_hash_table_foreach_remove(d->attrs_by_id,destroy_attrs,NULL); - g_hash_table_foreach_remove(d->vendors_by_id,destroy_vendors,NULL); + g_hash_table_foreach_remove(d->vendors_by_id,destroy_vendors,NULL); g_hash_table_destroy(d->vendors_by_id); g_hash_table_destroy(d->attrs_by_id); g_hash_table_destroy(d->vendors_by_name); @@ -370,16 +372,16 @@ static void destroy_dict(radius_dictionary_t* d) { radius_dictionary_t* radius_load_dictionary (gchar* dir, const gchar* filename, gchar** err_str) { int i; - + directory = dir; - + fullpaths[include_stack_ptr] = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", directory,filename); - + error = g_string_new(""); - yyin = fopen(fullpaths[include_stack_ptr],"r"); - + yyin = eth_fopen(fullpaths[include_stack_ptr],"r"); + if (!yyin) { g_string_sprintfa(error, "Could not open file: '%s', error: %s\n", fullpaths[include_stack_ptr], strerror(errno) ); g_free(fullpaths[include_stack_ptr]); @@ -393,24 +395,24 @@ radius_dictionary_t* radius_load_dictionary (gchar* dir, const gchar* filename, dict->attrs_by_name = g_hash_table_new(g_str_hash,g_str_equal); dict->vendors_by_id = g_hash_table_new(g_direct_hash,g_direct_equal); dict->vendors_by_name = g_hash_table_new(g_str_hash,g_str_equal); - + value_strings = g_hash_table_new(g_str_hash,g_str_equal); - + BEGIN WS_OUT; yylex(); if (yyin != NULL) fclose(yyin); yyin = NULL; - + for (i=0; i < 10; i++) { if (fullpaths[i]) g_free(fullpaths[i]); } - + g_hash_table_foreach(dict->attrs_by_id,setup_attrs,NULL); - g_hash_table_foreach(dict->vendors_by_id,setup_vendors,NULL); + g_hash_table_foreach(dict->vendors_by_id,setup_vendors,NULL); g_hash_table_foreach_remove(value_strings,destroy_value_strings,NULL); - + if (error->len > 0) { *err_str = error->str; g_string_free(error,FALSE); diff --git a/epan/uat.c b/epan/uat.c index 1d3dd753af..b5148753c9 100644 --- a/epan/uat.c +++ b/epan/uat.c @@ -11,17 +11,17 @@ * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> * Copyright 2001 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 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -43,6 +43,7 @@ #include <epan/filesystem.h> #include <epan/packet.h> #include <epan/range.h> +#include <wiretap/file_util.h> #include "uat-int.h" @@ -65,14 +66,14 @@ uat_t* uat_new(const char* name, uat_field_t* flds_array) { uat_t* uat = g_malloc(sizeof(uat_t)); guint i; - + if (!all_uats) all_uats = g_ptr_array_new(); - + g_ptr_array_add(all_uats,uat); - + g_assert(name && size && filename && data_ptr && numitems_ptr); - + uat->name = g_strdup(name); uat->record_size = size; uat->filename = g_strdup(filename); @@ -89,23 +90,23 @@ uat_t* uat_new(const char* name, uat->free_rep = NULL; uat->help = help; uat->category = category; - + for (i=0;flds_array[i].name;i++) { fld_data_t* f = g_malloc(sizeof(fld_data_t)); - + f->colnum = i+1; f->rep = NULL; f->free_rep = NULL; - + flds_array[i].priv = f; } - + uat->ncols = i; - - + + *data_ptr = NULL; *numitems_ptr = 0; - + return uat; } @@ -113,22 +114,22 @@ void* uat_add_record(uat_t* uat, const void* data) { void* rec; g_array_append_vals (uat->user_data, data, 1); - + rec = uat->user_data->data + (uat->record_size * (uat->user_data->len-1)); - + if (uat->copy_cb) { uat->copy_cb(rec, data, uat->record_size); } - + UAT_UPDATE(uat); - + return rec; } void uat_swap(uat_t* uat, guint a, guint b) { guint s = uat->record_size; void* tmp = ep_alloc(s); - + g_assert( a < uat->user_data->len && b < uat->user_data->len ); if (a == b) return; @@ -140,15 +141,15 @@ void uat_swap(uat_t* uat, guint a, guint b) { } void uat_remove_record_idx(uat_t* uat, guint idx) { - + g_assert( idx < uat->user_data->len ); if (uat->free_cb) { uat->free_cb(UAT_INDEX_PTR(uat,idx)); } - + g_array_remove_index(uat->user_data, idx); - + UAT_UPDATE(uat); } @@ -158,52 +159,52 @@ gchar* uat_get_actual_filename(uat_t* uat, gboolean for_writing) { if (! for_writing ) { gchar* data_fname = get_datafile_path(uat->filename); - + if (file_exists(data_fname)) { return data_fname; } } - + if ((! file_exists(pers_fname) ) && (! for_writing ) ) { return NULL; } - + return pers_fname; } static void putfld(FILE* fp, void* rec, uat_field_t* f) { guint fld_len; const char* fld_ptr; - + f->cb.tostr(rec,&fld_ptr,&fld_len,f->cbdata.tostr,f->fld_data); - + switch(f->mode){ case PT_TXTMOD_ENUM: case PT_TXTMOD_STRING: { guint i; - + putc('"',fp); - + for(i=0;i<fld_len;i++) { char c = fld_ptr[i]; - + if (c == '"' || c == '\\' || ! isprint((guchar)c) ) { fprintf(fp,"\\x%.2x",c); } else { putc(c,fp); } } - + putc('"',fp); return; } case PT_TXTMOD_HEXBYTES: { guint i; - + for(i=0;i<fld_len;i++) { fprintf(fp,"%.2x",((guint8*)fld_ptr)[i]); } - + return; } default: @@ -215,11 +216,11 @@ gboolean uat_save(uat_t* uat, char** error) { guint i; gchar* fname = uat_get_actual_filename(uat,TRUE); FILE* fp; - + if (! fname ) return FALSE; - fp = fopen(fname,"w"); - + fp = eth_fopen(fname,"w"); + if (!fp) { *error = ep_strdup_printf("uat_save: error opening '%s': %s",fname,strerror(errno)); return FALSE; @@ -228,15 +229,15 @@ gboolean uat_save(uat_t* uat, char** error) { *error = NULL; fprintf(fp,"# This file is automatically generated, DO NOT MODIFY.\n"); - + for ( i = 0 ; i < uat->user_data->len ; i++ ) { void* rec = uat->user_data->data + (uat->record_size * i); uat_field_t* f; guint j; f = uat->fields; - - + + for( j=0 ; j < uat->ncols ; j++ ) { putfld(fp, rec, &(f[j])); fputs((j == uat->ncols - 1) ? "\n" : "," ,fp); @@ -245,16 +246,16 @@ gboolean uat_save(uat_t* uat, char** error) { } fclose(fp); - + uat->changed = FALSE; - + return TRUE; } void uat_destroy(uat_t* uat) { /* XXX still missing a destructor */ g_ptr_array_remove(all_uats,uat); - + } void uat_clear(uat_t* uat) { @@ -265,9 +266,9 @@ void uat_clear(uat_t* uat) { uat->free_cb(UAT_INDEX_PTR(uat,i)); } } - + g_array_set_size(uat->user_data,0); - + *((uat)->user_ptr) = NULL; *((uat)->nrows_p) = 0; } @@ -295,24 +296,24 @@ void uat_cleanup(void) { void uat_foreach_table(uat_cb_t cb,void* user_data) { guint i; - + for (i=0; i < all_uats->len; i++) cb(g_ptr_array_index(all_uats,i), user_data); - -} + +} void uat_load_all(void) { guint i; gchar* err; - + for (i=0; i < all_uats->len; i++) { uat_t* u = g_ptr_array_index(all_uats,i); err = NULL; - + if (!u->loaded) uat_load(u, &err); - + if (err) { report_failure("Error loading table '%s': %s",u->name,err); } @@ -325,7 +326,7 @@ gboolean uat_fld_chk_str(void* u1 _U_, const char* strptr, unsigned len _U_, voi *err = "NULL pointer"; return FALSE; } - + *err = NULL; return TRUE; } @@ -335,7 +336,7 @@ gboolean uat_fld_chk_proto(void* u1 _U_, const char* strptr, unsigned len, void* char* name = ep_strndup(strptr,len); g_strdown(name); g_strchug(name); - + if (find_dissector(name)) { *err = NULL; return TRUE; @@ -345,19 +346,19 @@ gboolean uat_fld_chk_proto(void* u1 _U_, const char* strptr, unsigned len, void* } } else { *err = NULL; - return TRUE; + return TRUE; } } gboolean uat_fld_chk_num_dec(void* u1 _U_, const char* strptr, unsigned len, void* u2 _U_, void* u3 _U_, const char** err) { char* str = ep_strndup(strptr,len); long i = strtol(str,&str,10); - + if ( ( i == 0) && (errno == ERANGE || errno == EINVAL) ) { *err = strerror(errno); return FALSE; } - + *err = NULL; return TRUE; } @@ -365,12 +366,12 @@ gboolean uat_fld_chk_num_dec(void* u1 _U_, const char* strptr, unsigned len, voi gboolean uat_fld_chk_num_hex(void* u1 _U_, const char* strptr, unsigned len, void* u2 _U_, void* u3 _U_, const char** err) { char* str = ep_strndup(strptr,len); long i = strtol(str,&str,16); - + if ( ( i == 0) && (errno == ERANGE || errno == EINVAL) ) { *err = strerror(errno); return FALSE; } - + *err = NULL; return TRUE; } @@ -379,7 +380,7 @@ gboolean uat_fld_chk_enum(void* u1 _U_, const char* strptr, unsigned len, void* char* str = ep_strndup(strptr,len); guint i; value_string* vs = v; - + for(i=0;vs[i].strptr;i++) { if (g_str_equal(vs[i].strptr,str)) { *err = NULL; @@ -395,7 +396,7 @@ gboolean uat_fld_chk_range(void* u1 _U_, const char* strptr, unsigned len, void* char* str = ep_strndup(strptr,len); range_t* r = NULL; convert_ret_t ret = range_convert_str(&r, str,GPOINTER_TO_UINT(u3)); - + switch ( ret ) { case CVT_NO_ERROR: *err = NULL; @@ -415,7 +416,7 @@ gboolean uat_fld_chk_range(void* u1 _U_, const char* strptr, unsigned len, void* static int xton(char d) { switch(d) { case '0': return 0; - case '1': return 1; + case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; @@ -438,23 +439,23 @@ char* uat_unbinstring(const char* si, guint in_len, guint* len_p) { guint8* buf; guint len = in_len/2; int i = 0; - + if (in_len%2) { return NULL; } - + buf= g_malloc(len); *len_p = len; - + while(in_len) { int d1 = xton(*(si++)); int d0 = xton(*(si++)); - + buf[i++] = (d1 * 16) + d0; - + in_len -= 2; } - + return (void*)buf; } @@ -477,27 +478,27 @@ char* uat_unesc(const char* si, guint in_len, guint* len_p) { case 'r': *(p++) = '\r'; len++; break; case 't': *(p++) = '\t'; len++; break; case 'v': *(p++) = '\v'; len++; break; - + case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': { int c0 = 0; int c1 = 0; int c2 = 0; int c = 0; - + c0 = (*s) - '0'; - + if ( s[1] >= '0' && s[1] <= '7' ) { c1 = c0; c0 = (*++s) - '0'; - + if ( s[1] >= '0' && s[1] <= '7' ) { c2 = c1; c1 = c0; @@ -506,15 +507,15 @@ char* uat_unesc(const char* si, guint in_len, guint* len_p) { } c = (64 * c2) + (8 * c1) + c0; *(p++) = (char) (c > 255 ? 255 : c); - len++; + len++; break; } - + case 'x': { char c1 = *(s+1); char c0 = *(s+2); - + if (isxdigit((guchar)c1) && isxdigit((guchar)c0)) { *(p++) = (xton(c1) * 0x10) + xton(c0); s += 2; @@ -535,7 +536,7 @@ char* uat_unesc(const char* si, guint in_len, guint* len_p) { break; } } - + if (len_p) *len_p = len; return buf; } @@ -550,7 +551,7 @@ char* uat_esc(const char* buf, guint len) { char* out = ep_alloc0((4*len)+1); const guint8* b; char* s = out; - + for (b = (void*)buf; b < end; b++) { if (isprint(*b) ) { *(s++) = (*b); @@ -559,9 +560,9 @@ char* uat_esc(const char* buf, guint len) { s+=4; } } - + return out; - + } CHK_STR_IS_DEF(isprint) diff --git a/epan/uat_load.l b/epan/uat_load.l index 53175811bf..f5422e4cec 100644 --- a/epan/uat_load.l +++ b/epan/uat_load.l @@ -34,17 +34,17 @@ * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> * Copyright 2001 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 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -52,19 +52,20 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif - + #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <ctype.h> - + #include <glib.h> #include <epan/emem.h> #include "uat-int.h" #include "uat_load_lex.h" - +#include <wiretap/file_util.h> + static uat_t* uat; static guint colnum; static gchar* ptr; @@ -119,22 +120,22 @@ comment #[^\n]*\n <START_OF_LINE,NEXT_FIELD>{separator} { ptr = g_strdup(""); len = 0; - + DUMP_FIELD("empty->next"); - + SET_FIELD(); - + if ( colnum >= uat->ncols ) { ERROR(("more fields than required")); } - + BEGIN NEXT_FIELD; } <START_OF_LINE,NEXT_FIELD>{newline} { ptr = ""; len = 0; - + BEGIN END_OF_RECORD; yyless(yyleng); @@ -142,8 +143,8 @@ comment #[^\n]*\n <START_OF_LINE,NEXT_FIELD>{quoted_string} { ptr = uat_undquote(yytext,yyleng,&len); - - + + if (colnum < uat->ncols - 1) { DUMP("quoted_str->s"); BEGIN SEPARATOR; @@ -159,7 +160,7 @@ comment #[^\n]*\n if (!ptr) { ERROR(("uneven hexstring for field %s",uat->fields[colnum].name)); } - + if ( colnum < uat->ncols - 1 ) { DUMP("binstring->s"); BEGIN SEPARATOR; @@ -170,7 +171,7 @@ comment #[^\n]*\n } <SEPARATOR>{separator} { - + DUMP_FIELD("separator->next"); SET_FIELD(); @@ -178,7 +179,7 @@ comment #[^\n]*\n if ( colnum >= uat->ncols ) { ERROR(("more fields than required")); } - + BEGIN NEXT_FIELD; } @@ -201,27 +202,27 @@ comment #[^\n]*\n <END_OF_RECORD>{newline} { void* rec; const gchar* err = NULL; - + linenum++; DUMP_FIELD("newline->start"); SET_FIELD(); - + rec = uat_add_record(uat, record); if (uat->update_cb) uat->update_cb(rec,&err); - + if (err) { ERROR(("%s",err)); } - + colnum = 0;; ptr = NULL; len = 0; memset(record,0,uat->record_size); - + BEGIN START_OF_LINE; } @@ -250,21 +251,21 @@ gboolean uat_load(uat_t* uat_in, char** err) { UAT_UPDATE(uat); return TRUE; } - - if (!(yyin = fopen(fname,"r"))) { + + if (!(yyin = eth_fopen(fname,"r"))) { *err = strerror(errno); return FALSE; } - + error = NULL; colnum = 0; record = g_malloc0(uat->record_size); linenum = 1; - + BEGIN START_OF_LINE; DUMP(fname); - + yylex(); yyrestart(NULL); @@ -275,7 +276,7 @@ gboolean uat_load(uat_t* uat_in, char** err) { *err = ep_strdup(error); return FALSE; } else { - UAT_UPDATE(uat); + UAT_UPDATE(uat); *err = NULL; return TRUE; } |