#include "policy.hpp"
#include "naive_policy_db.hpp"
-//#include "tslog.hpp"
#include <cstdlib>
#include <sys/types.h>
#include <grp.h>
}
}
-void DbAdapter::updateDb(bool bus, boost::property_tree::ptree& xmlTree) {
+void DbAdapter::updateDb(bool bus, boost::property_tree::ptree& xmlTree, std::vector<std::string>& incl_dirs) {
const auto& children = xmlTree.get_child("busconfig");
PolicyType policy_type;
PolicyTypeValue policy_type_value;
__tag_state = POLICY;
__attr = false;
xmlTraversal(bus, x.second, POLICY, policy_type, policy_type_value);
+ } else if (x.first == "includedir") {
+ incl_dirs.push_back(x.second.data());
}
}
}
#include <boost/property_tree/xml_parser.hpp>
#include <dirent.h>
#include <libgen.h>
-//#include "xml_policy.hpp"
#include "libdbuspolicy1-private.hpp"
#include "tslog.hpp"
#include "policy.hpp"
ErrCode parse(bool bus, bool first, const std::string& filename, std::vector<std::string>& included_files) {
std::pair<ErrCode, std::string> errparam;
-
+ std::vector<std::string> incl_dirs;
if (tslog::verbose())
std::cout << "=== XML PARSING BEGIN === : " << filename << '\n';
- errparam = parseXml(bus, filename);
- if (first && errparam.first.get() >= 0 && errparam.second != "")
- getIncludedFiles(filename, errparam.second, included_files);
+ errparam = parseXml(bus, filename, incl_dirs);
+ for (int i = 0; i < incl_dirs.size(); i++) {
+ getIncludedFiles(filename, incl_dirs[i], included_files);
+ }
if (tslog::enabled()) {
if (tslog::verbose())
std::string fname;
std::copy(filename.begin(), filename.end(), fname.begin());
std::string dname = dirname(const_cast<char*>(fname.c_str()));
- dname += (std::string("/") + incldir);
+ if (incldir[0] != '/')
+ dname += (std::string("/") + incldir);
+ else
+ dname = incldir;
files.clear();
if((dir = opendir(dname.c_str())) != NULL) {
while((ent = readdir(dir)) != NULL) {
std::cout << "could not open directory " << dname << '\n';
}
- std::pair<ErrCode, std::string> parseXml(bool bus, const std::string& filename) {
+ std::pair<ErrCode, std::string> parseXml(bool bus, const std::string& filename, std::vector<std::string>& incl_dirs) {
std::pair<ErrCode, std::string> ret;
if (__parsed.insert(filename).second)
boost::property_tree::ptree pt;
read_xml(filename, pt);
if (!pt.empty()) {
- __adapter->updateDb(bus, pt);
- ret.second = pt.get("busconfig.includedir", "");
+ __adapter->updateDb(bus, pt, incl_dirs);
}
} catch(const boost::property_tree::xml_parser::xml_parser_error& ex) {
ret.first = ErrCode::error(ex.what());
goto err_close;
rp = __internal_init(bus_type, (bus_type == SYSTEM_BUS) ? SYSTEM_BUS_CONF_FILE_PRIMARY : SESSION_BUS_CONF_FILE_PRIMARY);
- rs = __internal_init(bus_type, (bus_type == SYSTEM_BUS) ? SYSTEM_BUS_CONF_FILE_SECONDARY : SESSION_BUS_CONF_FILE_SECONDARY);
+ if (rp < 0)
+ rs = __internal_init(bus_type, (bus_type == SYSTEM_BUS) ? SYSTEM_BUS_CONF_FILE_SECONDARY : SESSION_BUS_CONF_FILE_SECONDARY);
+ else
+ rs = 1;
+
+ pthread_mutex_unlock(&g_mutex);
__internal_init_flush_logs();
- if ((rp & rs) < 0) /* when both negative */
+ if (rp < 0 && rs < 0) /* when both negative */
goto err_close;
- pthread_mutex_unlock(&g_mutex);
return &g_conn[bus_type];
err_close: