allow the old style suid hashing in login server

This commit is contained in:
DarthArgus
2017-01-03 22:20:26 -06:00
parent 365ea61813
commit 11fc9a7564
6 changed files with 2021 additions and 2302 deletions
@@ -152,11 +152,13 @@ void ClientConnection::onReceive(const Archive::ByteStream &message) {
// originally was used to validate station API credentials, now uses our custom api
void ClientConnection::validateClient(const std::string &id, const std::string &key) {
bool authOK = false;
bool testMode = false;
static const std::string authURL(ConfigLoginServer::getExternalAuthUrl());
std::string uname;
std::string parentAccount;
std::string sessionID;
StationId user_id;
StationId parent_id;
std::unordered_map<int, std::string> childAccounts;
@@ -181,8 +183,21 @@ void ClientConnection::validateClient(const std::string &id, const std::string &
parentAccount = api.getString("mainAccount");
childAccounts = api.getStringMap("subAccounts");
user_id = static_cast<StationId>(api.getNullableValue<int>("user_id"));
parent_id = static_cast<StationId>(api.getNullableValue<int>("parent_id"));
if (!ConfigLoginServer::getUseOldSuidGenerator()) {
user_id = static_cast<StationId>(api.getNullableValue<int>("user_id"));
parent_id = static_cast<StationId>(api.getNullableValue<int>("parent_id"));
} else {
if (parentAccount.length() > MAX_ACCOUNT_NAME_LENGTH) {
parentAccount.resize(MAX_ACCOUNT_NAME_LENGTH);
}
if (uname.length() > MAX_ACCOUNT_NAME_LENGTH) {
uname.resize(MAX_ACCOUNT_NAME_LENGTH);
}
parent_id = std::hash<std::string>{}(parentAccount.c_str());
user_id = std::hash<std::string>{}(uname.c_str());
}
} else {
std::string msg(api.getString("message"));
if (msg.empty()) {
@@ -199,10 +214,19 @@ void ClientConnection::validateClient(const std::string &id, const std::string &
} else {
// test mode
authOK = true;
testMode = true;
uname = id;
if (uname.length() > MAX_ACCOUNT_NAME_LENGTH) {
uname.resize(MAX_ACCOUNT_NAME_LENGTH);
}
user_id = std::hash<std::string>{}(uname.c_str());
}
if (authOK) {
m_stationId = user_id;
if (authOK && !testMode) {
REPORT_LOG(true, ("Client connected. Username: %s (%i) \n", uname.c_str(), user_id));
if (!parentAccount.empty()) {
@@ -217,24 +241,33 @@ void ClientConnection::validateClient(const std::string &id, const std::string &
StationId child_id = static_cast<StationId>(i.first);
std::string child(i.second);
if (!child.empty()) {
REPORT_LOG((parent_id !=
child_id), ("\tchild of %s (%i) is %s (%i) \n", parentAccount.c_str(), parent_id, child.c_str(), child_id));
if (!child.empty() && i.first > 0) {
if (ConfigLoginServer::getUseOldSuidGenerator()) {
if (child.length() > MAX_ACCOUNT_NAME_LENGTH) {
child.resize(MAX_ACCOUNT_NAME_LENGTH);
}
child_id = std::hash<std::string>{}(child.c_str());
}
REPORT_LOG((parent_id != child_id), ("\tchild of %s (%i) is %s (%i) \n", parentAccount.c_str(), parent_id, child.c_str(), child_id));
// insert all related accounts, if not already there, into the db
if (parent_id != child_id) {
DatabaseConnection::getInstance().upsertAccountRelationship(parent_id, child_id);
}
} else {
WARNING(true, ("Login API returned empty child account(s)."));
}
} else {
WARNING(true, ("Login API returned empty child account(s)."));
}
}
LOG("LoginClientConnection", ("validateClient() for stationId (%i) at IP (%s), id (%s)", user_id, getRemoteAddress().c_str(), uname.c_str()));
m_stationId = user_id;
LOG("LoginClientConnection", ("validateClient() for stationId (%i) at IP (%s), id (%s)", user_id, getRemoteAddress().c_str(), uname.c_str()));
if (!testMode) {
LoginServer::getInstance().onValidateClient(m_stationId, uname, this, true, sessionID.c_str(), 0xFFFFFFFF, 0xFFFFFFFF);
} else {
LoginServer::getInstance().onValidateClient(m_stationId, uname, this, true, nullptr, 0xFFFFFFFF, 0xFFFFFFFF);
}
}