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: I9944a9103981fb5f4d0d8714ee2847ae020f76dfchanges/99/25099/2
parent
ce18705875
commit
96c6e06681
|
@ -300,32 +300,6 @@ struct mgcp_endpoint *mgcp_endp_by_name_trunk(int *cause, const char *epname,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Check if the domain name, which is supplied with the endpoint name
|
||||
* matches the configuration. */
|
||||
static int check_domain_name(const char *epname, 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 an endpoint by its name, search at all trunks.
|
||||
* \param[out] cause, pointer to store cause code, can be NULL.
|
||||
* \param[in] epname, must contain trunk prefix.
|
||||
|
@ -349,10 +323,6 @@ struct mgcp_endpoint *mgcp_endp_by_name(int *cause, const char *epname,
|
|||
if (!trunk)
|
||||
return NULL;
|
||||
|
||||
/* All endpoint names require a domain as suffix */
|
||||
if (check_domain_name(epname, cfg))
|
||||
return NULL;
|
||||
|
||||
/* Identify the endpoint on the trunk */
|
||||
endp = mgcp_endp_by_name_trunk(cause, epname, trunk);
|
||||
if (!endp) {
|
||||
|
|
|
@ -206,6 +206,32 @@ int e1_trunk_nr_from_epname(unsigned int *trunk_nr, const char *epname)
|
|||
}
|
||||
}
|
||||
|
||||
/* 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 @@ struct mgcp_trunk *mgcp_trunk_by_name(const struct mgcp_config *cfg, const char
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue