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();
|
onErrorBusy();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else if (memcmp(code, kMsgEUnknown, 4) == 0) {
|
||||||
|
onErrorUnknown();
|
||||||
|
break;
|
||||||
|
}
|
||||||
else if (memcmp(code, kMsgEBad, 4) == 0) {
|
else if (memcmp(code, kMsgEBad, 4) == 0) {
|
||||||
onErrorBad();
|
onErrorBad();
|
||||||
break;
|
break;
|
||||||
|
@ -606,6 +610,11 @@ void CClient::onErrorBusy()
|
||||||
log((CLOG_ERR "server already has a connected client with name \"%s\"", m_name.c_str()));
|
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()
|
void CClient::onErrorBad()
|
||||||
{
|
{
|
||||||
log((CLOG_ERR "server disconnected due to a protocol error"));
|
log((CLOG_ERR "server disconnected due to a protocol error"));
|
||||||
|
|
|
@ -53,6 +53,7 @@ private:
|
||||||
void onMouseWheel();
|
void onMouseWheel();
|
||||||
void onErrorIncompatible();
|
void onErrorIncompatible();
|
||||||
void onErrorBusy();
|
void onErrorBusy();
|
||||||
|
void onErrorUnknown();
|
||||||
void onErrorBad();
|
void onErrorBad();
|
||||||
|
|
||||||
private:
|
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()));
|
log((CLOG_WARN "a client with name \"%s\" is already connected", e.getName().c_str()));
|
||||||
CProtocolUtil::writef(output.get(), kMsgEBusy);
|
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) {
|
catch (XIncompatibleClient& e) {
|
||||||
// client is incompatible
|
// client is incompatible
|
||||||
// FIXME -- could print network address if socket had suitable method
|
// FIXME -- could print network address if socket had suitable method
|
||||||
|
@ -1278,7 +1283,10 @@ CServer::CScreenInfo* CServer::addConnection(
|
||||||
throw XDuplicateClient(name);
|
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
|
// save screen info
|
||||||
CScreenInfo* newScreen = new CScreenInfo(name, protocol);
|
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
|
// name provided when connecting is already in use: primary -> secondary
|
||||||
static const char kMsgEBusy[] = "EBSY";
|
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
|
// protocol violation: primary -> secondary
|
||||||
// primary should disconnect after sending this message.
|
// primary should disconnect after sending this message.
|
||||||
static const char kMsgEBad[] = "EBAD";
|
static const char kMsgEBad[] = "EBAD";
|
||||||
|
|
|
@ -55,3 +55,23 @@ CString XDuplicateClient::getWhat() const throw()
|
||||||
{
|
{
|
||||||
return "XDuplicateClient";
|
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;
|
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
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue