static boolean peer_recv_callback(rdpTransport* transport, STREAM* s, void* extra) { rdpPeer* peer = (rdpPeer*) extra; switch (peer->rdp->state) { case CONNECTION_STATE_INITIAL: if (!rdp_server_accept_nego(peer->rdp, s)) return False; break; case CONNECTION_STATE_NEGO: if (!rdp_server_accept_mcs_connect_initial(peer->rdp, s)) return False; break; case CONNECTION_STATE_MCS_CONNECT: if (!rdp_server_accept_mcs_erect_domain_request(peer->rdp, s)) return False; break; case CONNECTION_STATE_MCS_ERECT_DOMAIN: if (!rdp_server_accept_mcs_attach_user_request(peer->rdp, s)) return False; break; case CONNECTION_STATE_MCS_ATTACH_USER: if (!rdp_server_accept_mcs_channel_join_request(peer->rdp, s)) return False; break; case CONNECTION_STATE_MCS_CHANNEL_JOIN: if (!rdp_server_accept_client_info(peer->rdp, s)) return False; break; case CONNECTION_STATE_LICENSE: if (!rdp_server_accept_confirm_active(peer->rdp, s)) return False; break; case CONNECTION_STATE_ACTIVE: if (!peer_recv_pdu(peer, s)) return False; break; default: printf("Invalid state %d\n", peer->rdp->state); return False; } return True; }
static int peer_recv_tpkt_pdu(freerdp_peer* client, wStream* s) { rdpRdp* rdp; UINT16 length; UINT16 pduType; UINT16 pduLength; UINT16 pduSource; UINT16 channelId; UINT16 securityFlags = 0; rdp = client->context->rdp; if (!rdp_read_header(rdp, s, &length, &channelId)) { WLog_ERR(TAG, "Incorrect RDP header."); return -1; } if (freerdp_shall_disconnect(rdp->instance)) return 0; if (rdp->settings->UseRdpSecurityLayer) { if (!rdp_read_security_header(s, &securityFlags)) return -1; if (securityFlags & SEC_ENCRYPT) { if (!rdp_decrypt(rdp, s, length - 4, securityFlags)) { WLog_ERR(TAG, "rdp_decrypt failed"); return -1; } } } if (channelId == MCS_GLOBAL_CHANNEL_ID) { if (!rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource)) return -1; client->settings->PduSource = pduSource; switch (pduType) { case PDU_TYPE_DATA: if (!peer_recv_data_pdu(client, s)) return -1; break; case PDU_TYPE_CONFIRM_ACTIVE: if (!rdp_server_accept_confirm_active(rdp, s)) return -1; break; case PDU_TYPE_FLOW_RESPONSE: case PDU_TYPE_FLOW_STOP: case PDU_TYPE_FLOW_TEST: break; default: WLog_ERR(TAG, "Client sent pduType %"PRIu16"", pduType); return -1; } } else if (rdp->mcs->messageChannelId && channelId == rdp->mcs->messageChannelId) { if (!rdp->settings->UseRdpSecurityLayer) if (!rdp_read_security_header(s, &securityFlags)) return -1; return rdp_recv_message_channel_pdu(rdp, s, securityFlags); } else { if (!freerdp_channel_peer_process(client, s, channelId)) return -1; } return 0; }
static int peer_recv_callback(rdpTransport* transport, wStream* s, void* extra) { freerdp_peer* client = (freerdp_peer*) extra; rdpRdp* rdp = client->context->rdp; switch (rdp->state) { case CONNECTION_STATE_INITIAL: if (!rdp_server_accept_nego(rdp, s)) return -1; if (rdp->nego->selected_protocol & PROTOCOL_NLA) { sspi_CopyAuthIdentity(&client->identity, &(rdp->nego->transport->credssp->identity)); IFCALLRET(client->Logon, client->authenticated, client, &client->identity, TRUE); credssp_free(rdp->nego->transport->credssp); } else { IFCALLRET(client->Logon, client->authenticated, client, &client->identity, FALSE); } break; case CONNECTION_STATE_NEGO: if (!rdp_server_accept_mcs_connect_initial(rdp, s)) return -1; break; case CONNECTION_STATE_MCS_CONNECT: if (!rdp_server_accept_mcs_erect_domain_request(rdp, s)) return -1; break; case CONNECTION_STATE_MCS_ERECT_DOMAIN: if (!rdp_server_accept_mcs_attach_user_request(rdp, s)) return -1; break; case CONNECTION_STATE_MCS_ATTACH_USER: if (!rdp_server_accept_mcs_channel_join_request(rdp, s)) return -1; break; case CONNECTION_STATE_MCS_CHANNEL_JOIN: if (rdp->settings->DisableEncryption) { if (!rdp_server_accept_client_keys(rdp, s)) return -1; break; } rdp->state = CONNECTION_STATE_ESTABLISH_KEYS; /* FALLTHROUGH */ case CONNECTION_STATE_ESTABLISH_KEYS: if (!rdp_server_accept_client_info(rdp, s)) return -1; IFCALL(client->Capabilities, client); if (!rdp_send_demand_active(rdp)) return -1; break; case CONNECTION_STATE_LICENSE: if (!rdp_server_accept_confirm_active(rdp, s)) { /** * During reactivation sequence the client might sent some input or channel data * before receiving the Deactivate All PDU. We need to process them as usual. */ stream_set_pos(s, 0); return peer_recv_pdu(client, s); } break; case CONNECTION_STATE_ACTIVE: if (peer_recv_pdu(client, s) < 0) return -1; break; default: fprintf(stderr, "Invalid state %d\n", rdp->state); return -1; } return 0; }
static int peer_recv_tpkt_pdu(freerdp_peer* client, wStream* s) { rdpRdp* rdp; UINT16 length; UINT16 pduType; UINT16 pduLength; UINT16 pduSource; UINT16 channelId; UINT16 securityFlags; rdp = client->context->rdp; if (!rdp_read_header(rdp, s, &length, &channelId)) { DEBUG_WARN( "Incorrect RDP header.\n"); return -1; } if (rdp->settings->DisableEncryption) { if (!rdp_read_security_header(s, &securityFlags)) return -1; if (securityFlags & SEC_ENCRYPT) { if (!rdp_decrypt(rdp, s, length - 4, securityFlags)) { DEBUG_WARN( "rdp_decrypt failed\n"); return -1; } } } if (channelId != MCS_GLOBAL_CHANNEL_ID) { if (!freerdp_channel_peer_process(client, s, channelId)) return -1; } else { if (!rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource)) return -1; client->settings->PduSource = pduSource; switch (pduType) { case PDU_TYPE_DATA: if (!peer_recv_data_pdu(client, s)) return -1; break; case PDU_TYPE_CONFIRM_ACTIVE: if (!rdp_server_accept_confirm_active(rdp, s)) return -1; break; default: DEBUG_WARN( "Client sent pduType %d\n", pduType); return -1; } } return 0; }