Beispiel #1
0
static int delete_directory(const char *directory) {
    WS_DIR *dir;
    WS_DIRENT *file;
    gchar *filename;
    int ret = 0;

    /* delete all contents of directory */
    if ((dir = ws_dir_open(directory, 0, NULL)) != NULL) {
        while ((file = ws_dir_read_name(dir)) != NULL) {
            filename = g_strdup_printf ("%s%s%s", directory, G_DIR_SEPARATOR_S,
                            ws_dir_get_name(file));
            if (test_for_directory(filename) != EISDIR) {
                ret = ws_remove(filename);
            } else {
                /* recurse */
                ret = delete_directory (filename);
            }
            if (ret != 0) {
                break;
            }
            g_free (filename);
        }
        ws_dir_close(dir);
    }

    if (ret == 0) {
        ret = ws_remove(directory);
    }

    return ret;
}
Beispiel #2
0
void
init_profile_list(void)
{
    WS_DIR        *dir;             /* scanned directory */
    WS_DIRENT     *file;            /* current file */
    const gchar   *profiles_dir, *name;
    gchar         *filename;

    empty_profile_list(TRUE);

    /* Default entry */
    add_to_profile_list(DEFAULT_PROFILE, DEFAULT_PROFILE, PROF_STAT_DEFAULT, FALSE, FALSE);

    /* Local (user) profiles */
    profiles_dir = get_profiles_dir();
    if ((dir = ws_dir_open(profiles_dir, 0, NULL)) != NULL) {
        while ((file = ws_dir_read_name(dir)) != NULL) {
            name = ws_dir_get_name(file);
            filename = g_strdup_printf ("%s%s%s", profiles_dir, G_DIR_SEPARATOR_S, name);

            if (test_for_directory(filename) == EISDIR) {
                /*fl_entry =*/ add_to_profile_list(name, name, PROF_STAT_EXISTS, FALSE, FALSE);
            }
            g_free (filename);
        }
        ws_dir_close (dir);
    }

    /* Global profiles */
    profiles_dir = get_global_profiles_dir();
    if ((dir = ws_dir_open(profiles_dir, 0, NULL)) != NULL) {
        while ((file = ws_dir_read_name(dir)) != NULL) {
            name = ws_dir_get_name(file);
            filename = g_strdup_printf ("%s%s%s", profiles_dir, G_DIR_SEPARATOR_S, name);

            if (test_for_directory(filename) == EISDIR) {
                /*fl_entry =*/ add_to_profile_list(name, name, PROF_STAT_EXISTS, TRUE, TRUE);
                /*profile = (profile_def *) fl_entry->data;*/
            }
            g_free (filename);
        }
        ws_dir_close (dir);
    }

    /* Make the current list and the edited list equal */
    copy_profile_list ();
}
Beispiel #3
0
static GtkTreeIter *
fill_list(GtkWidget *main_w)
{
  WS_DIR        *dir;             /* scanned directory */
  WS_DIRENT     *file;            /* current file */
  GList         *fl_entry;
  profile_def   *profile;
  GtkTreeView   *profile_l;
  GtkListStore  *store;
  GtkTreeIter    iter, *l_select = NULL;
  const gchar   *profile_name = get_profile_name ();
  const gchar   *profiles_dir, *name;
  gchar         *filename;

  profile_l = GTK_TREE_VIEW(g_object_get_data(G_OBJECT(main_w), E_PROF_PROFILE_L_KEY));
  store = GTK_LIST_STORE(gtk_tree_view_get_model(profile_l));

  fl_entry = add_to_profile_list(DEFAULT_PROFILE, DEFAULT_PROFILE, PROF_STAT_DEFAULT);
  gtk_list_store_append(store, &iter);
  gtk_list_store_set(store, &iter, 0, DEFAULT_PROFILE, 1, fl_entry, -1);
  if (strcmp (profile_name, DEFAULT_PROFILE)==0) {
    l_select = g_memdup(&iter, sizeof(iter));
  }

  /* fill in data */
  profiles_dir = get_profiles_dir();
  if ((dir = ws_dir_open(profiles_dir, 0, NULL)) != NULL) {
    while ((file = ws_dir_read_name(dir)) != NULL) {
      name = ws_dir_get_name(file);
      filename = g_strdup_printf ("%s%s%s", profiles_dir, G_DIR_SEPARATOR_S, name);

      if (test_for_directory(filename) == EISDIR) {
	fl_entry = add_to_profile_list(name, name, PROF_STAT_EXISTS);
	profile    = (profile_def *) fl_entry->data;
	gtk_list_store_append(store, &iter);
	gtk_list_store_set(store, &iter, 0, profile->name, 1, fl_entry, -1);

	if (profile->name) {
	  if (strcmp(profile_name, profile->name) == 0) {
	    /*
	     * XXX - We're assuming that we can just copy a GtkTreeIter
	     * and use it later without any crashes.  This may not be a
	     * valid assumption.
	     */
	    l_select = g_memdup(&iter, sizeof(iter));
	  }
	}
      }
      g_free (filename);
    }
    ws_dir_close (dir);
  }

  /* Make the current list and the edited list equal */
  copy_profile_list ();

  return l_select;
}
Beispiel #4
0
/* walk through the directory of the loaded file and add every file matching the current file */
void
fileset_add_dir(const char *fname)
{
    WS_DIR        *dir;             /* scanned directory */
    WS_DIRENT     *file;            /* current file */
    const char    *name;
    fileset_entry *entry;
    GString       *dirname;
    gchar         *fname_dup;


    /* get (convert) directory name, but don't touch the given string */
    fname_dup = get_dirname(g_strdup(fname));
    dirname = g_string_new(fname_dup);
    g_free(fname_dup);

    set.dirname = g_strdup(dirname->str);

    dirname = g_string_append_c(dirname, G_DIR_SEPARATOR);

    /* is the current file probably a part of any fileset? */
    if(fileset_filename_match_pattern(fname)) {
        /* yes, go through the files in the directory and check if the file in question is part of the current file set */
        if ((dir = ws_dir_open(dirname->str, 0, NULL)) != NULL) {
	        while ((file = ws_dir_read_name(dir)) != NULL) {
	            name = ws_dir_get_name(file);
                if(fileset_filename_match_pattern(name) && fileset_is_file_in_set(name, get_basename(fname))) {
                    fileset_add_file(dirname->str, name, strcmp(name, get_basename(fname))== 0 /* current */);
                }
            } /* while */

            ws_dir_close(dir);
        } /* if */
    } else {
        /* no, this is a "standalone file", just add this one */
        entry = fileset_add_file(dirname->str, get_basename(fname), TRUE /* current */);
        /* don't add the file to the dialog here, this will be done in fileset_update_dlg() below */
    }

    g_string_free(dirname, TRUE /* free_segment */);

    /* sort entries by creation time */
    set.entries = g_list_sort(set.entries, fileset_sort_compare);

    fileset_update_dlg();
}
Beispiel #5
0
/*
 * add all etch symbol from directory to our symbol cache
 */
static void
read_hashed_symbols_from_dir(const char *dirname)
{
  WS_DIR     *dir;
  WS_DIRENT  *file;
  const char *name;
  char       *filename;
  GError     *err_p = NULL;

  if(gbl_current_keytab_folder != NULL) {
    g_free(gbl_current_keytab_folder);
    gbl_current_keytab_folder = NULL;
  }

  gbl_symbols_free();

  if ((dirname == NULL) || (dirname[0] == '\0'))
    return;

  if ((dir = ws_dir_open(dirname, 0, &err_p)) != NULL) {
    gbl_symbols_new();

    gbl_current_keytab_folder = g_strdup(dirname);
    while ((file = ws_dir_read_name(dir)) != NULL) {
      name = ws_dir_get_name(file);

      if (g_str_has_suffix(file, ".ewh")) {
        filename =
          g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", dirname,
                          name);
        add_symbols_of_file(filename);
        g_free(filename);
      }
    }
    ws_dir_close(dir);
    gbl_symbols_vs_ext_new();
  }else{
    report_failure("etch: %s", err_p->message);
    g_error_free(err_p);
  }
}
Beispiel #6
0
/*
 * Scan for plugins.
 */
void
scan_plugins(void)
{
    const char *plugin_dir;
    const char *name;
    char *plugin_dir_path;
    char *plugins_pers_dir;
    WS_DIR *dir;                /* scanned directory */
    WS_DIRENT *file;                /* current file */

    if (plugin_list == NULL)      /* ensure scan_plugins is only run once */
    {
        /*
         * Scan the global plugin directory.
         * If we're running from a build directory, scan the subdirectories
         * of that directory, as the global plugin directory is the
         * "plugins" directory of the source tree, and the subdirectories
         * are the source directories for the plugins, with the plugins
         * built in those subdirectories.
         */
        plugin_dir = get_plugin_dir();
        if (running_in_build_directory())
        {
            if ((dir = ws_dir_open(plugin_dir, 0, NULL)) != NULL)
            {
                while ((file = ws_dir_read_name(dir)) != NULL)
                {
                    name = ws_dir_get_name(file);
                    if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
                        continue;        /* skip "." and ".." */
                    /*
                     * Get the full path of a ".libs" subdirectory of that
                     * directory.
                     */
                    plugin_dir_path = g_strdup_printf(
                        "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S ".libs",
                        plugin_dir, name);
                    if (test_for_directory(plugin_dir_path) != EISDIR) {
                        /*
                         * Either it doesn't refer to a directory or it
                         * refers to something that doesn't exist.
                         *
                         * Assume that means that the plugins are in
                         * the subdirectory of the plugin directory, not
                         * a ".libs" subdirectory of that subdirectory.
                         */
                        g_free(plugin_dir_path);
                        plugin_dir_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
                            plugin_dir, name);
                    }
                    plugins_scan_dir(plugin_dir_path);
                    g_free(plugin_dir_path);
                }
                ws_dir_close(dir);
            }
        }
        else
            plugins_scan_dir(plugin_dir);

        /*
         * If the program wasn't started with special privileges,
         * scan the users plugin directory.  (Even if we relinquish
         * them, plugins aren't safe unless we've *permanently*
         * relinquished them, and we can't do that in Wireshark as,
         * if we need privileges to start capturing, we'd need to
         * reclaim them before each time we start capturing.)
         */
        if (!started_with_special_privs())
        {
            plugins_pers_dir = get_plugins_pers_dir();
            plugins_scan_dir(plugins_pers_dir);
            g_free(plugins_pers_dir);
        }
    }
}
Beispiel #7
0
static void
plugins_scan_dir(const char *dirname)
{
#define FILENAME_LEN        1024
    WS_DIR        *dir;             /* scanned directory */
    WS_DIRENT     *file;            /* current file */
    const char    *name;
    gchar          filename[FILENAME_LEN];   /* current file name */
    GModule       *handle;          /* handle returned by g_module_open */
    gpointer       gp;
    plugin        *new_plug;
    gchar         *dot;
    int            cr;

    if ((dir = ws_dir_open(dirname, 0, NULL)) != NULL)
    {
        while ((file = ws_dir_read_name(dir)) != NULL)
        {
            name = ws_dir_get_name(file);

            /*
             * GLib 2.x defines G_MODULE_SUFFIX as the extension used on
             * this platform for loadable modules.
             */
            /* skip anything but files with G_MODULE_SUFFIX */
            dot = strrchr(name, '.');
            if (dot == NULL || strcmp(dot+1, G_MODULE_SUFFIX) != 0)
                continue;

            g_snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s",
                       dirname, name);
            if ((handle = g_module_open(filename, (GModuleFlags)0)) == NULL)
            {
                report_failure("Couldn't load module %s: %s", filename,
                               g_module_error());
                continue;
            }

            if (!g_module_symbol(handle, "version", &gp))
            {
                report_failure("The plugin %s has no version symbol", name);
                g_module_close(handle);
                continue;
            }

            new_plug = (plugin *)g_malloc(sizeof(plugin));
            new_plug->handle = handle;
            new_plug->name = g_strdup(name);
            new_plug->version = (char *)gp;
            new_plug->types = 0;
            new_plug->next = NULL;

            /*
             * Hand the plugin to each of the plugin type callbacks.
             */
            g_slist_foreach(plugin_types, call_plugin_callback, new_plug);

            /*
             * Does this dissector do anything useful?
             */
            if (new_plug->types == 0)
            {
                /*
                 * No.
                 */
                report_failure("The plugin '%s' has no registration routines",
                               name);
                g_module_close(handle);
                g_free(new_plug->name);
                g_free(new_plug);
                continue;
            }

            /*
             * OK, attempt to add it to the list of plugins.
             */
            if ((cr = add_plugin(new_plug)))
            {
                if (cr == EEXIST)
                    fprintf(stderr, "The plugin %s, version %s\n"
                            "was found in multiple directories\n",
                            new_plug->name, new_plug->version);
                else
                    fprintf(stderr, "Memory allocation problem\n"
                            "when processing plugin %s, version %s\n",
                            new_plug->name, new_plug->version);
                g_module_close(handle);
                g_free(new_plug->name);
                g_free(new_plug);
                continue;
            }

        }
        ws_dir_close(dir);
    }
}
Beispiel #8
0
/*
 * XXX - when we remove support for old-style plugins (which we should
 * probably do eventually, as all plugins should be written as new-style
 * ones), we may want to have "init_plugins()" merely save a pointer
 * to the plugin's "init" routine, just as we save a pointer to its
 * "reg_handoff" routine, and have a "register_all_plugins()" routine
 * to go through the list of plugins and call all of them.
 *
 * Then we'd have "epan_init()", or perhaps even something higher up
 * in the call tree, call "init_plugins()", and have "proto_init()"
 * call "register_all_plugins()" right after calling "register_all_protocols()";
 * this might be a bit cleaner.
 */
static void
plugins_scan_dir(const char *dirname)
{
#define FILENAME_LEN        1024
    WS_DIR        *dir;             /* scanned directory */
    WS_DIRENT     *file;            /* current file */
    const char    *name;
    gchar          filename[FILENAME_LEN];   /* current file name */
    GModule       *handle;          /* handle returned by g_module_open */
    gchar         *version;
    gpointer       gp;
    void         (*register_protoinfo)(void);
    void         (*reg_handoff)(void);
    void         (*register_tap_listener)(void);
    void         (*register_wtap_module)(void);
    void         (*register_codec_module)(void);

    gchar         *dot;
    int            cr;

    if ((dir = ws_dir_open(dirname, 0, NULL)) != NULL)
    {
        while ((file = ws_dir_read_name(dir)) != NULL)
        {
            name = ws_dir_get_name(file);

            /*
             * GLib 2.x defines G_MODULE_SUFFIX as the extension used on
             * this platform for loadable modules.
             */
            /* skip anything but files with G_MODULE_SUFFIX */
            dot = strrchr(name, '.');
            if (dot == NULL || strcmp(dot+1, G_MODULE_SUFFIX) != 0)
                continue;

            g_snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s",
                       dirname, name);
            if ((handle = g_module_open(filename, 0)) == NULL)
            {
                report_failure("Couldn't load module %s: %s", filename,
                               g_module_error());
                continue;
            }

            if (!g_module_symbol(handle, "version", &gp))
            {
                report_failure("The plugin %s has no version symbol", name);
                g_module_close(handle);
                continue;
            }
            version = gp;

            /*
             * Do we have a register routine?
             */
            if (g_module_symbol(handle, "plugin_register", &gp))
            {
                /*
                 * Yes - this plugin includes one or more dissectors.
                 */
                register_protoinfo = gp;
            }
            else
            {
                /*
                 * No - no dissectors.
                 */
                register_protoinfo = NULL;
            }

            /*
             * Do we have a reg_handoff routine?
             */
            if (g_module_symbol(handle, "plugin_reg_handoff", &gp))
            {
                /*
                 * Yes.
                 */
                reg_handoff = gp;
            }
            else
            {
                /*
                 * No - that's OK even if we have dissectors, as long
                 * as the plugin registers by name *and* there's
                 * a caller looking for that name.
                 */
                reg_handoff = NULL;
            }

            /*
             * Do we have a register_tap_listener routine?
             */
            if (g_module_symbol(handle, "plugin_register_tap_listener", &gp))
            {
                /*
                 * Yes - this plugin includes one or more taps.
                 */
                register_tap_listener = gp;
            }
            else
            {
                /*
                 * No - no taps here.
                 */
                register_tap_listener = NULL;
            }

            /*
             * Do we have an old-style init routine?
             */
            if (g_module_symbol(handle, "plugin_init", &gp))
            {
                /*
                 * Yes - do we also have a register routine or a
                 * register_tap_listener routine?  If so, this is a bogus
                 * hybrid of an old-style and new-style plugin.
                 */
                if (register_protoinfo != NULL || register_tap_listener != NULL)
                {
                    report_failure("The plugin '%s' has an old plugin init routine\nand a new register or register_tap_listener routine.",
                                   name);
                    g_module_close(handle);
                    continue;
                }

                /*
                 * It's just an unsupported old-style plugin;
                 */
                report_failure("The plugin '%s' has an old plugin init routine. Support has been dropped.\n Information on how to update your plugin is available at \nhttp://anonsvn.wireshark.org/wireshark/trunk/doc/README.plugins",
                               name);
                g_module_close(handle);
                continue;
            }

            /*
             * Do we have a register_wtap_module routine?
             */
            if (g_module_symbol(handle, "register_wtap_module", &gp))
            {
                register_wtap_module = gp;
            }
            else
            {
                register_wtap_module = NULL;
            }

            /*
             * Do we have a register_codec_module routine?
             */
            if (g_module_symbol(handle, "register_codec_module", &gp))
            {
                register_codec_module = gp;
            }
            else
            {
                register_codec_module = NULL;
            }

            /*
             * Does this dissector do anything useful?
             */
            if (register_protoinfo == NULL &&
                register_tap_listener == NULL &&
                register_wtap_module == NULL &&
                register_codec_module == NULL )
            {
                /*
                 * No.
                 */
                report_failure("The plugin '%s' has neither a register routine, "
                               "a register_tap_listener or a register_wtap_module or a register_codec_module routine",
                               name);
                g_module_close(handle);
                continue;
            }

            /*
             * OK, attempt to add it to the list of plugins.
             */
            if ((cr = add_plugin(handle, g_strdup(name), version,
                                 register_protoinfo, reg_handoff,
                                 register_tap_listener,register_wtap_module,register_codec_module)))
            {
                if (cr == EEXIST)
                    fprintf(stderr, "The plugin %s, version %s\n"
                            "was found in multiple directories\n", name, version);
                else
                    fprintf(stderr, "Memory allocation problem\n"
                            "when processing plugin %s, version %s\n",
                            name, version);
                g_module_close(handle);
                continue;
            }

        }
        ws_dir_close(dir);
    }
}
Beispiel #9
0
static void
plugins_scan_dir(const char *dirname, plugin_load_failure_mode mode)
{
#define FILENAME_LEN        1024
    WS_DIR        *dir;             /* scanned directory */
    WS_DIRENT     *file;            /* current file */
    const char    *name;
    gchar          filename[FILENAME_LEN];   /* current file name */
    GModule       *handle;          /* handle returned by g_module_open */
    gpointer       gp;
    plugin        *new_plug;
    gchar         *dot;
    int            cr;

    if ((dir = ws_dir_open(dirname, 0, NULL)) != NULL)
    {
        while ((file = ws_dir_read_name(dir)) != NULL)
        {
            name = ws_dir_get_name(file);

            /*
             * GLib 2.x defines G_MODULE_SUFFIX as the extension used on
             * this platform for loadable modules.
             */
            /* skip anything but files with G_MODULE_SUFFIX */
            dot = strrchr(name, '.');
            if (dot == NULL || strcmp(dot+1, G_MODULE_SUFFIX) != 0)
                continue;

            g_snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s",
                       dirname, name);
            if ((handle = g_module_open(filename, G_MODULE_BIND_LOCAL)) == NULL)
            {
                /*
                 * Only report load failures if we were asked to.
                 *
                 * XXX - we really should put different types of plugins
                 * (libwiretap, libwireshark) in different subdirectories,
                 * give libwiretap and libwireshark init routines that
                 * load the plugins, and have them scan the appropriate
                 * subdirectories so tha we don't even *try* to, for
                 * example, load libwireshark plugins in programs that
                 * only use libwiretap.
                 */
                if (mode == REPORT_LOAD_FAILURE) {
                    report_failure("Couldn't load module %s: %s", filename,
                                   g_module_error());
                }
                continue;
            }

            if (!g_module_symbol(handle, "version", &gp))
            {
                report_failure("The plugin %s has no version symbol", name);
                g_module_close(handle);
                continue;
            }

            new_plug = (plugin *)g_malloc(sizeof(plugin));
            new_plug->handle = handle;
            new_plug->name = g_strdup(name);
            new_plug->version = (char *)gp;
            new_plug->types = 0;
            new_plug->next = NULL;

            /*
             * Hand the plugin to each of the plugin type callbacks.
             */
            g_slist_foreach(plugin_types, call_plugin_callback, new_plug);

            /*
             * Does this dissector do anything useful?
             */
            if (new_plug->types == 0)
            {
                /*
                 * No.
                 *
                 * Only report this failure if we were asked to; it might
                 * just mean that it's a plugin type that this program
                 * doesn't support, such as a libwireshark plugin in
                 * a program that doesn't use libwireshark.
                 *
                 * XXX - we really should put different types of plugins
                 * (libwiretap, libwireshark) in different subdirectories,
                 * give libwiretap and libwireshark init routines that
                 * load the plugins, and have them scan the appropriate
                 * subdirectories so tha we don't even *try* to, for
                 * example, load libwireshark plugins in programs that
                 * only use libwiretap.
                 */
                if (mode == REPORT_LOAD_FAILURE) {
                    report_failure("The plugin '%s' has no registration routines",
                                   name);
                }
                g_module_close(handle);
                g_free(new_plug->name);
                g_free(new_plug);
                continue;
            }

            /*
             * OK, attempt to add it to the list of plugins.
             */
            cr = add_plugin(new_plug);
            if (cr != 0)
            {
                g_assert(cr == EEXIST);
                fprintf(stderr, "The plugin '%s' version %s "
                        "was found in multiple directories.\n",
                        new_plug->name, new_plug->version);
                g_module_close(handle);
                g_free(new_plug->name);
                g_free(new_plug);
                continue;
            }

        }
        ws_dir_close(dir);
    }
}