Skip to content

Commit

Permalink
RdpNegociation::get_license: propagate no license packet to parent
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpoelen committed Oct 23, 2023
1 parent 3820b72 commit 84a75f5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
11 changes: 8 additions & 3 deletions src/core/RDP/tpdu_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace Extractors

struct X224Extractor
{
HeaderResult read_header(Buf64k & buf)
HeaderResult read_header(Buf64k const & buf)
{
// fast path header occupies 2 or 3 octets, but assume then data len at least 2 octets.
if (buf.remaining() < 4)
Expand Down Expand Up @@ -175,7 +175,7 @@ namespace Extractors

struct CreedsppExtractor
{
static HeaderResult read_header(Buf64k & buf)
static HeaderResult read_header(Buf64k const & buf)
{
if (buf.remaining() < 4)
{
Expand Down Expand Up @@ -280,6 +280,11 @@ struct TpduBuffer
this->pdu_len = 0;
}

void rewind_current_packet() noexcept
{
this->pdu_len = 0;
}

private:
enum class StateRead : bool
{
Expand All @@ -289,7 +294,7 @@ struct TpduBuffer

struct Extractor // Extractor concept
{
Extractors::HeaderResult read_header(Buf64k& buf);
Extractors::HeaderResult read_header(Buf64k const &);
void check_data(Buf64k const &) const;
};

Expand Down
4 changes: 2 additions & 2 deletions src/core/RDP/x224.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,8 @@ namespace X224
}

uint8_t LI = stream.in_uint8();
uint8_t code = stream.in_uint8();
if (!(code == X224::DT_TPDU)){
uint8_t code = stream.in_uint8();
if (code != X224::DT_TPDU){
LOG(LOG_ERR, "Unexpected TPDU opcode, expected DT_TPDU, got %u", code);
throw Error(ERR_X224);
}
Expand Down
5 changes: 5 additions & 0 deletions src/core/buf64k.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ struct BasicStaticBuffer
return writable_bytes_view{this->buf + this->idx, this->remaining()};
}

[[nodiscard]] bytes_view av() const noexcept
{
return {this->buf + this->idx, this->remaining()};
}

writable_bytes_view av(std::size_t n) noexcept
{
assert(n <= this->remaining());
Expand Down
8 changes: 4 additions & 4 deletions src/mod/rdp/rdp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3090,7 +3090,7 @@ class mod_rdp : public mod_api, public rdp_api, public sespro_api
}
case WAITING_SYNCHRONIZE:
LOG_IF(bool(this->verbose & RDPVerbose::basic_trace),
LOG_WARNING, "WAITING_SYNCHRONIZE");
LOG_INFO, "WAITING_SYNCHRONIZE");

{
ShareData_Recv sdata(sctrl.payload, &this->mppc_dec);
Expand Down Expand Up @@ -3149,7 +3149,7 @@ class mod_rdp : public mod_api, public rdp_api, public sespro_api
break;
case WAITING_CTL_COOPERATE:
LOG_IF(bool(this->verbose & RDPVerbose::basic_trace),
LOG_WARNING, "WAITING_CTL_COOPERATE");
LOG_INFO, "WAITING_CTL_COOPERATE");
this->connection_finalization_state = WAITING_GRANT_CONTROL_COOPERATE;
{
ShareData_Recv sdata(sctrl.payload, &this->mppc_dec);
Expand All @@ -3159,7 +3159,7 @@ class mod_rdp : public mod_api, public rdp_api, public sespro_api
break;
case WAITING_GRANT_CONTROL_COOPERATE:
LOG_IF(bool(this->verbose & RDPVerbose::basic_trace),
LOG_WARNING, "WAITING_GRANT_CONTROL_COOPERATE");
LOG_INFO, "WAITING_GRANT_CONTROL_COOPERATE");
this->connection_finalization_state = WAITING_FONT_MAP;
{
ShareData_Recv sdata(sctrl.payload, &this->mppc_dec);
Expand All @@ -3169,7 +3169,7 @@ class mod_rdp : public mod_api, public rdp_api, public sespro_api
break;
case WAITING_FONT_MAP:
LOG_IF(bool(this->verbose & RDPVerbose::basic_trace),
LOG_WARNING, "PDUTYPE2_FONTMAP");
LOG_INFO, "PDUTYPE2_FONTMAP");
this->connection_finalization_state = UP_AND_RUNNING;

if (!this->deactivation_reactivation_in_progress) {
Expand Down
8 changes: 3 additions & 5 deletions src/mod/rdp/rdp_negociation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ bool RdpNegociation::recv_data(TpduBuffer& buf)
}
break;
default:
if (this->get_license(x224_data)) {
if (this->get_license(x224_data, buf)) {
this->state = State::TERMINATED;
return true;
}
Expand Down Expand Up @@ -1143,7 +1143,7 @@ bool RdpNegociation::channel_join_confirm(InStream & x224_data)
return true;
}

bool RdpNegociation::get_license(InStream & stream)
bool RdpNegociation::get_license(InStream & stream, TpduBuffer& buf)
{
LOG_IF(bool(this->verbose & RDPVerbose::license), LOG_INFO, "RdpNegociation: Licensing");

Expand Down Expand Up @@ -1489,10 +1489,8 @@ bool RdpNegociation::get_license(InStream & stream)
}
else {
LOG(LOG_WARNING, "RdpNegociation: Failed to get expected license negotiation PDU. sec.flags=0x%X", sec.flags);
hexdump(x224.payload.get_data(), x224.payload.get_capacity());
//throw Error(ERR_SEC);
buf.rewind_current_packet();
r = true;
hexdump(sec.payload.get_data(), sec.payload.get_capacity());
}
return r;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mod/rdp/rdp_negociation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class RdpNegociation
void send_connectInitialPDUwithGccConferenceCreateRequest();
bool channel_connection_attach_user(InStream & stream);
bool channel_join_confirm(InStream & x224_data);
bool get_license(InStream & stream);
bool get_license(InStream & stream, TpduBuffer& buf);

template<class... WriterData>
void send_data_request(uint16_t channelId, WriterData... writer_data);
Expand Down

0 comments on commit 84a75f5

Please sign in to comment.