| 57 | } |
| 58 | |
| 59 | std::vector<std::shared_ptr<RuleSet>> RuleSetFactory::generateRuleSetBySource(NSHandler::SourceType type) |
| 60 | { |
| 61 | NSHandler& ns = NSHandler::getRef(); |
| 62 | std::vector<std::shared_ptr<RuleSet>> ruleSet; |
| 63 | |
| 64 | switch (type) { |
| 65 | case NSHandler::SourceType::LOCAL: |
| 66 | if (!ns.getRulesPath().empty()) { |
| 67 | ruleSet.emplace_back(new FileRuleSet(interface_ptr, ns.getRulesPath())); |
| 68 | } |
| 69 | |
| 70 | if (!ns.getRulesDirPath().empty()) { |
| 71 | for (auto path : getConfigsFromDir(ns.getRulesDirPath())) { |
| 72 | auto frs = std::make_shared<FileRuleSet>(interface_ptr, path); |
| 73 | auto rs = std::dynamic_pointer_cast<RuleSet>(frs); |
| 74 | ruleSet.push_back(rs); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * This means one of the following: |
| 80 | * - Neither RuleFile nor RuleFolder are specified |
| 81 | * - RuleFile not specified, RuleFolder is but it does not contain any files, |
| 82 | * where we could save permanent rules |
| 83 | */ |
| 84 | if (ruleSet.empty()) { |
| 85 | std::string msg; |
| 86 | |
| 87 | if (ns.getRulesPath().empty() && ns.getRulesDirPath().empty()) { |
| 88 | msg = "Neither RuleFile nor RuleFolder are set."; |
| 89 | } |
| 90 | else { |
| 91 | msg = "RuleFile is not set, RuleFolder is but it does not contain any rule files."; |
| 92 | } |
| 93 | |
| 94 | USBGUARD_LOG(Warning) << "Modification of the permanent policy won't be possible." |
| 95 | << " Reason: " << msg; |
| 96 | ruleSet = generateDefaultRuleSet(); |
| 97 | } |
| 98 | |
| 99 | break; |
| 100 | #ifdef HAVE_LDAP |
| 101 | |
| 102 | case NSHandler::SourceType::LDAP: |
| 103 | ruleSet.emplace_back(new LDAPRuleSet(interface_ptr, ns.getLDAPHandler())); |
| 104 | break; |
| 105 | #endif |
| 106 | |
| 107 | default: |
| 108 | ruleSet = generateDefaultRuleSet(); |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | return ruleSet; |
| 113 | } |
| 114 | |
| 115 | } /* namespace usbguard */ |
| 116 |
nothing calls this directly
no test coverage detected