]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
metaplugin: Add plugin command duplication check.
authorRadosław Korzeniewski <radekk@inteos.pl>
Fri, 8 Jan 2021 16:06:21 +0000 (17:06 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:00 +0000 (09:03 +0100)
The duplicate plugin command prohibits a proper backend switching
and leads to backup errors. This is a configuration issue and Bacula
plugin API limitation. Now we will detect it and properly handle.

bacula/src/plugins/fd/pluginlib/metaplugin.cpp
bacula/src/plugins/fd/pluginlib/pluginlib.h

index 18d9d566705afdddd8f09eb076a5b89d31f57911..de2870621b7c2127ca73a5c7cabe5a501f9e890b 100644 (file)
@@ -787,7 +787,7 @@ bRC METAPLUGIN::send_parameters(bpContext *ctx, char *command)
    }
 
    /* send backend info that parameters are coming */
-   bsnprintf(cmd.c_str(), cmd.size(), "Params\n");
+   pm_strcpy(cmd, "Params\n");
    rc = backend.ctx->write_command(ctx, cmd.c_str());
    if (rc < 0){
       /* error */
@@ -1037,16 +1037,24 @@ bRC METAPLUGIN::switch_or_run_backend(bpContext *ctx, char *command)
  */
 bRC METAPLUGIN::prepare_backend(bpContext *ctx, char type, char *command)
 {
-   bRC status;
-
-   /* check if it is our Plugin command */
-   if (strncmp(PLUGINPREFIX, command, strlen(PLUGINPREFIX)) != 0){
-      /* it is not our plugin prefix */
+   // check if it is our Plugin command
+   if (!isourplugincommand(PLUGINPREFIX, command) != 0){
+      // it is not our plugin prefix
       return bRC_OK;
    }
 
+   // check for prohibitted command duplication
+   if (backend.check_command(command))
+   {
+      // already exist, report
+      DMSG1(ctx, DERROR, "Plugin command=%s already defined, cannot proceed.\n", command);
+      JMSG1(ctx, M_FATAL, "Plugin command already defined: \"%s\" Cannot proceed. You should correct FileSet configuration.\n", command);
+      terminate_all_backends(ctx);
+      return bRC_Error;
+   }
+
    /* switch backend context, so backendctx has all required variables available */
-   status = switch_or_run_backend(ctx, command);
+   bRC status = switch_or_run_backend(ctx, command);
    if (status == bRC_Max){
       /* already prepared, skip rest of preparation */
       return bRC_OK;
index 06a5650537c4a0488c2990c778bbdd7211432f0d..4f8f4d1b1396c17470c54d4f977d039f44bf6ae1 100644 (file)
@@ -147,7 +147,7 @@ inline bool isourplugincommand(const char *pluginprefix, const char *command)
 {
    /* check if it is our Plugin command */
    if (strncmp(pluginprefix, command, strlen(pluginprefix)) == 0){
-      /* it is not our plugin prefix */
+      /* it is our plugin prefix */
       return true;
    }
    return false;