BOOL freerdp_check_fds(freerdp* instance) { int status; rdpRdp* rdp; assert(instance); assert(instance->context); assert(instance->context->rdp); rdp = instance->context->rdp; status = rdp_check_fds(rdp); if (status < 0) { TerminateEventArgs e; rdpContext* context = instance->context; EventArgsInit(&e, "freerdp"); e.code = 0; PubSub_OnTerminate(context->pubSub, context, &e); return FALSE; } return TRUE; }
BOOL freerdp_check_fds(freerdp* instance) { int status; rdpRdp* rdp; if (!instance) return FALSE; if (!instance->context) return FALSE; if (!instance->context->rdp) return FALSE; rdp = instance->context->rdp; status = rdp_check_fds(rdp); if (status < 0) { TerminateEventArgs e; rdpContext* context = instance->context; WLog_DBG(TAG, "rdp_check_fds() - %i", status); EventArgsInit(&e, "freerdp"); e.code = 0; PubSub_OnTerminate(context->pubSub, context, &e); return FALSE; } return TRUE; }
boolean rdp_recv_deactivate_all(rdpRdp* rdp, STREAM* s) { uint16 lengthSourceDescriptor; /* * Windows XP can send short DEACTIVATE_ALL PDU that doesn't contain * the following fields. */ if (stream_get_left(s) > 0) { stream_read_uint32(s, rdp->settings->share_id); /* shareId (4 bytes) */ stream_read_uint16(s, lengthSourceDescriptor); /* lengthSourceDescriptor (2 bytes) */ stream_seek(s, lengthSourceDescriptor); /* sourceDescriptor (should be 0x00) */ } rdp->state = CONNECTION_STATE_CAPABILITY; while (rdp->state != CONNECTION_STATE_ACTIVE) { if (rdp_check_fds(rdp) < 0) return false; if (rdp->disconnect) break; } return true; }
boolean rdp_client_connect(rdpRdp* rdp) { boolean status; uint32 selectedProtocol; rdpSettings* settings = rdp->settings; nego_init(rdp->nego); nego_set_target(rdp->nego, settings->hostname, settings->port); nego_set_cookie(rdp->nego, settings->username); nego_enable_rdp(rdp->nego, settings->rdp_security); if(!rdp->settings->tsg) { nego_enable_nla(rdp->nego, settings->nla_security); nego_enable_tls(rdp->nego, settings->tls_security); } if (nego_connect(rdp->nego) != true) { printf("Error: protocol security negotiation failure\n"); return false; } selectedProtocol = rdp->nego->selected_protocol; if ((selectedProtocol & PROTOCOL_TLS) || (selectedProtocol == PROTOCOL_RDP)) { if ((settings->username != NULL) && ((settings->password != NULL) || (settings->password_cookie != NULL && settings->password_cookie->length > 0))) settings->autologon = true; } status = false; if (selectedProtocol & PROTOCOL_NLA) status = transport_connect_nla(rdp->transport); else if (selectedProtocol & PROTOCOL_TLS) status = transport_connect_tls(rdp->transport); else if (selectedProtocol == PROTOCOL_RDP) /* 0 */ status = transport_connect_rdp(rdp->transport); if (status != true) return false; rdp_set_blocking_mode(rdp, false); rdp->state = CONNECTION_STATE_NEGO; rdp->finalize_sc_pdus = 0; if (mcs_send_connect_initial(rdp->mcs) != true) { printf("Error: unable to send MCS Connect Initial\n"); return false; } while (rdp->state != CONNECTION_STATE_ACTIVE) { if (rdp_check_fds(rdp) < 0) return false; } return true; }
boolean rdp_client_connect(rdpRdp* rdp) { rdpSettings* settings = rdp->settings; nego_init(rdp->nego); nego_set_target(rdp->nego, settings->hostname, settings->port); nego_set_cookie(rdp->nego, settings->username); nego_set_send_preconnection_pdu(rdp->nego, settings->send_preconnection_pdu); nego_set_preconnection_id(rdp->nego, settings->preconnection_id); nego_set_preconnection_blob(rdp->nego, settings->preconnection_blob); nego_set_negotiation_enabled(rdp->nego, settings->security_layer_negotiation); nego_enable_rdp(rdp->nego, settings->rdp_security); if (!settings->ts_gateway) { nego_enable_nla(rdp->nego, settings->nla_security); nego_enable_tls(rdp->nego, settings->tls_security); } if (!nego_connect(rdp->nego)) { freerdp_log(rdp->instance, "Error: protocol security negotiation failure\n"); return false; } if ((rdp->nego->selected_protocol & PROTOCOL_TLS) || (rdp->nego->selected_protocol == PROTOCOL_RDP)) { if ((settings->username != NULL) && ((settings->password != NULL) || (settings->password_cookie != NULL && settings->password_cookie->length > 0))) settings->autologon = true; } rdp_set_blocking_mode(rdp, false); rdp->state = CONNECTION_STATE_NEGO; rdp->finalize_sc_pdus = 0; if (!mcs_send_connect_initial(rdp->mcs)) { if (!connectErrorCode) { connectErrorCode = MCSCONNECTINITIALERROR; } freerdp_log(rdp->instance, "Error: unable to send MCS Connect Initial\n"); return false; } rdp->transport->process_single_pdu = true; while (rdp->state != CONNECTION_STATE_ACTIVE) { if (rdp_check_fds(rdp) < 0) return false; } rdp->transport->process_single_pdu = false; return true; }
static BOOL freerdp_peer_check_fds(freerdp_peer* peer) { int status; rdpRdp* rdp; rdp = peer->context->rdp; status = rdp_check_fds(rdp); if (status < 0) return FALSE; return TRUE; }
boolean freerdp_check_fds(freerdp* instance) { rdpRdp* rdp; int status; rdp = (rdpRdp*) instance->rdp; status = rdp_check_fds(rdp); if (status < 0) return False; return True; }
static boolean freerdp_peer_check_fds(freerdp_peer* client) { rdpPeer* peer = (rdpPeer*)client->peer; rdpRdp* rdp; int status; rdp = (rdpRdp*) peer->rdp; status = rdp_check_fds(rdp); if (status < 0) return False; return True; }
BOOL freerdp_check_fds(freerdp* instance) { int status; rdpRdp* rdp; rdp = instance->context->rdp; status = rdp_check_fds(rdp); if (status < 0) return FALSE; return TRUE; }
boolean freerdp_check_fds(freerdp* instance) { int status; rdpRdp* rdp; rdp = instance->context->rdp; status = rdp_check_fds(rdp); if (status < 0) return false; return true; }
BOOL rdp_recv_deactivate_all(rdpRdp* rdp, wStream* s) { UINT16 lengthSourceDescriptor; if (rdp->state == CONNECTION_STATE_ACTIVE) rdp->deactivation_reactivation = TRUE; else rdp->deactivation_reactivation = FALSE; /* * Windows XP can send short DEACTIVATE_ALL PDU that doesn't contain * the following fields. */ if (Stream_GetRemainingLength(s) > 0) { do { if (Stream_GetRemainingLength(s) < 4) break; Stream_Read_UINT32(s, rdp->settings->ShareId); /* shareId (4 bytes) */ if (Stream_GetRemainingLength(s) < 2) break; Stream_Read_UINT16(s, lengthSourceDescriptor); /* lengthSourceDescriptor (2 bytes) */ if (Stream_GetRemainingLength(s) < lengthSourceDescriptor) break; Stream_Seek(s, lengthSourceDescriptor); /* sourceDescriptor (should be 0x00) */ } while (0); } rdp_client_transition_to_state(rdp, CONNECTION_STATE_CAPABILITIES_EXCHANGE); while (rdp->state != CONNECTION_STATE_ACTIVE) { if (rdp_check_fds(rdp) < 0) return FALSE; if (freerdp_shall_disconnect(rdp->instance)) break; SwitchToThread(); } return TRUE; }
boolean rdp_client_connect(rdpRdp* rdp) { boolean status; rdp->settings->autologon = 1; nego_init(rdp->nego); nego_set_target(rdp->nego, rdp->settings->hostname, rdp->settings->port); nego_set_cookie(rdp->nego, rdp->settings->username); nego_enable_rdp(rdp->nego, rdp->settings->rdp_security); nego_enable_nla(rdp->nego, rdp->settings->nla_security); nego_enable_tls(rdp->nego, rdp->settings->tls_security); if (nego_connect(rdp->nego) != True) { printf("Error: protocol security negotiation failure\n"); return False; } status = False; if (rdp->nego->selected_protocol & PROTOCOL_NLA) status = transport_connect_nla(rdp->transport); else if (rdp->nego->selected_protocol & PROTOCOL_TLS) status = transport_connect_tls(rdp->transport); else if (rdp->nego->selected_protocol == PROTOCOL_RDP) /* 0 */ status = transport_connect_rdp(rdp->transport); if (status != True) return False; rdp_set_blocking_mode(rdp, False); rdp->state = CONNECTION_STATE_NEGO; if (mcs_send_connect_initial(rdp->mcs) != True) { printf("Error: unable to send MCS Connect Initial\n"); return False; } while (rdp->state != CONNECTION_STATE_ACTIVE) { if (rdp_check_fds(rdp) < 0) return False; } return True; }
BOOL rdp_client_connect(rdpRdp* rdp) { rdpSettings* settings = rdp->settings; if (rdp->settingsCopy) { freerdp_settings_free(rdp->settingsCopy); rdp->settingsCopy = NULL; } rdp->settingsCopy = freerdp_settings_clone(settings); nego_init(rdp->nego); nego_set_target(rdp->nego, settings->ServerHostname, settings->ServerPort); if (settings->GatewayEnabled) { char* user = NULL; char* domain = NULL; char* cookie = NULL; int user_length = 0; int domain_length = 0; int cookie_length = 0; if (settings->Username) { user = settings->Username; user_length = strlen(settings->Username); } if (settings->Domain) domain = settings->Domain; else domain = settings->ComputerName; domain_length = strlen(domain); cookie_length = domain_length + 1 + user_length; cookie = (char*) malloc(cookie_length + 1); CopyMemory(cookie, domain, domain_length); CharUpperBuffA(cookie, domain_length); cookie[domain_length] = '\\'; if (settings->Username) CopyMemory(&cookie[domain_length + 1], user, user_length); cookie[cookie_length] = '\0'; nego_set_cookie(rdp->nego, cookie); free(cookie); } else { nego_set_cookie(rdp->nego, settings->Username); } nego_set_send_preconnection_pdu(rdp->nego, settings->SendPreconnectionPdu); nego_set_preconnection_id(rdp->nego, settings->PreconnectionId); nego_set_preconnection_blob(rdp->nego, settings->PreconnectionBlob); nego_set_negotiation_enabled(rdp->nego, settings->NegotiateSecurityLayer); nego_set_restricted_admin_mode_required(rdp->nego, settings->RestrictedAdminModeRequired); nego_enable_rdp(rdp->nego, settings->RdpSecurity); nego_enable_tls(rdp->nego, settings->TlsSecurity); nego_enable_nla(rdp->nego, settings->NlaSecurity); nego_enable_ext(rdp->nego, settings->ExtSecurity); if (settings->MstscCookieMode) settings->CookieMaxLength = MSTSC_COOKIE_MAX_LENGTH; nego_set_cookie_max_length(rdp->nego, settings->CookieMaxLength); if (settings->LoadBalanceInfo) nego_set_routing_token(rdp->nego, settings->LoadBalanceInfo, settings->LoadBalanceInfoLength); if (!nego_connect(rdp->nego)) { fprintf(stderr, "Error: protocol security negotiation or connection failure\n"); return FALSE; } if ((rdp->nego->selected_protocol & PROTOCOL_TLS) || (rdp->nego->selected_protocol == PROTOCOL_RDP)) { if ((settings->Username != NULL) && ((settings->Password != NULL) || (settings->RedirectionPassword != NULL && settings->RedirectionPasswordLength > 0))) settings->AutoLogonEnabled = TRUE; } rdp_set_blocking_mode(rdp, FALSE); rdp_client_transition_to_state(rdp, CONNECTION_STATE_NEGO); rdp->finalize_sc_pdus = 0; if (!mcs_send_connect_initial(rdp->mcs)) { if (!connectErrorCode) { connectErrorCode = MCSCONNECTINITIALERROR; } fprintf(stderr, "Error: unable to send MCS Connect Initial\n"); return FALSE; } while (rdp->state != CONNECTION_STATE_ACTIVE) { if (rdp_check_fds(rdp) < 0) return FALSE; } return TRUE; }
BOOL rdp_client_connect(rdpRdp* rdp) { BOOL status; rdpSettings* settings = rdp->settings; if (rdp->settingsCopy) { freerdp_settings_free(rdp->settingsCopy); rdp->settingsCopy = NULL; } rdp->settingsCopy = freerdp_settings_clone(settings); if (!rdp->settingsCopy) return FALSE; nego_init(rdp->nego); nego_set_target(rdp->nego, settings->ServerHostname, settings->ServerPort); if (settings->GatewayEnabled) { char* user = NULL; char* domain = NULL; char* cookie = NULL; int user_length = 0; int domain_length = 0; int cookie_length = 0; if (settings->Username) { user = settings->Username; user_length = strlen(settings->Username); } if (settings->Domain) domain = settings->Domain; else domain = settings->ComputerName; domain_length = strlen(domain); cookie_length = domain_length + 1 + user_length; cookie = (char*) malloc(cookie_length + 1); if (!cookie) return FALSE; CopyMemory(cookie, domain, domain_length); CharUpperBuffA(cookie, domain_length); cookie[domain_length] = '\\'; if (settings->Username) CopyMemory(&cookie[domain_length + 1], user, user_length); cookie[cookie_length] = '\0'; status = nego_set_cookie(rdp->nego, cookie); free(cookie); } else { status = nego_set_cookie(rdp->nego, settings->Username); } if (!status) return FALSE; nego_set_send_preconnection_pdu(rdp->nego, settings->SendPreconnectionPdu); nego_set_preconnection_id(rdp->nego, settings->PreconnectionId); nego_set_preconnection_blob(rdp->nego, settings->PreconnectionBlob); nego_set_negotiation_enabled(rdp->nego, settings->NegotiateSecurityLayer); nego_set_restricted_admin_mode_required(rdp->nego, settings->RestrictedAdminModeRequired); nego_set_gateway_enabled(rdp->nego, settings->GatewayEnabled); nego_set_gateway_bypass_local(rdp->nego, settings->GatewayBypassLocal); nego_enable_rdp(rdp->nego, settings->RdpSecurity); nego_enable_tls(rdp->nego, settings->TlsSecurity); nego_enable_nla(rdp->nego, settings->NlaSecurity); nego_enable_ext(rdp->nego, settings->ExtSecurity); if (settings->MstscCookieMode) settings->CookieMaxLength = MSTSC_COOKIE_MAX_LENGTH; nego_set_cookie_max_length(rdp->nego, settings->CookieMaxLength); if (settings->LoadBalanceInfo) { if (!nego_set_routing_token(rdp->nego, settings->LoadBalanceInfo, settings->LoadBalanceInfoLength)) return FALSE; } rdp_client_transition_to_state(rdp, CONNECTION_STATE_NEGO); if (!nego_connect(rdp->nego)) { if (!freerdp_get_last_error(rdp->context)) freerdp_set_last_error(rdp->context, FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED); WLog_ERR(TAG, "Error: protocol security negotiation or connection failure"); return FALSE; } if ((rdp->nego->SelectedProtocol & PROTOCOL_TLS) || (rdp->nego->SelectedProtocol == PROTOCOL_RDP)) { if ((settings->Username != NULL) && ((settings->Password != NULL) || (settings->RedirectionPassword != NULL && settings->RedirectionPasswordLength > 0))) settings->AutoLogonEnabled = TRUE; } /* everything beyond this point is event-driven and non blocking */ rdp->transport->ReceiveCallback = rdp_recv_callback; rdp->transport->ReceiveExtra = rdp; transport_set_blocking_mode(rdp->transport, FALSE); if (rdp->state != CONNECTION_STATE_NLA) { if (!mcs_client_begin(rdp->mcs)) return FALSE; } while (rdp->state != CONNECTION_STATE_ACTIVE) { if (rdp_check_fds(rdp) < 0) { if (!freerdp_get_last_error(rdp->context)) freerdp_set_last_error(rdp->context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED); return FALSE; } } return TRUE; }
tbool rdp_client_connect(rdpRdp* rdp) { tbool status; uint32 selectedProtocol; rdpSettings* settings = rdp->settings; nego_init(rdp->nego); nego_set_target(rdp->nego, settings->hostname, settings->port); nego_set_cookie(rdp->nego, settings->username); nego_enable_rdp(rdp->nego, settings->rdp_security); nego_enable_nla(rdp->nego, settings->nla_security); nego_enable_tls(rdp->nego, settings->tls_security); if (nego_connect(rdp->nego) == false) { printf("Error: protocol security negotiation failure\n"); return false; } selectedProtocol = rdp->nego->selected_protocol; if ((selectedProtocol & PROTOCOL_TLS) || (selectedProtocol == PROTOCOL_RDP)) { if ((settings->username != NULL) && ((settings->password != NULL) || (settings->password_cookie != NULL && settings->password_cookie->length > 0))) settings->autologon = true; } status = false; if (selectedProtocol & PROTOCOL_NLA) { status = transport_connect_nla(rdp->transport); } else if (selectedProtocol & PROTOCOL_TLS) { status = transport_connect_tls(rdp->transport); } else if (selectedProtocol == PROTOCOL_RDP) /* 0 */ { status = transport_connect_rdp(rdp->transport); } if (status == false) { return false; } rdp_set_blocking_mode(rdp, false); rdp->state = CONNECTION_STATE_NEGO; rdp->finalize_sc_pdus = 0; LLOGLN(10, ("rdp_client_connect: calling mcs_send_connect_initial")); //freerdp_usleep(1000 * 1000 * 10); if (mcs_send_connect_initial(rdp->mcs) == false) { printf("Error: unable to send MCS Connect Initial\n"); return false; } //freerdp_usleep(1000 * 1000 * 10); while (rdp->state != CONNECTION_STATE_ACTIVE) { /* TODO: don't use sleep here */ freerdp_usleep(1000 * 100); if (rdp_check_fds(rdp) < 0) { LLOGLN(0, ("rdp_client_connect: error rdp_check_fds failed")); return false; } } return true; }
BOOL rdp_client_connect(rdpRdp* rdp) { BOOL status; rdpSettings* settings = rdp->settings; /* make sure SSL is initialize for earlier enough for crypto, by taking advantage of winpr SSL FIPS flag for openssl initialization */ DWORD flags = WINPR_SSL_INIT_DEFAULT; if (settings->FIPSMode) flags |= WINPR_SSL_INIT_ENABLE_FIPS; winpr_InitializeSSL(flags); /* FIPS Mode forces the following and overrides the following(by happening later */ /* in the command line processing): */ /* 1. Disables NLA Security since NLA in freerdp uses NTLM(no Kerberos support yet) which uses algorithms */ /* not allowed in FIPS for sensitive data. So, we disallow NLA when FIPS is required. */ /* 2. Forces the only supported RDP encryption method to be FIPS. */ if (settings->FIPSMode || winpr_FIPSMode()) { settings->NlaSecurity = FALSE; settings->EncryptionMethods = ENCRYPTION_METHOD_FIPS; } nego_init(rdp->nego); nego_set_target(rdp->nego, settings->ServerHostname, settings->ServerPort); if (settings->GatewayEnabled) { char* user = NULL; char* domain = NULL; char* cookie = NULL; int user_length = 0; int domain_length = 0; int cookie_length = 0; if (settings->Username) { user = settings->Username; user_length = strlen(settings->Username); } if (settings->Domain) domain = settings->Domain; else domain = settings->ComputerName; domain_length = strlen(domain); cookie_length = domain_length + 1 + user_length; cookie = (char*) malloc(cookie_length + 1); if (!cookie) return FALSE; CopyMemory(cookie, domain, domain_length); CharUpperBuffA(cookie, domain_length); cookie[domain_length] = '\\'; if (settings->Username) CopyMemory(&cookie[domain_length + 1], user, user_length); cookie[cookie_length] = '\0'; status = nego_set_cookie(rdp->nego, cookie); free(cookie); } else { status = nego_set_cookie(rdp->nego, settings->Username); } if (!status) return FALSE; nego_set_send_preconnection_pdu(rdp->nego, settings->SendPreconnectionPdu); nego_set_preconnection_id(rdp->nego, settings->PreconnectionId); nego_set_preconnection_blob(rdp->nego, settings->PreconnectionBlob); nego_set_negotiation_enabled(rdp->nego, settings->NegotiateSecurityLayer); nego_set_restricted_admin_mode_required(rdp->nego, settings->RestrictedAdminModeRequired); nego_set_gateway_enabled(rdp->nego, settings->GatewayEnabled); nego_set_gateway_bypass_local(rdp->nego, settings->GatewayBypassLocal); nego_enable_rdp(rdp->nego, settings->RdpSecurity); nego_enable_tls(rdp->nego, settings->TlsSecurity); nego_enable_nla(rdp->nego, settings->NlaSecurity); nego_enable_ext(rdp->nego, settings->ExtSecurity); if (settings->MstscCookieMode) settings->CookieMaxLength = MSTSC_COOKIE_MAX_LENGTH; nego_set_cookie_max_length(rdp->nego, settings->CookieMaxLength); if (settings->LoadBalanceInfo) { if (!nego_set_routing_token(rdp->nego, settings->LoadBalanceInfo, settings->LoadBalanceInfoLength)) return FALSE; } rdp_client_transition_to_state(rdp, CONNECTION_STATE_NEGO); if (!nego_connect(rdp->nego)) { if (!freerdp_get_last_error(rdp->context)) freerdp_set_last_error(rdp->context, FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED); WLog_ERR(TAG, "Error: protocol security negotiation or connection failure"); return FALSE; } if ((rdp->nego->SelectedProtocol & PROTOCOL_TLS) || (rdp->nego->SelectedProtocol == PROTOCOL_RDP)) { if ((settings->Username != NULL) && ((settings->Password != NULL) || (settings->RedirectionPassword != NULL && settings->RedirectionPasswordLength > 0))) settings->AutoLogonEnabled = TRUE; } /* everything beyond this point is event-driven and non blocking */ rdp->transport->ReceiveCallback = rdp_recv_callback; rdp->transport->ReceiveExtra = rdp; transport_set_blocking_mode(rdp->transport, FALSE); if (rdp->state != CONNECTION_STATE_NLA) { if (!mcs_client_begin(rdp->mcs)) return FALSE; } while (rdp->state != CONNECTION_STATE_ACTIVE) { if (rdp_check_fds(rdp) < 0) { if (!freerdp_get_last_error(rdp->context)) freerdp_set_last_error(rdp->context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED); return FALSE; } } return TRUE; }