2 * Declarations of routines for reading and writing protocols file that determine
3 * enabling and disabling of protocols.
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include <wsutil/filesystem.h>
33 #include <epan/proto.h>
34 #include <epan/packet.h>
36 #include "disabled_protos.h"
37 #include <wsutil/file_util.h>
38 #include <wsutil/ws_printf.h> /* ws_g_warning */
39 #include <wsutil/report_message.h>
41 #define ENABLED_PROTOCOLS_FILE_NAME "enabled_protos"
42 #define DISABLED_PROTOCOLS_FILE_NAME "disabled_protos"
43 #define HEURISTICS_FILE_NAME "heuristic_protos"
46 * Item in a list of disabled protocols.
49 char *name; /* protocol name */
53 * Item in a list of heuristic dissectors and their enabled state.
56 char *name; /* heuristic short name */
57 gboolean enabled; /* heuristc enabled */
61 * List of disabled protocols
63 static GList *global_disabled_protos = NULL;
64 static GList *disabled_protos = NULL;
66 * List of enabled protocols (that are disabled by default)
68 static GList *global_enabled_protos = NULL;
69 static GList *enabled_protos = NULL;
71 * List of disabled heuristics
73 static GList *global_disabled_heuristics = NULL;
74 static GList *disabled_heuristics = NULL;
76 #define INIT_BUF_SIZE 128
79 discard_existing_list (GList **flp)
85 fl_ent = g_list_first(*flp);
86 while (fl_ent != NULL) {
87 prot = (protocol_def *) fl_ent->data;
90 fl_ent = fl_ent->next;
98 heur_discard_existing_list (GList **flp)
101 heur_protocol_def *prot;
104 fl_ent = g_list_first(*flp);
105 while (fl_ent != NULL) {
106 prot = (heur_protocol_def *) fl_ent->data;
109 fl_ent = fl_ent->next;
117 * Enable/Disable protocols as per the stored configuration
120 set_protos_list(GList *protos_list, GList *global_protos_list, gboolean enable)
127 * Assume no protocols disabled by default wants to be enabled
129 if (protos_list == NULL)
132 fl_ent = g_list_first(protos_list);
134 while (fl_ent != NULL) {
135 prot = (protocol_def *) fl_ent->data;
136 i = proto_get_id_by_filter_name(prot->name);
138 /* XXX - complain here? */
140 if (proto_can_toggle_protocol(i))
141 proto_set_decoding(i, enable);
144 fl_ent = fl_ent->next;
148 if (global_protos_list == NULL)
151 fl_ent = g_list_first(global_protos_list);
153 while (fl_ent != NULL) {
154 prot = (protocol_def *) fl_ent->data;
155 i = proto_get_id_by_filter_name(prot->name);
157 /* XXX - complain here? */
159 if (proto_can_toggle_protocol(i)) {
160 proto_set_decoding(i, enable);
161 proto_set_cant_toggle(i);
165 fl_ent = fl_ent->next;
170 * Write out a list of protocols based on condition
172 * On success, "*pref_path_return" is set to NULL.
173 * On error, "*pref_path_return" is set to point to the pathname of
174 * the file we tried to read - it should be freed by our caller -
175 * and "*errno_return" is set to the error.
178 save_protos_list(char **pref_path_return, int *errno_return, const char* filename,
179 const char* header_comment, gboolean (*protocol_check)(protocol_t *protocol))
181 gchar *ff_path, *ff_path_new;
184 protocol_t *protocol;
186 gboolean first = TRUE;
188 *pref_path_return = NULL; /* assume no error */
190 ff_path = get_persconffile_path(filename, TRUE);
192 /* Write to "XXX.new", and rename if that succeeds.
193 That means we don't trash the file if we fail to write it out
195 ff_path_new = g_strdup_printf("%s.new", ff_path);
197 if ((ff = ws_fopen(ff_path_new, "w")) == NULL) {
198 *pref_path_return = ff_path;
199 *errno_return = errno;
204 /* Iterate over all the protocols */
205 for (i = proto_get_first_protocol(&cookie); i != -1;
206 i = proto_get_next_protocol(&cookie)) {
208 if (!proto_can_toggle_protocol(i)) {
212 protocol = find_protocol_by_id(i);
213 if (protocol_check(protocol) == FALSE)
217 if (header_comment != NULL) {
218 /* Write out a comment explaining what the file is */
219 fprintf(ff, "%s\n", header_comment);
224 /* Write out the protocol name. */
225 fprintf(ff, "%s\n", proto_get_protocol_filter_name(i));
228 if (fclose(ff) == EOF) {
229 *pref_path_return = ff_path;
230 *errno_return = errno;
231 ws_unlink(ff_path_new);
237 /* ANSI C doesn't say whether "rename()" removes the target if it
238 exists; the Win32 call to rename files doesn't do so, which I
239 infer is the reason why the MSVC++ "rename()" doesn't do so.
240 We must therefore remove the target file first, on Windows.
242 XXX - ws_rename() should be ws_stdio_rename() on Windows,
243 and ws_stdio_rename() uses MoveFileEx() with MOVEFILE_REPLACE_EXISTING,
244 so it should remove the target if it exists, so this stuff
245 shouldn't be necessary. Perhaps it dates back to when we were
246 calling rename(), with that being a wrapper around Microsoft's
247 _rename(), which didn't remove the target. */
248 if (ws_remove(ff_path) < 0 && errno != ENOENT) {
249 /* It failed for some reason other than "it's not there"; if
250 it's not there, we don't need to remove it, so we just
252 *pref_path_return = ff_path;
253 *errno_return = errno;
254 ws_unlink(ff_path_new);
260 if (ws_rename(ff_path_new, ff_path) < 0) {
261 *pref_path_return = ff_path;
262 *errno_return = errno;
263 ws_unlink(ff_path_new);
272 read_protos_list_file(const char *ff_path, FILE *ff, GList **flp)
280 gboolean in_comment = FALSE;
283 /* Allocate the protocol name buffer. */
284 prot_name_len = INIT_BUF_SIZE;
285 prot_name = (char *)g_malloc(prot_name_len + 1);
287 for (line = 1; ; line++) {
288 /* Lines in a protocol file contain the "filter name" of a protocol
289 to be enabled or disabled. */
291 /* Skip over leading white space, if any. */
292 while ((c = ws_getc_unlocked(ff)) != EOF && g_ascii_isspace(c)) {
301 goto error; /* I/O error */
303 break; /* Nothing more to read */
305 ungetc(c, ff); /* Unread the non-white-space character. */
307 /* Get the name of the protocol. */
310 c = ws_getc_unlocked(ff);
312 break; /* End of file, or I/O error */
313 if (g_ascii_isspace(c))
314 break; /* Trailing white space, or end of line. */
317 break; /* Start of comment, running to end of line. */
319 /* Add this character to the protocol name string. */
320 if (prot_name_index >= prot_name_len) {
321 /* protocol name buffer isn't long enough; double its length. */
323 prot_name = (char *)g_realloc(prot_name, prot_name_len + 1);
325 prot_name[prot_name_index] = c;
329 if (g_ascii_isspace(c) && c != '\n') {
330 /* Skip over trailing white space. */
331 while ((c = ws_getc_unlocked(ff)) != EOF && c != '\n' && g_ascii_isspace(c))
333 if (c != EOF && c != '\n' && c != '#') {
334 /* Non-white-space after the protocol name; warn about it,
335 in case we come up with a reason to use it. */
336 ws_g_warning("'%s' line %d has extra stuff after the protocol name.",
340 if (c != EOF && c != '\n' && in_comment == TRUE) {
341 /* Skip to end of line. */
342 while ((c = ws_getc_unlocked(ff)) != EOF && c != '\n')
348 goto error; /* I/O error */
350 /* EOF, not error; no newline seen before EOF */
351 ws_g_warning("'%s' line %d doesn't have a newline.", ff_path,
354 break; /* nothing more to read */
362 /* Null-terminate the protocol name. */
363 if (prot_name_index >= prot_name_len) {
364 /* protocol name buffer isn't long enough; double its length. */
366 prot_name = (char *)g_realloc(prot_name, prot_name_len + 1);
368 prot_name[prot_name_index] = '\0';
370 /* Add the new protocol to the list of disabled protocols */
371 prot = (protocol_def *) g_malloc(sizeof(protocol_def));
372 prot->name = g_strdup(prot_name);
373 *flp = g_list_append(*flp, prot);
384 * Read in global and personal versions of a list of protocols.
386 * If we can open and read the global version, *gpath_return is set to
387 * NULL. Otherwise, *gpath_return is set to point to the pathname of
388 * the file we tried to read - it should be freed by our caller - and
389 * *gopen_errno_return is set to the error if an open failed or
390 * *gread_errno_return is set to the error if a read failed.
392 * If we can open and read the personal version, *path_return is set to
393 * NULL. Otherwise, *path_return is set to point to the pathname of
394 * the file we tried to read - it should be freed by our caller - and
395 * *open_errno_return is set to the error if an open failed or
396 * *read_errno_return is set to the error if a read failed.
399 read_protos_list(char **gpath_return, int *gopen_errno_return,
400 int *gread_errno_return,
401 char **path_return, int *open_errno_return,
402 int *read_errno_return,
403 const char* filename,
404 GList **global_protos_list, GList **protos_list)
407 char *gff_path, *ff_path;
410 /* Construct the pathname of the global disabled protocols file. */
411 gff_path = get_datafile_path(filename);
413 /* If we already have a list of protocols, discard it. */
414 discard_existing_list (global_protos_list);
416 /* Read the global disabled protocols file, if it exists. */
417 *gpath_return = NULL;
418 if ((ff = ws_fopen(gff_path, "r")) != NULL) {
419 /* We succeeded in opening it; read it. */
420 err = read_protos_list_file(gff_path, ff, global_protos_list);
422 /* We had an error reading the file; return the errno and the
423 pathname, so our caller can report the error. */
424 *gopen_errno_return = 0;
425 *gread_errno_return = err;
426 *gpath_return = gff_path;
431 /* We failed to open it. If we failed for some reason other than
432 "it doesn't exist", return the errno and the pathname, so our
433 caller can report the error. */
434 if (errno != ENOENT) {
435 *gopen_errno_return = errno;
436 *gread_errno_return = 0;
437 *gpath_return = gff_path;
442 /* Construct the pathname of the user's disabled protocols file. */
443 ff_path = get_persconffile_path(filename, TRUE);
445 /* If we already have a list of protocols, discard it. */
446 discard_existing_list (protos_list);
448 /* Read the user's disabled protocols file, if it exists. */
450 if ((ff = ws_fopen(ff_path, "r")) != NULL) {
451 /* We succeeded in opening it; read it. */
452 err = read_protos_list_file(ff_path, ff, protos_list);
454 /* We had an error reading the file; return the errno and the
455 pathname, so our caller can report the error. */
456 *open_errno_return = 0;
457 *read_errno_return = err;
458 *path_return = ff_path;
463 /* We failed to open it. If we failed for some reason other than
464 "it doesn't exist", return the errno and the pathname, so our
465 caller can report the error. */
466 if (errno != ENOENT) {
467 *open_errno_return = errno;
468 *read_errno_return = 0;
469 *path_return = ff_path;
475 /************************************************************************
476 * Disabling dissectors
477 ************************************************************************/
480 * Disable a particular protocol by name
483 proto_disable_proto_by_name(const char *name)
485 protocol_t *protocol;
488 proto_id = proto_get_id_by_filter_name(name);
489 if (proto_id >= 0 ) {
490 protocol = find_protocol_by_id(proto_id);
491 if (proto_is_protocol_enabled(protocol) == TRUE) {
492 if (proto_can_toggle_protocol(proto_id) == TRUE) {
493 proto_set_decoding(proto_id, FALSE);
499 static gboolean disable_proto_list_check(protocol_t *protocol)
501 if (proto_is_protocol_enabled(protocol) == FALSE)
507 /************************************************************************
508 * Enabling dissectors (that are disabled by default)
509 ************************************************************************/
512 proto_enable_proto_by_name(const char *name)
514 protocol_t *protocol;
517 proto_id = proto_get_id_by_filter_name(name);
518 if (proto_id >= 0 ) {
519 protocol = find_protocol_by_id(proto_id);
520 if ((proto_is_protocol_enabled_by_default(protocol) == FALSE) &&
521 (proto_is_protocol_enabled(protocol) == FALSE)) {
522 if (proto_can_toggle_protocol(proto_id) == TRUE) {
523 proto_set_decoding(proto_id, TRUE);
529 static gboolean enable_proto_list_check(protocol_t *protocol)
531 if ((proto_is_protocol_enabled_by_default(protocol) == FALSE) &&
532 (proto_is_protocol_enabled(protocol) == TRUE))
538 /************************************************************************
539 * Heuristic dissectors
540 ************************************************************************/
544 set_disabled_heur_dissector_list(void)
547 heur_protocol_def *heur;
548 heur_dtbl_entry_t* h;
550 if (disabled_heuristics == NULL)
553 fl_ent = g_list_first(disabled_heuristics);
555 while (fl_ent != NULL) {
556 heur = (heur_protocol_def *) fl_ent->data;
557 h = find_heur_dissector_by_unique_short_name(heur->name);
559 h->enabled = heur->enabled;
562 fl_ent = fl_ent->next;
566 if (global_disabled_heuristics == NULL)
569 fl_ent = g_list_first(global_disabled_heuristics);
571 while (fl_ent != NULL) {
572 heur = (heur_protocol_def *) fl_ent->data;
574 h = find_heur_dissector_by_unique_short_name(heur->name);
576 h->enabled = heur->enabled;
579 fl_ent = fl_ent->next;
584 read_heur_dissector_list_file(const char *ff_path, FILE *ff, GList **flp)
586 heur_protocol_def *heur;
588 char *heuristic_name;
589 int heuristic_name_len;
591 gboolean parse_enabled;
596 /* Allocate the protocol name buffer. */
597 heuristic_name_len = INIT_BUF_SIZE;
598 heuristic_name = (char *)g_malloc(heuristic_name_len + 1);
600 for (line = 1; ; line++) {
601 /* Lines in a disabled protocol file contain the "filter name" of
602 a protocol to be disabled. */
604 /* Skip over leading white space, if any. */
605 while ((c = ws_getc_unlocked(ff)) != EOF && g_ascii_isspace(c)) {
614 goto error; /* I/O error */
616 break; /* Nothing more to read */
618 ungetc(c, ff); /* Unread the non-white-space character. */
620 /* Get the name of the protocol. */
623 parse_enabled = FALSE;
625 c = ws_getc_unlocked(ff);
627 break; /* End of file, or I/O error */
628 if (g_ascii_isspace(c))
629 break; /* Trailing white space, or end of line. */
630 if (c == ',') {/* Separator for enable/disable */
631 parse_enabled = TRUE;
635 break; /* Start of comment, running to end of line. */
637 enabled = ((c == '1') ? TRUE : FALSE);
640 /* Add this character to the protocol name string. */
641 if (name_index >= heuristic_name_len) {
642 /* protocol name buffer isn't long enough; double its length. */
643 heuristic_name_len *= 2;
644 heuristic_name = (char *)g_realloc(heuristic_name, heuristic_name_len + 1);
646 heuristic_name[name_index] = c;
650 if (g_ascii_isspace(c) && c != '\n') {
651 /* Skip over trailing white space. */
652 while ((c = ws_getc_unlocked(ff)) != EOF && c != '\n' && g_ascii_isspace(c))
654 if (c != EOF && c != '\n' && c != '#') {
655 /* Non-white-space after the protocol name; warn about it,
656 in case we come up with a reason to use it. */
657 ws_g_warning("'%s' line %d has extra stuff after the protocol name.",
661 if (c != EOF && c != '\n') {
662 /* Skip to end of line. */
663 while ((c = ws_getc_unlocked(ff)) != EOF && c != '\n')
669 goto error; /* I/O error */
671 /* EOF, not error; no newline seen before EOF */
672 ws_g_warning("'%s' line %d doesn't have a newline.", ff_path,
675 break; /* nothing more to read */
678 /* Null-terminate the protocol name. */
679 if (name_index >= heuristic_name_len) {
680 /* protocol name buffer isn't long enough; double its length. */
681 heuristic_name_len *= 2;
682 heuristic_name = (char *)g_realloc(heuristic_name, heuristic_name_len + 1);
684 heuristic_name[name_index] = '\0';
686 /* Add the new protocol to the list of protocols */
687 heur = (heur_protocol_def *) g_malloc(sizeof(heur_protocol_def));
688 heur->name = g_strdup(heuristic_name);
689 heur->enabled = enabled;
690 *flp = g_list_append(*flp, heur);
692 g_free(heuristic_name);
696 g_free(heuristic_name);
701 read_heur_dissector_list(char **gpath_return, int *gopen_errno_return,
702 int *gread_errno_return,
703 char **path_return, int *open_errno_return,
704 int *read_errno_return)
707 char *gff_path, *ff_path;
710 /* If we already have a list of protocols, discard it. */
711 heur_discard_existing_list(&global_disabled_heuristics);
713 /* Construct the pathname of the global disabled heuristic dissectors file. */
714 gff_path = get_datafile_path(HEURISTICS_FILE_NAME);
716 /* Read the global disabled protocols file, if it exists. */
717 *gpath_return = NULL;
718 if ((ff = ws_fopen(gff_path, "r")) != NULL) {
719 /* We succeeded in opening it; read it. */
720 err = read_heur_dissector_list_file(gff_path, ff,
721 &global_disabled_heuristics);
723 /* We had an error reading the file; return the errno and the
724 pathname, so our caller can report the error. */
725 *gopen_errno_return = 0;
726 *gread_errno_return = err;
727 *gpath_return = gff_path;
732 /* We failed to open it. If we failed for some reason other than
733 "it doesn't exist", return the errno and the pathname, so our
734 caller can report the error. */
735 if (errno != ENOENT) {
736 *gopen_errno_return = errno;
737 *gread_errno_return = 0;
738 *gpath_return = gff_path;
743 /* Construct the pathname of the user's disabled protocols file. */
744 ff_path = get_persconffile_path(HEURISTICS_FILE_NAME, TRUE);
746 /* If we already have a list of protocols, discard it. */
747 heur_discard_existing_list (&disabled_heuristics);
749 /* Read the user's disabled protocols file, if it exists. */
751 if ((ff = ws_fopen(ff_path, "r")) != NULL) {
752 /* We succeeded in opening it; read it. */
753 err = read_heur_dissector_list_file(ff_path, ff, &disabled_heuristics);
755 /* We had an error reading the file; return the errno and the
756 pathname, so our caller can report the error. */
757 *open_errno_return = 0;
758 *read_errno_return = err;
759 *path_return = ff_path;
764 /* We failed to open it. If we failed for some reason other than
765 "it doesn't exist", return the errno and the pathname, so our
766 caller can report the error. */
767 if (errno != ENOENT) {
768 *open_errno_return = errno;
769 *read_errno_return = 0;
770 *path_return = ff_path;
777 heur_compare(gconstpointer a, gconstpointer b)
779 return strcmp(((const heur_dtbl_entry_t *)a)->short_name,
780 ((const heur_dtbl_entry_t *)b)->short_name);
784 write_heur_dissector(gpointer data, gpointer user_data)
786 heur_dtbl_entry_t* dtbl_entry = (heur_dtbl_entry_t*)data;
787 FILE *ff = (FILE*)user_data;
789 /* Write out the heuristic short name and its enabled state */
790 fprintf(ff, "%s,%d\n", dtbl_entry->short_name, dtbl_entry->enabled ? 1 : 0);
794 sort_dissector_table_entries(const char *table_name _U_,
795 heur_dtbl_entry_t *dtbl_entry, gpointer user_data)
797 GSList **list = (GSList**)user_data;
798 *list = g_slist_insert_sorted(*list, dtbl_entry, heur_compare);
802 sort_heur_dissector_tables(const char *table_name, struct heur_dissector_list *list, gpointer w)
805 heur_dissector_table_foreach(table_name, sort_dissector_table_entries, w);
810 save_disabled_heur_dissector_list(char **pref_path_return, int *errno_return)
812 gchar *ff_path, *ff_path_new;
813 GSList *sorted_heur_list = NULL;
816 *pref_path_return = NULL; /* assume no error */
818 ff_path = get_persconffile_path(HEURISTICS_FILE_NAME, TRUE);
820 /* Write to "XXX.new", and rename if that succeeds.
821 That means we don't trash the file if we fail to write it out
823 ff_path_new = g_strdup_printf("%s.new", ff_path);
825 if ((ff = ws_fopen(ff_path_new, "w")) == NULL) {
826 *pref_path_return = ff_path;
827 *errno_return = errno;
832 /* Iterate over all the heuristic dissectors to sort them in alphabetical order by short name */
833 dissector_all_heur_tables_foreach_table(sort_heur_dissector_tables, &sorted_heur_list, NULL);
836 g_slist_foreach(sorted_heur_list, write_heur_dissector, ff);
837 g_slist_free(sorted_heur_list);
839 if (fclose(ff) == EOF) {
840 *pref_path_return = ff_path;
841 *errno_return = errno;
842 ws_unlink(ff_path_new);
848 /* ANSI C doesn't say whether "rename()" removes the target if it
849 exists; the Win32 call to rename files doesn't do so, which I
850 infer is the reason why the MSVC++ "rename()" doesn't do so.
851 We must therefore remove the target file first, on Windows.
853 XXX - ws_rename() should be ws_stdio_rename() on Windows,
854 and ws_stdio_rename() uses MoveFileEx() with MOVEFILE_REPLACE_EXISTING,
855 so it should remove the target if it exists, so this stuff
856 shouldn't be necessary. Perhaps it dates back to when we were
857 calling rename(), with that being a wrapper around Microsoft's
858 _rename(), which didn't remove the target. */
859 if (ws_remove(ff_path) < 0 && errno != ENOENT) {
860 /* It failed for some reason other than "it's not there"; if
861 it's not there, we don't need to remove it, so we just
863 *pref_path_return = ff_path;
864 *errno_return = errno;
865 ws_unlink(ff_path_new);
871 if (ws_rename(ff_path_new, ff_path) < 0) {
872 *pref_path_return = ff_path;
873 *errno_return = errno;
874 ws_unlink(ff_path_new);
883 proto_enable_heuristic_by_name(const char *name, gboolean enable)
885 heur_dtbl_entry_t* heur = find_heur_dissector_by_unique_short_name(name);
887 heur->enabled = enable;
895 disabled_protos_free(gpointer p, gpointer user_data _U_)
897 protocol_def* pd = (protocol_def*)p;
903 * Read the files that enable and disable protocols and heuristic
904 * dissectors. Report errors through the UI.
907 read_enabled_and_disabled_lists(void)
910 int gopen_errno, gread_errno;
911 int open_errno, read_errno;
914 * Read the global and personal disabled protocols files.
916 read_protos_list(&gpath, &gopen_errno, &gread_errno,
917 &path, &open_errno, &read_errno,
918 DISABLED_PROTOCOLS_FILE_NAME,
919 &global_disabled_protos, &disabled_protos);
921 if (gopen_errno != 0) {
922 report_warning("Could not open global disabled protocols file\n\"%s\": %s.",
923 gpath, g_strerror(gopen_errno));
925 if (gread_errno != 0) {
926 report_warning("I/O error reading global disabled protocols file\n\"%s\": %s.",
927 gpath, g_strerror(gread_errno));
933 if (open_errno != 0) {
934 report_warning("Could not open your disabled protocols file\n\"%s\": %s.",
935 path, g_strerror(open_errno));
937 if (read_errno != 0) {
938 report_warning("I/O error reading your disabled protocols file\n\"%s\": %s.",
939 path, g_strerror(read_errno));
946 * Read the global and personal enabled protocols files.
948 read_protos_list(&gpath, &gopen_errno, &gread_errno,
949 &path, &open_errno, &read_errno,
950 ENABLED_PROTOCOLS_FILE_NAME,
951 &global_enabled_protos, &enabled_protos);
953 if (gopen_errno != 0) {
954 report_warning("Could not open global enabled protocols file\n\"%s\": %s.",
955 gpath, g_strerror(gopen_errno));
957 if (gread_errno != 0) {
958 report_warning("I/O error reading global enabled protocols file\n\"%s\": %s.",
959 gpath, g_strerror(gread_errno));
965 if (open_errno != 0) {
966 report_warning("Could not open your enabled protocols file\n\"%s\": %s.",
967 path, g_strerror(open_errno));
969 if (read_errno != 0) {
970 report_warning("I/O error reading your enabled protocols file\n\"%s\": %s.",
971 path, g_strerror(read_errno));
978 * Read the global and personal heuristic dissector list files.
980 read_heur_dissector_list(&gpath, &gopen_errno, &gread_errno,
981 &path, &open_errno, &read_errno);
983 if (gopen_errno != 0) {
984 report_warning("Could not open global heuristic dissectors file\n\"%s\": %s.",
985 gpath, g_strerror(gopen_errno));
987 if (gread_errno != 0) {
988 report_warning("I/O error reading global heuristic dissectors file\n\"%s\": %s.",
989 gpath, g_strerror(gread_errno));
995 if (open_errno != 0) {
996 report_warning("Could not open your heuristic dissectors file\n\"%s\": %s.",
997 path, g_strerror(open_errno));
999 if (read_errno != 0) {
1000 report_warning("I/O error reading your heuristic dissectors file\n\"%s\": %s.",
1001 path, g_strerror(read_errno));
1008 * Enable/disable protocols and heuristic dissectors as per the
1009 * contents of the files we just read.
1011 set_protos_list(disabled_protos, global_disabled_protos, FALSE);
1012 set_protos_list(enabled_protos, global_enabled_protos, TRUE);
1013 set_disabled_heur_dissector_list();
1017 * Write out the lists of enabled and disabled protocols and heuristic
1018 * dissectors to the corresponding files. Report errors through the UI.
1021 save_enabled_and_disabled_lists(void)
1027 /* Create the directory that holds personal configuration files, if
1029 if (create_persconffile_dir(&pf_dir_path) == -1) {
1030 report_failure("Can't create directory\n\"%s\"\nfor disabled protocols file: %s.",
1031 pf_dir_path, g_strerror(errno));
1032 g_free(pf_dir_path);
1036 save_protos_list(&pf_path, &pf_save_errno, DISABLED_PROTOCOLS_FILE_NAME,
1037 NULL, disable_proto_list_check);
1038 if (pf_path != NULL) {
1039 report_failure("Could not save to your disabled protocols file\n\"%s\": %s.",
1040 pf_path, g_strerror(pf_save_errno));
1044 save_protos_list(&pf_path, &pf_save_errno, ENABLED_PROTOCOLS_FILE_NAME,
1045 "#This file is for enabling protocols that are disabled by default",
1046 enable_proto_list_check);
1047 if (pf_path != NULL) {
1048 report_failure("Could not save to your enabled protocols file\n\"%s\": %s.",
1049 pf_path, g_strerror(pf_save_errno));
1053 save_disabled_heur_dissector_list(&pf_path, &pf_save_errno);
1054 if (pf_path != NULL) {
1055 report_failure("Could not save to your disabled heuristic protocol file\n\"%s\": %s.",
1056 pf_path, g_strerror(pf_save_errno));
1062 cleanup_enabled_and_disabled_lists(void)
1064 g_list_foreach(global_disabled_heuristics, disabled_protos_free, NULL);
1065 g_list_free(global_disabled_heuristics);
1066 g_list_foreach(disabled_heuristics, disabled_protos_free, NULL);
1067 g_list_free(disabled_heuristics);
1068 g_list_foreach(global_disabled_protos, disabled_protos_free, NULL);
1069 g_list_free(global_disabled_protos);
1070 g_list_foreach(disabled_protos, disabled_protos_free, NULL);
1071 g_list_free(disabled_protos);
1075 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1080 * indent-tabs-mode: nil
1083 * ex: set shiftwidth=2 tabstop=8 expandtab:
1084 * :indentSize=2:tabSize=8:noTabs=true: