From 2c4c27654c92f89ae46d640db2be6c9db259bcac Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Mon, 21 Sep 2009 23:20:25 -0500 Subject: [PATCH] Make sure we try to lock/unlock/change only PINs --- src/sim.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/sim.c b/src/sim.c index 8f24459..4b509d8 100644 --- a/src/sim.c +++ b/src/sim.c @@ -148,6 +148,33 @@ static enum ofono_sim_password_type sim_string_to_passwd(const char *name) return OFONO_SIM_PASSWORD_INVALID; } +static gboolean password_is_pin(enum ofono_sim_password_type type) +{ + switch(type) { + case OFONO_SIM_PASSWORD_SIM_PIN: + case OFONO_SIM_PASSWORD_PHSIM_PIN: + case OFONO_SIM_PASSWORD_PHFSIM_PIN: + case OFONO_SIM_PASSWORD_SIM_PIN2: + case OFONO_SIM_PASSWORD_PHNET_PIN: + case OFONO_SIM_PASSWORD_PHNETSUB_PIN: + case OFONO_SIM_PASSWORD_PHSP_PIN: + case OFONO_SIM_PASSWORD_PHCORP_PIN: + return TRUE; + case OFONO_SIM_PASSWORD_SIM_PUK: + case OFONO_SIM_PASSWORD_PHFSIM_PUK: + case OFONO_SIM_PASSWORD_SIM_PUK2: + case OFONO_SIM_PASSWORD_PHNET_PUK: + case OFONO_SIM_PASSWORD_PHNETSUB_PUK: + case OFONO_SIM_PASSWORD_PHSP_PUK: + case OFONO_SIM_PASSWORD_PHCORP_PUK: + case OFONO_SIM_PASSWORD_INVALID: + case OFONO_SIM_PASSWORD_NONE: + return FALSE; + } + + return FALSE; +} + static char **get_own_numbers(GSList *own_numbers) { int nelem = 0; @@ -441,8 +468,7 @@ static DBusMessage *sim_lock_or_unlock(struct ofono_sim *sim, int lock, dbus_message_iter_get_basic(&iter, &typestr); type = sim_string_to_passwd(typestr); - if (type == OFONO_SIM_PASSWORD_NONE || - type == OFONO_SIM_PASSWORD_INVALID) + if (password_is_pin(type) == FALSE) return __ofono_error_invalid_format(msg); dbus_message_iter_next(&iter); @@ -516,8 +542,8 @@ static DBusMessage *sim_change_pin(DBusConnection *conn, DBusMessage *msg, dbus_message_iter_get_basic(&iter, &typestr); type = sim_string_to_passwd(typestr); - if (type == OFONO_SIM_PASSWORD_NONE || - type == OFONO_SIM_PASSWORD_INVALID) + + if (password_is_pin(type) == FALSE) return __ofono_error_invalid_format(msg); dbus_message_iter_next(&iter); @@ -587,6 +613,7 @@ static DBusMessage *sim_enter_pin(DBusConnection *conn, DBusMessage *msg, dbus_message_iter_get_basic(&iter, &typestr); type = sim_string_to_passwd(typestr); + if (type == OFONO_SIM_PASSWORD_NONE || type != sim->pin_type) return __ofono_error_invalid_format(msg); @@ -630,6 +657,7 @@ static DBusMessage *sim_reset_pin(DBusConnection *conn, DBusMessage *msg, dbus_message_iter_get_basic(&iter, &typestr); type = sim_string_to_passwd(typestr); + if (type == OFONO_SIM_PASSWORD_NONE || type != sim->pin_type) return __ofono_error_invalid_format(msg); -- 2.7.4