Stefan Schuermans commited on 2020-08-24 20:18:23
Showing 1 changed files, with 15 additions and 16 deletions.
| ... | ... |
@@ -1,5 +1,6 @@ |
| 1 | 1 |
#include <permissioner/Config.h> |
| 2 | 2 |
|
| 3 |
+#include <boost/filesystem.hpp> |
|
| 3 | 4 |
#include <cstdlib> |
| 4 | 5 |
#include <grp.h> |
| 5 | 6 |
#include <iomanip> |
| ... | ... |
@@ -23,7 +24,7 @@ extern "C" int lchown(const char *pathname, uid_t owner, gid_t group) {
|
| 23 | 24 |
return 0; |
| 24 | 25 |
} |
| 25 | 26 |
|
| 26 |
-bool check_lchown(unsigned int idx, std::string const &path_suffix, |
|
| 27 |
+bool check_lchown(unsigned int idx, std::string const &path, |
|
| 27 | 28 |
uid_t owner, gid_t group) {
|
| 28 | 29 |
bool ret = true; |
| 29 | 30 |
if (idx > logs_lchown.size()) {
|
| ... | ... |
@@ -31,11 +32,10 @@ bool check_lchown(unsigned int idx, std::string const &path_suffix, |
| 31 | 32 |
return false; |
| 32 | 33 |
} |
| 33 | 34 |
LogLchown const & log_lchown = logs_lchown.at(idx); |
| 34 |
- std::string pn = log_lchown.pathname; |
|
| 35 |
- if (pn.length() < path_suffix.length() || |
|
| 36 |
- pn.substr(pn.length() - path_suffix.length()) != path_suffix) {
|
|
| 37 |
- std::cerr << "lchown call #" << idx << ": unexpcted path \"" |
|
| 38 |
- << pn << "\" != ...\"" << path_suffix << "\"" << std::endl; |
|
| 35 |
+ if (log_lchown.pathname != path) {
|
|
| 36 |
+ std::cerr << "lchown call #" << idx << ": unexpected path \"" |
|
| 37 |
+ << log_lchown.pathname << "\" != ...\"" << path << "\"" |
|
| 38 |
+ << std::endl; |
|
| 39 | 39 |
ret = false; |
| 40 | 40 |
} |
| 41 | 41 |
if (log_lchown.owner != owner) {
|
| ... | ... |
@@ -63,19 +63,17 @@ extern "C" int chmod(const char *pathname, mode_t mode) {
|
| 63 | 63 |
return 0; |
| 64 | 64 |
} |
| 65 | 65 |
|
| 66 |
-bool check_chmod(unsigned int idx, std::string const &path_suffix, |
|
| 67 |
- mode_t mode) {
|
|
| 66 |
+bool check_chmod(unsigned int idx, std::string const &path, mode_t mode) {
|
|
| 68 | 67 |
bool ret = true; |
| 69 | 68 |
if (idx > logs_chmod.size()) {
|
| 70 | 69 |
std::cerr << "no such chmod call #" << idx << std::endl; |
| 71 | 70 |
return false; |
| 72 | 71 |
} |
| 73 | 72 |
LogChmod const & log_chmod = logs_chmod.at(idx); |
| 74 |
- std::string pn = log_chmod.pathname; |
|
| 75 |
- if (pn.length() < path_suffix.length() || |
|
| 76 |
- pn.substr(pn.length() - path_suffix.length()) != path_suffix) {
|
|
| 77 |
- std::cerr << "chmod call #" << idx << ": unexpcted path \"" |
|
| 78 |
- << pn << "\" != ...\"" << path_suffix << "\"" << std::endl; |
|
| 73 |
+ if (log_chmod.pathname != path) {
|
|
| 74 |
+ std::cerr << "chmod call #" << idx << ": unexpected path \"" |
|
| 75 |
+ << log_chmod.pathname << "\" != ...\"" << path << "\"" |
|
| 76 |
+ << std::endl; |
|
| 79 | 77 |
ret = false; |
| 80 | 78 |
} |
| 81 | 79 |
if (log_chmod.mode != mode) {
|
| ... | ... |
@@ -87,13 +85,14 @@ bool check_chmod(unsigned int idx, std::string const &path_suffix, |
| 87 | 85 |
return ret; |
| 88 | 86 |
} |
| 89 | 87 |
|
| 90 |
-bool check(unsigned int idx, std::string const &path_suffix, |
|
| 88 |
+bool check(unsigned int idx, std::string const &rel_path, |
|
| 91 | 89 |
uid_t owner, gid_t group, mode_t mode) {
|
| 92 | 90 |
bool ret = true; |
| 93 |
- if (! check_lchown(idx, path_suffix, owner, group)) {
|
|
| 91 |
+ std::string path = boost::filesystem::canonical(rel_path).string(); |
|
| 92 |
+ if (! check_lchown(idx, path, owner, group)) {
|
|
| 94 | 93 |
ret = false; |
| 95 | 94 |
} |
| 96 |
- if (! check_chmod(idx, path_suffix, mode)) {
|
|
| 95 |
+ if (! check_chmod(idx, path, mode)) {
|
|
| 97 | 96 |
ret = false; |
| 98 | 97 |
} |
| 99 | 98 |
return ret; |
| 100 | 99 |