From eb5150a002a4aca1bd0406859ec37a82ebd1ecae Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Sun, 12 Jul 2020 03:05:51 +0200 Subject: [PATCH] Cedar: change ProtoHandleConnection() so that it supports direct protocol specification --- src/Cedar/Connection.c | 2 +- src/Cedar/Proto.c | 27 +++++++++++++++++++++------ src/Cedar/Proto.h | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Cedar/Connection.c b/src/Cedar/Connection.c index d105ef12..be0262d6 100644 --- a/src/Cedar/Connection.c +++ b/src/Cedar/Connection.c @@ -2936,7 +2936,7 @@ void ConnectionAccept(CONNECTION *c) if (c->Cedar != NULL && c->Cedar->Server != NULL) { PROTO *proto = c->Cedar->Server->Proto; - if (proto && ProtoHandleConnection(proto, s) == true) + if (proto && ProtoHandleConnection(proto, s, NULL) == true) { c->Type = CONNECTION_TYPE_OTHER; goto FINAL; diff --git a/src/Cedar/Proto.c b/src/Cedar/Proto.c index 2c59f371..ecaa25cb 100644 --- a/src/Cedar/Proto.c +++ b/src/Cedar/Proto.c @@ -309,10 +309,10 @@ bool ProtoSetUdpPorts(PROTO *proto, const LIST *ports) return true; } -bool ProtoHandleConnection(PROTO *proto, SOCK *sock) +bool ProtoHandleConnection(PROTO *proto, SOCK *sock, const char *protocol) { + const PROTO_IMPL *impl = NULL; void *impl_data = NULL; - const PROTO_IMPL *impl; UCHAR *buf; TCP_RAW_DATA *recv_raw_data; @@ -325,6 +325,20 @@ bool ProtoHandleConnection(PROTO *proto, SOCK *sock) return false; } + if (protocol != NULL) + { + UINT i; + for (i = 0; i < LIST_NUM(proto->Impls); ++i) + { + const PROTO_IMPL *tmp = LIST_DATA(proto->Impls, i); + if (StrCmp(tmp->Name(), protocol) == 0) + { + impl = tmp; + break; + } + } + } + else { UCHAR tmp[PROTO_CHECK_BUFFER_SIZE]; if (Peek(sock, tmp, sizeof(tmp)) == 0) @@ -333,10 +347,11 @@ bool ProtoHandleConnection(PROTO *proto, SOCK *sock) } impl = ProtoImplDetect(proto, PROTO_MODE_TCP, tmp, sizeof(tmp)); - if (impl == NULL) - { - return false; - } + } + + if (impl == NULL) + { + return false; } im = NewInterruptManager(); diff --git a/src/Cedar/Proto.h b/src/Cedar/Proto.h index b9b946f2..b82bb7bf 100644 --- a/src/Cedar/Proto.h +++ b/src/Cedar/Proto.h @@ -68,7 +68,7 @@ void ProtoDeleteSession(PROTO_SESSION *session); bool ProtoSetListenIP(PROTO *proto, const IP *ip); bool ProtoSetUdpPorts(PROTO *proto, const LIST *ports); -bool ProtoHandleConnection(PROTO *proto, SOCK *sock); +bool ProtoHandleConnection(PROTO *proto, SOCK *sock, const char *protocol); void ProtoHandleDatagrams(UDPLISTENER *listener, LIST *datagrams); void ProtoSessionThread(THREAD *thread, void *param);