+ } else if (strstr(filename, ".file_contexts")) {
+ if (!impl->file_contexts.empty()) {
+ // Found more than one file containing in .file_contexts,
+ // don't know how to handle that so bail for now
+ xar_close(x);
+ throw "Multiple file_contexts files in policy package";
+ }
+ impl->file_contexts = std::string(fbuf);
+ } else if (strstr(filename, ".seusers")) {
+ if (!impl->seusers.empty()) {
+ // Found more than one file containing in .seusers,
+ // don't know how to handle that so bail for now
+ xar_close(x);
+ throw "Multiple seusers files in policy package";
+ }
+ impl->seusers = std::string(fbuf);
As we discussed privately - these copies are not great. Perhaps just use
raw char*.
Ok, I don't know if this code is ever going to do anything with those
and was trying to keep it in a format that would be more accessible if
we needed to. I can change to char * though and see if anything develops
that makes std::string make more sense.
+ } else if (strstr(filename, ".user_extra")) {
+ if (!impl->user_extra.empty()) {
+ // Found more than one file containing in .user_extra,
+ // don't know how to handle that so bail for now
+ xar_close(x);
+ throw "Multiple user_extra files in policy package";
+ }
+ impl->user_extra = std::string(fbuf);
+ } else if (strstr(filename, ".netfilter_contexts")) {
+ if (!impl->netfilter_contexts.empty()) {
+ // Found more than one file containing in .netfilter_contexts,
+ // don't know how to handle that so bail for now
+ xar_close(x);
+ throw "Multiple netfilter_contexts files in policy package";
+ }
+ impl->netfilter_contexts = std::string(fbuf);
+ } else {
+ // unrecognized file, just skip it
+ continue;
+ }
+
+ }
+
+ xar_close(x);
+
+ return 0;
+ }
+
+ PolicyPackage::PolicyPackage() {
+ init();
+ }
+
+ PolicyPackage::PolicyPackage(std::string filename) {
+ init();
+ read_package(filename);
+ }
+
+ PolicyPackage::~PolicyPackage() { delete impl; }
+
+ const Module PolicyPackage::get_policy_module() const {
+ return impl->policy_module;
+ }
This should definitely not be by value. It should also likely not be
const - this is how the user will retrieve the module after reading to
use, correct? Then it shouldn't be const (they might want to much with
it), should be a reference, and shouldn't be const for the class (as
allowing users to change the module changes the object).
Fair enough. I was basically thinking users would read a module and make
their own copies (eg., copying the data into a merged copy or something)
but that isn't really how policyrep works so I'll change all these to be
non-const.