mgcp: make domain name configurable

At the moment the MGW has a fixed domain name string that is not even
checked properly.

- Make domain name configurable, use the current "mgw" string as
  defualt to maintain compatibility

- Check the domain name with each request. If the endpoint contains
  an unexpected domain name, the request must be rejected.

Change-Id: Ia91ac428ba83ac1f9b52a0ec8dbf00ef7876da9e
diff --git a/src/libosmo-mgcp/mgcp_msg.c b/src/libosmo-mgcp/mgcp_msg.c
index 45195de..74acffa 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -181,6 +181,22 @@
 	return &tcfg->endpoints[endp];
 }
 
+/* Check if the domain name, which is supplied with the endpoint name
+ * matches the configuration. */
+static int check_domain_name(struct mgcp_config *cfg, const char *mgcp)
+{
+	char *domain_to_check;
+
+	domain_to_check = strstr(mgcp, "@");
+	if (!domain_to_check)
+		return -EINVAL;
+
+	if (strcmp(domain_to_check+1, cfg->domain) != 0)
+		return -EINVAL;
+
+	return 0;
+}
+
 /* Search the endpoint pool for the endpoint that had been selected via the
  * MGCP message (helper function for mgcp_analyze_header()) */
 static struct mgcp_endpoint *find_endpoint(struct mgcp_config *cfg,
@@ -189,6 +205,11 @@
 	char *endptr = NULL;
 	unsigned int gw = INT_MAX;
 
+	if (check_domain_name(cfg, mgcp)) {
+		LOGP(DLMGCP, LOGL_ERROR, "Wrong domain name '%s'\n", mgcp);
+		return NULL;
+	}
+
 	if (strncmp(mgcp, "ds/e1", 5) == 0)
 		return find_e1_endpoint(cfg, mgcp);