| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,7 +49,8 @@ void NODE_EXTERN_PRIVATE FWrite(FILE* file, const std::string& str); | |||
| 49 | 49 | V(CODE_CACHE) \ | |
| 50 | 50 | V(NGTCP2_DEBUG) \ | |
| 51 | 51 | V(WASI) \ | |
| 52 | - V(MKSNAPSHOT) | ||
| 52 | + V(MKSNAPSHOT) \ | ||
| 53 | + V(PERMISSION_MODEL) | ||
| 53 | 54 | ||
| 54 | 55 | enum class DebugCategory : unsigned int { | |
| 55 | 56 | #define V(name) name, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 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) { | |
@@ -176,6 +217,12 @@ void FSPermission::RadixTree::Insert(const std::string& path) { | |||
| 176 | 217 | parent_node_prefix_len = i; | |
| 177 | 218 | } | |
| 178 | 219 | } | |
| 220 | + | ||
| 221 | + if (UNLIKELY(per_process::enabled_debug_list.enabled( | ||
| 222 | + DebugCategory::PERMISSION_MODEL))) { | ||
| 223 | + per_process::Debug(DebugCategory::PERMISSION_MODEL, "Inserting %s\n", path); | ||
| 224 | + PrintTree(root_node_); | ||
| 225 | + } | ||
| 179 | 226 | } | |
| 180 | 227 | ||
| 181 | 228 | } // namespace permission | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,8 +18,6 @@ class FSPermission final : public PermissionBase { | |||
| 18 | 18 | void Apply(const std::string& allow, PermissionScope scope) override; | |
| 19 | 19 | bool is_granted(PermissionScope perm, const std::string_view& param) override; | |
| 20 | 20 | ||
| 21 | - // For debugging purposes, use the gist function to print the whole tree | ||
| 22 | - // https://gist.github.com/RafaelGSS/5b4f09c559a54f53f9b7c8c030744d19 | ||
| 23 | 21 | struct RadixTree { | |
| 24 | 22 | struct Node { | |
| 25 | 23 | std::string prefix; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments