Unified plugin handling
This commit is contained in:
78
src/main.cpp
78
src/main.cpp
@@ -20,7 +20,6 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "auth_manager.cpp"
|
||||
#include "client.cpp"
|
||||
#include "util.h"
|
||||
|
||||
@@ -181,70 +180,46 @@ void runClient(struct ftpconn* cfd) {
|
||||
cfd->close = true;
|
||||
}
|
||||
|
||||
void initializeAuth() {
|
||||
AuthManager& auth_manager = AuthManager::getInstance();
|
||||
auth_manager.setLogger(logger);
|
||||
|
||||
// Load auth plugins from plugin directory
|
||||
void initializePlugins() {
|
||||
std::string plugin_dir = config->getValue("core", "plugin_path", PLUGIN_DIR);
|
||||
|
||||
// Load any additional plugins from plugin directory
|
||||
// Load auth plugins
|
||||
auto& auth_manager = PluginManager<Auth>::getInstance();
|
||||
auth_manager.setLogger(logger);
|
||||
|
||||
// Load filer plugins
|
||||
auto& filer_manager = PluginManager<Filer>::getInstance();
|
||||
filer_manager.setLogger(logger);
|
||||
|
||||
for (const auto& entry : std::filesystem::directory_iterator(plugin_dir)) {
|
||||
if (entry.path().extension() == ".so" &&
|
||||
entry.path().filename().string().find("libauth_") == 0) {
|
||||
auth_manager.loadPlugin(entry.path().string());
|
||||
if (entry.path().extension() == ".so") {
|
||||
const std::string& filename = entry.path().filename().string();
|
||||
if (filename.find(PluginTraits<Auth>::pluginPrefix()) == 0) {
|
||||
auth_manager.loadPlugin(entry.path().string());
|
||||
}
|
||||
else if (filename.find(PluginTraits<Filer>::pluginPrefix()) == 0) {
|
||||
filer_manager.loadPlugin(entry.path().string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create auth instance based on config
|
||||
// Initialize auth
|
||||
std::string auth_type = config->getValue("core", "auth_engine", "pam");
|
||||
auth = auth_manager.createAuth(auth_type);
|
||||
auth = auth_manager.createPlugin(auth_type);
|
||||
|
||||
if (!auth) {
|
||||
logger->print(LOGLEVEL_CRITICAL, "Failed to create auth engine: %s", auth_type.c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Initialize auth plugin with config
|
||||
std::map<std::string, std::string> auth_config = config->get("auth_"+auth_type)->get();
|
||||
|
||||
if (!auth->initialize(auth_config)) {
|
||||
logger->print(LOGLEVEL_CRITICAL, "Failed to initialize auth engine: %s", auth_type.c_str());
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void initializeFiler() {
|
||||
FilerManager& filer_manager = FilerManager::getInstance();
|
||||
filer_manager.setLogger(logger);
|
||||
|
||||
std::string plugin_dir = config->getValue("core", "plugin_path", PLUGIN_DIR);
|
||||
|
||||
for (const auto& entry : std::filesystem::directory_iterator(plugin_dir)) {
|
||||
if (entry.path().extension() == ".so" &&
|
||||
entry.path().filename().string().find("libfiler_") == 0) {
|
||||
filer_manager.loadPlugin(entry.path().string());
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize filer
|
||||
std::string filer_type = config->getValue("core", "filer_engine", "local");
|
||||
|
||||
default_filer_factory = filer_manager.getFactory(filer_type);
|
||||
|
||||
if (!default_filer_factory) {
|
||||
logger->print(LOGLEVEL_CRITICAL, "Failed to get filer factory for type: %s", filer_type.c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> filer_config = config->get("filer_"+filer_type)->get();
|
||||
|
||||
// Test create using the factory
|
||||
Filer* test_filer = default_filer_factory();
|
||||
if (!test_filer) {
|
||||
logger->print(LOGLEVEL_CRITICAL, "Failed to create filer instance");
|
||||
exit(1);
|
||||
}
|
||||
delete test_filer;
|
||||
}
|
||||
|
||||
int main(int argc , char *argv[]) {
|
||||
@@ -307,14 +282,10 @@ int main(int argc , char *argv[]) {
|
||||
if (!config->getBool("ssl", "tls_v1_3", true))
|
||||
ssl_flags+=SSL_OP_NO_TLSv1_3;
|
||||
|
||||
if ((ssl_flags & SSL_OP_NO_SSLv2) &&
|
||||
(ssl_flags & SSL_OP_NO_SSLv3) &&
|
||||
(ssl_flags & SSL_OP_NO_TLSv1) &&
|
||||
(ssl_flags & SSL_OP_NO_TLSv1_1) &&
|
||||
(ssl_flags & SSL_OP_NO_TLSv1_2) &&
|
||||
(ssl_flags & SSL_OP_NO_TLSv1_3)) {
|
||||
if ((ssl_flags & SSL_OP_NO_SSLv2) && (ssl_flags & SSL_OP_NO_SSLv3) &&
|
||||
(ssl_flags & SSL_OP_NO_TLSv1) && (ssl_flags & SSL_OP_NO_TLSv1_1) &&
|
||||
(ssl_flags & SSL_OP_NO_TLSv1_2) && (ssl_flags & SSL_OP_NO_TLSv1_3))
|
||||
logger->print(LOGLEVEL_WARNING, "All SSL/TLS protocols disabled. You're a mad man!");
|
||||
}
|
||||
|
||||
if (!config->getBool("ssl", "compression", true))
|
||||
ssl_flags+=SSL_OP_NO_COMPRESSION;
|
||||
@@ -323,8 +294,7 @@ int main(int argc , char *argv[]) {
|
||||
SSLManager::getInstance().setFlags(ssl_flags);
|
||||
}
|
||||
|
||||
initializeAuth();
|
||||
initializeFiler();
|
||||
initializePlugins();
|
||||
|
||||
int opt = 1,
|
||||
master_socket = -1,
|
||||
|
||||
Reference in New Issue
Block a user