Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions xff/registry/registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,20 @@ constexpr std::array kDescriptors = std::to_array<Descriptor>({
{.name = "-printf", .kind = Kind::kAction, .arity = 1},
{.name = "-println", .kind = Kind::kAction, .arity = 0}, // xff: -print with the OS line ending
{.name = "-printfln", .kind = Kind::kAction, .arity = 1}, // xff: -printf + the OS line ending
{.name = "-delete", .kind = Kind::kAction, .arity = 0},
{.name = "-delete", .kind = Kind::kAction, .arity = 0, .safety = Safety::kSafety},
{.name = "-prune", .kind = Kind::kAction, .arity = 0},
{.name = "-quit", .kind = Kind::kAction, .arity = 0},
{.name = "-exec", .kind = Kind::kAction, .arity = -1},
{.name = "-execdir", .kind = Kind::kAction, .arity = -1}, // -exec in the matched entry's directory
{.name = "-ok", .kind = Kind::kAction, .arity = -1}, // -exec that prompts; runs only on an affirmative reply
{.name = "-okdir", .kind = Kind::kAction, .arity = -1}, // -execdir that prompts; runs only on an affirmative reply
{.name = "-capture", .kind = Kind::kAction, .arity = -1}, // -capture=NAME[=REGEX] cmd... ;
{.name = "-capturedir", .kind = Kind::kAction, .arity = -1}, // -capture run in the matched entry's directory
{.name = "-exec", .kind = Kind::kAction, .arity = -1, .safety = Safety::kSecurity},
// -exec in the matched entry's directory
{.name = "-execdir", .kind = Kind::kAction, .arity = -1, .safety = Safety::kSecurity},
// -exec that prompts; runs only on an affirmative reply
{.name = "-ok", .kind = Kind::kAction, .arity = -1, .safety = Safety::kSecurity},
// -execdir that prompts; runs only on an affirmative reply
{.name = "-okdir", .kind = Kind::kAction, .arity = -1, .safety = Safety::kSecurity},
// -capture=NAME[=REGEX] cmd... ;
{.name = "-capture", .kind = Kind::kAction, .arity = -1, .safety = Safety::kSecurity},
// -capture run in the matched entry's directory
{.name = "-capturedir", .kind = Kind::kAction, .arity = -1, .safety = Safety::kSecurity},
{.name = "-a", .kind = Kind::kOperator, .arity = 0},
{.name = "-and", .kind = Kind::kOperator, .arity = 0},
{.name = "-o", .kind = Kind::kOperator, .arity = 0},
Expand Down
14 changes: 14 additions & 0 deletions xff/registry/registry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
namespace xff::registry {
namespace {

using ::testing::Field;
using ::testing::IsNull;
using ::testing::NotNull;
using ::testing::Pointee;

struct RegistryTest : ::testing::Test {};

Expand Down Expand Up @@ -53,5 +55,17 @@ TEST_F(RegistryTest, UnknownTokenIsNull) {
EXPECT_THAT(Lookup("."), IsNull());
}

TEST_F(RegistryTest, SecurityRelevantPrimariesAreClassified) {
// The exec family runs arbitrary commands (kSecurity); -delete loses data
// (kSafety); everything else is unclassified (kNone). The config policy gate
// (phase C) keys its safe-by-default deny off this.
for (const char* const name : {"-exec", "-execdir", "-ok", "-okdir", "-capture", "-capturedir"}) {
EXPECT_THAT(Lookup(name), Pointee(Field("safety", &Descriptor::safety, Safety::kSecurity))) << name;
}
EXPECT_THAT(Lookup("-delete"), Pointee(Field("safety", &Descriptor::safety, Safety::kSafety)));
EXPECT_THAT(Lookup("-name"), Pointee(Field("safety", &Descriptor::safety, Safety::kNone)));
EXPECT_THAT(Lookup("-print"), Pointee(Field("safety", &Descriptor::safety, Safety::kNone)));
}

} // namespace
} // namespace xff::registry
Loading