FreeRDP
freerdp.h
1 
22 #ifndef FREERDP_H
23 #define FREERDP_H
24 
25 #include <winpr/stream.h>
26 #include <winpr/sspi.h>
27 
28 #include <freerdp/api.h>
29 #include <freerdp/types.h>
30 #include <freerdp/error.h>
31 #include <freerdp/event.h>
32 
33 #include <freerdp/settings.h>
34 
35 #include <freerdp/gdi/gdi.h>
36 #include <freerdp/codecs.h>
37 #include <freerdp/metrics.h>
38 #include <freerdp/extension.h>
39 #include <freerdp/heartbeat.h>
40 #include <freerdp/message.h>
41 #include <freerdp/autodetect.h>
42 #include <freerdp/streamdump.h>
43 
44 #ifdef __cplusplus
45 extern "C"
46 {
47 #endif
48 
49  typedef struct rdp_rdp rdpRdp;
50  typedef struct rdp_rail rdpRail;
51  typedef struct rdp_cache rdpCache;
52 
53  typedef struct rdp_client_context rdpClientContext;
54  typedef struct rdp_client_entry_points_v1 RDP_CLIENT_ENTRY_POINTS_V1;
55  typedef RDP_CLIENT_ENTRY_POINTS_V1 RDP_CLIENT_ENTRY_POINTS;
56 
57 #include <freerdp/utils/smartcardlogon.h>
58 #include <freerdp/update.h>
59 #include <freerdp/input.h>
60 #include <freerdp/graphics.h>
61 
62 #define MCS_BASE_CHANNEL_ID 1001
63 #define MCS_GLOBAL_CHANNEL_ID 1003
64 
65 /* Flags used by certificate callbacks */
66 #define VERIFY_CERT_FLAG_NONE 0x00
67 #define VERIFY_CERT_FLAG_LEGACY 0x02
68 #define VERIFY_CERT_FLAG_REDIRECT 0x10
69 #define VERIFY_CERT_FLAG_GATEWAY 0x20
70 #define VERIFY_CERT_FLAG_CHANGED 0x40
71 #define VERIFY_CERT_FLAG_MISMATCH 0x80
72 #define VERIFY_CERT_FLAG_MATCH_LEGACY_SHA1 0x100
73 #define VERIFY_CERT_FLAG_FP_IS_PEM 0x200
74 
75 /* Message types used by gateway messaging callback */
76 #define GATEWAY_MESSAGE_CONSENT 1
77 #define GATEWAY_MESSAGE_SERVICE 2
78 
79  typedef enum
80  {
81  AUTH_NLA,
82  AUTH_TLS,
83  AUTH_RDP,
84  GW_AUTH_HTTP,
85  GW_AUTH_RDG,
86  GW_AUTH_RPC,
87  AUTH_SMARTCARD_PIN
88  } rdp_auth_reason;
89 
90  typedef BOOL (*pContextNew)(freerdp* instance, rdpContext* context);
91  typedef void (*pContextFree)(freerdp* instance, rdpContext* context);
92 
93  typedef BOOL (*pConnectCallback)(freerdp* instance);
94  typedef void (*pPostDisconnect)(freerdp* instance);
95 
109  typedef BOOL (*pAuthenticate)(freerdp* instance, char** username, char** password,
110  char** domain);
111 
126  typedef BOOL (*pAuthenticateEx)(freerdp* instance, char** username, char** password,
127  char** domain, rdp_auth_reason reason);
128  typedef BOOL (*pChooseSmartcard)(freerdp* instance, SmartcardCertInfo** cert_list, DWORD count,
129  DWORD* choice, BOOL gateway);
130 
131  typedef enum
132  {
133  ACCESS_TOKEN_TYPE_AAD,
134  ACCESS_TOKEN_TYPE_AVD
135  } AccessTokenType;
136 
137  typedef BOOL (*pGetAccessToken)(freerdp* instance, AccessTokenType tokenType, char** token,
138  size_t count, ...);
139 
151  typedef SSIZE_T (*pRetryDialog)(freerdp* instance, const char* what, size_t current,
152  void* userarg);
153 
169 #if defined(WITH_FREERDP_DEPRECATED)
170  typedef WINPR_DEPRECATED_VAR(
171  "Use pVerifyCertificateEx",
172  DWORD (*pVerifyCertificate)(freerdp* instance, const char* common_name, const char* subject,
173  const char* issuer, const char* fingerprint,
174  BOOL host_mismatch));
175 #endif
176 
192  typedef DWORD (*pVerifyCertificateEx)(freerdp* instance, const char* host, UINT16 port,
193  const char* common_name, const char* subject,
194  const char* issuer, const char* fingerprint, DWORD flags);
195 
211 #if defined(WITH_FREERDP_DEPRECATED)
212  typedef WINPR_DEPRECATED_VAR(
213  "Use pVerifyChangedCertificateEx",
214  DWORD (*pVerifyChangedCertificate)(freerdp* instance, const char* common_name,
215  const char* subject, const char* issuer,
216  const char* new_fingerprint, const char* old_subject,
217  const char* old_issuer, const char* old_fingerprint));
218 #endif
219 
240  typedef DWORD (*pVerifyChangedCertificateEx)(freerdp* instance, const char* host, UINT16 port,
241  const char* common_name, const char* subject,
242  const char* issuer, const char* new_fingerprint,
243  const char* old_subject, const char* old_issuer,
244  const char* old_fingerprint, DWORD flags);
245 
259  typedef int (*pVerifyX509Certificate)(freerdp* instance, const BYTE* data, size_t length,
260  const char* hostname, UINT16 port, DWORD flags);
261 
262  typedef int (*pLogonErrorInfo)(freerdp* instance, UINT32 data, UINT32 type);
263 
264  typedef BOOL (*pSendChannelData)(freerdp* instance, UINT16 channelId, const BYTE* data,
265  size_t size);
266  typedef BOOL (*pSendChannelPacket)(freerdp* instance, UINT16 channelId, size_t totalSize,
267  UINT32 flags, const BYTE* data, size_t chunkSize);
268  typedef BOOL (*pReceiveChannelData)(freerdp* instance, UINT16 channelId, const BYTE* data,
269  size_t size, UINT32 flags, size_t totalSize);
270 
271  /* type can be one of the GATEWAY_MESSAGE_ type defines */
272  typedef BOOL (*pPresentGatewayMessage)(freerdp* instance, UINT32 type, BOOL isDisplayMandatory,
273  BOOL isConsentMandatory, size_t length,
274  const WCHAR* message);
275 
281  struct rdp_context
282  {
283  ALIGN64 freerdp* instance;
287  ALIGN64 freerdp_peer* peer;
291  ALIGN64 BOOL ServerMode;
293  ALIGN64 UINT32 LastError; /* 3 */
294 
295  UINT64 paddingA[16 - 4]; /* 4 */
296 
297  ALIGN64 int argc;
302  ALIGN64 char** argv;
308  ALIGN64 wPubSub* pubSub; /* (offset 18) */
309 
310  ALIGN64 HANDLE channelErrorEvent; /* (offset 19)*/
311  ALIGN64 UINT channelErrorNum; /*(offset 20)*/
312  ALIGN64 char* errorDescription; /*(offset 21)*/
313 
314  UINT64 paddingB[32 - 22]; /* 22 */
315 
316  ALIGN64 rdpRdp*
317  rdp;
322  ALIGN64 rdpGdi* gdi;
326  ALIGN64 rdpRail* rail; /* 34 */
327  ALIGN64 rdpCache* cache; /* 35 */
328  ALIGN64 rdpChannels* channels; /* 36 */
329  ALIGN64 rdpGraphics* graphics; /* 37 */
330  ALIGN64 rdpInput* input; /* 38 owned by rdpRdp */
331  ALIGN64 rdpUpdate* update; /* 39 owned by rdpRdp */
332  ALIGN64 rdpSettings* settings; /* 40 owned by rdpRdp */
333  ALIGN64 rdpMetrics* metrics; /* 41 */
334  ALIGN64 rdpCodecs* codecs; /* 42 */
335  ALIGN64 rdpAutoDetect* autodetect; /* 43 owned by rdpRdp */
336  UINT64 paddingC1[45 - 44]; /* 44 */
337  ALIGN64 int disconnectUltimatum; /* 45 */
338  UINT64 paddingC[64 - 46]; /* 46 */
339 
340  ALIGN64 rdpStreamDumpContext* dump; /* 64 */
341  ALIGN64 wLog* log; /* 65 */
342 
343  UINT64 paddingD[96 - 66]; /* 66 */
344  UINT64 paddingE[128 - 96]; /* 96 */
345  };
346 
352  enum Disconnect_Ultimatum
353  {
354  Disconnect_Ultimatum_domain_disconnected = 0,
355  Disconnect_Ultimatum_provider_initiated = 1,
356  Disconnect_Ultimatum_token_purged = 2,
357  Disconnect_Ultimatum_user_requested = 3,
358  Disconnect_Ultimatum_channel_purged = 4
359  };
360 
361 #include <freerdp/client.h>
362 
370  struct rdp_freerdp
371  {
372  ALIGN64
373  rdpContext* context;
383  ALIGN64 RDP_CLIENT_ENTRY_POINTS* pClientEntryPoints;
384 
385  UINT64 paddingA[16 - 2]; /* 2 */
386 
387 #if defined(WITH_FREERDP_DEPRECATED)
388  WINPR_DEPRECATED_VAR("use rdpContext::input instead", ALIGN64 rdpInput* input;) /* (offset
389  16) Input handle for the connection. Will be initialized by a call
390  to freerdp_context_new() owned by rdpRdp */
391  WINPR_DEPRECATED_VAR("use rdpContext::update instead",
392  ALIGN64 rdpUpdate* update;) /* (offset 17)
393  Update display parameters. Used to register display events callbacks
394 and settings. Will be initialized by a call to freerdp_context_new() owned by rdpRdp */
395  WINPR_DEPRECATED_VAR("use rdpContext::settings instead",
396  ALIGN64 rdpSettings* settings;)
402  WINPR_DEPRECATED_VAR("use rdpContext::autodetect instead",
403  ALIGN64 rdpAutoDetect* autodetect;) /* (offset 19)
404  Auto-Detect handle for the connection.
405  Will be initialized by a call to freerdp_context_new()
406 owned by rdpRdp */
407 #else
408  UINT64 paddingX[4];
409 #endif
410  ALIGN64 rdpHeartbeat* heartbeat; /* (offset 21) owned by rdpRdp*/
411 
412  UINT64 paddingB[32 - 21]; /* 21 */
413 
414  ALIGN64 size_t
415  ContextSize; /* (offset 32)
416  Specifies the size of the 'context' field. freerdp_context_new() will use this
417  size to allocate the context buffer. freerdp_new() sets it to
418  sizeof(rdpContext). If modifying it, there should always be a minimum of
419  sizeof(rdpContext), as the freerdp library will assume it can use the 'context'
420  field to set the required information in it. Clients will typically make it
421  bigger, and use a context structure embedding the rdpContext, and adding
422  additional information after that.
423  */
424 
425  ALIGN64 pContextNew
431  ALIGN64 pContextFree
436  UINT64 paddingC[47 - 35]; /* 35 */
437 
438  ALIGN64 UINT ConnectionCallbackState; /* 47 */
439 
440  ALIGN64 pConnectCallback
446  ALIGN64 pConnectCallback
452  ALIGN64 pAuthenticate Authenticate;
456 #if defined(WITH_FREERDP_DEPRECATED)
457  WINPR_DEPRECATED_VAR("Use VerifyCertificateEx or VerifyX509Certificate instead",
458  ALIGN64 pVerifyCertificate VerifyCertificate;)
459  WINPR_DEPRECATED_VAR("Use VerifyChangedCertificateEx or VerifyX509Certificate instead",
460  ALIGN64 pVerifyChangedCertificate
461  VerifyChangedCertificate;)
462 #else
463  ALIGN64 UINT64 reserved[2];
464 #endif
465  ALIGN64 pVerifyX509Certificate
469  ALIGN64 pLogonErrorInfo
473  ALIGN64 pPostDisconnect
482  ALIGN64 pAuthenticate GatewayAuthenticate;
487  ALIGN64 pPresentGatewayMessage PresentGatewayMessage;
491  ALIGN64 pConnectCallback Redirect;
497  ALIGN64 pConnectCallback
502  ALIGN64 pPostDisconnect
503  PostFinalDisconnect;
509  UINT64 paddingD[64 - 61]; /* 61 */
510 
511  ALIGN64 pSendChannelData
512  SendChannelData; /* (offset 64)
513  Callback for sending data to a channel.
514  By default, it is set by freerdp_new() to freerdp_send_channel_data(), which
515  eventually calls freerdp_channel_send() */
516  ALIGN64 pReceiveChannelData
517  ReceiveChannelData; /* (offset 65)
518  Callback for receiving data from a channel.
519  This is called by freerdp_channel_process() (if not NULL).
520  Clients will typically use a function that calls freerdp_channels_data()
521  to perform the needed tasks. */
522 
523  ALIGN64 pVerifyCertificateEx
527  ALIGN64 pVerifyChangedCertificateEx
531  ALIGN64 pSendChannelPacket
532  SendChannelPacket; /* (offset 68)
533  * Callback for sending RAW data to a channel. In contrast to
534  * SendChannelData data fragmentation is up to the user and this
535  * function sends data as is with the provided flags.
536  */
537  ALIGN64 pAuthenticateEx AuthenticateEx;
541  ALIGN64 pChooseSmartcard
542  ChooseSmartcard; /* (offset 70)
543  Callback for choosing a smartcard for logon.
544  Used when multiple smartcards are available. Returns an index into a list
545  of SmartcardCertInfo pointers */
546  ALIGN64 pGetAccessToken GetAccessToken; /* (offset 71)
547  Callback for obtaining an access token
548  for \b AccessTokenType authentication */
549  ALIGN64 pRetryDialog RetryDialog; /* (offset 72) Callback for displaying a dialog in case of
550  something needs a retry */
551  UINT64 paddingE[80 - 73]; /* 73 */
552  };
553 
555  {
556  wListDictionary* init;
557  wListDictionary* open;
558  };
559  typedef struct rdp_channel_handles rdpChannelHandles;
560 
561  FREERDP_API void freerdp_context_free(freerdp* instance);
562 
563  FREERDP_API BOOL freerdp_context_new(freerdp* instance);
564  FREERDP_API BOOL freerdp_context_new_ex(freerdp* instance, rdpSettings* settings);
565 
566  FREERDP_API BOOL freerdp_context_reset(freerdp* instance);
567 
568  FREERDP_API BOOL freerdp_connect(freerdp* instance);
569 
570  WINPR_DEPRECATED_VAR("use freerdp_abort_connect_context instead",
571  FREERDP_API BOOL freerdp_abort_connect(freerdp* instance));
572 
573  FREERDP_API BOOL freerdp_abort_connect_context(rdpContext* context);
574  FREERDP_API HANDLE freerdp_abort_event(rdpContext* context);
575 
576  WINPR_DEPRECATED_VAR("use freerdp_shall_disconnect_context instead",
577  FREERDP_API BOOL freerdp_shall_disconnect(freerdp* instance));
578 
579  FREERDP_API BOOL freerdp_shall_disconnect_context(const rdpContext* context);
580  FREERDP_API BOOL freerdp_disconnect(freerdp* instance);
581 
582  WINPR_DEPRECATED_VAR("use freerdp_disconnect_before_reconnect_context instead",
583  FREERDP_API BOOL freerdp_disconnect_before_reconnect(freerdp* instance));
584  FREERDP_API BOOL freerdp_disconnect_before_reconnect_context(rdpContext* context);
585 
586  FREERDP_API BOOL freerdp_reconnect(freerdp* instance);
587 
588  FREERDP_API UINT freerdp_channels_attach(freerdp* instance);
589  FREERDP_API UINT freerdp_channels_detach(freerdp* instance);
590 
591 #if defined(WITH_FREERDP_DEPRECATED)
592  FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_get_event_handles",
593  BOOL freerdp_get_fds(freerdp* instance, void** rfds,
594  int* rcount, void** wfds, int* wcount));
595 #endif
596 
597  FREERDP_API BOOL freerdp_check_fds(freerdp* instance);
598 
599  FREERDP_API DWORD freerdp_get_event_handles(rdpContext* context, HANDLE* events, DWORD count);
600  FREERDP_API BOOL freerdp_check_event_handles(rdpContext* context);
601 
602  FREERDP_API wMessageQueue* freerdp_get_message_queue(freerdp* instance, DWORD id);
603  FREERDP_API HANDLE freerdp_get_message_queue_event_handle(freerdp* instance, DWORD id);
604  FREERDP_API int freerdp_message_queue_process_message(freerdp* instance, DWORD id,
605  wMessage* message);
606  FREERDP_API int freerdp_message_queue_process_pending_messages(freerdp* instance, DWORD id);
607 
608  FREERDP_API UINT32 freerdp_error_info(freerdp* instance);
609  FREERDP_API void freerdp_set_error_info(rdpRdp* rdp, UINT32 error);
610  FREERDP_API BOOL freerdp_send_error_info(rdpRdp* rdp);
611  FREERDP_API BOOL freerdp_get_stats(rdpRdp* rdp, UINT64* inBytes, UINT64* outBytes,
612  UINT64* inPackets, UINT64* outPackets);
613 
614  FREERDP_API void freerdp_get_version(int* major, int* minor, int* revision);
615  FREERDP_API const char* freerdp_get_version_string(void);
616  FREERDP_API const char* freerdp_get_build_revision(void);
617  FREERDP_API const char* freerdp_get_build_config(void);
618 
619  FREERDP_API void freerdp_free(freerdp* instance);
620 
621  WINPR_ATTR_MALLOC(freerdp_free, 1)
622  FREERDP_API freerdp* freerdp_new(void);
623 
624  FREERDP_API BOOL freerdp_focus_required(freerdp* instance);
625  FREERDP_API void freerdp_set_focus(freerdp* instance);
626 
627  FREERDP_API int freerdp_get_disconnect_ultimatum(rdpContext* context);
628 
629  FREERDP_API UINT32 freerdp_get_last_error(rdpContext* context);
630  FREERDP_API const char* freerdp_get_last_error_name(UINT32 error);
631  FREERDP_API const char* freerdp_get_last_error_string(UINT32 error);
632  FREERDP_API const char* freerdp_get_last_error_category(UINT32 error);
633 
634 #define freerdp_set_last_error(context, lastError) \
635  freerdp_set_last_error_ex((context), (lastError), __func__, __FILE__, __LINE__)
636 
637 #define freerdp_set_last_error_if_not(context, lastError) \
638  do \
639  { \
640  if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS) \
641  freerdp_set_last_error_log(context, lastError); \
642  } while (0)
643 
644 #define freerdp_set_last_error_log(context, lastError) \
645  freerdp_set_last_error_ex((context), (lastError), __func__, __FILE__, __LINE__)
646  FREERDP_API void freerdp_set_last_error_ex(rdpContext* context, UINT32 lastError,
647  const char* fkt, const char* file, int line);
648 
649  FREERDP_API const char* freerdp_get_logon_error_info_type(UINT32 type);
650  FREERDP_API const char* freerdp_get_logon_error_info_type_ex(UINT32 type, char* buffer,
651  size_t size);
652 
653  FREERDP_API const char* freerdp_get_logon_error_info_data(UINT32 data);
654  FREERDP_API const char* freerdp_get_logon_error_info_data_ex(UINT32 data, char* buffer,
655  size_t size);
656 
657  FREERDP_API ULONG freerdp_get_transport_sent(rdpContext* context, BOOL resetCount);
658 
659  FREERDP_API BOOL freerdp_nla_impersonate(rdpContext* context);
660  FREERDP_API BOOL freerdp_nla_revert_to_self(rdpContext* context);
661 
662  FREERDP_API UINT32 freerdp_get_nla_sspi_error(rdpContext* context);
663 
672  FREERDP_API BOOL freerdp_nla_encrypt(rdpContext* context, const SecBuffer* inBuffer,
673  SecBuffer* outBuffer);
674 
683  FREERDP_API BOOL freerdp_nla_decrypt(rdpContext* context, const SecBuffer* inBuffer,
684  SecBuffer* outBuffer);
685 
695  FREERDP_API SECURITY_STATUS freerdp_nla_QueryContextAttributes(rdpContext* context,
696  DWORD ulAttr, PVOID pBuffer);
697 
698  FREERDP_API void clearChannelError(rdpContext* context);
699  FREERDP_API HANDLE getChannelErrorEventHandle(rdpContext* context);
700  FREERDP_API UINT getChannelError(rdpContext* context);
701  FREERDP_API const char* getChannelErrorDescription(rdpContext* context);
702  FREERDP_API void setChannelError(rdpContext* context, UINT errorNum, const char* format, ...);
703  FREERDP_API BOOL checkChannelErrorEvent(rdpContext* context);
704 
705  FREERDP_API const char* freerdp_nego_get_routing_token(rdpContext* context, DWORD* length);
706 
713  FREERDP_API CONNECTION_STATE freerdp_get_state(const rdpContext* context);
714 
721  FREERDP_API const char* freerdp_state_string(CONNECTION_STATE state);
722 
732  FREERDP_API BOOL freerdp_is_active_state(const rdpContext* context);
733 
734  FREERDP_API BOOL freerdp_channels_from_mcs(rdpSettings* settings, const rdpContext* context);
735 
736  FREERDP_API BOOL freerdp_is_valid_mcs_create_request(const BYTE* data, size_t size);
737  FREERDP_API BOOL freerdp_is_valid_mcs_create_response(const BYTE* data, size_t size);
738 
739 #ifdef __cplusplus
740 }
741 #endif
742 
743 #endif /* FREERDP_H */
ALIGN64 char ** argv
Definition: freerdp.h:302
ALIGN64 rdpRdp * rdp
Definition: freerdp.h:317
ALIGN64 freerdp_peer * peer
Definition: freerdp.h:287
ALIGN64 BOOL ServerMode
Definition: freerdp.h:291
ALIGN64 rdpGdi * gdi
Definition: freerdp.h:322
ALIGN64 int argc
Definition: freerdp.h:297
ALIGN64 freerdp * instance
Definition: freerdp.h:283
UINT64 paddingD[64 - 61]
Definition: freerdp.h:509
ALIGN64 pConnectCallback LoadChannels
Definition: freerdp.h:498
ALIGN64 pVerifyChangedCertificateEx VerifyChangedCertificateEx
Definition: freerdp.h:528
ALIGN64 pVerifyCertificateEx VerifyCertificateEx
Definition: freerdp.h:524
ALIGN64 pConnectCallback Redirect
Definition: freerdp.h:491
ALIGN64 pConnectCallback PostConnect
Definition: freerdp.h:447
ALIGN64 pAuthenticateEx AuthenticateEx
Definition: freerdp.h:537
ALIGN64 pPostDisconnect PostDisconnect
Definition: freerdp.h:474
ALIGN64 pLogonErrorInfo LogonErrorInfo
Definition: freerdp.h:470
ALIGN64 rdpContext * context
Definition: freerdp.h:373
ALIGN64 pAuthenticate Authenticate
Definition: freerdp.h:452
ALIGN64 pAuthenticate GatewayAuthenticate
Definition: freerdp.h:482
ALIGN64 pContextFree ContextFree
Definition: freerdp.h:432
ALIGN64 pVerifyX509Certificate VerifyX509Certificate
Definition: freerdp.h:466
ALIGN64 pConnectCallback PreConnect
Definition: freerdp.h:441
ALIGN64 pContextNew ContextNew
Definition: freerdp.h:426
ALIGN64 pPresentGatewayMessage PresentGatewayMessage
Definition: freerdp.h:487
Definition: rdp.h:147