server now rejects clients that are not in the configuration.
added a protocol message to indicate this.
This commit is contained in:
parent
1e8a5d7fa9
commit
793c968f00
|
@ -294,6 +294,10 @@ void CClient::runSession(void*)
|
|||
onErrorBusy();
|
||||
break;
|
||||
}
|
||||
else if (memcmp(code, kMsgEUnknown, 4) == 0) {
|
||||
onErrorUnknown();
|
||||
break;
|
||||
}
|
||||
else if (memcmp(code, kMsgEBad, 4) == 0) {
|
||||
onErrorBad();
|
||||
break;
|
||||
|
@ -606,6 +610,11 @@ void CClient::onErrorBusy()
|
|||
log((CLOG_ERR "server already has a connected client with name \"%s\"", m_name.c_str()));
|
||||
}
|
||||
|
||||
void CClient::onErrorUnknown()
|
||||
{
|
||||
log((CLOG_ERR "server refused client with name \"%s\"", m_name.c_str()));
|
||||
}
|
||||
|
||||
void CClient::onErrorBad()
|
||||
{
|
||||
log((CLOG_ERR "server disconnected due to a protocol error"));
|
||||
|
|
|
@ -53,6 +53,7 @@ private:
|
|||
void onMouseWheel();
|
||||
void onErrorIncompatible();
|
||||
void onErrorBusy();
|
||||
void onErrorUnknown();
|
||||
void onErrorBad();
|
||||
|
||||
private:
|
||||
|
|
|
@ -992,6 +992,11 @@ void CServer::handshakeClient(void* vsocket)
|
|||
log((CLOG_WARN "a client with name \"%s\" is already connected", e.getName().c_str()));
|
||||
CProtocolUtil::writef(output.get(), kMsgEBusy);
|
||||
}
|
||||
catch (XUnknownClient& e) {
|
||||
// client has unknown name
|
||||
log((CLOG_WARN "a client with name \"%s\" is not in the map", e.getName().c_str()));
|
||||
CProtocolUtil::writef(output.get(), kMsgEUnknown);
|
||||
}
|
||||
catch (XIncompatibleClient& e) {
|
||||
// client is incompatible
|
||||
// FIXME -- could print network address if socket had suitable method
|
||||
|
@ -1278,7 +1283,10 @@ CServer::CScreenInfo* CServer::addConnection(
|
|||
throw XDuplicateClient(name);
|
||||
}
|
||||
|
||||
// FIXME -- throw if the name is not in our map
|
||||
// name must be in our configuration
|
||||
if (!m_config.isScreen(name)) {
|
||||
throw XUnknownClient(name);
|
||||
}
|
||||
|
||||
// save screen info
|
||||
CScreenInfo* newScreen = new CScreenInfo(name, protocol);
|
||||
|
|
|
@ -131,6 +131,11 @@ static const char kMsgEIncompatible[] = "EICV%2i%2i";
|
|||
// name provided when connecting is already in use: primary -> secondary
|
||||
static const char kMsgEBusy[] = "EBSY";
|
||||
|
||||
// unknown client: primary -> secondary
|
||||
// name provided when connecting is not in primary's screen
|
||||
// configuration map.
|
||||
static const char kMsgEUnknown[] = "EUNK";
|
||||
|
||||
// protocol violation: primary -> secondary
|
||||
// primary should disconnect after sending this message.
|
||||
static const char kMsgEBad[] = "EBAD";
|
||||
|
|
|
@ -55,3 +55,23 @@ CString XDuplicateClient::getWhat() const throw()
|
|||
{
|
||||
return "XDuplicateClient";
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// XUnknownClient
|
||||
//
|
||||
|
||||
XUnknownClient::XUnknownClient(const CString& name) : m_name(name)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
const CString& XUnknownClient::getName() const throw()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
CString XUnknownClient::getWhat() const throw()
|
||||
{
|
||||
return "XUnknownClient";
|
||||
}
|
||||
|
|
|
@ -50,4 +50,23 @@ private:
|
|||
CString m_name;
|
||||
};
|
||||
|
||||
// client has unknown name (i.e. name is not in server's screen map)
|
||||
class XUnknownClient : public XSynergy {
|
||||
public:
|
||||
XUnknownClient(const CString& name);
|
||||
|
||||
// manipulators
|
||||
|
||||
// accessors
|
||||
|
||||
virtual const CString&
|
||||
getName() const throw();
|
||||
|
||||
protected:
|
||||
virtual CString getWhat() const throw();
|
||||
|
||||
private:
|
||||
CString m_name;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue