summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2009-09-21 23:20:25 -0500
committerDenis Kenzior <denkenz@gmail.com>2009-09-22 00:07:07 -0500
commit2c4c27654c92f89ae46d640db2be6c9db259bcac (patch)
tree41f5e1da9a09d9f5b751374b2865539cdcc501eb
parent5fd083f6f4b1daf9affc9a6c8415db015a57d8c7 (diff)
downloadofono-2c4c27654c92f89ae46d640db2be6c9db259bcac.tar.bz2
Make sure we try to lock/unlock/change only PINs
-rw-r--r--src/sim.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/sim.c b/src/sim.c
index 8f244597..4b509d83 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);