sgsn: fix problem with leading-zero-IMSIs

When the IMSI ACL is maintained via the VTY, users may enter IMSIs
without leading zeros. Especially in test environments, where
MCC=001 and MNC=01 is common, it is likely that someone enters the
corresponding IMSI (001010000000001) without the two zeros at the
beginning.

This patch fixes the problem by sanitizing the IMSI, eventually
missing zeros in the beginning will be automatically added.

Change-Id: I56ba0da61978bbdce71d0e320166c52b20b42517
This commit is contained in:
Philipp Maier 2017-02-28 16:53:07 +01:00 committed by Harald Welte
parent 3f8a8f7736
commit 6ee49d8416
1 changed files with 11 additions and 2 deletions

View File

@ -586,10 +586,20 @@ DEFUN(imsi_acl, cfg_imsi_acl_cmd,
"Remove IMSI from ACL\n"
"IMSI of subscriber\n")
{
char imsi_sanitized[GSM23003_IMSI_MAX_DIGITS+1];
const char *op = argv[0];
const char *imsi = argv[1];
const char *imsi = imsi_sanitized;
int rc;
/* Sanitize IMSI */
if (strlen(argv[1]) > GSM23003_IMSI_MAX_DIGITS) {
vty_out(vty, "%% IMSI (%s) too long -- ignored!%s",
argv[1], VTY_NEWLINE);
return CMD_WARNING;
}
memset(imsi_sanitized, '0', sizeof(imsi_sanitized));
strcpy(imsi_sanitized+GSM23003_IMSI_MAX_DIGITS-strlen(argv[1]),argv[1]);
if (!strcmp(op, "add"))
rc = sgsn_acl_add(imsi, g_cfg);
else
@ -597,7 +607,6 @@ DEFUN(imsi_acl, cfg_imsi_acl_cmd,
if (rc < 0) {
vty_out(vty, "%% unable to %s ACL%s", op, VTY_NEWLINE);
return CMD_WARNING;
}