From e6e92705e4ad57755e67950af612b9d55a83e340 Mon Sep 17 00:00:00 2001 From: Matthew McGill <mhollismcgill@gmail.com> Date: Tue, 16 Oct 2018 17:18:58 +0000 Subject: [PATCH] thanos integration Former-commit-id: 12a9f89e9dfb99d4551d436989be6206aac5c2f2 --- libIRDB/test/fill_in_cfg.cpp | 2 +- libIRDB/test/fill_in_cfg.hpp | 12 ++++++-- libtransform/include/transform_step.h | 7 ++++- tools/thanos/thanos.cpp | 42 ++++++++++++++++++--------- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/libIRDB/test/fill_in_cfg.cpp b/libIRDB/test/fill_in_cfg.cpp index 43352e4c0..5902eb56f 100644 --- a/libIRDB/test/fill_in_cfg.cpp +++ b/libIRDB/test/fill_in_cfg.cpp @@ -659,7 +659,7 @@ int PopulateCFG::ExecuteStep(IRDBObjects_t *irdb_objects) extern "C" -Transform_SDK::TransformStep_t* TransformStepFactory(void) +Transform_SDK::TransformStep_t* GetTransformStep(void) { return new PopulateCFG(); } diff --git a/libIRDB/test/fill_in_cfg.hpp b/libIRDB/test/fill_in_cfg.hpp index ac75298bd..e4e3fa558 100644 --- a/libIRDB/test/fill_in_cfg.hpp +++ b/libIRDB/test/fill_in_cfg.hpp @@ -27,13 +27,19 @@ class PopulateCFG : public Transform_SDK::TransformStep_t elfiop = NULL; } + + ~PopulateCFG(void) override + { + // do nothing (this class uses shared IRDB objects that + // are not managed by this class). + } - std::string GetStepName(void) + std::string GetStepName(void) override { return std::string("fill_in_cfg"); } - int ParseArgs(int argc, char* argv[]); - int ExecuteStep(libIRDB::IRDBObjects_t*); + int ParseArgs(int argc, char* argv[]) override; + int ExecuteStep(libIRDB::IRDBObjects_t*) override; private: // methods diff --git a/libtransform/include/transform_step.h b/libtransform/include/transform_step.h index 0b64a4b22..445a4d1f6 100644 --- a/libtransform/include/transform_step.h +++ b/libtransform/include/transform_step.h @@ -22,11 +22,16 @@ namespace Transform_SDK virtual int ExecuteStep(libIRDB::IRDBObjects_t *irdb_objects) { return 0; // success + } + + virtual ~TransformStep_t(void) + { + // do nothing } }; } extern "C" -Transform_SDK::TransformStep_t* TransformStepFactory(void); +Transform_SDK::TransformStep_t* GetTransformStep(void); #endif diff --git a/tools/thanos/thanos.cpp b/tools/thanos/thanos.cpp index 9427d3e01..ed9b8fbfb 100644 --- a/tools/thanos/thanos.cpp +++ b/tools/thanos/thanos.cpp @@ -38,6 +38,14 @@ int main(int argc, char *argv[]) char buf[MAX_BUF]; buf[0] = '\0'; + const char* base_path = getenv("SECURITY_TRANSFORMS_HOME"); + if(base_path == NULL) + { + cerr << "Environment variables not set." << endl; + return -1; + } + string plugin_path (string(base_path).append("/plugins_install/")); + fd = open(input_pipe, O_RDONLY); if (fd == -1) { cerr << "Not a valid pipe name." << endl; @@ -96,31 +104,36 @@ int main(int argc, char *argv[]) *end = '\0'; string command (buf+22); - size_t step_path_end = command.find_first_of(" "); - char* step_path; - if(step_path_end == string::npos) + size_t step_name_end = command.find_first_of(" "); + char* step_name; + if(step_name_end == string::npos) { - step_path = (buf+22); + step_name = (buf+22); } else { - step_path = (char*) (command.substr(0, step_path_end)).c_str(); + step_name = (char*) (command.substr(0, step_name_end)).c_str(); } - void* dlhdl = dlopen(step_path, RTLD_LAZY); + + void* dlhdl = dlopen((plugin_path.append(step_name)).c_str(), RTLD_NOW); if(dlhdl == NULL) { res = write(outfd, (void*) "STEP_UNSUPPORTED\n", 17); } else - { - TransformStep_t* (*func)(void); - func = (TransformStep_t* (*)(void)) dlsym(dlhdl, "TransformStepFactory"); - if(func == NULL) + { + void* sym = dlsym(dlhdl, "GetTransformStep"); + if(sym == NULL) { res = write(outfd, (void*) "STEP_UNSUPPORTED\n", 17); } else { + TransformStep_t* (*func)(void); + func = (TransformStep_t* (*)(void)) sym; + TransformStep_t* the_step = (*func)(); + assert(the_step != NULL); + int argc = (int) count(command.begin(), command.end(), ' ')+1; char** argv = (char**) malloc(argc); argv[0] = buf+22; @@ -139,13 +152,14 @@ int main(int argc, char *argv[]) { step_optional = false; } - cout << "GOT HERE 3" << endl; int step_retval = 0; + if(exec_mode == Mode::DEFAULT) - step_retval = execute_step(argc, argv, step_optional, shared_objects, (*func)()); - free(argv); + step_retval = execute_step(argc, argv, step_optional, shared_objects, the_step); + delete the_step; + free(argv); dlclose(dlhdl); - res = write(outfd, (void*) "STEP_RETVAL\n", 14); + res = write(outfd, (void*) "STEP_RETVAL\n", 12); assert(sizeof(step_retval) == 4); } } -- GitLab