diff mbox series

[14/14] provision: Detect duplicates

Message ID 20240119211017.474598-14-denkenz@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series [01/14] include: Allow multiple context types | expand

Commit Message

Denis Kenzior Jan. 19, 2024, 9:09 p.m. UTC
Duplicate contexts can't really be handled without user intervention, in
which case it is better to fail provisioning entirely.  Most vendors
will choose to ship a custom provisioning database to ensure that
duplicate contexts do not happen for the supported operators.
---
 src/provision.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/src/provision.c b/src/provision.c
index e419d15c..cd5cf569 100644
--- a/src/provision.c
+++ b/src/provision.c
@@ -25,6 +25,7 @@  bool __ofono_provision_get_settings(const char *mcc,
 	struct ofono_gprs_provision_data *contexts;
 	int r;
 	size_t i;
+	uint32_t type;
 
 	if (mcc == NULL || strlen(mcc) == 0 || mnc == NULL || strlen(mnc) == 0)
 		return false;
@@ -47,6 +48,20 @@  bool __ofono_provision_get_settings(const char *mcc,
 					ap->message_center);
 	}
 
+	/* Make sure there are no duplicates */
+	for (i = 0, type = 0; i < n_contexts; i++) {
+		struct ofono_gprs_provision_data *ap = contexts + i;
+
+		if (type & ap->type) {
+			ofono_warn("Duplicate detected for %s%s, spn: %s",
+					mcc, mnc, spn);
+			l_free(contexts);
+			return false;
+		}
+
+		type |= ap->type;
+	}
+
 	*count = n_contexts;
 	*settings = contexts;