All 161 task packages, including the 21 batch 6 C++17 tasks that passed
gates 1/2, are now in Git. rollout.catalog builds docs/task-catalog.{json,md}
from the task packages, a fresh trace5 calibration (128/128 PASS), every
verified controller receipt on the current task digest, documented holds
and digest-bound difficulty reviews. 123 tasks are usable (6 HARD),
5 are on hold and 33 still need a subprocess-only grader.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
3.3 KiB
C++
120 lines
3.3 KiB
C++
#include "sysctl_overlay.hpp"
|
|
#include <set>
|
|
#include <utility>
|
|
|
|
namespace sysctloverlay {
|
|
namespace detail {
|
|
bool text_structure(const std::string &text);
|
|
}
|
|
namespace {
|
|
|
|
bool basename_value(const std::string &name)
|
|
{
|
|
if (name.size() < 5 || name.size() > 128 ||
|
|
name.compare(name.size() - 5, 5, ".conf") != 0) {
|
|
return false;
|
|
}
|
|
for (unsigned char byte : name) {
|
|
const bool letter = (byte >= 'A' && byte <= 'Z') ||
|
|
(byte >= 'a' && byte <= 'z');
|
|
const bool digit = byte >= '0' && byte <= '9';
|
|
if (!letter && !digit && byte != '_' && byte != '.' && byte != '-') {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool structures(const std::vector<Layer> &layers)
|
|
{
|
|
if (layers.size() > 8) {
|
|
return false;
|
|
}
|
|
std::size_t files = 0;
|
|
std::size_t bytes = 0;
|
|
for (const Layer &layer : layers) {
|
|
if (layer.size() > 64) {
|
|
return false;
|
|
}
|
|
files += layer.size();
|
|
if (files > 128) {
|
|
return false;
|
|
}
|
|
std::set<std::string> seen;
|
|
for (const File &file : layer) {
|
|
if (!basename_value(file.basename) || !seen.insert(file.basename).second) {
|
|
return false;
|
|
}
|
|
if (file.text.has_value()) {
|
|
if (!detail::text_structure(*file.text)) {
|
|
return false;
|
|
}
|
|
bytes += file.text->size();
|
|
if (bytes > 262144) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|
|
Error select_files(const std::vector<Layer> &layers,
|
|
std::vector<SelectedFile> &output)
|
|
{
|
|
output.clear();
|
|
if (!structures(layers)) {
|
|
return Error::invalid;
|
|
}
|
|
std::vector<SelectedFile> selected;
|
|
std::set<std::string> seen;
|
|
for (std::size_t index = 0; index < layers.size(); ++index) {
|
|
for (const File &file : layers[index]) {
|
|
if (seen.insert(file.basename).second) {
|
|
selected.push_back(SelectedFile{index, file});
|
|
}
|
|
}
|
|
}
|
|
output = std::move(selected);
|
|
return Error::none;
|
|
}
|
|
|
|
Error compile_configuration(const std::vector<Layer> &layers,
|
|
Configuration &output)
|
|
{
|
|
output = Configuration{};
|
|
Configuration result;
|
|
if (select_files(layers, result.selected) != Error::none) {
|
|
return Error::invalid;
|
|
}
|
|
std::set<std::string> excluded;
|
|
for (const SelectedFile &selected : result.selected) {
|
|
if (!selected.file.text.has_value()) {
|
|
continue;
|
|
}
|
|
std::vector<Rule> rules;
|
|
if (parse_text(*selected.file.text, rules) != Error::none ||
|
|
result.rules.size() + rules.size() > 512) {
|
|
return Error::invalid;
|
|
}
|
|
for (const Rule &rule : rules) {
|
|
if (rule.kind == RuleKind::assignment && !rule.pattern &&
|
|
!rule.ignore_error) {
|
|
excluded.insert(rule.key);
|
|
}
|
|
LocatedRule located;
|
|
located.layer = selected.layer;
|
|
located.basename = selected.file.basename;
|
|
located.rule = rule;
|
|
result.rules.push_back(std::move(located));
|
|
}
|
|
}
|
|
result.excluded.assign(excluded.begin(), excluded.end());
|
|
output = std::move(result);
|
|
return Error::none;
|
|
}
|
|
|
|
}
|