Stefan Schuermans commited on 2020-08-24 20:49:59
Showing 5 changed files, with 97 additions and 2 deletions.
| ... | ... |
@@ -23,7 +23,7 @@ void Permissions::parseParams(std::string const ¶mStr) {
|
| 23 | 23 |
set = who * what; |
| 24 | 24 |
setCond = who * whatCond; |
| 25 | 25 |
clear = who * (what ^ (flagRead | flagWrite | flagExecute)); |
| 26 |
- clearCond = who * (what ^ flagExecute); |
|
| 26 |
+ clearCond = 0; |
|
| 27 | 27 |
break; |
| 28 | 28 |
case '+': |
| 29 | 29 |
set = who * what; |
| ... | ... |
@@ -1,10 +1,102 @@ |
| 1 | 1 |
#include <permissioner/Config.h> |
| 2 |
+#include <permissioner/Group.h> |
|
| 3 |
+#include <permissioner/Permissions.h> |
|
| 4 |
+#include <permissioner/User.h> |
|
| 5 |
+#include <permissioner/Tree.h> |
|
| 2 | 6 |
|
| 7 |
+#include <boost/filesystem.hpp> |
|
| 8 |
+#include <boost/optional.hpp> |
|
| 9 |
+#include <boost/optional/optional_io.hpp> |
|
| 3 | 10 |
#include <cstdlib> |
| 11 |
+#include <iomanip> |
|
| 12 |
+#include <iostream> |
|
| 13 |
+#include <string> |
|
| 14 |
+ |
|
| 15 |
+bool check(TreeMap const &treeMap, std::string const &rel_path, |
|
| 16 |
+ boost::optional<std::string> user, |
|
| 17 |
+ boost::optional<std::string> group, |
|
| 18 |
+ mode_t setMode, mode_t setCondMode, |
|
| 19 |
+ mode_t clearMode, mode_t clearCondMode) {
|
|
| 20 |
+ std::string path = boost::filesystem::canonical(rel_path).string(); |
|
| 21 |
+ TreeMap::const_iterator itTree = treeMap.find(path); |
|
| 22 |
+ if (itTree == treeMap.end()) {
|
|
| 23 |
+ std::cerr << "tree map entry \"" << path << "\" not found" << std::endl; |
|
| 24 |
+ return false; |
|
| 25 |
+ } |
|
| 26 |
+ Tree const &tree = itTree->second; |
|
| 27 |
+ |
|
| 28 |
+ bool ret = true; |
|
| 29 |
+ |
|
| 30 |
+ if (tree.getRoot() != path) {
|
|
| 31 |
+ std::cerr << "tree map entry \"" << path << "\": unexpected root \"" |
|
| 32 |
+ << tree.getRoot() << "\"" << std::endl; |
|
| 33 |
+ ret = false; |
|
| 34 |
+ } |
|
| 35 |
+ if (tree.getUser().getUserName() != user) {
|
|
| 36 |
+ std::cerr << "tree map entry \"" << path << "\": unexpected user \"" |
|
| 37 |
+ << tree.getUser().getUserName() << "\"" << std::endl; |
|
| 38 |
+ ret = false; |
|
| 39 |
+ } |
|
| 40 |
+ if (tree.getGroup().getGroupName() != group) {
|
|
| 41 |
+ std::cerr << "tree map entry \"" << path << "\": unexpected group \"" |
|
| 42 |
+ << tree.getGroup().getGroupName() << "\"" << std::endl; |
|
| 43 |
+ ret = false; |
|
| 44 |
+ } |
|
| 45 |
+ Permissions const &perms = tree.getPermissions(); |
|
| 46 |
+ if (perms.getSet() != setMode) {
|
|
| 47 |
+ std::cerr << "tree map entry \"" << path |
|
| 48 |
+ << "\": unexpected set mode " |
|
| 49 |
+ << std::oct << perms.getSet() << " != " << setMode |
|
| 50 |
+ << std::dec << std::endl; |
|
| 51 |
+ ret = false; |
|
| 52 |
+ } |
|
| 53 |
+ if (perms.getSetCond() != setCondMode) {
|
|
| 54 |
+ std::cerr << "tree map entry \"" << path |
|
| 55 |
+ << "\": unexpected set cond mode " |
|
| 56 |
+ << std::oct << perms.getSetCond() << " != " << setCondMode |
|
| 57 |
+ << std::dec << std::endl; |
|
| 58 |
+ ret = false; |
|
| 59 |
+ } |
|
| 60 |
+ if (perms.getClear() != clearMode) {
|
|
| 61 |
+ std::cerr << "tree map entry \"" << path |
|
| 62 |
+ << "\": unexpected clear mode " |
|
| 63 |
+ << std::oct << perms.getClear() << " != " << clearMode |
|
| 64 |
+ << std::dec << std::endl; |
|
| 65 |
+ ret = false; |
|
| 66 |
+ } |
|
| 67 |
+ if (perms.getClearCond() != clearCondMode) {
|
|
| 68 |
+ std::cerr << "tree map entry \"" << path |
|
| 69 |
+ << "\": unexpected clear cond mode " |
|
| 70 |
+ << std::oct << perms.getClearCond() << " != " << clearCondMode |
|
| 71 |
+ << std::dec << std::endl; |
|
| 72 |
+ ret = false; |
|
| 73 |
+ } |
|
| 74 |
+ |
|
| 75 |
+ return ret; |
|
| 76 |
+} |
|
| 4 | 77 |
|
| 5 | 78 |
int main(int argc, char const **argv) {
|
| 6 | 79 |
(void)argc; |
| 7 | 80 |
Config config; |
| 8 | 81 |
config.parseFile(argv[1]); |
| 9 |
- return EXIT_SUCCESS; |
|
| 82 |
+ |
|
| 83 |
+ int ret = EXIT_SUCCESS; |
|
| 84 |
+ |
|
| 85 |
+ TreeMap const &treeMap = config.getTrees(); |
|
| 86 |
+ if (treeMap.size() != 2) {
|
|
| 87 |
+ std::cerr << "unexpected number of trees: " << treeMap.size() << std::endl; |
|
| 88 |
+ ret = EXIT_FAILURE; |
|
| 89 |
+ } |
|
| 90 |
+ if (! check(treeMap, "some/dir", std::string("nobody"),
|
|
| 91 |
+ std::string("nogroup"),
|
|
| 92 |
+ 0011, 0044, 0022, 000)) {
|
|
| 93 |
+ ret = EXIT_FAILURE; |
|
| 94 |
+ } |
|
| 95 |
+ if (! check(treeMap, "some/other/dir", boost::none, |
|
| 96 |
+ boost::none, |
|
| 97 |
+ 0777, 0000, 0000, 0000)) {
|
|
| 98 |
+ ret = EXIT_FAILURE; |
|
| 99 |
+ } |
|
| 100 |
+ |
|
| 101 |
+ return ret; |
|
| 10 | 102 |
} |