From 66a69a26e27783f495456fa73eb232875fd7ab83 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 21 May 2025 13:35:18 +0200 Subject: [PATCH] [client,common] initialize sso-mib late Only initialize the sso-mib library when a token is requested for the first time. This allows proper rdpSettings initialization in PreConnect. --- client/common/client.c | 30 +++++++++++++----------------- client/common/sso_mib_tokens.c | 12 ++++++++++++ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/client/common/client.c b/client/common/client.c index b56ac8b9e..863645af2 100644 --- a/client/common/client.c +++ b/client/common/client.c @@ -199,16 +199,7 @@ int freerdp_client_start(rdpContext* context) client_context->mibClientWrapper = (MIBClientWrapper*)calloc(1, sizeof(MIBClientWrapper)); if (!client_context->mibClientWrapper) return ERROR_NOT_ENOUGH_MEMORY; - const char* client_id = - freerdp_settings_get_string(context->settings, FreeRDP_GatewayAvdClientID); - client_context->mibClientWrapper->app = - mib_public_client_app_new(client_id, MIB_AUTHORITY_COMMON, NULL, NULL); - if (!client_context->mibClientWrapper->app) - { - free(client_context->mibClientWrapper); - client_context->mibClientWrapper = NULL; - return ERROR_INTERNAL_ERROR; - } + client_context->mibClientWrapper->GetCommonAccessToken = freerdp_get_common_access_token(context); if (!freerdp_set_common_access_token(context, sso_mib_get_access_token)) @@ -227,15 +218,20 @@ int freerdp_client_stop(rdpContext* context) if (!context || !context->instance || !context->instance->pClientEntryPoints) return ERROR_BAD_ARGUMENTS; + pEntryPoints = context->instance->pClientEntryPoints; + const int rc = IFCALLRESULT(CHANNEL_RC_OK, pEntryPoints->ClientStop, context); + #ifdef WITH_SSO_MIB rdpClientContext* client_context = (rdpClientContext*)context; - if (client_context->mibClientWrapper->app) - g_object_unref(client_context->mibClientWrapper->app); - free(client_context->mibClientWrapper); -#endif - - pEntryPoints = context->instance->pClientEntryPoints; - return IFCALLRESULT(CHANNEL_RC_OK, pEntryPoints->ClientStop, context); + if (client_context->mibClientWrapper) + { + if (client_context->mibClientWrapper->app) + g_object_unref(client_context->mibClientWrapper->app); + free(client_context->mibClientWrapper); + } + client_context->mibClientWrapper = NULL; +#endif // WITH_SSO_MIB + return rc; } freerdp* freerdp_client_get_instance(rdpContext* context) diff --git a/client/common/sso_mib_tokens.c b/client/common/sso_mib_tokens.c index 22ec3f973..719030cd6 100644 --- a/client/common/sso_mib_tokens.c +++ b/client/common/sso_mib_tokens.c @@ -123,6 +123,18 @@ BOOL sso_mib_get_access_token(rdpContext* context, AccessTokenType tokenType, ch BOOL rc = FALSE; rdpClientContext* client_context = (rdpClientContext*)context; WINPR_ASSERT(client_context); + WINPR_ASSERT(client_context->mibClientWrapper); + + if (!client_context->mibClientWrapper->app) + { + const char* client_id = + freerdp_settings_get_string(context->settings, FreeRDP_GatewayAvdClientID); + client_context->mibClientWrapper->app = + mib_public_client_app_new(client_id, MIB_AUTHORITY_COMMON, NULL, NULL); + } + + if (!client_context->mibClientWrapper->app) + return ERROR_INTERNAL_ERROR; const char* scope = NULL; const char* req_cnf = NULL;