Change in osmo-mgw[master]: mgcp_trunk: check MGW domain name earlier

dexter gerrit-no-reply at lists.osmocom.org
Thu Jul 29 13:19:44 UTC 2021


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-mgw/+/25099 )


Change subject: mgcp_trunk: check MGW domain name earlier
......................................................................

mgcp_trunk: check MGW domain name earlier

The MGW domain name is usually checked while resolving the endpoint
after the trunk has been resolved. This was no problem before, but since
we allow wildcarded DLCX requests, which require only a trunk to work,
the check is not done correctly for wildcarded DLCX requests and invalid
domain names may slip through.

Checking the domain name earlier while the trunk is resolved makes sense
and it fixes the problem.

Change-Id: I9944a9103981fb5f4d0d8714ee2847ae020f76df
---
M src/libosmo-mgcp/mgcp_trunk.c
1 file changed, 30 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/99/25099/1

diff --git a/src/libosmo-mgcp/mgcp_trunk.c b/src/libosmo-mgcp/mgcp_trunk.c
index 27663b4..73de972 100644
--- a/src/libosmo-mgcp/mgcp_trunk.c
+++ b/src/libosmo-mgcp/mgcp_trunk.c
@@ -206,6 +206,32 @@
 	}
 }
 
+/* Check if the domain name, which is supplied with the endpoint name
+ * matches the configuration. */
+static int check_domain_name(const char *epname, const struct mgcp_config *cfg)
+{
+	char *domain_to_check;
+
+	domain_to_check = strstr(epname, "@");
+	if (!domain_to_check) {
+		LOGP(DLMGCP, LOGL_ERROR, "missing domain name in endpoint name \"%s\", expecting \"%s\"\n",
+		     epname, cfg->domain);
+		return -EINVAL;
+	}
+
+	/* Accept any domain if configured as "*" */
+	if (!strcmp(cfg->domain, "*"))
+		return 0;
+
+	if (strcmp(domain_to_check+1, cfg->domain) != 0) {
+		LOGP(DLMGCP, LOGL_ERROR, "wrong domain name in endpoint name \"%s\", expecting \"%s\"\n",
+		     epname, cfg->domain);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 /*! Find a trunk by the trunk prefix in the endpoint name.
  *  \param[in] epname endpoint name with trunk prefix to look up.
  *  \param[in] cfg that contains the trunks where the endpoint is located.
@@ -220,6 +246,10 @@
 	osmo_str_tolower_buf(epname_lc, sizeof(epname_lc), epname);
 	epname = epname_lc;
 
+	/* All endpoint names require a domain as suffix */
+	if (check_domain_name(epname, cfg))
+		return NULL;
+
 	prefix_len = sizeof(MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK) - 1;
 	if (strncmp(epname, MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK, prefix_len) == 0) {
 		return mgcp_trunk_by_num(cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/25099
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I9944a9103981fb5f4d0d8714ee2847ae020f76df
Gerrit-Change-Number: 25099
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210729/658e8295/attachment.htm>


More information about the gerrit-log mailing list