#include <map>
#include <sstream>
#include <string>
+#include <utility>
#include <vector>
using namespace ldp_xml_parser;
{ "error", MessageType::ERROR }
};
+static const std::map<std::string, BusAccessType> buses {
+ { "user", BusAccessType::USER },
+ { "group", BusAccessType::GROUP },
+ { "all_users", BusAccessType::ALL_USERS },
+ {"all_groups", BusAccessType::ALL_GROUPS}
+};
+
MessageType stringToMessageType(std::string tmp) {
std::transform(tmp.begin(), tmp.end(), tmp.begin(),
[](unsigned char c) { return std::tolower(c); } );
}
}
+std::pair <std::string, std::string> getItemStrings (const ItemSend &) {
+ return std::make_pair ("send", "send_destination");
+}
+std::pair <std::string, std::string> getItemStrings (const ItemReceive &) {
+ return std::make_pair ("receive", "receive_sender");
+}
+
+template <typename T> void printDecision(const T & item) {
+ bool everything_is_null = true;
+ const auto strings = getItemStrings(item);
+
+ if (!item.getInterface().empty()) {
+ everything_is_null = false;
+ std::cout << " " << strings.first << "=\"" << item.getInterface() << "\"";
+ }
+ if (!item.getMember().empty()) {
+ everything_is_null = false;
+ std::cout << " " << strings.first << "=\"" << item.getMember() << "\"";
+ }
+ if (!item.getPath().empty()) {
+ everything_is_null = false;
+ std::cout << " " << strings.first << "=\"" << item.getPath() << "\"";
+ }
+ if (!item.getName().empty()) {
+ everything_is_null = false;
+ std::cout << " " << strings.first << "=\"" << item.getName() << "\"";
+ }
+ if (!item.getName().empty() && item.isNamePrefix()) {
+ everything_is_null = false;
+ std::cout << " " << strings.second << "=\"" << item.getName() << "\"";
+ }
+ const auto type_it = std::find_if(types.begin(), types.end(), [&item] (const decltype(types)::value_type & type) { return type.second == item.getType(); } );
+
+ if (type_it != types.end()) {
+ everything_is_null = false;
+ std::cout << " type=\"" << type_it->first << "\"";
+ }
+ if (everything_is_null)
+ std::cout << '*';
+
+ std::cout << std::endl;
+}
+
+void printDecision(const ItemAccess & item) {
+ bool everything_is_null = true;
+ std::cout << " access" <<
+ " uid=\"" << item.getUid() << "\"" <<
+ " gid=\"" << item.getGid() << "\"";
+
+ const auto bus_it = std::find_if(buses.begin(), buses.end(), [&item] (const decltype(buses)::value_type & bus) { return bus.second == item.getType(); } );
+
+ if (bus_it != buses.end()) {
+ everything_is_null = false;
+ std::cout << " type=\"" << bus_it->first << "\"";
+ }
+ if (everything_is_null)
+ std::cout << '*';
+
+ std::cout << std::endl;
+}
+
+template <typename T> void printDecisionMain(const typename T::item_type & item) {
+ const auto tmp = item.getDecision().getDecision();
+
+ if (tmp == Decision::ALLOW)
+ std::cout << "allow";
+
+ else if (tmp == Decision::DENY)
+ std::cout << "deny";
+
+ else if (tmp == Decision::CHECK)
+ std::cout << "check";
+
+ printDecision(item);
+}
+
void printDecision(const Decision & di, const std::string & token, const std::string & extraText, Print_once & printer) {
if (di == Decision::ANY)
return;
for (const auto & iter : policy.getItems()) {
if (noFilter || mi.match(iter.getType(), iter.getInterface(), iter.getPath(), iter.getMember(), iter.getName(), iter.isNamePrefix(), Decision::ANY)) {
printer.print();
- std::cout << iter << std::endl;
+ printDecisionMain<T>(iter);
}
}
}
for (const auto & iter : policy.getItems()) {
if (noFilter || mi.match(iter.getType(), iter.getUid(), iter.getGid())) {
printer.print();
- std::cout << iter << std::endl;
+ printDecisionMain<PolicyAccess>(iter);
}
}
}
if (numberGroup == ((gid_t) -1) && numberUser == ((uid_t) -1)) {
for (const auto & gid : groups) {
- matchPolicy<T>(gid.second, mi, noFilter, std::string("Group:") + std::to_string(gid.first));
+ matchPolicy<T>(gid.second, mi, noFilter, std::string("Group: ") + std::to_string(gid.first));
}
for (const auto & uid : users) {
- matchPolicy<T>(uid.second, mi, noFilter, std::string("User:") + std::to_string(uid.first));
+ matchPolicy<T>(uid.second, mi, noFilter, std::string("User: ") + std::to_string(uid.first));
}
} else {
if (numberGroup != (gid_t) -1) {
if (it == groups.end())
std::cout << "No rules for group in policy!" << std::endl;
else
- matchPolicy<T>(it->second, mi, noFilter, std::string("Group:") + std::to_string(numberGroup));
+ matchPolicy<T>(it->second, mi, noFilter, std::string("Group: ") + std::to_string(numberGroup));
}
if (numberUser != (uid_t) -1) {
const auto it = users.find(numberUser);
if (it == users.end())
std::cout << "No rules for user in policy!" << std::endl;
else
- matchPolicy<T>(it->second, mi, noFilter, std::string("User:") + std::to_string(numberUser));
+ matchPolicy<T>(it->second, mi, noFilter, std::string("User: ") + std::to_string(numberUser));
}
}
matchPolicy<T>(storage.getPolicyContextMandatory<T>(), mi, noFilter, "Context Mandatory:");