diff --git a/mbuni/doc/examples/mmsc.conf b/mbuni/doc/examples/mmsc.conf index e28c8ad..ab5d148 100644 --- a/mbuni/doc/examples/mmsc.conf +++ b/mbuni/doc/examples/mmsc.conf @@ -23,7 +23,7 @@ sendsms-password = foobar mms-port = 1981 mm7-port = 1982 #allow-ip = 192.168.129.11 -email2mms-relay-prefixes = "037;035;25637" +email2mms-relay-hosts = "mbuni.org;dsmagic.com;ds.co.ug" billing-module-parameters = "/tmp/log/cdr.log" # billing-library = billdemo.so #prov-server-notify-script = ~/src/mmprov/provnotify.sh diff --git a/mbuni/doc/userguide.shtml b/mbuni/doc/userguide.shtml index 6d82e4b..72c0286 100644 --- a/mbuni/doc/userguide.shtml +++ b/mbuni/doc/userguide.shtml @@ -1081,19 +1081,23 @@ lists all the configuration directives. Items in black are used by - email2mms-relay-prefixes + email2mms-relay-hosts     Number list     - When MMS is received + A semi-colon separated list of hosts/domains. When MMS is received via SMTP, the gateway needs to determine whether it is for a local or a foreign recipient. To determine if the recipient is local recipient, we use - the local-prefixes setting. If the recipient is not local, - the message should be forwarded on to the relevant foreign MMS gateway, only - if the recipient number matches one of the prefixes in this comma-separated - list. + the resolver module, if supplied. (Note that default resolution + uses local-prefixes setting to determine if the recipient + is local, returning the local MMSC name, if not, then it checks each + of the defined relays to see if the recipient address is for one + of them, by checking the prefixes, returning the matching + proxy/relay name.) The resolver should return a host name that is + matched against this setting. If any name matches, the message is + queued, otherwise it is discarded.     diff --git a/mbuni/mmlib/mms_cfg.def b/mbuni/mmlib/mms_cfg.def index 1ab45b0..03324e9 100644 --- a/mbuni/mmlib/mms_cfg.def +++ b/mbuni/mmlib/mms_cfg.def @@ -61,7 +61,7 @@ SINGLE_GROUP(mbuni, OCTSTR(mm7-port) OCTSTR(allow-ip) OCTSTR(deny-ip) - OCTSTR(email2mms-relay-prefixes) + OCTSTR(email2mms-relay-hosts) OCTSTR(billing-module-parameters) OCTSTR(billing-library) OCTSTR(resolver-module-parameters) diff --git a/mbuni/mmlib/mms_util.c b/mbuni/mmlib/mms_util.c index 83f282c..1c17b81 100644 --- a/mbuni/mmlib/mms_util.c +++ b/mbuni/mmlib/mms_util.c @@ -998,3 +998,24 @@ void _mms_fixup_address(Octstr *address) else octstr_append(address, octstr_imm("@unknown")); } + +/* compare, reversed result! */ +static int comp_fn(void *item, void *pattern) +{ + return (octstr_case_compare(item, pattern) == 0) ? 1 : 0; +} +int is_allowed_host(Octstr *host, Octstr *host_list) +{ + List *l; + int ret; + gw_assert(host_list); + gw_assert(host); + + l = octstr_split(host_list, octstr_imm(";")); + + ret = (list_search(l, host, comp_fn) != NULL) ? 1 : 0; + + list_destroy(l, (void *)octstr_destroy); + + return ret; +} diff --git a/mbuni/mmlib/mms_util.h b/mbuni/mmlib/mms_util.h index 96d5541..85f687b 100644 --- a/mbuni/mmlib/mms_util.h +++ b/mbuni/mmlib/mms_util.h @@ -140,6 +140,9 @@ unsigned long _mshash(char *s); int isphonenum(Octstr *s); /* Fixup an address: Add type, etc. */ void _mms_fixup_address(Octstr *address); + +/* Check that host is one of hosts in semi-colon separated list in host_list */ +int is_allowed_host(Octstr *host, Octstr *host_list); #define MAXQTRIES 100 #define BACKOFF_FACTOR 5*60 /* In seconds */ #define QUEUERUN_INTERVAL 15*60 /* 15 minutes. */ diff --git a/mbuni/mmsc/mmsc_cfg.c b/mbuni/mmsc/mmsc_cfg.c index e4d0ed9..2c36c45 100644 --- a/mbuni/mmsc/mmsc_cfg.c +++ b/mbuni/mmsc/mmsc_cfg.c @@ -197,8 +197,8 @@ MmscSettings *mms_load_mmsc_settings(mCfg *cfg, List **proxyrelays) m->allow_ip = _mms_cfg_getx(grp, octstr_imm("allow-ip")); m->deny_ip = _mms_cfg_getx(grp, octstr_imm("deny-ip")); - m->email2mmsrelay_prefixes = _mms_cfg_getx(grp, - octstr_imm("email2mms-relay-prefixes")); + m->email2mmsrelay_hosts = _mms_cfg_getx(grp, + octstr_imm("email2mms-relay-hosts")); m->prov_notify = _mms_cfg_getx(grp,octstr_imm("prov-server-notify-script")); diff --git a/mbuni/mmsc/mmsc_cfg.h b/mbuni/mmsc/mmsc_cfg.h index 9bd8f6d..96aa6ba 100644 --- a/mbuni/mmsc/mmsc_cfg.h +++ b/mbuni/mmsc/mmsc_cfg.h @@ -55,7 +55,7 @@ typedef struct MmscSettings { Octstr *allow_ip; Octstr *deny_ip; - Octstr *email2mmsrelay_prefixes; + Octstr *email2mmsrelay_hosts; Octstr *sendsms_url; #if 0 Octstr *sendsms_user, *sendsms_pass, *sendsms_globalsender; diff --git a/mbuni/mmsc/mmsfromemail.c b/mbuni/mmsc/mmsfromemail.c index 5c3df9a..96e4814 100644 --- a/mbuni/mmsc/mmsfromemail.c +++ b/mbuni/mmsc/mmsfromemail.c @@ -39,6 +39,7 @@ int main(int argc, char *argv[]) MmsMsg *msg; Octstr *email; + Octstr *home_mmsc = NULL; mms_lib_init(); @@ -78,10 +79,17 @@ int main(int argc, char *argv[]) fixup_recipient(); fixup_sender(); - if (!xto || - (ttype == TPLMN && !does_prefix_match(settings->email2mmsrelay_prefixes, xto))) { - error(0, " Not allowed to send to this recipient %s!", - xto ? octstr_get_cstr(xto) : "(null)"); + if (xto && ttype == TPLMN) /* Get the home mmsc domain for this recipient. */ + home_mmsc = settings->mms_resolvefuncs->mms_resolve(xto, + settings->mms_resolver_module_data, + settings, proxyrelays); + if (!xto || + (ttype == TPLMN && (!home_mmsc || + !is_allowed_host(home_mmsc, + settings->email2mmsrelay_hosts)))) { + error(0, " Not allowed to send to this recipient %s, resolved mmsc=%s!", + xto ? octstr_get_cstr(xto) : "(null)", + home_mmsc ? octstr_get_cstr(home_mmsc) : "(null)"); mms_lib_shutdown(); return -1; } @@ -123,11 +131,9 @@ int main(int argc, char *argv[]) switch(mms_messagetype(msg)) { case MMS_MSGTYPE_SEND_REQ: - if (ttype != TPLMN ||/* We only send to phones from this interface */ - !does_prefix_match(settings->email2mmsrelay_prefixes, - xto)) { - error(0, "Not allowed to send to %s!", octstr_get_cstr(xto)); - } else { + if (ttype != TPLMN) + error(0, "Not allowed to send to non-phone recipient, to=%s!", octstr_get_cstr(xto)); + else { List *lto = list_create(); Octstr *qf; Octstr *msgid = mms_get_header_value(msg, octstr_imm("Message-ID")); @@ -237,11 +243,9 @@ int main(int argc, char *argv[]) } break; case MMS_MSGTYPE_DELIVERY_IND: - if (ttype != TPLMN ||/* We only send to phones from this interface */ - !does_prefix_match(settings->email2mmsrelay_prefixes, - xto)) { + if (ttype != TPLMN) /* We only send to phones from this interface */ error(0, "Not allowed to send to %s!", octstr_get_cstr(xto)); - } else { + else { List *lto = list_create(); Octstr *qf; @@ -275,11 +279,9 @@ int main(int argc, char *argv[]) /* Fall through. */ case MMS_MSGTYPE_READ_ORIG_IND: - if (ttype != TPLMN ||/* We only send to phones from this interface */ - !does_prefix_match(settings->email2mmsrelay_prefixes, - xto)) { + if (ttype != TPLMN) /* We only send to phones from this interface */ error(0, "Not allowed to send to %s!", octstr_get_cstr(xto)); - } else { + else { List *lto = list_create(); Octstr *qf; @@ -314,6 +316,7 @@ int main(int argc, char *argv[]) break; } } + mms_destroy(msg); mms_lib_shutdown();