From 5b31e3a3d4a39a2fd89cd3fef4cda4d349cbe0ee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rados=C5=82aw=20Korzeniewski?= Date: Fri, 8 Jan 2021 17:06:21 +0100 Subject: [PATCH] metaplugin: Add plugin command duplication check. 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. --- .../src/plugins/fd/pluginlib/metaplugin.cpp | 22 +++++++++++++------ bacula/src/plugins/fd/pluginlib/pluginlib.h | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp index 18d9d5667..de2870621 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp +++ b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp @@ -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; diff --git a/bacula/src/plugins/fd/pluginlib/pluginlib.h b/bacula/src/plugins/fd/pluginlib/pluginlib.h index 06a565053..4f8f4d1b1 100644 --- a/bacula/src/plugins/fd/pluginlib/pluginlib.h +++ b/bacula/src/plugins/fd/pluginlib/pluginlib.h @@ -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; -- 2.47.3