Add checks in "rd_add_field_to_tree()" for the length of the field.
[obnox/wireshark/wip.git] / epan / plugins.c
index ffee7452d83b39558408a0f7467eb3be5feb16ee..79a4306fe1b15244b7386be3b0ad5f8806d50858 100644 (file)
@@ -1,23 +1,22 @@
 /* plugins.c
  * plugin routines
  *
- * $Id: plugins.c,v 1.3 2000/10/16 23:17:39 guy Exp $
+ * $Id$
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1999 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.
 # include "config.h"
 #endif
 
-#include <epan.h>
+#ifdef NEED_SNPRINTF_H
+# include "snprintf.h"
+#endif
+
 #include "plugins.h"
 
 #ifdef HAVE_PLUGINS
 
 #include <string.h>
 #include <stdlib.h>
-#include <errno.h> 
+#include <errno.h>
 
 #ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 #include "filesystem.h"
 
 #ifdef PLUGINS_NEED_ADDRESS_TABLE
+#include "conversation.h"
+#include "reassemble.h"
+#include <epan/prefs.h>
+#include <epan/dissectors/packet-giop.h>
+#include <epan/dissectors/packet-tpkt.h>
+#include <epan/dissectors/packet-tcp.h>
+#include <epan/dissectors/packet-rpc.h>
+#include <epan/tap.h>
+#include "asn1.h"
+#include <epan/dissectors/packet-per.h>
+#include <epan/dissectors/packet-ber.h>
+#include <epan/dissectors/packet-rtp.h>
+#include <epan/dissectors/packet-rtcp.h>
+#include <epan/xdlc.h>
+#include <epan/crc16.h>
+#include "report_err.h"
 #include "plugins/plugin_table.h"
-plugin_address_table_t patable;
+static plugin_address_table_t  patable = {
+/* file generated by plugin_gen.py */
+#include "plugins/Xass-list"
+};
 #endif
 
 /* linked list of all plugins */
 plugin *plugin_list;
-guint32 enabled_plugins_number;
-
-#ifdef WIN32
-static gchar std_plug_dir[] = "c:/program files/ethereal/plugins/0.8.12";
-static gchar local_plug_dir[] = "c:/ethereal/plugins/0.8.12";
-#else
-static gchar std_plug_dir[] = "/usr/lib/ethereal/plugins/0.8.12";
-static gchar local_plug_dir[] = "/usr/local/lib/ethereal/plugins/0.8.12";
-#endif
-static gchar *user_plug_dir = NULL;
-static gchar *plugin_status_file = NULL;
 
-#define PLUGINS_STATUS         "plugins.status"
 #define PLUGINS_DIR_NAME       "plugins"
 
 /*
@@ -93,13 +94,9 @@ static gchar *plugin_status_file = NULL;
  * - ENOMEM : memory allocation problem
  * - EEXIST : the same plugin (i.e. name/version) was already registered.
  */
-int
-add_plugin(void *handle, gchar *name, gchar *version, gchar *protocol,
-          gchar *filter_string, dfilter *filter,
-          void (*dissector) (const u_char *,
-                             int,
-                             frame_data *,
-                             proto_tree *))
+static int
+add_plugin(void *handle, gchar *name, gchar *version,
+          void (*reg_handoff)(void))
 {
     plugin *new_plug, *pt_plug;
 
@@ -134,262 +131,67 @@ add_plugin(void *handle, gchar *name, gchar *version, gchar *protocol,
     new_plug->handle = handle;
     new_plug->name = name;
     new_plug->version = version;
-    new_plug->enabled = FALSE;
-    new_plug->protocol = protocol;
-    new_plug->filter_string = g_strdup(filter_string);
-    new_plug->filter = filter;
-    new_plug->dissector = dissector;
+    new_plug->reg_handoff = reg_handoff;
     new_plug->next = NULL;
     return 0;
 }
 
 /*
- * enable a plugin
- * returns a pointer to the enabled plugin, or NULL if the plugin wasn't found
- * in the list
- */
-void *
-enable_plugin(const gchar *name, const gchar *version)
-{
-    plugin *pt_plug;
-
-    pt_plug = plugin_list;
-    while (pt_plug)
-    {
-       if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version))
-       {
-           pt_plug->enabled = TRUE;
-           enabled_plugins_number++;
-           return pt_plug;
-       }
-       pt_plug = pt_plug->next;
-    }
-    return NULL;
-}
-
-/*
- * disable a plugin
- * returns a pointer to the disabled plugin, or NULL if the plugin wasn't found
- * in the list
- */
-void *
-disable_plugin(const gchar *name, const gchar *version)
-{
-    plugin *pt_plug;
-
-    pt_plug = plugin_list;
-    while (pt_plug)
-    {
-       if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version))
-       {
-           pt_plug->enabled = FALSE;
-           enabled_plugins_number--;
-           return pt_plug;
-       }
-       pt_plug = pt_plug->next;
-    }
-    return NULL;
-}
-
-/*
- * find a plugin using its name/version
- */
-void *
-find_plugin(const gchar *name, const gchar *version)
-{
-    plugin *pt_plug;
-
-    pt_plug = plugin_list;
-    while (pt_plug)
-    {
-       if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version))
-       {
-           return pt_plug;
-       }
-       pt_plug = pt_plug->next;
-    }
-    return NULL;
-}
-
-/*
- * check if a plugin is enabled
- */
-gboolean
-is_enabled(const gchar *name, const gchar *version)
-{
-    plugin *pt_plug;
-
-    pt_plug = plugin_list;
-    while (pt_plug)
-    {
-       if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version))
-           return pt_plug->enabled;
-       pt_plug = pt_plug->next;
-    }
-    return FALSE;
-}
-
-/*
- * replace the filter used by a plugin (filter string and dfilter)
- */
-void
-plugin_replace_filter(const gchar *name, const gchar *version,
-       const gchar *filter_string, dfilter *filter)
-{
-    plugin *pt_plug;
-
-    pt_plug = plugin_list;
-    while (pt_plug)
-    {
-       if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version))
-       {
-           g_free(pt_plug->filter_string);
-           pt_plug->filter_string = g_strdup(filter_string);
-           dfilter_destroy(pt_plug->filter);
-           pt_plug->filter = filter;
-           return;
-       }
-       pt_plug = pt_plug->next;
-    }
-}
-
-/*
- * save plugin status, returns 0 on success, -1 on failure:
- * file format :
- * for each plugin, two lines are saved :
- * plugin_name plugin_version [0|1]    (0: disabled, 1: enabled)
- * filter_string
+ * 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.
  *
- * Ex :
- * gryphon.so 0.8.0 1
- * tcp.port == 7000
+ * 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.
  */
-
-int
-save_plugin_status(void)
-{
-    gchar  *pf_path;
-    FILE   *statusfile;
-    plugin *pt_plug;
-
-    if (!plugin_status_file) {
-       plugin_status_file = (gchar *)g_malloc(strlen(get_home_dir()) + 
-                                              strlen(PF_DIR) +
-                                              strlen(PLUGINS_STATUS) + 3);
-       sprintf(plugin_status_file, "%s/%s/%s", 
-               get_home_dir(), PF_DIR, PLUGINS_STATUS);
-    }
-    statusfile=fopen(plugin_status_file, "w");
-    if (!statusfile) {
-       pf_path = g_malloc(strlen(get_home_dir()) + strlen(PF_DIR) + 2);
-       sprintf(pf_path, "%s/%s", get_home_dir(), PF_DIR);
-#ifdef WIN32
-       mkdir(pf_path);
-#else
-       mkdir(pf_path, 0755);
-#endif
-       g_free(pf_path);
-       statusfile=fopen(plugin_status_file, "w");
-       if (!statusfile) return -1;
-    }
-
-    pt_plug = plugin_list;
-    while (pt_plug)
-    {
-       fprintf(statusfile,"%s %s %s\n%s\n", pt_plug->name, pt_plug->version,
-               (pt_plug->enabled ? "1" : "0"), pt_plug->filter_string);
-       pt_plug = pt_plug->next;
-    }
-    fclose(statusfile);
-    return 0;
-}
-
-/*
- * Check if the status of this plugin has been saved.
- * If necessary, enable the plugin, and change the filter.
- */
-static void
-check_plugin_status(gchar *name, gchar *version, GModule *handle,
-                   gchar *filter_string, FILE *statusfile)
-{
-    gchar   *ref_string;
-    guint16  ref_string_len;
-    gchar    line[512];
-    void   (*plugin_init)(void*);
-    dfilter *filter;
-
-    if (!statusfile) return;
-
-    ref_string = (gchar *)g_malloc(strlen(name) + strlen(version) + 2);
-    ref_string_len = sprintf(ref_string, "%s %s", name, version);
-
-    while (!feof(statusfile))
-    {
-       if (fgets(line, 512, statusfile) == NULL) return;
-       if (strncmp(line, ref_string, ref_string_len) != 0) { /* not the right plugin */
-           if (fgets(line, 512, statusfile) == NULL) return;
-       }
-       else { /* found the plugin */
-           if (line[ref_string_len+1] == '1') {
-               enable_plugin(name, version);
-               if (g_module_symbol(handle, "plugin_init", (gpointer*)&plugin_init) == TRUE) {
-#ifdef PLUGINS_NEED_ADDRESS_TABLE
-                   plugin_init(&patable);
-#else
-                   plugin_init(NULL);
-#endif
-               }
-#ifdef PLUGINS_NEED_ADDRESS_TABLE
-               else {
-                       return;
-               }
-#endif
-           }
-
-           if (fgets(line, 512, statusfile) == NULL) return;
-           if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = '\0';
-           /* only compile the new filter if it is different from the default */
-           if (strcmp(line, filter_string) && dfilter_compile(line, &filter) == 0)
-               plugin_replace_filter(name, version, line, filter);
-           return;
-       }
-    }
-    g_free(ref_string);
-}
-
 static void
 plugins_scan_dir(const char *dirname)
 {
 #define FILENAME_LEN   1024
+#if GLIB_MAJOR_VERSION < 2
+    gchar         *hack_path;       /* pathname used to construct lt_lib_ext */
+    gchar         *lt_lib_ext;      /* extension for loadable modules */
     DIR           *dir;             /* scanned directory */
     struct dirent *file;            /* current file */
+    gchar         *name;
+#else /* GLIB 2 */
+    GDir          *dir;             /* scanned directory */
+    GError        **dummy;
+    const gchar   *name;
+#endif
     gchar          filename[FILENAME_LEN];   /* current file name */
     GModule       *handle;          /* handle returned by dlopen */
-    gchar         *name;
     gchar         *version;
-    gchar         *protocol;
-    gchar         *filter_string;
+    void         (*init)(void *);
+    void         (*reg_handoff)(void);
     gchar         *dot;
-    dfilter       *filter = NULL;
-    void         (*dissector) (const u_char *, int, frame_data *, proto_tree *);
     int            cr;
-    FILE          *statusfile;
 
-#ifdef WIN32
-#define LT_LIB_EXT ".dll"
-#else
-#define LT_LIB_EXT ".so"
-#endif
-
-    if (!plugin_status_file)
+#if GLIB_MAJOR_VERSION < 2
+    /*
+     * We find the extension used on this platform for loadable modules
+     * by the sneaky hack of calling "g_module_build_path" to build
+     * the pathname for a module with an empty directory name and
+     * empty module name, and then search for the last "." and use
+     * everything from the last "." on.
+     */
+    hack_path = g_module_build_path("", "");
+    lt_lib_ext = strrchr(hack_path, '.');
+    if (lt_lib_ext == NULL)
     {
-       plugin_status_file = (gchar *)g_malloc(strlen(get_home_dir()) + 
-                                              strlen(PF_DIR) +
-                                              strlen(PLUGINS_STATUS) + 3);
-       sprintf(plugin_status_file, "%s/%s/%s", 
-               get_home_dir(), PF_DIR, PLUGINS_STATUS);
+       /*
+        * Does this mean there *is* no extension?  Assume so.
+        *
+        * XXX - the code below assumes that all loadable modules have
+        * an extension....
+        */
+       lt_lib_ext = "";
     }
-    statusfile = fopen(plugin_status_file, "r");
 
     if ((dir = opendir(dirname)) != NULL)
     {
@@ -399,68 +201,173 @@ plugins_scan_dir(const char *dirname)
            if (!(strcmp(file->d_name, "..") &&
                  strcmp(file->d_name, "."))) continue;
 
-            /* skip anything but files with LT_LIB_EXT */
+            /* skip anything but files with lt_lib_ext */
             dot = strrchr(file->d_name, '.');
-            if (dot == NULL || strcmp(dot, LT_LIB_EXT) != 0) continue;
+            if (dot == NULL || strcmp(dot, lt_lib_ext) != 0) continue;
 
-           snprintf(filename, FILENAME_LEN, "%s/%s", dirname, file->d_name);
-           if ((handle = g_module_open(filename, 0)) == NULL) continue;
+           snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s",
+               dirname, file->d_name);
            name = (gchar *)file->d_name;
-           if (g_module_symbol(handle, "version", (gpointer*)&version) == FALSE)
-           {
-               g_warning("The plugin %s has no version symbol", name);
-               g_module_close(handle);
-               continue;
-           }
-           if (g_module_symbol(handle, "protocol", (gpointer*)&protocol) == FALSE)
+#else /* GLIB 2 */
+    /*
+     * GLib 2.x defines G_MODULE_SUFFIX as the extension used on this
+     * platform for loadable modules.
+     */
+    dummy = g_malloc(sizeof(GError *));
+    *dummy = NULL;
+    if ((dir = g_dir_open(dirname, 0, dummy)) != NULL)
+    {
+       while ((name = g_dir_read_name(dir)) != NULL)
+       {
+           /* skip anything but files with G_MODULE_SUFFIX */
+            dot = strrchr(name, '.');
+            if (dot == NULL || strcmp(dot+1, G_MODULE_SUFFIX) != 0) continue;
+
+           snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s",
+               dirname, name);
+#endif
+           if ((handle = g_module_open(filename, 0)) == NULL)
            {
-               g_warning("The plugin %s has no protocol symbol", name);
-               g_module_close(handle);
+               g_warning("Couldn't load module %s: %s", filename,
+                         g_module_error());
                continue;
            }
-           if (g_module_symbol(handle, "filter_string", (gpointer*)&filter_string) == FALSE)
+           if (g_module_symbol(handle, "version", (gpointer*)&version) == FALSE)
            {
-               g_warning("The plugin %s has no filter_string symbol", name);
-               g_module_close(handle);
-               continue;
-           }
-           if (dfilter_compile(filter_string, &filter) != 0) {
-               g_warning("The plugin %s has a non compilable filter", name);
-               g_module_close(handle);
-               continue;
-           }
-           if (g_module_symbol(handle, "dissector", (gpointer*)&dissector) == FALSE) {
-               if (filter != NULL)
-                   dfilter_destroy(filter);
-               g_warning("The plugin %s has no dissector symbol", name);
+               g_warning("The plugin %s has no version symbol", name);
                g_module_close(handle);
                continue;
            }
 
-           if ((cr = add_plugin(handle, g_strdup(file->d_name), version,
-                                protocol, filter_string, filter, dissector)))
+           /*
+            * Old-style dissectors don't have a "plugin_reg_handoff()"
+            * routine; we no longer support them.
+            *
+            * New-style dissectors have one, because, otherwise, there's
+            * no way for them to arrange that they ever be called.
+            */
+           if (g_module_symbol(handle, "plugin_reg_handoff",
+                                        (gpointer*)&reg_handoff))
            {
-               if (cr == EEXIST)
-                   fprintf(stderr, "The plugin : %s, version %s\n"
+               /*
+                * We require it to have a "plugin_init()" routine.
+                */
+               if (!g_module_symbol(handle, "plugin_init", (gpointer*)&init))
+               {
+                   g_warning("The plugin %s has a plugin_reg_handoff symbol but no plugin_init routine",
+                             name);
+                   g_module_close(handle);
+                   continue;
+               }
+
+               /*
+                * We have a "plugin_reg_handoff()" routine, so we don't
+                * need the protocol, filter string, or dissector pointer.
+                */
+               if ((cr = add_plugin(handle, g_strdup(name), version,
+                                    reg_handoff)))
+               {
+                   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 %sn",
+                   else
+                       fprintf(stderr, "Memory allocation problem\n"
+                           "when processing plugin %s, version %s\n",
                            name, version);
-               if (filter != NULL)
-                   dfilter_destroy(filter);
-               g_module_close(handle);
-               continue;
+                   g_module_close(handle);
+                   continue;
+               }
+
+               /*
+                * Call its init routine.
+                */
+#ifdef PLUGINS_NEED_ADDRESS_TABLE
+               init(&patable);
+#else
+               init(NULL);
+#endif
            }
-           if (statusfile) {
-               check_plugin_status(file->d_name, version, handle,
-                                   filter_string, statusfile);
-               rewind(statusfile);
+           else
+           {
+               /*
+                * This is an old-style dissector; warn that it won't
+                * be used, as those aren't supported.
+                */
+               fprintf(stderr,
+                   "The plugin %s, version %s is an old-style plugin;\n"
+                   "Those are no longer supported.\n", name, version);
            }
        }
+#if GLIB_MAJOR_VERSION < 2
        closedir(dir);
     }
-    if (statusfile) fclose(statusfile);
+    g_free(hack_path);
+#else /* GLIB 2 */
+       g_dir_close(dir);
+    }
+    g_clear_error(dummy);
+    g_free(dummy);
+#endif
+}
+
+
+/* get the global plugin dir */
+/* Return value is malloced so the caller should g_free() it. */
+const char *get_plugins_global_dir(const char *plugin_dir)
+{
+#ifdef _WIN32
+       char *install_plugin_dir;
+
+       /*
+        * On Windows, the data file directory is the installation
+        * directory; the plugins are stored under it.
+        *
+        * Assume we're running the installed version of Ethereal;
+        * on Windows, the data file directory is the directory
+        * in which the Ethereal binary resides.
+        */
+       install_plugin_dir = g_strdup_printf("%s\\plugins\\%s", get_datafile_dir(), VERSION);
+
+       /*
+        * Make sure that pathname refers to a directory.
+        */
+       if (test_for_directory(install_plugin_dir) != EISDIR) {
+               /*
+                * Either it doesn't refer to a directory or it
+                * refers to something that doesn't exist.
+                *
+                * Assume that means we're running, for example,
+                * a version of Ethereal we've built in a source
+                * directory, and fall back on the default
+                * installation directory, so you can put the plugins
+                * somewhere so they can be used with this version
+                * of Ethereal.
+                *
+                * XXX - should we, instead, have the Windows build
+                * procedure create a subdirectory of the "plugins"
+                * source directory, and copy the plugin DLLs there,
+                * so that you use the plugins from the build tree?
+                */
+               g_free(install_plugin_dir);
+               install_plugin_dir =
+                   g_strdup("C:\\Program Files\\Ethereal\\plugins\\" VERSION);
+       }
+
+       return install_plugin_dir;
+#else
+       /*
+        * Scan the plugin directory.
+        */
+       return strdup(plugin_dir);
+#endif
+}
+
+
+/* get the personal plugin dir */
+/* Return value is malloced so the caller should g_free() it. */
+const char *get_plugins_pers_dir(void)
+{
+    return get_persconffile_path(PLUGINS_DIR_NAME, FALSE);
 }
 
 /*
@@ -469,119 +376,45 @@ plugins_scan_dir(const char *dirname)
 void
 init_plugins(const char *plugin_dir)
 {
-    struct stat std_dir_stat, local_dir_stat, plugin_dir_stat;
+    const char *datafile_dir;
 
     if (plugin_list == NULL)      /* ensure init_plugins is only run once */
     {
-       enabled_plugins_number = 0;
-
-#ifdef PLUGINS_NEED_ADDRESS_TABLE
-       /* Intialize address table */
-       patable.p_check_col                     = check_col;
-       patable.p_col_add_fstr                  = col_add_fstr;
-       patable.p_col_append_fstr               = col_append_str;
-       patable.p_col_add_str                   = col_add_str;
-       patable.p_col_append_str                = col_append_str;
-
-       patable.p_dfilter_init                  = dfilter_init;
-       patable.p_dfilter_cleanup               = dfilter_cleanup;
-
-       patable.p_pi                            = &pi;
-
-       patable.p_proto_register_protocol       = proto_register_protocol;
-       patable.p_proto_register_field_array    = proto_register_field_array;
-       patable.p_proto_register_subtree_array  = proto_register_subtree_array;
-
-       patable.p_dissector_add                 = dissector_add;
-
-       patable.p_heur_dissector_add            = heur_dissector_add;
-
-       patable.p_proto_item_add_subtree        = proto_item_add_subtree;
-       patable.p_proto_tree_add_item           = proto_tree_add_item;
-       patable.p_proto_tree_add_item_hidden    = proto_tree_add_item_hidden;
-       patable.p_proto_tree_add_protocol_format = proto_tree_add_protocol_format;
-       patable.p_proto_tree_add_bytes          = proto_tree_add_bytes;
-       patable.p_proto_tree_add_bytes_hidden   = proto_tree_add_bytes_hidden;
-       patable.p_proto_tree_add_bytes_format   = proto_tree_add_bytes_format;
-       patable.p_proto_tree_add_time           = proto_tree_add_time;
-       patable.p_proto_tree_add_time_hidden    = proto_tree_add_time_hidden;
-       patable.p_proto_tree_add_time_format    = proto_tree_add_time_format;
-       patable.p_proto_tree_add_ipxnet         = proto_tree_add_ipxnet;
-       patable.p_proto_tree_add_ipxnet_hidden  = proto_tree_add_ipxnet_hidden;
-       patable.p_proto_tree_add_ipxnet_format  = proto_tree_add_ipxnet_format;
-       patable.p_proto_tree_add_ipv4           = proto_tree_add_ipv4;
-       patable.p_proto_tree_add_ipv4_hidden    = proto_tree_add_ipv4_hidden;
-       patable.p_proto_tree_add_ipv4_format    = proto_tree_add_ipv4_format;
-       patable.p_proto_tree_add_ipv6           = proto_tree_add_ipv6;
-       patable.p_proto_tree_add_ipv6_hidden    = proto_tree_add_ipv6_hidden;
-       patable.p_proto_tree_add_ipv6_format    = proto_tree_add_ipv6_format;
-       patable.p_proto_tree_add_ether          = proto_tree_add_ether;
-       patable.p_proto_tree_add_ether_hidden   = proto_tree_add_ether_hidden;
-       patable.p_proto_tree_add_ether_format   = proto_tree_add_ether_format;
-       patable.p_proto_tree_add_string         = proto_tree_add_string;
-       patable.p_proto_tree_add_string_hidden  = proto_tree_add_string_hidden;
-       patable.p_proto_tree_add_string_format  = proto_tree_add_string_format;
-       patable.p_proto_tree_add_boolean        = proto_tree_add_boolean;
-       patable.p_proto_tree_add_boolean_hidden = proto_tree_add_boolean_hidden;
-       patable.p_proto_tree_add_boolean_format = proto_tree_add_boolean_format;
-       patable.p_proto_tree_add_double         = proto_tree_add_double;
-       patable.p_proto_tree_add_double_hidden  = proto_tree_add_double_hidden;
-       patable.p_proto_tree_add_double_format  = proto_tree_add_double_format;
-       patable.p_proto_tree_add_uint           = proto_tree_add_uint;
-       patable.p_proto_tree_add_uint_hidden    = proto_tree_add_uint_hidden;
-       patable.p_proto_tree_add_uint_format    = proto_tree_add_uint_format;
-       patable.p_proto_tree_add_int            = proto_tree_add_int;
-       patable.p_proto_tree_add_int_hidden     = proto_tree_add_int_hidden;
-       patable.p_proto_tree_add_int_format     = proto_tree_add_int_format;
-       patable.p_proto_tree_add_text           = proto_tree_add_text;
-       patable.p_proto_tree_add_notext         = proto_tree_add_notext;
-#endif
-
-       plugins_scan_dir(std_plug_dir);
-       plugins_scan_dir(local_plug_dir);
-       if ((strcmp(std_plug_dir, plugin_dir) != 0) &&
-               (strcmp(local_plug_dir, plugin_dir) != 0))
-       {
-           if (stat(plugin_dir, &plugin_dir_stat) == 0)
-           {
-               /* check if plugin_dir is really different from std_dir and
-                * local_dir if they exist ! */
-               if (stat(std_plug_dir, &std_dir_stat) == 0)
-               {
-                   if (stat(local_plug_dir, &local_dir_stat) == 0)
-                   {
-                       if ((plugin_dir_stat.st_dev != std_dir_stat.st_dev ||
-                                   plugin_dir_stat.st_ino != std_dir_stat.st_ino) &&
-                               (plugin_dir_stat.st_dev != local_dir_stat.st_dev ||
-                                plugin_dir_stat.st_ino != local_dir_stat.st_ino))
-                           plugins_scan_dir(plugin_dir);
-                   }
-                   else
-                   {
-                       if ((plugin_dir_stat.st_dev != std_dir_stat.st_dev ||
-                                   plugin_dir_stat.st_ino != std_dir_stat.st_ino))
-                           plugins_scan_dir(plugin_dir);
-                   }
-               }
-               else if (stat(local_plug_dir, &local_dir_stat) == 0)
-               {
-                   if ((plugin_dir_stat.st_dev != local_dir_stat.st_dev ||
-                               plugin_dir_stat.st_ino != local_dir_stat.st_ino))
-                       plugins_scan_dir(plugin_dir);
-               }
-               else plugins_scan_dir(plugin_dir);
-           }
-       }
-       if (!user_plug_dir)
-       {
-           user_plug_dir = (gchar *)g_malloc(strlen(get_home_dir()) +
-                                             strlen(PF_DIR) +
-                                             strlen(PLUGINS_DIR_NAME) + 3);
-           sprintf(user_plug_dir, "%s/%s/%s", get_home_dir(), 
-                   PF_DIR, PLUGINS_DIR_NAME);
-       }
-       plugins_scan_dir(user_plug_dir);
+       /*
+        * Scan the global plugin directory.
+        */
+       datafile_dir = get_plugins_global_dir(plugin_dir);
+       plugins_scan_dir(datafile_dir);
+       g_free((char *) datafile_dir);
+
+       /*
+        * Scan the users plugin directory.
+        */
+       datafile_dir = get_plugins_pers_dir();
+       plugins_scan_dir(datafile_dir);
+       g_free((char *) datafile_dir);
     }
 }
 
+void
+register_all_plugin_handoffs(void)
+{
+  plugin *pt_plug;
+
+  /*
+   * For all new-style plugins, call the register-handoff routine.
+   * This is called from "proto_init()"; it must be called after
+   * "register_all_protocols()" and "init_plugins()" are called,
+   * in case one plugin registers itself either with a built-in
+   * dissector or with another plugin; we must first register all
+   * dissectors, whether built-in or plugin, so their dissector tables
+   * are initialized, and only then register all handoffs.
+   *
+   * We treat those protocols as always being enabled; they should
+   * use the standard mechanism for enabling/disabling protocols, not
+   * the plugin-specific mechanism.
+   */
+  for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
+    (pt_plug->reg_handoff)();
+}
 #endif