diff --git a/libIRDB/test/fill_in_cfg.cpp b/libIRDB/test/fill_in_cfg.cpp index 43352e4c093ce58a4fab0b8c125a994c6a028b10..5902eb56f1b4d2a051e48c84a13616d77e007ddf 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 ac75298bd8640cc60bcb1d7e3479d4712fc9fcc8..e4e3fa5587838ccbeeb515fe21740b4089afaf0b 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 0b64a4b22b1487d8ad21caaa4fbbce1622833978..445a4d1f64782c4777abc4008d3fa432705b9811 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 9427d3e0133d5b8fb734cec0e7c221f2f84d4257..ed9b8fbfb0ddae0bc2908deb8d1cd0e20edec5fd 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); } }