2025-03-27 04:14:47 +00:00
|
|
|
/**
|
|
|
|
* @file verify_commands.cpp
|
|
|
|
* @brief Implementation of command handlers for the verify module
|
|
|
|
*
|
|
|
|
* Implements the command handlers for verifying package checksums and signatures.
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2025 SILO GROUP LLC
|
|
|
|
* @author Chris Punches <chris.punches@silogroup.org>
|
|
|
|
*
|
|
|
|
* Part of the Dark Horse Linux Package Manager (DPM)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "verify_commands.hpp"
|
|
|
|
|
2025-03-28 01:51:21 +00:00
|
|
|
int check_and_load_build_module(void*& module_handle) {
|
|
|
|
// Get the module path using the new direct accessor
|
|
|
|
const char* module_path = dpm_get_module_path();
|
|
|
|
if (!module_path || strlen(module_path) == 0) {
|
|
|
|
dpm_log(LOG_ERROR, "Module path not available");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a proper path object
|
|
|
|
std::filesystem::path modules_dir(module_path);
|
|
|
|
|
|
|
|
// Build path to the build module
|
|
|
|
std::filesystem::path build_module_path = modules_dir / "build.so";
|
|
|
|
|
|
|
|
// Check if the file exists
|
|
|
|
if (!std::filesystem::exists(build_module_path)) {
|
|
|
|
dpm_log(LOG_ERROR, ("Build module not found at: " + build_module_path.string()).c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the module
|
|
|
|
module_handle = dlopen(build_module_path.c_str(), RTLD_LAZY);
|
|
|
|
if (!module_handle) {
|
|
|
|
dpm_log(LOG_ERROR, ("Failed to load build module: " + std::string(dlerror())).c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear any error
|
|
|
|
dlerror();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2025-03-27 04:14:47 +00:00
|
|
|
int cmd_checksum(int argc, char** argv) {
|
|
|
|
// Parse command line arguments
|
|
|
|
bool all_packages = false;
|
|
|
|
std::string package_name = "";
|
|
|
|
bool verbose = false;
|
|
|
|
bool show_help = false;
|
|
|
|
|
|
|
|
// Process command-line arguments
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
std::string arg = argv[i];
|
|
|
|
|
|
|
|
if (arg == "-a" || arg == "--all") {
|
|
|
|
all_packages = true;
|
|
|
|
} else if (arg == "-p" || arg == "--package") {
|
|
|
|
if (i + 1 < argc) {
|
|
|
|
package_name = argv[i + 1];
|
|
|
|
i++; // Skip the next argument
|
|
|
|
}
|
|
|
|
} else if (arg == "-v" || arg == "--verbose") {
|
|
|
|
verbose = true;
|
|
|
|
} else if (arg == "-h" || arg == "--help" || arg == "help") {
|
|
|
|
show_help = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If help was requested, show it and return
|
|
|
|
if (show_help) {
|
|
|
|
dpm_con(LOG_INFO, "Usage: dpm verify checksum [options]");
|
|
|
|
dpm_con(LOG_INFO, "");
|
|
|
|
dpm_con(LOG_INFO, "Verifies the checksums of installed packages.");
|
|
|
|
dpm_con(LOG_INFO, "");
|
|
|
|
dpm_con(LOG_INFO, "Options:");
|
|
|
|
dpm_con(LOG_INFO, " -a, --all Verify all installed packages");
|
|
|
|
dpm_con(LOG_INFO, " -p, --package NAME Verify a specific package");
|
|
|
|
dpm_con(LOG_INFO, " -v, --verbose Enable verbose output");
|
|
|
|
dpm_con(LOG_INFO, " -h, --help Display this help message");
|
|
|
|
dpm_con(LOG_INFO, "");
|
|
|
|
dpm_con(LOG_INFO, "Examples:");
|
|
|
|
dpm_con(LOG_INFO, " dpm verify checksum --all");
|
|
|
|
dpm_con(LOG_INFO, " dpm verify checksum --package=mypackage");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set verbose logging if requested
|
|
|
|
if (verbose) {
|
|
|
|
dpm_set_logging_level(LOG_DEBUG);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate that either all packages or a specific package is specified
|
|
|
|
if (!all_packages && package_name.empty()) {
|
|
|
|
dpm_con(LOG_ERROR, "Either --all or --package must be specified");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate that both all packages and a specific package are not specified
|
|
|
|
if (all_packages && !package_name.empty()) {
|
|
|
|
dpm_con(LOG_ERROR, "Cannot specify both --all and --package");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Placeholder implementation
|
|
|
|
if (all_packages) {
|
|
|
|
dpm_con(LOG_INFO, "Verifying checksums for all installed packages...");
|
|
|
|
dpm_con(LOG_INFO, "Not yet implemented.");
|
|
|
|
} else {
|
|
|
|
dpm_con(LOG_INFO, ("Verifying checksums for package: " + package_name).c_str());
|
|
|
|
dpm_con(LOG_INFO, "Not yet implemented.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmd_signature(int argc, char** argv) {
|
|
|
|
// Parse command line arguments
|
|
|
|
bool all_packages = false;
|
|
|
|
std::string package_name = "";
|
|
|
|
bool verbose = false;
|
|
|
|
bool show_help = false;
|
|
|
|
|
|
|
|
// Process command-line arguments
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
std::string arg = argv[i];
|
|
|
|
|
|
|
|
if (arg == "-a" || arg == "--all") {
|
|
|
|
all_packages = true;
|
|
|
|
} else if (arg == "-p" || arg == "--package") {
|
|
|
|
if (i + 1 < argc) {
|
|
|
|
package_name = argv[i + 1];
|
|
|
|
i++; // Skip the next argument
|
|
|
|
}
|
|
|
|
} else if (arg == "-v" || arg == "--verbose") {
|
|
|
|
verbose = true;
|
|
|
|
} else if (arg == "-h" || arg == "--help" || arg == "help") {
|
|
|
|
show_help = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If help was requested, show it and return
|
|
|
|
if (show_help) {
|
|
|
|
dpm_con(LOG_INFO, "Usage: dpm verify signature [options]");
|
|
|
|
dpm_con(LOG_INFO, "");
|
|
|
|
dpm_con(LOG_INFO, "Verifies the signatures of installed packages.");
|
|
|
|
dpm_con(LOG_INFO, "");
|
|
|
|
dpm_con(LOG_INFO, "Options:");
|
|
|
|
dpm_con(LOG_INFO, " -a, --all Verify all installed packages");
|
|
|
|
dpm_con(LOG_INFO, " -p, --package NAME Verify a specific package");
|
|
|
|
dpm_con(LOG_INFO, " -v, --verbose Enable verbose output");
|
|
|
|
dpm_con(LOG_INFO, " -h, --help Display this help message");
|
|
|
|
dpm_con(LOG_INFO, "");
|
|
|
|
dpm_con(LOG_INFO, "Examples:");
|
|
|
|
dpm_con(LOG_INFO, " dpm verify signature --all");
|
|
|
|
dpm_con(LOG_INFO, " dpm verify signature --package=mypackage");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set verbose logging if requested
|
|
|
|
if (verbose) {
|
|
|
|
dpm_set_logging_level(LOG_DEBUG);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate that either all packages or a specific package is specified
|
|
|
|
if (!all_packages && package_name.empty()) {
|
|
|
|
dpm_con(LOG_ERROR, "Either --all or --package must be specified");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate that both all packages and a specific package are not specified
|
|
|
|
if (all_packages && !package_name.empty()) {
|
|
|
|
dpm_con(LOG_ERROR, "Cannot specify both --all and --package");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Placeholder implementation
|
|
|
|
if (all_packages) {
|
|
|
|
dpm_con(LOG_INFO, "Verifying signatures for all installed packages...");
|
|
|
|
dpm_con(LOG_INFO, "Not yet implemented.");
|
|
|
|
} else {
|
|
|
|
dpm_con(LOG_INFO, ("Verifying signatures for package: " + package_name).c_str());
|
|
|
|
dpm_con(LOG_INFO, "Not yet implemented.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmd_help(int argc, char** argv) {
|
|
|
|
dpm_con(LOG_INFO, "DPM Verify Module - Verifies the integrity and signatures of installed packages.");
|
|
|
|
dpm_con(LOG_INFO, "");
|
|
|
|
dpm_con(LOG_INFO, "Available commands:");
|
|
|
|
dpm_con(LOG_INFO, "");
|
|
|
|
dpm_con(LOG_INFO, " checksum - Verify checksums of installed packages");
|
|
|
|
dpm_con(LOG_INFO, " signature - Verify signatures of installed packages");
|
|
|
|
dpm_con(LOG_INFO, " help - Display this help message");
|
|
|
|
dpm_con(LOG_INFO, "");
|
|
|
|
dpm_con(LOG_INFO, "Usage: dpm verify <command>");
|
|
|
|
dpm_con(LOG_INFO, "");
|
|
|
|
dpm_con(LOG_INFO, "For command-specific help, use: dpm verify <command> --help");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmd_unknown(const char* command, int argc, char** argv) {
|
|
|
|
std::string msg = "Unknown command: ";
|
|
|
|
msg += (command ? command : "");
|
|
|
|
dpm_con(LOG_WARN, msg.c_str());
|
|
|
|
dpm_con(LOG_WARN, "Run 'dpm verify help' for a list of available commands");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Command parse_command(const char* cmd_str) {
|
|
|
|
if (cmd_str == nullptr || strlen(cmd_str) == 0) {
|
|
|
|
return CMD_HELP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(cmd_str, "help") == 0) {
|
|
|
|
return CMD_HELP;
|
|
|
|
}
|
|
|
|
else if (strcmp(cmd_str, "checksum") == 0) {
|
|
|
|
return CMD_CHECKSUM;
|
|
|
|
}
|
|
|
|
else if (strcmp(cmd_str, "signature") == 0) {
|
|
|
|
return CMD_SIGNATURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CMD_UNKNOWN;
|
|
|
|
}
|