static tbool rdp_recv_fastpath_pdu(rdpRdp* rdp, STREAM* s) { uint16 length; uint16 securityFlags; rdpFastPath* fastpath; LLOGLN(10, ("rdp_recv_fastpath_pdu:")); LHEXDUMP(10, (s->p, 4)); fastpath = rdp->fastpath; length = fastpath_read_header_rdp(fastpath, s); LLOGLN(10, ("rdp_recv_fastpath_pdu: length %d", length)); if (length == 0 || length > stream_get_left(s)) { LLOGLN(0, ("rdp_recv_fastpath_pdu: incorrect FastPath PDU header length %d", length)); return false; } if (fastpath->encryptionFlags & FASTPATH_OUTPUT_ENCRYPTED) { securityFlags = fastpath->encryptionFlags & FASTPATH_OUTPUT_SECURE_CHECKSUM ? SEC_SECURE_CHECKSUM : 0; rdp_decrypt(rdp, s, length, securityFlags); LLOGLN(10, ("rdp_recv_fastpath_pdu: decrypted data length %d", length)); LHEXDUMP(10, (s->p, length)); } return fastpath_recv_updates(rdp->fastpath, s); }
static int send_message(int code, char *data, int bytes) { char header[8]; pthread_mutex_lock(&g_mutex); SET_UINT32(header, 0, bytes); SET_UINT32(header, 4, code); if (send(g_sck, header, 8, 0) != 8) { pthread_mutex_unlock(&g_mutex); return 1; } if (send(g_sck, data, bytes, 0) != bytes) { pthread_mutex_unlock(&g_mutex); return 1; } LLOGLN(10, ("send_message:")); LHEXDUMP(10, (data, bytes)); pthread_mutex_unlock(&g_mutex); return 0; }
int tls_write(rdpTls* tls, uint8* data, int length) { int status; LLOGLN(10, ("tls_write: int length %d", length)); status = SSL_write(tls->ssl, data, length); LLOGLN(10, ("tls_write: ssl %p SSL_write rv %d", tls->ssl, status)); if (status > 0) { LHEXDUMP(10, (data, status)); return status; } if (status == 0) { return -1; /* disconnected */ } switch (SSL_get_error(tls->ssl, status)) { case SSL_ERROR_NONE: break; case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_WRITE: status = 0; break; default: tls_print_error("SSL_write", tls->ssl, status); status = -1; break; } LLOGLN(10, ("tls_write: out status %d", status)); return status; }
PCSC_API LONG SCardTransmit(SCARDHANDLE hCard, const SCARD_IO_REQUEST *pioSendPci, LPCBYTE pbSendBuffer, DWORD cbSendLength, SCARD_IO_REQUEST *pioRecvPci, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength) { char *msg; int bytes; int code; int offset; int status; int extra_len; int got_recv_pci; LLOGLN(10, ("SCardTransmit:")); if (g_sck == -1) { LLOGLN(0, ("SCardTransmit: error, not connected")); return SCARD_F_INTERNAL_ERROR; } LLOGLN(10, (" hCard 0x%8.8x", (int)hCard)); LLOGLN(10, (" cbSendLength %d", (int)cbSendLength)); LLOGLN(10, (" cbRecvLength %d", (int)*pcbRecvLength)); LLOGLN(10, (" pioSendPci->dwProtocol %d", (int)(pioSendPci->dwProtocol))); LLOGLN(10, (" pioSendPci->cbPciLength %d", (int)(pioSendPci->cbPciLength))); LLOGLN(10, (" pioRecvPci %p", pioRecvPci)); if (pioRecvPci != 0) { LLOGLN(10, (" pioRecvPci->dwProtocol %d", (int)(pioRecvPci->dwProtocol))); LLOGLN(10, (" pioRecvPci->cbPciLength %d", (int)(pioRecvPci->cbPciLength))); } msg = (char *) malloc(8192); offset = 0; SET_UINT32(msg, offset, hCard); offset += 4; SET_UINT32(msg, offset, pioSendPci->dwProtocol); offset += 4; /* SET_UINT32(msg, offset, pioSendPci->cbPciLength); */ SET_UINT32(msg, offset, 8); offset += 4; /* extra_len = pioSendPci->cbPciLength - 8; */ extra_len = 0; SET_UINT32(msg, offset, extra_len); offset += 4; memcpy(msg + offset, pioSendPci + 1, extra_len); offset += extra_len; SET_UINT32(msg, offset, cbSendLength); offset += 4; memcpy(msg + offset, pbSendBuffer, cbSendLength); offset += cbSendLength; // TODO figure out why recv pci does not work if (1 || (pioRecvPci == 0) || (pioRecvPci->cbPciLength < 8)) { got_recv_pci = 0; SET_UINT32(msg, offset, 0); /* dwProtocol */ offset += 4; SET_UINT32(msg, offset, 0); /* cbPciLength */ offset += 4; SET_UINT32(msg, offset, 0); /* extra_len */ offset += 4; } else { got_recv_pci = 1; SET_UINT32(msg, offset, pioRecvPci->dwProtocol); offset += 4; SET_UINT32(msg, offset, pioRecvPci->cbPciLength); offset += 4; extra_len = pioRecvPci->cbPciLength - 8; SET_UINT32(msg, offset, extra_len); offset += 4; memcpy(msg + offset, pioRecvPci + 1, extra_len); offset += extra_len; } SET_UINT32(msg, offset, *pcbRecvLength); offset += 4; if (send_message(SCARD_TRANSMIT, msg, offset) != 0) { LLOGLN(0, ("SCardTransmit: error, send_message")); free(msg); return SCARD_F_INTERNAL_ERROR; } bytes = 8192; code = SCARD_TRANSMIT; if (get_message(&code, msg, &bytes) != 0) { LLOGLN(0, ("SCardTransmit: error, get_message")); free(msg); return SCARD_F_INTERNAL_ERROR; } if (code != SCARD_TRANSMIT) { LLOGLN(0, ("SCardTransmit: error, bad code")); free(msg); return SCARD_F_INTERNAL_ERROR; } offset = 0; if (got_recv_pci == 0) { offset += 8; extra_len = GET_UINT32(msg, offset); offset += 4; offset += extra_len; } else { pioRecvPci->dwProtocol = GET_UINT32(msg, offset); offset += 4; pioRecvPci->cbPciLength = GET_UINT32(msg, offset); offset += 4; extra_len = GET_UINT32(msg, offset); offset += 4; offset += extra_len; } *pcbRecvLength = GET_UINT32(msg, offset); offset += 4; LLOGLN(10, (" cbRecvLength %d", (int)*pcbRecvLength)); memcpy(pbRecvBuffer, msg + offset, *pcbRecvLength); LHEXDUMP(10, (pbRecvBuffer, *pcbRecvLength)); offset += *pcbRecvLength; status = GET_UINT32(msg, offset); free(msg); return status; }
/* try to read length bytes * returns the number of bytes read or -1 on error * returns zero on SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE * returns zero if length < 1 */ int tls_read(rdpTls* tls, uint8* data, int length) { int status; int left; LLOGLN(10, ("tls_read: in length %d", length)); if (length < 1) { return 0; } if (tls->read_extra != NULL) { LLOGLN(10, ("tls_read: got left over, using first")); left = stream_get_left(tls->read_extra); if (length < left) { memcpy(data, tls->read_extra->p, length); tls->read_extra->p += length; LHEXDUMP(10, (data, length)); return length; } memcpy(data, tls->read_extra->p, left); LLOGLN(10, ("tls_read: freeing read_extra")); stream_free(tls->read_extra); tls->read_extra = NULL; status = tls_read(tls, data + left, length - left); if (status < 0) { return -1; } LHEXDUMP(10, (data, left + status)); return left + status; } status = SSL_read(tls->ssl, data, length); LLOGLN(10, ("tls_read: ssl %p SSL_read rv %d", tls->ssl, status)); if (status > 0) { g_total_read += status; LLOGLN(10, ("tls_read: g_total_read %d", g_total_read)); LHEXDUMP(10, (data, status)); return status; } if (status == 0) { return -1; /* disconnected */ } /* status must be < 0 */ switch (SSL_get_error(tls->ssl, status)) { case SSL_ERROR_NONE: break; case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_WRITE: status = 0; break; default: tls_print_error("SSL_read", tls->ssl, status); status = -1; break; } LLOGLN(10, ("tls_read: out status %d", status)); return status; }