modem-helpers-qmi: perform validation in allowed_auth_to_qmi_authentication()

If we find that none of the requested auth settings are supported, we
should fail and return an error.

Also, make sure we set the CHAP fallback default only if either user
or password are given.
This commit is contained in:
Aleksander Morgado
2021-04-29 10:13:22 +00:00
parent 865014510a
commit fffe49d03e
4 changed files with 42 additions and 26 deletions
+9 -20
View File
@@ -2098,27 +2098,16 @@ _connect (MMBaseBearer *_self,
auth = mm_bearer_properties_get_allowed_auth (properties);
g_object_unref (properties);
if (auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) {
/* We'll default to CHAP later if needed */
if (!ctx->user && !ctx->password)
ctx->auth = QMI_WDS_AUTHENTICATION_NONE;
} else if (auth & (MM_BEARER_ALLOWED_AUTH_PAP |
MM_BEARER_ALLOWED_AUTH_CHAP |
MM_BEARER_ALLOWED_AUTH_NONE)) {
/* Only PAP and/or CHAP or NONE are supported */
ctx->auth = mm_bearer_allowed_auth_to_qmi_authentication (auth);
} else {
gchar *str;
str = mm_bearer_allowed_auth_build_string_from_mask (auth);
g_task_return_new_error (
task,
MM_CORE_ERROR,
MM_CORE_ERROR_UNSUPPORTED,
"Cannot use any of the specified authentication methods (%s)",
str);
g_object_unref (task);
g_free (str);
goto out;
else {
auth = mm_bearer_properties_get_allowed_auth (properties);
ctx->auth = mm_bearer_allowed_auth_to_qmi_authentication (auth, self, &error);
if (error) {
g_task_return_error (task, error);
g_object_unref (task);
goto out;
}
}
multiplex = mm_bearer_properties_get_multiplex (properties);
+11 -3
View File
@@ -6039,8 +6039,16 @@ modem_3gpp_profile_manager_store_profile (MMIfaceModem3gppProfileManager *self,
ctx->user = g_strdup (mm_3gpp_profile_get_user (profile));
ctx->password = g_strdup (mm_3gpp_profile_get_password (profile));
allowed_auth = mm_3gpp_profile_get_allowed_auth (profile);
if ((allowed_auth != MM_BEARER_ALLOWED_AUTH_UNKNOWN) || ctx->user || ctx->password)
ctx->qmi_auth = mm_bearer_allowed_auth_to_qmi_authentication (allowed_auth);
if ((allowed_auth != MM_BEARER_ALLOWED_AUTH_UNKNOWN) || ctx->user || ctx->password) {
GError *error = NULL;
ctx->qmi_auth = mm_bearer_allowed_auth_to_qmi_authentication (allowed_auth, self, &error);
if (error) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
}
ip_type = mm_3gpp_profile_get_ip_type (profile);
if (!mm_bearer_ip_family_to_qmi_pdp_type (ip_type, &ctx->qmi_pdp_type)) {
@@ -8880,7 +8888,7 @@ set_initial_eps_bearer_modify_profile (GTask *task)
allowed_auth = mm_bearer_properties_get_allowed_auth (ctx->settings);
if (allowed_auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN)
allowed_auth = MM_BEARER_ALLOWED_AUTH_NONE;
auth = mm_bearer_allowed_auth_to_qmi_authentication (allowed_auth);
auth = mm_bearer_allowed_auth_to_qmi_authentication (allowed_auth, self, NULL);
qmi_message_wds_modify_profile_input_set_authentication (input, auth, NULL);
str = mm_bearer_properties_get_user (ctx->settings);
+19 -2
View File
@@ -1467,16 +1467,33 @@ mm_sms_state_from_qmi_message_tag (QmiWmsMessageTagType tag)
/*****************************************************************************/
QmiWdsAuthentication
mm_bearer_allowed_auth_to_qmi_authentication (MMBearerAllowedAuth auth)
mm_bearer_allowed_auth_to_qmi_authentication (MMBearerAllowedAuth auth,
gpointer log_object,
GError **error)
{
QmiWdsAuthentication out;
QmiWdsAuthentication out;
g_autofree gchar *str = NULL;
if (auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) {
mm_obj_dbg (log_object, "using default (CHAP) authentication method");
return QMI_WDS_AUTHENTICATION_CHAP;
}
if (auth == MM_BEARER_ALLOWED_AUTH_NONE)
return QMI_WDS_AUTHENTICATION_NONE;
/* otherwise find a bitmask that matches the input bitmask */
out = QMI_WDS_AUTHENTICATION_NONE;
if (auth & MM_BEARER_ALLOWED_AUTH_PAP)
out |= QMI_WDS_AUTHENTICATION_PAP;
if (auth & MM_BEARER_ALLOWED_AUTH_CHAP)
out |= QMI_WDS_AUTHENTICATION_CHAP;
/* and if the bitmask cannot be built, error out */
str = mm_bearer_allowed_auth_build_string_from_mask (auth);
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
"Unsupported authentication methods (%s)",
str);
return out;
}
+3 -1
View File
@@ -114,7 +114,9 @@ MMSmsState mm_sms_state_from_qmi_message_tag (QmiWmsMessageTagType tag);
/*****************************************************************************/
/* QMI/WDS to MM translations */
QmiWdsAuthentication mm_bearer_allowed_auth_to_qmi_authentication (MMBearerAllowedAuth auth);
QmiWdsAuthentication mm_bearer_allowed_auth_to_qmi_authentication (MMBearerAllowedAuth auth,
gpointer log_object,
GError **error);
MMBearerAllowedAuth mm_bearer_allowed_auth_from_qmi_authentication (QmiWdsAuthentication auth);
MMBearerIpFamily mm_bearer_ip_family_from_qmi_ip_support_type (QmiWdsIpSupportType ip_support_type);
MMBearerIpFamily mm_bearer_ip_family_from_qmi_pdp_type (QmiWdsPdpType pdp_type);