| 260 | |
| 261 | |
| 262 | Try<Nothing> parseSyscallArgument( |
| 263 | const JSON::Object& json, |
| 264 | ContainerSeccompProfile::Syscall::Arg* arg) |
| 265 | { |
| 266 | auto parseField = [&json](const string& field) -> Try<JSON::Number> { |
| 267 | const auto number = json.at<JSON::Number>(field); |
| 268 | if (!number.isSome()) { |
| 269 | return Error( |
| 270 | "Cannot determine '" + field + "' field for 'args' item: " + |
| 271 | (number.isError() ? number.error() : "Not found")); |
| 272 | } |
| 273 | |
| 274 | return number.get(); |
| 275 | }; |
| 276 | |
| 277 | const auto index = parseField("index"); |
| 278 | if (index.isError()) { |
| 279 | return Error(index.error()); |
| 280 | } |
| 281 | |
| 282 | arg->set_index(index->as<uint32_t>()); |
| 283 | |
| 284 | const auto value = parseField("value"); |
| 285 | if (value.isError()) { |
| 286 | return Error(value.error()); |
| 287 | } |
| 288 | |
| 289 | arg->set_value(value->as<uint64_t>()); |
| 290 | |
| 291 | const auto valueTwo = parseField("valueTwo"); |
| 292 | if (valueTwo.isError()) { |
| 293 | return Error(valueTwo.error()); |
| 294 | } |
| 295 | |
| 296 | arg->set_value_two(valueTwo->as<uint64_t>()); |
| 297 | |
| 298 | const auto op = json.at<JSON::String>("op"); |
| 299 | if (!op.isSome()) { |
| 300 | return Error( |
| 301 | "Cannot determine 'op' field for 'args' item: " + |
| 302 | (op.isError() ? op.error() : "Not found")); |
| 303 | } |
| 304 | |
| 305 | if (!strings::startsWith(op->value, SCMP_PREFIX)) { |
| 306 | return Error("Unexpected operation: '" + op->value + "'"); |
| 307 | } |
| 308 | |
| 309 | ContainerSeccompProfile::Syscall::Arg::Operator opVal; |
| 310 | |
| 311 | if (!ContainerSeccompProfile::Syscall::Arg::Operator_Parse( |
| 312 | string(op->value, strlen(SCMP_PREFIX)), &opVal)) { |
| 313 | return Error("Unknown operator: '" + op->value + "'"); |
| 314 | } |
| 315 | |
| 316 | arg->set_op(opVal); |
| 317 | |
| 318 | return Nothing(); |
| 319 | } |