]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/fd_plugins.c
Fix bug #1246 Sometimes access denied with VSS enabled. UCS
[bacula/bacula] / bacula / src / filed / fd_plugins.c
index 27c4c2038aac32497815698bfe3be7a341428320..ec6ce7449a669142b8c8da8147fd28c5b4522088 100644 (file)
@@ -62,6 +62,7 @@ static bRC baculaDebugMsg(bpContext *ctx, const char *file, int line,
 static void *baculaMalloc(bpContext *ctx, const char *file, int line,
               size_t size);
 static void baculaFree(bpContext *ctx, const char *file, int line, void *mem);
+static bool is_plugin_compatible(Plugin *plugin);
 
 /*
  * These will be plugged into the global pointer structure for
@@ -213,6 +214,8 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
    char *cmd = ff_pkt->top_fname;
    struct save_pkt sp;
    bEvent event;
+   POOL_MEM fname(PM_FNAME);
+   POOL_MEM link(PM_FNAME);
 
    if (!plugin_list || !jcr->plugin_ctx_list) {
       return 1;                            /* Return if no plugins loaded */
@@ -276,13 +279,22 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
          }
          jcr->plugin_sp = &sp;
          ff_pkt = jcr->ff;
-         ff_pkt->fname = sp.fname;
-         ff_pkt->link = sp.link;
+         /*
+          * Copy fname and link because save_file() zaps them.  This 
+          *  avoids zaping the plugin's strings.
+          */
+         pm_strcpy(fname, sp.fname);
+         pm_strcpy(link, sp.link);
+         ff_pkt->fname = fname.c_str();
+         ff_pkt->link = link.c_str();
          ff_pkt->type = sp.type;
          memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp));
-         Dmsg1(dbglvl, "Save_file: file=%s\n", ff_pkt->fname);
+         Dmsg1(dbglvl, "Save_file: file=%s\n", fname.c_str());
          save_file(jcr, ff_pkt, true);
          bRC rc = plug_func(plugin)->endBackupFile(jcr->plugin_ctx);
+         if (rc == bRC_More || rc == bRC_OK) {
+            accurate_mark_file_as_seen(jcr, fname.c_str());
+         }
          if (rc == bRC_More) {
             continue;
          }
@@ -435,6 +447,7 @@ bail_out:
 
 /*
  * Tell the plugin to create the file.  Return values are
+ *   This is called only during Restore
  *
  *  CF_ERROR    -- error
  *  CF_SKIP     -- skip processing this file
@@ -509,6 +522,7 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
  * Reset the file attributes after all file I/O is done -- this allows
  *  the previous access time/dates to be set properly, and it also allows
  *  us to properly set directory permissions.
+ *  Not currently Implemented.
  */
 bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
 {
@@ -520,12 +534,15 @@ bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
    return true;
 }
 
+/*
+ * Print to file the plugin info.
+ */
 void dump_fd_plugin(Plugin *plugin, FILE *fp)
 {
    if (!plugin) {
       return ;
    }
-   pInfo *info = (pInfo *) plugin->pinfo;
+   pInfo *info = (pInfo *)plugin->pinfo;
    fprintf(fp, "\tversion=%d\n", info->version);
    fprintf(fp, "\tdate=%s\n", NPRTB(info->plugin_date));
    fprintf(fp, "\tmagic=%s\n", NPRTB(info->plugin_magic));
@@ -549,7 +566,8 @@ void load_fd_plugins(const char *plugin_dir)
    }
 
    plugin_list = New(alist(10, not_owned_by_alist));
-   if (!load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type)) {
+   if (!load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type,
+                     is_plugin_compatible)) {
       /* Either none found, or some error */
       if (plugin_list->size() == 0) {
          delete plugin_list;
@@ -565,15 +583,58 @@ void load_fd_plugins(const char *plugin_dir)
    plugin_bread  = my_plugin_bread;
    plugin_bwrite = my_plugin_bwrite;
    plugin_blseek = my_plugin_blseek;
+
+   /* 
+    * Verify that the plugin is acceptable, and print information
+    *  about it.
+    */
    foreach_alist(plugin, plugin_list) {
       Jmsg(NULL, M_INFO, 0, _("Loaded plugin: %s\n"), plugin->file);
       Dmsg1(dbglvl, "Loaded plugin: %s\n", plugin->file);
-
    }
 
    dbg_plugin_add_hook(dump_fd_plugin);
 }
 
+/*
+ * Check if a plugin is compatible.  Called by the load_plugin function
+ *  to allow us to verify the plugin.
+ */
+static bool is_plugin_compatible(Plugin *plugin)
+{
+   pInfo *info = (pInfo *)plugin->pinfo;
+   Dmsg0(50, "is_plugin_compatible called\n");
+   if (debug_level >= 50) {
+      dump_fd_plugin(plugin, stdin);
+   }
+   if (strcmp(info->plugin_magic, FD_PLUGIN_MAGIC) != 0) {
+      Jmsg(NULL, M_ERROR, 0, _("Plugin magic wrong. Plugin=%s wanted=%s got=%s\n"),
+           plugin->file, FD_PLUGIN_MAGIC, info->plugin_magic);
+      Dmsg3(50, "Plugin magic wrong. Plugin=%s wanted=%s got=%s\n",
+           plugin->file, FD_PLUGIN_MAGIC, info->plugin_magic);
+
+      return false;
+   }
+   if (info->version != FD_PLUGIN_INTERFACE_VERSION) {
+      Jmsg(NULL, M_ERROR, 0, _("Plugin version incorrect. Plugin=%s wanted=%d got=%d\n"),
+           plugin->file, FD_PLUGIN_INTERFACE_VERSION, info->version);
+      Dmsg3(50, "Plugin version incorrect. Plugin=%s wanted=%d got=%d\n",
+           plugin->file, FD_PLUGIN_INTERFACE_VERSION, info->version);
+      return false;
+   }
+   if (strcmp(info->plugin_license, "Bacula GPLv2") != 0 &&
+       strcmp(info->plugin_license, "GPLv2") != 0) {
+      Jmsg(NULL, M_ERROR, 0, _("Plugin license incompatible. Plugin=%s license=%s\n"),
+           plugin->file, info->plugin_license);
+      Dmsg2(50, "Plugin license incompatible. Plugin=%s license=%s\n",
+           plugin->file, info->plugin_license);
+      return false;
+   }
+      
+   return true;
+}
+
+
 /*
  * Create a new instance of each plugin for this Job
  *   Note, plugin_list can exist but jcr->plugin_ctx_list can