Add detailed logging to libxrdp (#1742)
* Added s_rem(s) for getting the remaining bytes in a stream * Added s_rem_out() macro * Fixed 15bpp pointer error checking * Combined the 512 and 2048 bit certificate sending code paths * Other detailed comments and logging added following MS-RDPBCGR
This commit is contained in:
+11
-6
@@ -22,6 +22,7 @@
|
||||
#include <pthread.h>
|
||||
|
||||
#include "arch.h"
|
||||
#include "defines.h"
|
||||
#include "list.h"
|
||||
|
||||
/* logging buffer size */
|
||||
@@ -95,7 +96,7 @@ enum logReturns
|
||||
* @param ... the arguments for the printf format c-string
|
||||
*/
|
||||
#define LOG_DEVEL(log_level, args...) \
|
||||
log_message_with_location(__func__, __FILE__, __LINE__, log_level, args);
|
||||
log_message_with_location(__func__, __FILE__, __LINE__, log_level, args)
|
||||
|
||||
/**
|
||||
* @brief Logging macro for messages that are for a systeam administrator to
|
||||
@@ -109,7 +110,7 @@ enum logReturns
|
||||
* @param ... the arguments for the printf format c-string
|
||||
*/
|
||||
#define LOG(log_level, args...) \
|
||||
log_message_with_location(__func__, __FILE__, __LINE__, log_level, args);
|
||||
log_message_with_location(__func__, __FILE__, __LINE__, log_level, args)
|
||||
|
||||
/**
|
||||
* @brief Logging macro for logging the contents of a byte array using a hex
|
||||
@@ -124,12 +125,16 @@ enum logReturns
|
||||
* @param length, the length of the byte array to log
|
||||
*/
|
||||
#define LOG_DEVEL_HEXDUMP(log_level, message, buffer, length) \
|
||||
log_hexdump_with_location(__func__, __FILE__, __LINE__, log_level, message, buffer, length);
|
||||
log_hexdump_with_location(__func__, __FILE__, __LINE__, log_level, message, buffer, length)
|
||||
|
||||
#else
|
||||
#define LOG_DEVEL(log_level, args...)
|
||||
#define LOG(log_level, args...) log_message(log_level, args);
|
||||
#define LOG_DEVEL_HEXDUMP(log_level, message, buffer, length)
|
||||
#define LOG(log_level, args...) log_message(log_level, args)
|
||||
|
||||
/* Since log_message() returns a value ensure that the elided versions of
|
||||
* LOG_DEVEL and LOG_DEVEL_HEXDUMP also "fake" returning the success value
|
||||
*/
|
||||
#define LOG_DEVEL(log_level, args...) UNUSED_VAR(LOG_STARTUP_OK)
|
||||
#define LOG_DEVEL_HEXDUMP(log_level, message, buffer, length) UNUSED_VAR(LOG_STARTUP_OK)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -369,6 +369,15 @@
|
||||
#define PDUTYPE_DATAPDU 0x7
|
||||
#define PDUTYPE_SERVER_REDIR_PKT 0xA
|
||||
|
||||
#define PDUTYPE_TO_STR(pdu_type) \
|
||||
((pdu_type) == PDUTYPE_DEMANDACTIVEPDU ? "PDUTYPE_DEMANDACTIVEPDU" : \
|
||||
(pdu_type) == PDUTYPE_CONFIRMACTIVEPDU ? "PDUTYPE_CONFIRMACTIVEPDU" : \
|
||||
(pdu_type) == PDUTYPE_DEACTIVATEALLPDU ? "PDUTYPE_DEACTIVATEALLPDU" : \
|
||||
(pdu_type) == PDUTYPE_DATAPDU ? "PDUTYPE_DATAPDU" : \
|
||||
(pdu_type) == PDUTYPE_SERVER_REDIR_PKT ? "PDUTYPE_SERVER_REDIR_PKT" : \
|
||||
"unknown" \
|
||||
)
|
||||
|
||||
/* Share Data Header: pduType2 (2.2.8.1.1.1.2) */
|
||||
/* TODO: to be renamed */
|
||||
#define RDP_DATA_PDU_UPDATE 2 /* PDUTYPE2_UPDATE */
|
||||
@@ -378,6 +387,9 @@
|
||||
#define RDP_DATA_PDU_SYNCHRONISE 31
|
||||
#define PDUTYPE2_REFRESH_RECT 33
|
||||
#define RDP_DATA_PDU_PLAY_SOUND 34
|
||||
#define PDUTYPE2_SUPPRESS_OUTPUT 35
|
||||
#define PDUTYPE2_SHUTDOWN_REQUEST 36
|
||||
#define PDUTYPE2_SHUTDOWN_DENIED 37
|
||||
#define RDP_DATA_PDU_LOGON 38
|
||||
#define RDP_DATA_PDU_FONT2 39
|
||||
#define RDP_DATA_PDU_DISCONNECT 47
|
||||
@@ -457,6 +469,14 @@
|
||||
#define RDP_UPDATE_PALETTE 2
|
||||
#define RDP_UPDATE_SYNCHRONIZE 3
|
||||
|
||||
#define GRAPHICS_UPDATE_TYPE_TO_STR(type) \
|
||||
((type) == RDP_UPDATE_ORDERS ? "RDP_UPDATE_ORDERS" : \
|
||||
(type) == RDP_UPDATE_BITMAP ? "RDP_UPDATE_BITMAP" : \
|
||||
(type) == RDP_UPDATE_PALETTE ? "RDP_UPDATE_PALETTE" : \
|
||||
(type) == RDP_UPDATE_SYNCHRONIZE ? "RDP_UPDATE_SYNCHRONIZE" : \
|
||||
"unknown" \
|
||||
)
|
||||
|
||||
/* Server Pointer Update PDU: messageType (2.2.9.1.1.4) */
|
||||
/* TODO: to be renamed */
|
||||
#define RDP_POINTER_SYSTEM 1 /* TS_PTRMSGTYPE_SYSTEM */
|
||||
|
||||
+48
-1
@@ -26,6 +26,7 @@
|
||||
#define PARSE_H
|
||||
|
||||
#include "arch.h"
|
||||
#include "log.h"
|
||||
|
||||
#if defined(L_ENDIAN)
|
||||
#elif defined(B_ENDIAN)
|
||||
@@ -54,17 +55,63 @@ struct stream
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
#define s_check(s) ((s)->p <= (s)->end)
|
||||
#define s_check(s) s_check_rem(s, 0)
|
||||
|
||||
/******************************************************************************/
|
||||
#define s_check_rem(s, n) ((s)->p + (n) <= (s)->end)
|
||||
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @returns true if there are at least n bytes remaining in the stream,
|
||||
* else false and logs an error message
|
||||
*/
|
||||
#define s_check_rem_and_log(s, n, msg_prefix) \
|
||||
( s_check_rem((s), (n)) ? \
|
||||
1 : \
|
||||
LOG(LOG_LEVEL_ERROR, \
|
||||
"%s Not enough bytes in the stream: expected %d, remaining %d", \
|
||||
(msg_prefix), (n), s_rem(s)) \
|
||||
&& 0 )
|
||||
|
||||
/******************************************************************************/
|
||||
#define s_check_rem_out(s, n) ((s)->p + (n) <= (s)->data + (s)->size)
|
||||
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @returns true if there are at least n bytes remaining in the stream,
|
||||
* else false and logs an error message
|
||||
*/
|
||||
#define s_check_rem_out_and_log(s, n, msg_prefix) \
|
||||
( s_check_rem_out((s), (n)) ? \
|
||||
1 : \
|
||||
LOG(LOG_LEVEL_ERROR, \
|
||||
"%s Not enough bytes in the stream: expected %d, remaining %d", \
|
||||
(msg_prefix), (n), s_rem_out(s)) \
|
||||
&& 0 )
|
||||
|
||||
/******************************************************************************/
|
||||
#define s_check_end(s) ((s)->p == (s)->end)
|
||||
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @returns true if there are exactly 0 bytes remaining in the stream,
|
||||
* else false and logs an error message
|
||||
*/
|
||||
#define s_check_end_and_log(s, msg_prefix) \
|
||||
( s_check_end((s)) ? \
|
||||
1 : \
|
||||
LOG(LOG_LEVEL_ERROR, \
|
||||
"%s Expected to be at the end of the stream, " \
|
||||
"but there are %d bytes remaining", \
|
||||
(msg_prefix), s_rem(s)) \
|
||||
&& 0 )
|
||||
|
||||
/******************************************************************************/
|
||||
#define s_rem(s) ((int) ((s)->end - (s)->p))
|
||||
|
||||
/******************************************************************************/
|
||||
#define s_rem_out(s) ((int) ((s)->data + (s)->size - (s)->p))
|
||||
|
||||
/******************************************************************************/
|
||||
#define make_stream(s) \
|
||||
(s) = (struct stream*)g_malloc(sizeof(struct stream), 1)
|
||||
|
||||
@@ -95,8 +95,8 @@
|
||||
* not yet sorted out
|
||||
*/
|
||||
|
||||
#define MCS_CONNECT_INITIAL 0x7f65
|
||||
#define MCS_CONNECT_RESPONSE 0x7f66
|
||||
#define MCS_CONNECT_INITIAL 0x7f65 /* MCS BER: big endian, class=application (0x4000), constructed (0x2000), tag number > 30 (0x1f00), tag number=101 (0x0065) */
|
||||
#define MCS_CONNECT_RESPONSE 0x7f66 /* MCS BER: application 102 */
|
||||
|
||||
#define BER_TAG_BOOLEAN 1
|
||||
#define BER_TAG_INTEGER 2
|
||||
|
||||
Reference in New Issue
Block a user