summaryrefslogtreecommitdiffstats
path: root/src/common.c
diff options
context:
space:
mode:
authorPekka Pessi <Pekka.Pessi@nokia.com>2010-03-19 19:49:54 +0200
committerDenis Kenzior <denkenz@gmail.com>2010-03-19 13:48:04 -0500
commit9a398a1087ebf3c327dcd3ed8191da33fc0d361b (patch)
treef0f23239935967d79922a3f0628fa5a4624d05d3 /src/common.c
parentc0c682d5c04f1e1b75c624e26c44c9f11e07b44b (diff)
downloadofono-9a398a1087ebf3c327dcd3ed8191da33fc0d361b.tar.bz2
Fix: Check password length based on its type
The different password types have different length requirements, so update is_valid_pin to validate according to the password type being validated (PIN / PUK / NET)
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/common.c b/src/common.c
index db3e38bc..e67a6550 100644
--- a/src/common.c
+++ b/src/common.c
@@ -580,7 +580,7 @@ const char *bearer_class_to_string(enum bearer_class cls)
return NULL;
}
-gboolean is_valid_pin(const char *pin)
+gboolean is_valid_pin(const char *pin, enum pin_type type)
{
unsigned int i;
@@ -588,14 +588,33 @@ gboolean is_valid_pin(const char *pin)
if (pin == NULL || pin[0] == '\0')
return FALSE;
- for (i = 0; i < strlen(pin); i++)
- if (pin[i] < '0' || pin[i] > '9')
- return FALSE;
-
- if (i > 8)
+ i = strlen(pin);
+ if (i != strspn(pin, "012345679"))
return FALSE;
- return TRUE;
+ switch (type)
+ {
+ case PIN_TYPE_PIN:
+ /* 11.11 Section 9.3 ("CHV"): 4..8 IA-5 digits */
+ if (4 <= i && i <= 8)
+ return TRUE;
+ break;
+ case PIN_TYPE_PUK:
+ /* 11.11 Section 9.3 ("UNBLOCK CHV"), 8 IA-5 digits */
+ if (i == 8)
+ return TRUE;
+ break;
+ case PIN_TYPE_NET:
+ /* 22.004 Section 5.2, 4 IA-5 digits */
+ if (i == 4)
+ return TRUE;
+ break;
+ case PIN_TYPE_NONE:
+ if (i < 8)
+ return TRUE;
+ }
+
+ return FALSE;
}
const char *registration_status_to_string(int status)