X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=sidebyside;f=src%2Fconfig.cpp;h=164e0bbadef6e43eb989ddfad665833bfc4594a9;hb=2554cc985f2715ac9458c22e5f2970f38f8fa034;hp=ce78f417582a8a8049389f18435279cde60b7fa8;hpb=f69f31caeda734d6d9c8ab00e693671ac7512bea;p=cassiopeia.git diff --git a/src/config.cpp b/src/config.cpp index ce78f41..164e0bb 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -6,20 +6,24 @@ #include "crypto/sslUtil.h" +#include "log/logger.hpp" + std::string keyDir; std::unordered_map profiles; std::unordered_map> CAs; std::string sqlHost, sqlUser, sqlPass, sqlDB; std::string serialPath; +std::string crlPrefix; +std::string crtPrefix; std::shared_ptr> parseConf( std::string path ) { - std::shared_ptr> map( new std::unordered_map() ); + auto map = std::make_shared>(); std::ifstream config; config.open( path ); if( !config.is_open() ) { - std::cout << "Where is " << path << "?" << std::endl; - throw "Config missing"; + logger::notef( "Where is \"%s\"?", path ); + throw std::runtime_error("Config missing"); } std::string line1; @@ -32,7 +36,7 @@ std::shared_ptr> parseConf( std::st int splitter = line1.find( "=" ); if( splitter == -1 ) { - std::cerr << "Ignoring malformed config line: " << line1 << std::endl; + logger::warn( "Ignoring malformed config line: ", line1 ); continue; } @@ -54,7 +58,7 @@ int parseProfiles() { dp = opendir( "profiles" ); if( dp == NULL ) { - std::cerr << "Profiles not found " << std::endl; + logger::error( "Profiles directory not found" ); return -1; } @@ -68,14 +72,14 @@ int parseProfiles() { int splitter = profileName.find( "-" ); if( splitter == -1 ) { - std::cerr << "Ignoring malformed profile: " << profileName << std::endl; + logger::warn( "Ignoring malformed profile: ", profileName ); continue; } std::string id = profileName.substr( 0, splitter ); if( profileName.substr( profileName.size() - 4 ) != ".cfg" ) { - std::cerr << "Ignoring malformed profile: " << profileName << std::endl; + logger::warn( "Ignoring malformed profile: ", profileName ); continue; } @@ -91,42 +95,43 @@ int parseProfiles() { std::string cas = map->at( "ca" ); - for( size_t pos = 0; pos != std::string::npos; ) { - size_t end = cas.find( ",", pos ); - std::string sub; + DIR* dir; + struct dirent* ent; - if( end == std::string::npos ) { - sub = cas.substr( pos ); - } else { - sub = cas.substr( pos, end - pos ); - end++; - } + if( ( dir = opendir( "ca" ) ) != NULL ) { + while( ( ent = readdir( dir ) ) != NULL ) { + std::string caName = std::string( ent->d_name ); - pos = end; + if( caName.find( cas ) != 0 ) { + continue; + } - if( CAs.find( sub ) == CAs.end() ) { - std::shared_ptr ca( new CAConfig( sub ) ); - CAs.emplace( sub, ca ); - } + if( CAs.find( caName ) == CAs.end() ) { + auto ca = std::make_shared( caName ); + CAs.emplace( caName, ca ); + } - prof.ca.push_back( CAs.at( sub ) ); + prof.ca.push_back( CAs.at( caName ) ); + logger::note( "Adding CA: ", caName ); + } + closedir( dir ); + } else { + throw std::runtime_error("Directory with CAConfigs not found"); } profiles.emplace( profileName, prof ); - std::cout << "Profile: " << profileName << " up and running." << std::endl; + logger::notef( "Profile: \"%s\" up and running.", profileName ); } ( void ) closedir( dp ); - - std::cout << profiles.size() << " profiles loaded." << std::endl; + logger::notef( "%s profiles loaded.", profiles.size() ); return 0; } int parseConfig( std::string path ) { - auto masterConf = parseConf( path ); keyDir = masterConf->at( "key.directory" ); @@ -135,9 +140,11 @@ int parseConfig( std::string path ) { sqlPass = masterConf->at( "sql.password" ); sqlDB = masterConf->at( "sql.database" ); serialPath = masterConf->at( "serialPath" ); + crlPrefix = masterConf->at( "crlPrefix" ); + crtPrefix = masterConf->at( "crtPrefix" ); if( keyDir == "" ) { - std::cerr << "Missing config property key.directory" << std::endl; + logger::error( "Missing config property key.directory" ); return -1; }