]> WPIA git - cassiopeia.git/blobdiff - src/config.cpp
Fix: uninitialized fields
[cassiopeia.git] / src / config.cpp
index 2eb1f491c3bc42ca41e35eefbb183c42e644409d..ce78f417582a8a8049389f18435279cde60b7fa8 100644 (file)
@@ -4,7 +4,7 @@
 #include <dirent.h>
 #include <unordered_map>
 
-#include "sslUtil.h"
+#include "crypto/sslUtil.h"
 
 std::string keyDir;
 std::unordered_map<std::string, Profile> profiles;
@@ -46,17 +46,7 @@ std::shared_ptr<std::unordered_map<std::string, std::string>> parseConf( std::st
     return map;
 }
 
-int parseConfig( std::string path ) {
-
-    auto masterConf = parseConf( path );
-
-    keyDir = masterConf->at( "key.directory" );
-    sqlHost = masterConf->at( "sql.host" );
-    sqlUser = masterConf->at( "sql.user" );
-    sqlPass = masterConf->at( "sql.password" );
-    sqlDB = masterConf->at( "sql.database" );
-    serialPath = masterConf->at( "serialPath" );
-
+int parseProfiles() {
     CAs = std::unordered_map<std::string, std::shared_ptr<CAConfig>>();
 
     DIR* dp;
@@ -97,13 +87,31 @@ int parseConfig( std::string path ) {
         prof.id = std::stoi( id );
         prof.eku = map->at( "eku" );
         prof.ku = map->at( "ku" );
+        prof.maxValidity = std::stoi( map->at( "days" ) ) * /* DAYS */24 * 60 * 60;
 
-        if( CAs.find( map->at( "ca" ) ) == CAs.end() ) {
-            std::shared_ptr<CAConfig> ca( new CAConfig( map->at( "ca" ) ) );
-            CAs.emplace( map->at( "ca" ), ca );
-        }
+        std::string cas = map->at( "ca" );
+
+        for( size_t pos = 0; pos != std::string::npos; ) {
+            size_t end = cas.find( ",", pos );
+            std::string sub;
+
+            if( end == std::string::npos ) {
+                sub = cas.substr( pos );
+            } else {
+                sub = cas.substr( pos, end - pos );
+                end++;
+            }
 
-        prof.ca = CAs.at( map->at( "ca" ) );
+            pos = end;
+
+            if( CAs.find( sub ) == CAs.end() ) {
+                std::shared_ptr<CAConfig> ca( new CAConfig( sub ) );
+                CAs.emplace( sub, ca );
+            }
+
+            prof.ca.push_back( CAs.at( sub ) );
+
+        }
 
         profiles.emplace( profileName, prof );
         std::cout << "Profile: " << profileName << " up and running." << std::endl;
@@ -114,10 +122,28 @@ int parseConfig( std::string path ) {
 
     std::cout << profiles.size() << " profiles loaded." << std::endl;
 
+    return 0;
+}
+
+int parseConfig( std::string path ) {
+
+    auto masterConf = parseConf( path );
+
+    keyDir = masterConf->at( "key.directory" );
+    sqlHost = masterConf->at( "sql.host" );
+    sqlUser = masterConf->at( "sql.user" );
+    sqlPass = masterConf->at( "sql.password" );
+    sqlDB = masterConf->at( "sql.database" );
+    serialPath = masterConf->at( "serialPath" );
+
     if( keyDir == "" ) {
         std::cerr << "Missing config property key.directory" << std::endl;
         return -1;
     }
 
+    if( parseProfiles() != 0 ) {
+        return -1;
+    }
+
     return 0;
 }