Check if client name is correct before starting backup

This commit is contained in:
Martin 2020-03-16 16:15:50 +01:00
parent bc89c88226
commit 49db6344e1
5 changed files with 54 additions and 0 deletions

View File

@ -1098,6 +1098,10 @@ void ClientConnector::ReceivePackets(IRunOtherCallback* p_run_other)
{
CMD_ADD_IDENTITY(cmd.substr(13)); continue;
}
else if (cmd=="GET CLIENTNAME")
{
CMD_GET_CLIENTNAME(cmd); continue;
}
}
if(pw_ok) //Commands from client frontend
{

View File

@ -342,6 +342,7 @@ private:
void CMD_RESTORE_OK(str_map &params);
void CMD_CLIENT_ACCESS_KEY(const std::string& cmd);
void CMD_WRITE_TOKENS(const std::string& cmd);
void CMD_GET_CLIENTNAME(const std::string& cmd);
int getCapabilities(IDatabase* db);
bool multipleChannelServers();

View File

@ -2989,4 +2989,10 @@ void ClientConnector::CMD_WRITE_TOKENS(const std::string& cmd)
tcpstack.Send(pipe, "ASYNC-async_id=" + bytesToHex(async_id));
}
void ClientConnector::CMD_GET_CLIENTNAME(const std::string& cmd)
{
std::string name = IndexThread::getFileSrv()->getServerName();
tcpstack.Send(pipe, "name="+EscapeParamString(name));
}

View File

@ -853,6 +853,15 @@ void ClientMain::operator ()(void)
if(backup_queue[i].ticket==ILLEGAL_THREADPOOL_TICKET)
{
can_start=true;
break;
}
}
if (can_start)
{
if (!checkClientName(can_start))
{
break;
}
}
@ -3422,6 +3431,38 @@ void ClientMain::updateVirtualClients()
}
BackupServer::setVirtualClients(clientname, virtual_clients);
}
bool ClientMain::checkClientName(bool& continue_start_backups)
{
if (internet_connection
|| !clientsubname.empty())
return true;
std::string msg = sendClientMessageRetry("GET CLIENTNAME", "Error getting name of client", 10000, 10, false);
if (msg == "ERR")
{
return true;
}
else if (msg.empty())
{
continue_start_backups = false;
return true;
}
str_map msg_params;
ParseParamStrHttp(msg, &msg_params);
if (msg_params["name"] == clientname)
{
return true;
}
else
{
Server->Log("Client name check failed. Expected name is \"" + clientname + "\" got \"" + msg_params["name"] + "\"", LL_WARNING);
return false;
}
}
bool ClientMain::renameClient(const std::string & clientuid)

View File

@ -313,6 +313,8 @@ private:
bool renameClient(const std::string& clientuid);
void updateVirtualClients();
bool checkClientName(bool& continue_start_backups);
struct SPathComponents
{