|
1 | 1 | #include "fs_permission.h"
|
2 | 2 | #include "base_object-inl.h"
|
| 3 | +#include "debug_utils-inl.h" |
3 | 4 | #include "util.h"
|
4 | 5 | #include "v8.h"
|
5 | 6 |
|
@@ -72,6 +73,46 @@ namespace node {
|
72 | 73 |
|
73 | 74 | namespace permission {
|
74 | 75 |
|
| 76 | +void PrintTree(FSPermission::RadixTree::Node* node, int spaces = 0) { |
| 77 | + std::string whitespace(spaces, ' '); |
| 78 | + |
| 79 | + if (node == nullptr) { |
| 80 | + return; |
| 81 | + } |
| 82 | + if (node->wildcard_child != nullptr) { |
| 83 | + per_process::Debug(DebugCategory::PERMISSION_MODEL, |
| 84 | + "%s Wildcard: %s\n", |
| 85 | + whitespace, |
| 86 | + node->prefix); |
| 87 | + } else { |
| 88 | + per_process::Debug(DebugCategory::PERMISSION_MODEL, |
| 89 | + "%s Prefix: %s\n", |
| 90 | + whitespace, |
| 91 | + node->prefix); |
| 92 | + if (node->children.size()) { |
| 93 | + int child = 0; |
| 94 | + for (const auto pair : node->children) { |
| 95 | + ++child; |
| 96 | + per_process::Debug(DebugCategory::PERMISSION_MODEL, |
| 97 | + "%s Child(%s): %s\n", |
| 98 | + whitespace, |
| 99 | + child, |
| 100 | + std::string(1, pair.first)); |
| 101 | + PrintTree(pair.second, spaces + 2); |
| 102 | + } |
| 103 | + per_process::Debug(DebugCategory::PERMISSION_MODEL, |
| 104 | + "%s End of tree - child(%s)\n", |
| 105 | + whitespace, |
| 106 | + child); |
| 107 | + } else { |
| 108 | + per_process::Debug(DebugCategory::PERMISSION_MODEL, |
| 109 | + "%s End of tree: %s\n", |
| 110 | + whitespace, |
| 111 | + node->prefix); |
| 112 | + } |
| 113 | + } |
| 114 | +} |
| 115 | + |
75 | 116 | // allow = '*'
|
76 | 117 | // allow = '/tmp/,/home/example.js'
|
77 | 118 | void FSPermission::Apply(const std::string& allow, PermissionScope scope) {
|
@@ -175,6 +216,12 @@ void FSPermission::RadixTree::Insert(const std::string& path) {
|
175 | 216 | parent_node_prefix_len = i;
|
176 | 217 | }
|
177 | 218 | }
|
| 219 | + |
| 220 | + if (UNLIKELY(per_process::enabled_debug_list.enabled( |
| 221 | + DebugCategory::PERMISSION_MODEL))) { |
| 222 | + per_process::Debug(DebugCategory::PERMISSION_MODEL, "Inserting %s\n", path); |
| 223 | + PrintTree(root_node_); |
| 224 | + } |
178 | 225 | }
|
179 | 226 |
|
180 | 227 | } // namespace permission
|
|
0 commit comments