2019-05-17 15:32:54 +03:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* FreeRDP Proxy Server
|
|
|
|
*
|
|
|
|
* Copyright 2019 Mati Shabtay <matishabtay@gmail.com>
|
|
|
|
* Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>
|
|
|
|
* Copyright 2019 Idan Freiberg <speidy@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FREERDP_SERVER_PROXY_PFCONTEXT_H
|
|
|
|
#define FREERDP_SERVER_PROXY_PFCONTEXT_H
|
|
|
|
|
|
|
|
#include <freerdp/freerdp.h>
|
|
|
|
#include <freerdp/channels/wtsvc.h>
|
2019-06-11 17:13:42 +03:00
|
|
|
|
2021-08-24 13:50:13 +03:00
|
|
|
#include <freerdp/server/proxy/proxy_config.h>
|
2019-05-17 15:32:54 +03:00
|
|
|
|
2020-06-10 10:16:59 +03:00
|
|
|
#define PROXY_SESSION_ID_LENGTH 32
|
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
2021-12-14 15:02:29 +03:00
|
|
|
{
|
2022-01-20 13:12:36 +03:00
|
|
|
#endif
|
2021-12-14 15:02:29 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
typedef struct proxy_data proxyData;
|
|
|
|
typedef struct proxy_module proxyModule;
|
2022-06-15 11:21:29 +03:00
|
|
|
typedef struct p_server_static_channel_context pServerStaticChannelContext;
|
2021-12-14 15:02:29 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct s_InterceptContextMapEntry
|
2022-01-20 13:12:36 +03:00
|
|
|
{
|
2022-02-14 16:59:22 +03:00
|
|
|
void (*free)(struct s_InterceptContextMapEntry*);
|
2022-01-20 13:12:36 +03:00
|
|
|
} InterceptContextMapEntry;
|
2021-12-14 15:02:29 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
/* All proxy interception channels derive from this base struct
|
|
|
|
* and set their cleanup function accordingly. */
|
|
|
|
FREERDP_API void intercept_context_entry_free(void* obj);
|
2019-05-17 15:32:54 +03:00
|
|
|
|
2022-02-03 19:36:53 +03:00
|
|
|
/** @brief how is handled a channel */
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef enum
|
2022-02-03 19:36:53 +03:00
|
|
|
{
|
2022-03-07 15:46:49 +03:00
|
|
|
PF_UTILS_CHANNEL_NOT_HANDLED, /*!< channel not handled */
|
2022-06-23 08:57:38 +03:00
|
|
|
PF_UTILS_CHANNEL_BLOCK, /*!< block and drop traffic on this channel */
|
2022-03-07 15:46:49 +03:00
|
|
|
PF_UTILS_CHANNEL_PASSTHROUGH, /*!< pass traffic from this channel */
|
2022-06-23 08:57:38 +03:00
|
|
|
PF_UTILS_CHANNEL_INTERCEPT, /*!< inspect traffic from this channel */
|
2022-02-14 16:59:22 +03:00
|
|
|
} pf_utils_channel_mode;
|
2022-02-03 19:36:53 +03:00
|
|
|
|
2022-03-07 15:46:49 +03:00
|
|
|
/** @brief result of a channel treatment */
|
|
|
|
typedef enum
|
|
|
|
{
|
2022-06-23 08:57:38 +03:00
|
|
|
PF_CHANNEL_RESULT_PASS, /*!< pass the packet as is */
|
|
|
|
PF_CHANNEL_RESULT_DROP, /*!< drop the packet */
|
|
|
|
PF_CHANNEL_RESULT_ERROR /*!< error during packet treatment */
|
2022-03-07 15:46:49 +03:00
|
|
|
} PfChannelResult;
|
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
typedef PfChannelResult (*proxyChannelDataFn)(proxyData* pdata,
|
|
|
|
const pServerStaticChannelContext* channel,
|
|
|
|
const BYTE* xdata, size_t xsize, UINT32 flags,
|
|
|
|
size_t totalSizepServer);
|
|
|
|
typedef void (*proxyChannelContextDtor)(void* context);
|
2022-03-07 15:46:49 +03:00
|
|
|
|
2022-02-03 19:36:53 +03:00
|
|
|
/** @brief per channel configuration */
|
2022-06-15 11:21:29 +03:00
|
|
|
struct p_server_static_channel_context
|
2022-02-03 19:36:53 +03:00
|
|
|
{
|
|
|
|
char* channel_name;
|
2022-06-15 11:21:29 +03:00
|
|
|
UINT32 channel_id;
|
2022-02-03 19:36:53 +03:00
|
|
|
pf_utils_channel_mode channelMode;
|
2022-03-07 15:46:49 +03:00
|
|
|
proxyChannelDataFn onFrontData;
|
|
|
|
proxyChannelDataFn onBackData;
|
|
|
|
proxyChannelContextDtor contextDtor;
|
2022-06-23 08:57:38 +03:00
|
|
|
void* context;
|
2022-02-03 19:36:53 +03:00
|
|
|
};
|
|
|
|
|
2022-06-15 11:21:29 +03:00
|
|
|
void StaticChannelContext_free(pServerStaticChannelContext* ctx);
|
2022-02-03 19:36:53 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
/**
|
|
|
|
* Wraps rdpContext and holds the state for the proxy's server.
|
2019-07-15 10:55:57 +03:00
|
|
|
*/
|
2022-01-20 13:12:36 +03:00
|
|
|
struct p_server_context
|
|
|
|
{
|
|
|
|
rdpContext context;
|
2019-10-22 16:06:05 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
proxyData* pdata;
|
2021-08-24 13:50:13 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
HANDLE vcm;
|
|
|
|
HANDLE dynvcReady;
|
2021-08-24 13:50:13 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
wHashTable* interceptContextMap;
|
2022-02-03 19:36:53 +03:00
|
|
|
wHashTable* channelsById;
|
2022-01-20 13:12:36 +03:00
|
|
|
};
|
|
|
|
typedef struct p_server_context pServerContext;
|
2021-09-10 11:39:07 +03:00
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
pServerStaticChannelContext* StaticChannelContext_new(pServerContext* ps, const char* name,
|
|
|
|
UINT32 id);
|
2022-02-03 19:36:53 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
/**
|
|
|
|
* Wraps rdpContext and holds the state for the proxy's client.
|
|
|
|
*/
|
|
|
|
typedef struct p_client_context pClientContext;
|
2021-12-14 15:02:29 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
struct p_client_context
|
|
|
|
{
|
|
|
|
rdpContext context;
|
|
|
|
|
|
|
|
proxyData* pdata;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In a case when freerdp_connect fails,
|
|
|
|
* Used for NLA fallback feature, to check if the server should close the connection.
|
|
|
|
* When it is set to TRUE, proxy's client knows it shouldn't signal the server thread to
|
|
|
|
* closed the connection when pf_client_post_disconnect is called, because it is trying to
|
|
|
|
* connect reconnect without NLA. It must be set to TRUE before the first try, and to FALSE
|
|
|
|
* after the connection fully established, to ensure graceful shutdown of the connection
|
|
|
|
* when it will be closed.
|
|
|
|
*/
|
|
|
|
BOOL allow_next_conn_failure;
|
|
|
|
|
|
|
|
BOOL connected; /* Set after client post_connect. */
|
|
|
|
|
|
|
|
pReceiveChannelData client_receive_channel_data_original;
|
|
|
|
wQueue* cached_server_channel_data;
|
|
|
|
BOOL (*sendChannelData)(pClientContext* pc, const proxyChannelDataEventInfo* ev);
|
|
|
|
|
|
|
|
/* X509 specific */
|
|
|
|
char* remote_hostname;
|
|
|
|
wStream* remote_pem;
|
|
|
|
UINT16 remote_port;
|
|
|
|
UINT32 remote_flags;
|
|
|
|
|
|
|
|
BOOL input_state_sync_pending;
|
|
|
|
UINT32 input_state;
|
|
|
|
|
|
|
|
wHashTable* interceptContextMap;
|
|
|
|
UINT32 computerNameLen;
|
|
|
|
BOOL computerNameUnicode;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
WCHAR* wc;
|
|
|
|
char* c;
|
|
|
|
void* v;
|
|
|
|
} computerName;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds data common to both sides of a proxy's session.
|
|
|
|
*/
|
|
|
|
struct proxy_data
|
2021-12-14 15:02:29 +03:00
|
|
|
{
|
2022-01-20 13:12:36 +03:00
|
|
|
proxyModule* module;
|
|
|
|
const proxyConfig* config;
|
2019-05-17 15:32:54 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
pServerContext* ps;
|
|
|
|
pClientContext* pc;
|
2019-05-17 15:32:54 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
HANDLE abort_event;
|
|
|
|
HANDLE client_thread;
|
|
|
|
HANDLE gfx_server_ready;
|
2019-05-17 15:32:54 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
char session_id[PROXY_SESSION_ID_LENGTH + 1];
|
2019-12-26 11:25:13 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
/* used to external modules to store per-session info */
|
|
|
|
wHashTable* modules_info;
|
|
|
|
psPeerReceiveChannelData server_receive_channel_data_original;
|
|
|
|
};
|
2019-12-31 12:16:12 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
FREERDP_API BOOL pf_context_copy_settings(rdpSettings* dst, const rdpSettings* src);
|
|
|
|
FREERDP_API BOOL pf_context_init_server_context(freerdp_peer* client);
|
2022-11-22 14:28:18 +03:00
|
|
|
FREERDP_API pClientContext* pf_context_create_client_context(const rdpSettings* clientSettings);
|
2019-05-17 15:32:54 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
FREERDP_API proxyData* proxy_data_new(void);
|
|
|
|
FREERDP_API void proxy_data_set_client_context(proxyData* pdata, pClientContext* context);
|
|
|
|
FREERDP_API void proxy_data_set_server_context(proxyData* pdata, pServerContext* context);
|
|
|
|
FREERDP_API void proxy_data_free(proxyData* pdata);
|
2019-07-16 16:13:12 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
FREERDP_API BOOL proxy_data_shall_disconnect(proxyData* pdata);
|
|
|
|
FREERDP_API void proxy_data_abort_connect(proxyData* pdata);
|
2019-08-19 16:05:59 +03:00
|
|
|
|
2022-01-20 13:12:36 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2019-07-16 16:13:12 +03:00
|
|
|
|
2019-05-17 15:32:54 +03:00
|
|
|
#endif /* FREERDP_SERVER_PROXY_PFCONTEXT_H */
|