BUGFIX: correct issue where a completely incorrectly formatted identity table missing the appropriate number of entities would cause a startup crash; minor formatting cleanups for readability;

4.31h_maint
Bryan Biedenkapp 8 months ago
parent 9fe90d3238
commit fcdec00f32

@ -130,6 +130,12 @@ bool IdenTableLookup::load()
if (!next.empty())
parsed.push_back(next);
// ensure we have at least 5 fields
if (parsed.size() < 5) {
LogError(LOG_HOST, "Invalid entry in identity table lookup file - %s", line.c_str());
continue;
}
// parse tokenized line
uint8_t channelId = (uint8_t)::atoi(parsed[0].c_str());
uint32_t baseFrequency = (uint32_t)::atoi(parsed[1].c_str());

@ -228,30 +228,30 @@ bool PeerListLookup::load()
// parse tokenized line
uint32_t id = ::atoi(parsed[0].c_str());
// Parse optional alias field (at end of line to avoid breaking change with existing lists)
// parse optional alias field (at end of line to avoid breaking change with existing lists)
std::string alias = "";
if (parsed.size() >= 4)
alias = parsed[3].c_str();
// Parse peer link flag
// parse peer link flag
bool peerLink = false;
if (parsed.size() >= 3)
peerLink = ::atoi(parsed[2].c_str()) == 1;
// Parse can request keys flag
// parse can request keys flag
bool canRequestKeys = false;
if (parsed.size() >= 5)
canRequestKeys = ::atoi(parsed[4].c_str()) == 1;
// Parse optional password
// parse optional password
std::string password = "";
if (parsed.size() >= 2)
password = parsed[1].c_str();
// Load into table
// load into table
m_table[id] = PeerId(id, alias, password, peerLink, canRequestKeys, false);
// Log depending on what was loaded
// log depending on what was loaded
LogMessage(LOG_HOST, "Loaded peer ID %u%s into peer ID lookup table, %s%s%s", id,
(!alias.empty() ? (" (" + alias + ")").c_str() : ""),
(!password.empty() ? "using unique peer password" : "using master password"),
@ -296,43 +296,46 @@ bool PeerListLookup::save()
std::string line;
// iterate over each entry in the RID lookup and write it to the open file
for (auto& entry: m_table) {
// Get the parameters
// get the parameters
uint32_t peerId = entry.first;
std::string alias = entry.second.peerAlias();
std::string password = entry.second.peerPassword();
// Format into a string
// format into a string
line = std::to_string(peerId) + ",";
// Add the password if we have one
// add the password if we have one
if (password.length() > 0) {
line += password;
}
line += ",";
// Add peerLink flag
// add peerLink flag
bool peerLink = entry.second.peerLink();
if (peerLink) {
line += "1,";
} else {
line += "0,";
}
// Add alias if we have one
// add alias if we have one
if (alias.length() > 0) {
line += alias;
line += ",";
} else {
line += ",";
}
// Add canRequestKeys flag
// add canRequestKeys flag
bool canRequestKeys = entry.second.canRequestKeys();
if (canRequestKeys) {
line += "1,";
} else {
line += "0,";
}
// Add the newline
line += "\n";
// Write to file
file << line;
// Increment
lines++;
}

@ -209,6 +209,12 @@ bool RadioIdLookup::load()
if (!next.empty())
parsed.push_back(next);
// ensure we have at least 2 fields
if (parsed.size() < 2) {
LogError(LOG_HOST, "Invalid entry in radio ID lookup table - %s", line.c_str());
continue;
}
// parse tokenized line
uint32_t id = ::atoi(parsed[0].c_str());
bool radioEnabled = ::atoi(parsed[1].c_str()) == 1;
@ -267,34 +273,29 @@ bool RadioIdLookup::save()
// iterate over each entry in the RID lookup and write it to the open file
for (auto& entry: m_table) {
// Get the parameters
// get the parameters
uint32_t rid = entry.first;
bool enabled = entry.second.radioEnabled();
std::string alias = entry.second.radioAlias();
std::string ipAddress = entry.second.radioIPAddress();
// Format into a string
// format into a string
line = std::to_string(rid) + "," + std::to_string(enabled) + ",";
// Add the alias if we have one
// add the alias if we have one
if (alias.length() > 0) {
line += alias;
line += ",";
}
// Add the IP address if we have one
// add the IP address if we have one
if (ipAddress.length() > 0) {
line += ipAddress;
line += ",";
}
// Add the newline
line += "\n";
// Write to file
file << line;
// Increment
lines++;
}

@ -205,15 +205,16 @@ int HostSetup::run(int argc, char** argv)
}
g_logDisplayLevel = 0U;
LogInfo("Iden Table Lookups");
LogInfo(" File: %s", idenLookupFile.length() > 0U ? idenLookupFile.c_str() : "None");
if (idenReloadTime > 0U)
LogInfo(" Reload: %u mins", idenReloadTime);
g_logDisplayLevel = 1U;
m_idenTable = new IdenTableLookup(idenLookupFile, idenReloadTime);
m_idenTable->read();
g_logDisplayLevel = 0U;
LogInfo("General Parameters");
std::string identity = systemConf["identity"].as<std::string>();

Loading…
Cancel
Save

Powered by TurnKey Linux.